1.must have an entrypoint: WinMain
2.must have a function to solve message loop.
//sothing.c
#include <windows.h>
int PASCAL WinMain(HINSTANCE,HINSTANCE,LPSTR,INT);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE hInst;
char szAppName[]=“....“;
char szAppTitle[]=“...“;
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpszCmdParam,INT nCmdShow)
{
HWND hWnd;
MSG message;
WNDCLASS wc;
if(!hPreInstance)
{
wc.style=......
wc.lpfnWndProc=WndProc;
RegisterClass(&wc);
}
hWnd=CreateWindow(
.....
);
ShowWindow(hWnd,....);
UpdateWindow(hWnd);
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWndMain,
UNIT message,
WPARAM wParam,
LPARAM lParam)
{
...
switch(message)
{
case WM_DESTROY:
....
}
return DefWindowProc(hWndMain,message,wParam,lParam);
}
2.must have a function to solve message loop.
//sothing.c
#include <windows.h>
int PASCAL WinMain(HINSTANCE,HINSTANCE,LPSTR,INT);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE hInst;
char szAppName[]=“....“;
char szAppTitle[]=“...“;
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpszCmdParam,INT nCmdShow)
{
HWND hWnd;
MSG message;
WNDCLASS wc;
if(!hPreInstance)
{
wc.style=......
wc.lpfnWndProc=WndProc;
RegisterClass(&wc);
}
hWnd=CreateWindow(
.....
);
ShowWindow(hWnd,....);
UpdateWindow(hWnd);
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWndMain,
UNIT message,
WPARAM wParam,
LPARAM lParam)
{
...
switch(message)
{
case WM_DESTROY:
....
}
return DefWindowProc(hWndMain,message,wParam,lParam);
}
博客展示了Windows程序的编写要点,包括必须有入口点WinMain和解决消息循环的函数。给出了具体代码示例,包含WinMain函数的实现,用于创建窗口、显示窗口和处理消息循环,还有WndProc回调函数处理窗口消息。
1万+

被折叠的 条评论
为什么被折叠?



