我以this example为子类,将Form的HWND子类化为起点,然后从from here中添加了jrohde的代码,该代码旨在让您通过单击Form的任何位置(而不是标题)来拖动它酒吧)。此代码在ReleaseCapture()
行中失败,并显示以下消息:E2283 Use . or -> to call '_fastcall TCommonCustomForm::ReleaseCapture()
如果我注释掉那行代码,代码可以运行,并且我可以通过鼠标左键拖动并拖动表格,但是我不能放过它。鼠标卡住了像飞纸一样的形式。如果我将ReleaseCapture()
替换为ShowMessage
,我会爆发,但这显然不是解决之道...
我该怎么做才能让RestoreCapture()
运行?这是Win32应用。
以下是我添加到the original开关(uMsg)块中的代码:
// two int's defined above the switch statement
static int xClick;
static int yClick;
// new case added to the switch
case WM_LBUTTONDOWN:
SetCapture(hWnd);
xClick = LOWORD(lParam);
yClick = HIWORD(lParam);
break;
case WM_LBUTTONUP:
//ReleaseCapture(); // This is the problem spot <------------------------
ShowMessage("Up");
break;
case WM_MOUSEMOVE:
{
if (GetCapture() == hWnd) //Check if this window has mouse input
{
RECT rcWindow;
GetWindowRect(hWnd,&rcWindow);
int xMouse = LOWORD(lParam);
int yMouse = HIWORD(lParam);
int xWindow = rcWindow.left + xMouse - xClick;
int yWindow = rcWindow.top + yMouse - yClick;
SetWindowPos(hWnd,NULL,xWindow,yWindow,0,0,SWP_NOSIZE|SWP_NOZORDER);
}
break;
谢谢,鲁斯
答案 0 :(得分:1)
从错误消息中,您可以得出编译器将函数ReleaseCapture()解析为TCommonCustomForm :: ReleaseCapture()的信息。但是您想调用Win32 API函数ReleaseCapture()。使用::ReleaseCapture();
而非ReleaseCapture();
来强制执行此操作。