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.
Asked
Active
Viewed 2,539 times
2 Answers
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
-
@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. – Šimon Tóth Mar 09 '10 at 08:20
-
-
@Arman This is normal WinAPI, just add handlers to the main message loop in your code. Its the same for C and C++. – Šimon Tóth Mar 09 '10 at 08:27