[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Get HWND from a mouse release

Hello,

Is there a way for a user to click on a button, then drag the mouse to a child window and release the mouse while over the window and have that child window be recordered for sending keys to it?

If yes then how?

Thanks
0
Mad_Angel
Asked:
Mad_Angel
  • 4
1 Solution
 
Jaime OlivaresCommented:
Hi Mad_Angel,

You can implement your own drag and drop functionaly with SetCapture API:
http://www.codeproject.com/gdi/mousecapture.asp

You have to do this:
-Detect WM_LBUTTONDOWN event over your button
-Activate SetCapture to the button's window
-Change your icon to indicate you are dragging
-Detect WM_LBUTTONUP event, at this time call ReleaseCapture, and call GetWindowFromPoint to know which window is under the mouse cursor.
-Now you can take any action to that window


Good luck,
Jaime.
0
 
Jaime OlivaresCommented:
Dont be confused with screen and client coordinates.
When SetCapture is active, WM_LBUTTONUP event will tell you release position in "client coordinates" convert them to "screen coordinates" using:
http://msdn.microsoft.com/library/en-us/gdi/cordspac_2tny.asp

then obtain HWND of pointed window with:
http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/windowfrompoint.asp
0
 
Mad_AngelAuthor Commented:
Too complicated....is there a code example?

thanks
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Jaime OlivaresCommented:
>Too complicated....is there a code example?
No there is not an specific code sample, but drag and drop is always an annoying task, in my opinion.

Just have to generate WM_LBUTTONDOWN and WM_LBUTTONUP events in your buttons's window procedure, something like:
      // some initial variables
     static BOOL capturing = FALSE;
     HCURSOR hCursor;
     POINT point;
     HWND target;

        case WM_LBUTTONDOWN:
               SetCapture(hWnd);    // your own hWnd
               capturing = TRUE;       // some flag to specify you are capturing, could be a static or global variable
               SetCursor(hCursor);   // some cursor you have loaded previously with LoadCursor or you can try with SetCursor(LoadCursor(NULL,IDC_HAND));
               break;
        case WM_LBUTTONUP:
               if (capturing) {
                         ReleaseCapture();
                         point.x = LOWORD(lParam);
                         point.y = HIWORD(lParam);
                         ClientToScreen(hWnd, &point);
                         target = WindowFromPoint(point);
                         // SOME ACTION HERE WITH target
                }
                break;

0
 
xMadAngelxCommented:
When I try to put this in, i get a case error...don't i need to switch anything?
0
 
Jaime OlivaresCommented:
Of course you need a switch, is just a portion of your default window procedure.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now