WM_CREATE 无响应

#include <windows.h>
#include <string>
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);
/* HDC hdc1;
hdc1=GetDC(hwnd);
TextOut(hdc,0,0,"who am i?",strlen("who am i?"));
ReleaseDC(hwnd,hdc1);
*/ 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;

}

第1个回答  2014-01-15
IsWindow(hWnd)

在WM_CREATE的时候,窗口还没有创建完成。追问

应该怎么改才能在窗口创建时显示。
MFC窗口创建是响应CREATE的。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网