CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1

    Question How to keep my exe running to disable print screen?

    I'm using the following code to disable print screen. The problem is that my program will terminate once it hits the "return 0" statement in WinMain() , how to keep my exe program running so as to enforce the disabling?

    BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);
    typedef UINT (CALLBACK* LPREGISTERSERVICEPROC)(DWORD,DWORD);

    HHOOK hhkLowLevelKybd;

    LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    BOOL fSuppressKeystroke = FALSE;

    if (nCode == HC_ACTION) {
    switch (wParam) {
    case WM_KEYDOWN:
    case WM_SYSKEYDOWN:
    case WM_KEYUP:
    case WM_SYSKEYUP:
    PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;
    fSuppressKeystroke = ((p->vkCode == VK_SNAPSHOT));
    break;
    }
    }

    return (fSuppressKeystroke? 1: CallNextHookEx(NULL, nCode, wParam, lParam));
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PTSTR pszCmdLine, int nCmdShow)
    {
    // start disabling the PrintScreen key
    hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0);

    return 0;
    }

  2. #2
    Join Date
    May 2005
    Posts
    399

    Re: How to keep my exe running to disable print screen?

    add this before the return 0

    Code:
        while(GetMessage(&msg, NULL, NULL, NULL))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

  3. #3

    Re: How to keep my exe running to disable print screen?

    leojose

    What is the equivalence of your 'msg' in my code or is it a new variable to be defined?

  4. #4
    Join Date
    May 2005
    Posts
    399

    Re: How to keep my exe running to disable print screen?

    Quote Originally Posted by Kurosan
    l
    What is the equivalence of your 'msg' in my code or is it a new variable to be defined?
    msg is a MSG Structure
    So you just need to define it like this...
    Code:
    MSG msg

  5. #5

    Re: How to keep my exe running to disable print screen?

    Thanks leojose, it's working. Is there any way to hide my program from the Task Manager under WinXP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured