📄 subject_58479.htm
字号:
<p>
序号:58479 发表者:黄远文 发表日期:2003-11-01 12:38:19
<br>主题:一个简单的Win32程序调试错误问题(请教)
<br>内容:错误提示:<BR>D:\VC\basicapp\basicapp.cpp(28) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'<BR> Conversion from 'void*' to pointer to non-'void' requires an explicit cast<BR>Error executing cl.exe.<BR><BR>请问该如何修正程序呢?<BR><BR>源程序如下:<BR>// 一个基本的Win32应用程序<BR><BR>#include <windows.h><BR><BR>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, <BR> WPARAM wParam, LPARAM lParam);<BR><BR>int WINAPI WinMain(HINSTANCE hCurrentInst,<BR> HINSTANCE hPrevInstance, PSTR lpszCmdLine,<BR> int nCmdShow)<BR>{<BR> WNDCLASS wndClass;<BR> HWND hWnd;<BR> MSG msg;<BR> UINT width;<BR> UINT height;<BR><BR> // 初始化窗口类所需的值<BR> wndClass.style = CS_HREDRAW | CS_VREDRAW;<BR> wndClass.lpfnWndProc = WndProc;<BR> wndClass.cbClsExtra = 0;<BR> wndClass.cbWndExtra = 0;<BR> wndClass.hInstance = hCurrentInst;<BR> wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);<BR> wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);<BR><BR>// 出错行!<BR> wndClass.hbrBackground = GetStockObject(WHITE_BRUSH);<BR>// 出错行!<BR><BR> wndClass.lpszMenuName = NULL;<BR> wndClass.lpszClassName = "Basic App";<BR><BR> RegisterClass(&wndClass);<BR><BR> width = GetSystemMetrics(SM_CXSCREEN) / 2;<BR> height = GetSystemMetrics(SM_CYSCREEN) / 2;<BR><BR> hWnd = CreateWindow(<BR> "BasicApp", // Window的类名<BR> "Basic Application", // 标题栏文本<BR> WS_OVERLAPPEDWINDOW, // 窗口样式<BR> 10, // X 坐标<BR> 10, // Y坐标<BR> width, // 宽度<BR> height, // 高度<BR> NULL, <BR> NULL,<BR> hCurrentInst,<BR> NULL);<BR><BR> ShowWindow(hWnd, nCmdShow);<BR> UpdateWindow(hWnd);<BR><BR> while (GetMessage(&msg, NULL, 0, 0))<BR> {<BR> TranslateMessage(&msg);<BR> DispatchMessage(&msg);<BR> }<BR> <BR> return msg.wParam;<BR>}<BR><BR>LRESULT CALLBACK WndProc(HWND hWnd, UINT message,<BR> WPARAM wParam, LPARAM lParam)<BR>{<BR> HDC hDC;<BR> PAINTSTRUCT paintStruct;<BR><BR> switch(message)<BR> {<BR> case WM_PAINT:<BR> hDC = BeginPaint(hWnd, &paintStruct);<BR> TextOut(hDC, 10, 10, "This is a test.", 15);<BR> EndPaint(hWnd, &paintStruct);<BR> return 0;<BR> case WM_LBUTTONDOWN:<BR> MessageBox(hWnd, "Got mouse click!",<BR> "Basic Application",<BR> MB_ICONEXCLAMATION | MB_OK);<BR> return 0;<BR> case WM_DESTROY:<BR> PostQuitMessage(0);<BR> return 0;<BR> }<BR><BR> return DefWindowProc(hWnd, message, wParam, lParam);<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-11-01 12:47:49
<br>内容:wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);<BR> ~~~~~~~~~~~~<BR> 要进行强制类型转换
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:抽刀断水 回复日期:2003-11-01 13:17:48
<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 + -