devxlogo

Picking coordinates outside your window(s)

Picking coordinates outside your window(s)

Question:
How do I make my program respond to “mousedown” outside my form? For instance: How would I get my program to tell me the pixel coordinants of my cursor when I click?

Answer:
You really can’t do that under Win32. However, you *can* have it respond to MouseUp! I showed, in some detail, how to do this in the Q&A column (VBPJ, Sept 97).

In short, you create a drop-target, using the DragIcon property of a picture box. When MouseDown fires, call SetCapture, and that control’s MouseMove and MouseUp events will then fire regardless of where the cursor is. In MouseUp, call GetCursorPosition to obtain the screen coordinates of the cursor.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist