16,471
社区成员
发帖
与我相关
我的任务
分享
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInstance;
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nCmdShow)
{
TCHAR szAppName[] = TEXT ("Hello,World!!!");
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR);
return 0 ;
}
hWnd = CreateDialog(hInstance, (LPCTSTR)IDD_DIALOG1, 0, (DLGPROC)WndProc);
ShowWindow (hWnd, SW_SHOWNORMAL);
while(GetMessage (&msg, NULL, 0, 0))
{
if(msg.message == WM_KEYDOWN && 0x20 == msg.wParam)
{
MessageBox(hWnd, _T("Space Key is Down!!!"), _T("Message"), 0);
}
else if(!IsDialogMessage(hWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_COMMAND:
{
if (IDOK == LOWORD(wParam)|| IDCANCEL == LOWORD(wParam))
{
PostQuitMessage(0);
return TRUE;
}
}
break;
case WM_CLOSE:
EndDialog(hWnd, TRUE);
return TRUE;
case WM_PAINT:
BeginPaint(hWnd, &ps);
// ...
EndPaint(hWnd, &ps);
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}