|
|
#include <windows.h>
//#include <window.h>
int InitWindow( HINSTANCE hInstance, int nCmdShow );
LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam );
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//hPrevInstance=NULL;
// TODO: Place code here.
if (!InitWindow(hInstance,nCmdShow))
return FALSE ;
MSG msg;
for (;;)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
static BOOL InitWindow( HINSTANCE hInstance, int nCmdShow )
{
HWND hwnd;
WNDCLASS wc;
wc.style = CS_SAVEBITS;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 1;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = CreateSolidBrush (RGB(200, 0, 0)); //暗红色的背景
wc.lpszMenuName = NULL;
wc.lpszClassName = "wctext";
RegisterClass(&wc);
hwnd = CreateWindow("wctext","My first program",
WS_MAXIMIZE,0,0,
GetSystemMetrics( SM_CXSCREEN ), //此函数返回屏幕宽度
GetSystemMetrics( SM_CYSCREEN ), //此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if( !hwnd ) return FALSE;
ShowWindow(hwnd,SW_SHOWMAXIMIZED);//显示窗口
UpdateWindow(hwnd);//刷新窗口
return TRUE;
}
LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
switch(message)
{
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
MessageBox(hWnd,"你准备退出","退出",MB_OK);
PostMessage(hWnd, WM_CLOSE, 0, 0);//给窗口发送WM_CLOSE消息
break;
}
return 0;
}
}
[em6] |
|