/*
一個(gè)簡(jiǎn)單的win32窗口調(diào)用
*/
#include<Windows.h>
#include<tchar.h>
//聲明窗口函數(shù)
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lparam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInatance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndclass;
wndclass.lpfnWndProc=WindowProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpszClassName=_T("我的窗體");
wndclass.hInstance=hInstance;
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=0;
wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName=0;
//注冊(cè)窗口類
if(RegisterClass(&wndclass)==0)
{
MessageBox(0,_T("注冊(cè)窗口類失敗"),_T("我的窗體"),MB_OK);
return 0;
}
//創(chuàng)建窗口實(shí)列
HWND hWnd = CreateWindow(_T("我的窗體"),_T("我的第一個(gè)窗體"),WS_OVERLAPPEDWINDOW,100,100,500,400,0,0,hInstance,0);
//顯示和更新窗口
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
//消息循環(huán)
MSG msg;
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//定義窗口函數(shù)
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM IParam
)
{
switch(uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,IParam);
}
return 0;
}