//fsdaf
//asdff
#include <windows.h>
BOOL InitWindow(HINSTANCE hInstance, int nCmdShow);
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
//变量说明
HWND hWnd; //窗口句柄
int API WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
if ( !InitWindow( hInstance, nCmdShow ) ) return FALSE;
MSG msg;
for (;;)//消息循环1
{
if(msg.message== WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}//消息循环1
return msg.wParam;
}
static BOOL initWindow(HINSTANCE hInstance, int nCmdShow )
{
WNDCLASS wc;
wc.style=NULL;
wc.lpfnWndProc=(WNDPROC)WinProc;
wc.cbClsExtra=0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = CreateSolidBrush (RGB(100, 0, 0)); //暗红色的背景
wc.lpszMenuName = NULL;
wc.lpszClassName = "My_Test";
RegisterClass(&wc);//注册窗口
//按所给参数创造窗口
hWnd = CreateWindow("My_Test",
"My first program",
WS_POPUP|WS_MAXIMIZE,0,0,
GetSystemMetrics( SM_CXSCREEN ), //此函数返回屏幕宽度
GetSystemMetrics( SM_CYSCREEN ), //此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if( !hWnd ) return FALSE;
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);//刷新窗口
return TRUE;
}//end initWindows
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch( message )
{
case WM_KEYDOWN://击键消息
switch( wParam )
{
case VK_ESCAPE:
MessageBox(hWnd,"ESC键按下了! 确定后退出!","Keyboard",MB_OK);
PostMessage(hWnd, WM_CLOSE, 0, 0);//给窗口发送WM_CLOSE消息
break;
}
return 0; //处理完一个消息后返回0
case WM_CLOSE: //准备退出
DestroyWindow( hWnd ); //释放窗口
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);
return 0;
case WM_DESTROY: //如果窗口被人释放…
PostQuitMessage( 0 ); //给窗口发送WM_QUIT消息
return 0;
}
//调用缺省消息处理过程
return DefWindowProc(hWnd,message,wParam,lParam);
}
编译出错提示如下:
--------------------Configuration: dfdf - Win32 Debug--------------------
Compiling...
dfdf.cpp
e:\c\dfdf\dfdf.cpp(84) : fatal error C1010: unexpected end of file while looking for precompiled header directive
执行 cl.exe 时出错.
dfdf.exe - 1 error(s), 0 warning(s)