孙鑫视频中的“SetWindowLong”函数的使用有关问题
孙鑫视频中的“SetWindowLong”函数的使用问题
我现在在看孙鑫的视频,第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
意思是类型转换不过去。请问各位,类型转换应该怎么写呢?还是这个函数已经更新了,有新的函数代替这个函数了?
谢谢!!!
------解决方案--------------------
你的返回值是LRESULT 还是 long
------解决方案--------------------
用static_cast<LONG>强制转换下
prevProc = (WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd, GWL_WNDPROC, static_cast<LONG>WindowProc);
------解决方案--------------------
我现在在看孙鑫的视频,第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
意思是类型转换不过去。请问各位,类型转换应该怎么写呢?还是这个函数已经更新了,有新的函数代替这个函数了?
谢谢!!!
------解决方案--------------------
你的返回值是LRESULT 还是 long
------解决方案--------------------
用static_cast<LONG>强制转换下
prevProc = (WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd, GWL_WNDPROC, static_cast<LONG>WindowProc);
------解决方案--------------------
- 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); }