永发信息网

C++如何写一个空白的win32窗口

答案:1  悬赏:80  手机版
解决时间 2021-01-29 14:58
  • 提问者网友:温旧梦泪无声
  • 2021-01-29 02:16
如题,大牛们给小菜一点点提示也好,怎样做个最简单的win32窗口出来?
就是告诉我一下大致流程,细节我可以慢慢查
最佳答案
  • 五星知识达人网友:鸽屿
  • 2021-01-29 03:50
#include
#include

LRESULT CALLBACK WinSunProc(
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
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="5261";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;

RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("5261","HUC红客联盟",WS_OVERLAPPEDWINDOW,100,100,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

}

LRESULT CALLBACK WinSunProc(
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,"鼠标左击了","红盟",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,40,40,"红盟万岁",strlen("红盟万岁"));
ReleaseDC(hwnd,hdc);

break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,60,60,"冷无崖",strlen("冷无崖"));
EndPaint(hwnd,&ps);
break;
case WM_CHAR:
char a[20];
sprintf(a,"char is %d",wParam);
MessageBox(hwnd,a,"红盟",0);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否退出","冷无崖",MB_YESNO))
{
DestroyWindow(hwnd);
}

break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;

}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯