第一個windows exe程式
阿新 • • 發佈:2019-02-15
#include <windows.h>
#include <TChar.h>
#define CreateWndSty WS_EX_CLIENTEDGE
//宣告回撥函式
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT message ,
WPARAM wParam,
LPARAM lParam );
//主函式
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPreInstance,
LPSTR lpCmdLine,
int nCmdshow )
{
TCHAR className[]=L"你好";
TCHAR winName[]=L"大家好!!!";
WNDCLASSEX wndclass;
wndclass.style=CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor=LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = className ;
wndclass.cbSize = sizeof( WNDCLASSEX );
wndclass.hIconSm = NULL;
if (RegisterClassEx(&wndclass)==NULL){
MessageBox(NULL,_T("Error111"),_T("Error!!!"),MB_OK);
return 0;
}
HWND hwnd;
hwnd=CreateWindowEx(CreateWndSty,
className ,
winName,
WS_OVERLAPPEDWINDOW,
100,100,600,400,
NULL,NULL,hInstance,NULL);
if (hwnd==NULL){
MessageBox(NULL,L"建立主視窗時發生錯誤!",L"錯誤資訊",MB_OK|MB_ICONSTOP);
return 0;
}
ShowWindow(hwnd,SW_MINIMIZE);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd,
UINT message ,
WPARAM wParam,
LPARAM lParam )
{
switch (message)
{
case WM_LBUTTONDOWN:
MessageBox(NULL,_T("ok"),_T("ok!!!"),MB_OK);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}