中易网

WM_CREATE 无响应

答案:2  悬赏:80  
解决时间 2021-04-28 17:08
  • 提问者网友:多余借口
  • 2021-04-27 21:28
#include
#include
using namespace std ;

LRESULT CALLBACK winproc(
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
)
{
string classname="123";
string titlename="My first window";
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=winproc;
wndclass.lpszClassName="123";
wndclass.lpszMenuName=NULL;
wndclass.style=0;

RegisterClass(&wndclass);

HWND hwnd;
hwnd=CreateWindow("123","My first windows.",WS_OVERLAPPEDWINDOW,0,0,500,500,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
// return 0;

}
return msg.wParam;
}

LRESULT CALLBACK winproc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_PAINT :
PAINTSTRUCT ps;
HDC hdc;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,50,50,"where are you?",strlen("where are you?"));
EndPaint(hwnd,&ps);
break;
case WM_CREATE:
HDC hdc1;
hdc1=GetDC(hwnd);
TextOut(hdc1,0,0,"windows create.",strlen("windows create."));
ReleaseDC(hwnd,hdc1);
case WM_LBUTTONDOWN :
HDC hdc2;
hdc2=GetDC(hwnd);
TextOut(hdc2,0,0,"Left buttom down.",strlen("Left buttom down."));
ReleaseDC(hwnd,hdc2);
break;
case WM_CLOSE :
if (IDYES==MessageBox(hwnd,"是否确定关闭窗口?","message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;

default:
return DefWindowProc(hwnd,uMsg,wParam,lParam) ;
}

return 0;

}
最佳答案
  • 二级知识专家网友:一个很哇塞的汉子
  • 2021-04-27 22:45
IsWindow(hWnd)

在WM_CREATE的时候,窗口还没有创建完成。
全部回答
  • 1楼网友:桑稚给你看
  • 2021-04-27 23:25
不可能,窗口都没被创建wm_create, 自然不能被显示,也不能调整尺寸时触发wm_size
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息