⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_16727.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:16727 发表者:Jonny 发表日期:2002-10-02 10:30:29
<br>主题:请教一个不能再‘菜’的问题
<br>内容:以下源码是个最起码的WIN32程序,为何主窗口不显示?在任务管理器中,“应用程序栏”中没有,而“进程”中却有?<BR>#include &lt;windows.h&gt;<BR><BR>HWND hwnd;<BR>HINSTANCE pInstance;<BR><BR>LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);<BR><BR><BR>int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSTR szCmdLine,int iCmdShow){<BR>&nbsp;&nbsp;&nbsp;&nbsp;static char szClassName[]="MainClass";//class name<BR>&nbsp;&nbsp;&nbsp;&nbsp;MSG msg;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//defining a struct of type WNDCLASSEX<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;WNDCLASSEX wndclass;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.cbSize=sizeof(WNDCLASSEX);<BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.style=CS_HREDRAW|CS_VREDRAW;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.lpfnWndProc=WndProc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.cbClsExtra=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.cbWndExtra=0;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hInstance=hInstance;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);<BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);<BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.lpszMenuName=NULL; //No Menu<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.lpszClassName=szClassName;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;wndclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if(!RegisterClassEx(&wndclass))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;hwnd=CreateWindowEx(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WS_EX_LEFT,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;szClassName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Window Caption",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WS_OVERLAPPEDWINDOW,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CW_USEDEFAULT,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CW_USEDEFAULT,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CW_USEDEFAULT,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CW_USEDEFAULT,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hInstance,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;ShowWindow(hwnd,iCmdShow);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;UpdateWindow(hwnd);<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//Message loop<BR>&nbsp;&nbsp;&nbsp;&nbsp;while(GetMessage(&msg,NULL,0,0))<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TranslateMessage(&msg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DispatchMessage(&msg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return msg.wParam;<BR><BR>}<BR><BR>LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LPARAM lParam){<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR><BR>}<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:lp 回复日期:2002-10-02 12:20:39
<br>内容:真正的VC程序员不用API编程,只用MFC!Just forget it!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Norton AntivVirus 回复日期:2002-10-02 17:21:39
<br>内容:ShowWindow(hwnd,iCmdShow);<BR>iCmdShow是多少啊,直接用SW_SHOW不好吗?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:FullMoon 回复日期:2002-10-08 13:21:31
<br>内容:问题可能出在WndProc,至少应为return DefWindowProc(hWnd, message, wParam, lParam);
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Jonny 回复日期:2002-10-09 20:45:52
<br>内容:CanMoon 回答的有道理,我后来将WndProc修改后,窗口出现。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -