孙鑫视频中的“SetWindowLong”函数的使用问题
时间:2011-11-30
来源:互联网
我现在在看孙鑫的视频,第7集讲的是对话框。用一个函数“SetWindowLong”来改变窗口的窗口过程。我是在VSTS2010下学习的。有一个问题是,当按视频的说明使用这个函数:
prevProc = (WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd, GWL_WNDPROC, (LONG)WindowProc);
VS2010会产生错误,编译不过去,错误如下:
1>d:\practise\mfc\scale\scale\scaledlg.cpp(127): error C2440: 'type cast' : cannot convert from 'LRESULT (__thiscall CWnd::* )(UINT,WPARAM,LPARAM)' to 'LONG'
1> There is no context in which this conversion is possible
意思是类型转换不过去。请问各位,类型转换应该怎么写呢?还是这个函数已经更新了,有新的函数代替这个函数了?
谢谢!!!
prevProc = (WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd, GWL_WNDPROC, (LONG)WindowProc);
VS2010会产生错误,编译不过去,错误如下:
1>d:\practise\mfc\scale\scale\scaledlg.cpp(127): error C2440: 'type cast' : cannot convert from 'LRESULT (__thiscall CWnd::* )(UINT,WPARAM,LPARAM)' to 'LONG'
1> There is no context in which this conversion is possible
意思是类型转换不过去。请问各位,类型转换应该怎么写呢?还是这个函数已经更新了,有新的函数代替这个函数了?
谢谢!!!
作者: Purplepower 发布时间: 2011-11-30
你的返回值是LRESULT 还是 long
作者: heksn 发布时间: 2011-11-30
用static_cast<LONG>强制转换下
prevProc = (WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd, GWL_WNDPROC, static_cast<LONG>WindowProc);
prevProc = (WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd, GWL_WNDPROC, static_cast<LONG>WindowProc);
作者: gameslq 发布时间: 2011-11-30
C/C++ code
WNDPROC wpOrigEditProc; LRESULT APIENTRY EditBoxProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hwndEdit; switch(uMsg) { case WM_INITDIALOG: // Retrieve the handle to the edit control. hwndEdit = GetDlgItem(hwndDlg, ID_EDIT); // Subclass the edit control. wpOrigEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) EditSubclassProc); // // Continue the initialization procedure. // return TRUE; case WM_DESTROY: // Remove the subclass from the edit control. SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) wpOrigEditProc); // // Continue the cleanup procedure. // break; } return FALSE; UNREFERENCED_PARAMETER(lParam); } // Subclass procedure LRESULT APIENTRY EditSubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_GETDLGCODE) return DLGC_WANTALLKEYS; return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam); }
作者: VisualEleven 发布时间: 2011-11-30
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28