#include <windows.h>
LRESULT CALLBACK WndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
HWND mywnd;
MSG msg;
WNDCLASS wc;
wc.cbClsExtra = 0; //设计窗口类
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //刷新背景
wc.hCursor = LoadCursor(NULL,IDC_CROSS); //加载光标
wc.hIcon = LoadIcon(NULL,IDI_ERROR); //加载图标
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "myclass"; //类名
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW; //类的风格
RegisterClass(&wc); //注册窗口类
mywnd=CreateWindow("myclass","mywindow",WS_OVERLAPPEDWINDOW,50,50,700,500,NULL,NULL,hInstance,NULL );
//创建窗口
ShowWindow(mywnd,nCmdShow); //显示窗口
UpdateWindow(mywnd); //更新窗口
while(GetMessage(&msg,NULL,0,0)) //消息循环
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
) // 回调函数
{
switch(uMsg)
{
case WM_LBUTTONDOWN:
MessageBox(hwnd,"Hello,World!","Hello",0);
break;
case WM_DESTROY:
//DestroyWindow(hwnd); //只是关闭窗口,不能终止进程
PostQuitMessage(0); //能够终止进程
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
} 这是我的第一个Window程序,记录下来以备以后复习。
posted on 2011-07-24 15:00
大大木马 阅读(203)
评论(0) 编辑 收藏 引用