0

I took this example of subclassing a Form's HWND as a starting point and then added in jrohde's code from from here that is designed to let you drag a Form by clicking anywhere on it (not on the caption bar). This code fails on the ReleaseCapture()line with this message: E2283 Use . or -> to call '_fastcall TCommonCustomForm::ReleaseCapture()

If i comment that line out the code runs and i can move the form by left mouse don and drag, but i can't let go of it. The mouse gets stuck to the form like flypaper. If i replace the ReleaseCapture() with a ShowMessage i can break out but that is obviously not the way to go...

What do i need to do allow that RestoreCapture() to run? This is Win32 app.

BELOW IS THE CODE i added to the original switch(uMsg) block:

    // 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;

thanks, russ

relayman357
  • 793
  • 1
  • 6
  • 30

1 Answers1

1

From the error message you can derive that the compiler resolves the function ReleaseCapture() to TCommonCustomForm::ReleaseCapture(). But you want to call the Win32 API function ReleaseCapture(). Use ::ReleaseCapture(); instead of ReleaseCapture(); to enforce this.

Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36
  • That was it. Thank you Klaus. I had thought i needed a fully qualified namespace but i didn't know what it would be. Is there some documentation that describes what that prefix :: is doing when used by itself up front like that? – relayman357 Dec 09 '18 at 13:51
  • 1
    :: without any identifier on the left refers to the global namespace. – Klaus Gütter Dec 09 '18 at 15:22
  • 1
    And the Win32 API is a C-based API, not a C++-based API, so it does not use namespaces at all, everything is in the global namespace in C++. – Remy Lebeau Dec 10 '18 at 20:41