HWND WINAPI CreateWindow(
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
);
VC上课的时候,老师课堂演示CreateWindow(),在添加了WS_MAXIMIZE|WS_VISIBLE样式后,发现窗口并没有和预期的一样,显示最大化。然后老师让我们回来自己尝试解决一下。
这里列出三种解决方法:
1. 不在dwStyle里添加WS_MAXIMIZE|WS_VISIBLE,而是把nWidth和nHeight选项值由默认的CW_USEDEFALT改为WS_MAXIMIZE。不过,这种方式貌似偏离了我们的初衷。
2. 调用ShowWindow(hWnd,SW_SHOWMAXIMIZE|nCmdShow)时,即往显示参数里面添加了SW_SHOWMAXIMIZE,也达到了目的,但是,依然,偏离了初衷。
3. 这种方法是我阅读MSDN后,发现的。关于ShowWindow()函数有这么一段描述
On subsequent calls, the application mustcall ShowWindow with nCmdShow set to SW_SHOWDEFAULT to use the startupinformation provided by the program that launched the application. Thisbehavior is designed for the following situations:
Applications create their main window bycalling CreateWindow with the WS_VISIBLE flag set.
Applications create their main window bycalling CreateWindow with the WS_VISIBLE flag cleared, and later callShowWindow with the SW_SHOW flag set to make it visible.
然后在CreateWindow()函数中,dwStyle只是设置窗口初始化时的值。
所以,我们这里应该调用ShowWindow(hWnd,SW_SHOW|nCmdShow)!!!
SW_SHOW:Activates the windowand displays it in its current size and position.