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

📄 subject_30106.htm

📁 vc
💻 HTM
字号:
<p>
序号:30106 发表者:网络猎人 发表日期:2003-02-20 10:49:46
<br>主题:LRESULT CALLBACK 回调老是出现问题
<br>内容:<BR>#include "windows.h"<BR><BR>LRERULT&nbsp;&nbsp; CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);<BR><BR>char szwinName[]="mywin";<BR><BR>int WINAPI WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR lpszArgs,int nWinMode)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;HWND hwnd;<BR>&nbsp;&nbsp;&nbsp;&nbsp;MSG msg;<BR>&nbsp;&nbsp;&nbsp;&nbsp;WNDCLASSEX wcl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.cbSize =sizeof(WNDCLASSEX);//定义窗口类;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hInstance =hThisInst;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//句柄指向本身;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.lpszClassName =szwinName;&nbsp;&nbsp;//窗口名字;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.lpfnWndProc =(long)WindowFunc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.style =0;//默认风格;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hIcon =LoadIcon(NULL,IDI_APPLICATION);<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hIconSm =LoadIcon(NULL,IDI_WINLOGO);<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hCursor =LoadCursor(NULL,IDC_ARROW);//载入<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.lpszMenuName =NULL;//表示不需要菜单;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.cbClsExtra =0;//不要额外的信息;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.cbWndExtra =0;//同上;<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//让窗口的背景为白色;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//注册窗口类;//窗口类指的是窗口的样式;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(!RegisterClassEx(&amp;wcl)) return 0;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//窗口注册完过后就可以创建了;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hwnd=CreateWindow(szwinName,"firstwindow",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDFAULT,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CW_USEDEFAULT,CW_USEDEFAULT,HWND_DESKTOP,NULL,hThisInst,NULL);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; //创建过后就应该显示<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;ShowWindow(hwnd,nWinMode);<BR>&nbsp;&nbsp;&nbsp;&nbsp;UpdateWindow(hwnd);<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while(GetMessage(&amp;msg,NULL,0,0))<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TranslateMessage(&amp;msg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DispatchMessage(&amp;msg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return msg.wParam ;<BR>}<BR><BR>_stdcall LRERULT&nbsp;&nbsp;CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;switch(message)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;case WM_DESTROY:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PostQuitMessage(0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;default:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return DefWindowProc(hwnd,message,wparam,lparam);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}<BR><BR>老是出现下列错误<BR><BR><BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(3) : error C2143: syntax error : missing ';' before '__stdcall'<BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(3) : error C2501: 'LRERULT' : missing storage-class or type specifiers<BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(15) : error C2440: '=' : cannot convert from 'long' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast<BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(33) : error C2065: 'CW_USEDFAULT' : undeclared identifier<BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(48) : error C2143: syntax error : missing ';' before '__stdcall'<BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(48) : warning C4229: anachronism used : modifiers on data are ignored<BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(48) : error C2501: 'LRERULT' : missing storage-class or type specifiers<BR>D:\Program Files\Microsoft Visual Studio\MyProjects\123\123.cpp(48) : error C2086: 'LRERULT' : redefinition<BR>Error executing cl.exe.<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>
<font color=red>答案被接受</font><br>回复者:晚风也渡 回复日期:2003-02-20 13:16:59
<br>内容:改为如下:<BR>#include "windows.h"<BR><BR>LRESULT&nbsp;&nbsp; CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);<BR><BR>char szwinName[]="mywin";<BR><BR>int WINAPI WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR lpszArgs,int nWinMode)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;HWND hwnd;<BR>&nbsp;&nbsp;&nbsp;&nbsp;MSG msg;<BR>&nbsp;&nbsp;&nbsp;&nbsp;WNDCLASSEX wcl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.cbSize =sizeof(WNDCLASSEX);//定义窗口类;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hInstance =hThisInst;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//句柄指向本身;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.lpszClassName =szwinName;&nbsp;&nbsp;//窗口名字;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.lpfnWndProc =(WNDPROC)WindowFunc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.style =0;//默认风格;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hIcon =LoadIcon(NULL,IDI_APPLICATION);<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hIconSm =LoadIcon(NULL,IDI_WINLOGO);<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hCursor =LoadCursor(NULL,IDC_ARROW);//载入<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.lpszMenuName =NULL;//表示不需要菜单;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.cbClsExtra =0;//不要额外的信息;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.cbWndExtra =0;//同上;<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//让窗口的背景为白色;<BR>&nbsp;&nbsp;&nbsp;&nbsp;wcl.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//注册窗口类;//窗口类指的是窗口的样式;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(!RegisterClassEx(&amp;wcl)) return 0;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//窗口注册完过后就可以创建了;<BR>&nbsp;&nbsp;&nbsp;&nbsp;hwnd=CreateWindow(szwinName,"firstwindow",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CW_USEDEFAULT,CW_USEDEFAULT,HWND_DESKTOP,NULL,hThisInst,NULL);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; //创建过后就应该显示<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;ShowWindow(hwnd,nWinMode);<BR>&nbsp;&nbsp;&nbsp;&nbsp;UpdateWindow(hwnd);<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while(GetMessage(&amp;msg,NULL,0,0))<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TranslateMessage(&amp;msg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DispatchMessage(&amp;msg);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return msg.wParam ;<BR>}<BR><BR>LRESULT&nbsp;&nbsp;CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;switch(message)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;case WM_DESTROY:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PostQuitMessage(0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;default:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return DefWindowProc(hwnd,message,wparam,lparam);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}<BR>
<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 + -