首页 > 解决方案 > 恢复捕获 FMX - Win32

问题描述

我以这个将表单的 HWND 子类化的示例作为起点,然后从此处添加 jrohde 的代码,该代码旨在让您通过单击表单的任意位置(而不是标题栏上)来拖动表单。此代码失败并显示ReleaseCapture()此消息:E2283 Use . or -> to call '_fastcall TCommonCustomForm::ReleaseCapture()

如果我注释掉代码运行,我可以通过鼠标左键移动表单并拖动,但我不能放手。鼠标像蝇纸一样粘在表格上。如果我用 a 替换它ReleaseCapture()ShowMessage我可以突破,但这显然不是要走的路......

我需要做什么才能让它RestoreCapture()运行?这是 Win32 应用程序。

以下是我添加到原始switch(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;

谢谢,拉斯

标签: firemonkeyc++builder

解决方案


从错误消息中,您可以得出编译器将函数 ReleaseCapture() 解析为 TCommonCustomForm::ReleaseCapture()。但是你想调用 Win32 API 函数 ReleaseCapture()。使用::ReleaseCapture();而不是ReleaseCapture();强制执行此操作。


推荐阅读