3

I want to disable keyboard when my program Run, means that no one can use alt+F4 etc. How I can make it possible using c in window OS.

Siddiqui
  • 7,662
  • 17
  • 81
  • 129

2 Answers2

3

Handle WM_SYSKEYUP , WM_SYSKEYDOWN and return 0

Here's the WndProc to handle these messages

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_SYSKEYDOWN:
    case WM_SYSKEYUP:
    case WM_KEYDOWN:
    case WM_KEYUP:
        return 0;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Indy9000
  • 8,651
  • 2
  • 32
  • 37
  • How can I handle these type of messages in c?? – Siddiqui Mar 09 '10 at 07:59
  • Win32 is a C API. When you create a sample Windows application in Visual studio, you should see the WndProc generated for you. You handle messages there like shown above. – Indy9000 Mar 09 '10 at 08:28
2

Pressing alt + f4 sends WM_CLOSE message. You should properly handled this message.

Luka Rahne
  • 10,336
  • 3
  • 34
  • 56