Vista下使用CreateWindow时发现的问题
我使用CreateWindow的代码如下:
HINSTANCE hInstance = NULL;
if ( !(hInstance = GetModuleHandle(NULL)) )
{
assert(0);
return -1;
}
static TCHAR szAppName[] = TEXT ( "MciComponent ") ;
HWND hwnd = NULL;
MSG msg;
WNDCLASS 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 = szAppName;
if ( !RegisterClass (&wndclass) )
{
MessageBox(NULL,
TEXT( "This program requires Windows NT! "),
szAppName, MB_ICONERROR);
return 0 ;
}
hwnd = CreateWindow(szAppName, // window class name
TEXT ( " "), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT,// initial x position
CW_USEDEFAULT,// initial y position
CW_USEDEFAULT,// initial x size
CW_USEDEFAULT,// initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
if ( NULL == hwnd )
{
_tprintf(_T( "CreateWindow Error: %d\n "), GetLastError());
return -1;
}
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
每次都fail在CreateWindow上,即hwnd是NULL,但我使用GetLastError获得的错误号却为0。很让人困惑。
同样的代码在windows xp下却执行的相当好。
[解决办法]
CSND把帖子的TAB去掉了,看长的代码很费劲吧。
[解决办法]
你的wndproc是怎樣的,一般來講需要將 WM_CREATE 交給 默認的 窗口過程來處理.