#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
{::DestroyWindow(hWnd);}
case WM_DESTROY:
{::PostQuitMessage(0);}
}
return ::DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI _tWinMain( __in HINSTANCE hInstance,__in_opt HINSTANCE hPreIstance,__in_opt LPTSTR lpCmdline, __in int nShowCmd)
{
//註冊窗口類,12域
const TCHAR* pszClassName=_T("ITWIN");
WNDCLASSEX wce;
wce.cbSize=sizeof(WNDCLASSEX);//窗口類大小
wce.style=CS_HREDRAW | CS_VREDRAW;//窗口類樣式
wce.lpfnWndProc=WndProc;//窗口處理函數
wce.cbClsExtra=0;//窗口類額外空間
wce.cbWndExtra=0;
wce.hInstance=hInstance;
wce.hIcon=(HICON)::LoadIcon(NULL,IDI_APPLICATION);
wce.hIconSm=(HICON)::LoadIcon(NULL,IDI_APPLICATION);
wce.hbrBackground=(HBRUSH)::GetStockObject(GRAY_BRUSH);//畫刷
wce.hCursor=(HCURSOR)::LoadCursor(NULL,IDC_ARROW);//使用箭頭光標
wce.lpszClassName=pszClassName;//把定義的窗口類名傳入到註冊窗口信息中
wce.lpszMenuName=NULL;
bool bRet= ::RegisterClassEx(&wce);
if (!bRet)
{
MessageBox(NULL,_T("註冊窗口類失敗"),_T("註冊窗口"),0);
return false;
}
HWND hwnd= CreateWindowEx(0,pszClassName,_T("IT學霸"),WS_VISIBLE | WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
if (hwnd==NULL)
{
MessageBox(NULL,_T("創建窗口失敗"),_T("創建窗口"),0);
return false;
}
::ShowWindow(hwnd,SW_SHOW);
::UpdateWindow(hwnd);
MSG msg;
while ( ::GetMessage(&msg,NULL,NULL,NULL) )
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return true;
}