tags:

views:

71

answers:

2

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.

+2  A: 

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

ralu
How can I handle this type of messages???
Arman
@Arman, just to note, this will only disable the keyboard in your program, not in others. Plus you can never disable CTRL+ALT+DELETE combination.
Let_Me_Be
How to disable in c?? Any hint?
Arman
@Arman This is normal WinAPI, just add handlers to the main message loop in your code. Its the same for C and C++.
Let_Me_Be
+2  A: 

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;
}
Indeera
How can I handle these type of messages in c??
Arman
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.
Indeera
@Indeera Thanks
Arman