63,603
社区成员




#include <conio.h>
#include <windows.h>
int main() {
int k;
while (1) {
if (kbhit()) {
k=getch();
if (0==k || 0xE0==k) k=k<<8|getch();
if (27==k) break;//按Esc键退出
cprintf("\r\n%04X\r\n",k);
}
Sleep(200);
cprintf(".");
}
return 0;
}
#include <conio.h>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
int ch = _getch();
std::cout << ch;
if( ch == 27 )
{
std::cout << "\nEscape pressed!\n";
}
else
{
std::cout << "\n" << char(ch) << " pressed!\n";
}
return 0;
}
#include <windows.h>
#include <tchar.h>
HINSTANCE hInst;
TCHAR szTitle[] = _T("TestWindow");
TCHAR szWindowClass[] = _T("WNDCLASS_of_test_window");
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
{
MessageBox( hWnd, _T("Escape is pressed!"), _T("Key down"), MB_OK);//把这句换成你的代码。
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}