【发布时间】:2011-07-08 00:23:57
【问题描述】:
我创建了自己的自定义 GUI 按钮类,用于 Windows Mobile 应用程序。意识到我需要一些更好的控制并消除双击的烦恼,我想我需要做的就是像往常一样对它进行子类化。
但是,由于我将所有内容都封装到了一个类中,这似乎使事情变得复杂。
下面是我想做的事情的sn-p
// Graphic button class for Wizard(ing) dialogs.
class CButtonUXnav
{
private:
// Local subclasses of controls.
WNDPROC wpOldButton; // Handle to the original callback.
LRESULT CALLBACK Button_WndProc (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
。 . .
int CButtonUXnav::CreateButton (LPCTSTR lpButtonText, int x, int y, int iWidth, int iHeight, bool gradeL2R)
{
xLoc = x;
yLoc = y;
nWidth = iWidth;
nHeight = iHeight;
wcscpy (wszButtonText, lpButtonText);
PaintButtonInternals (x, y, iWidth, iHeight, gradeL2R);
hButton = CreateWindow (L"BUTTON", wszButtonText,
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_OWNERDRAW,
xLoc, yLoc, nWidth, nHeight,
hWndParent, IDbutn, hInstance, NULL);
// Subclass
// (to remove double-click annoyance.)
wpOldButton = (WNDPROC)GetWindowLong (hButton, GWL_WNDPROC);
if (wpOldButton == 0)
return 1;
// Insert our own callback.
SetWindowLong (hButton, GWL_WNDPROC, (LONG)Button_WndProc);
return 0;
}
但我似乎无法逃避解决这个错误:
错误 C2440:“类型转换”:不能 从 'LRESULT (__cdecl CButtonUXnav::* )(HWND,UINT,WPARAM,LPARAM)' 到 'LONG'
你的想法?
【问题讨论】:
标签: c++ visual-studio-2008 winapi subclass