GetMousePos over MFD (HDC object)

Topper

Addon Developer
Addon Developer
Donator
Joined
Mar 28, 2008
Messages
671
Reaction score
32
Points
43
Hi,
the following code can draw a circle relativ to the position of the mousecursor on the monitor (by using windows.h ) at the mfd:

Code:
void CircleMFD::Update (HDC hDC)
{
    MFD_HDC = hDC; 
    SetTextColor(MFD_HDC,GREEN);   //Setting up the color...

    POINT pos;
    GetCursorPos(&pos); 

    int RADIUS = 15;
    Ellipse (MFD_HDC, 
        pos.x - RADIUS, 
        pos.y + RADIUS,
        pos.x + RADIUS,
        pos.y - RADIUS);
}
My qutestion is now, how can i get the "position of the mousecursor over the MFD" / HDC-Object to draw the circle where the mousecursor is (if mousecursor is over the mfd)?
any ideas??
 
That's a very good question. But I am afraid of that there may not be a way to do that. I hope I am wrong.
 
GetCursorPos gets the current screen position of the mouse.
GetWindowRect will get the screen coordinates of the HWND. You can then subtract to get the Window pos of the cursor.

Edit: Oh, also, WindowFromDC will get the HWND from the HDC
 
Edit: Oh, also, WindowFromDC will get the HWND from the HDC

What about if the HDC is not a window DC ?

EDIT: For an example if the HDC is a handle of bitmap DC how does it know where the bitmap is blitted ?
 
Ah, so "touch-sensitive" MFD's (as in: using the mouse on the display itself) may be possible after all! I can think of some nice applications for this (even on some the current MFD's it would be handy).

Are there already some MFD's out there that use the mouse on the screen area itself?

regards,
mcduck
 
What about if the HDC is not a window DC ?

EDIT: For an example if the HDC is a handle of bitmap DC how does it know where the bitmap is blitted ?


There's a good point. I don't know if the MFD would have its own window handle when it's drawn on a 2D panel, but I'm pretty sure it wouldn't when drawn in a VC.
 
There's a good point. I don't know if the MFD would have its own window handle when it's drawn on a 2D panel, but I'm pretty sure it wouldn't when drawn in a VC.

Right, i think thats eaxactly the problem .
By using this code:

Code:
..
void TestMFD::Update (HDC hDC)
{
...
    HWND hwnd = WindowFromDC(hdc);
    if (hwnd == NULL) 
    {
        TextOut(mfdHdc, 15,  line(2), "ERROR", strlen("ERROR")); 
        return;
    }
...
}
i always get the "ERROR" message on my MFD.
I can't find a way to get the coordinates of the mouse over the MFD / the "TOP-LEFT" coordinate of the HDC-object :@

I wish it will be possible to make a "touchscreen MFD"!!
 
What about if the HDC is not a window DC ?

EDIT: For an example if the HDC is a handle of bitmap DC how does it know where the bitmap is blitted ?

The HDC won't have a concept of where it is blitted to as that location information is passed to the blit command and not stored along with the DC. This is because essentially the bitmap is not at a 'location' - it's a bitmap that's stored in memory. This bitmap is then blitted onto the window. Even at this time, the bitmap is locationless and it's merely a copy of it that's put onto the screen somewhere.

You could hook the clbkPanelMouseEvent function of the VESSEL2 class that gives you the relative mouse position (see LaunchMFD code for hooking of VESSEL2 functions).
 
I know Vchamp has a touchscreen in the VC of intermod, it's a custom screen though. I don't know if the same is possible for an MFD...
 
(sorry for digging up an old thread)
Using the MFD hDC, WindowFromDC() always seems to return NULL, so jarmonik/agentgonzo where right. But there are ways of getting the HWND of Orbiter itself if needed.


You could hook the clbkPanelMouseEvent function of the VESSEL2 class that gives you the relative mouse position (see LaunchMFD code for hooking of VESSEL2 functions).
This is what I'm trying now, but is this only possible in panel and VC modes? (as there are only clbkPanelMouseEvent and clbkVCMouseEvent)

Using GetCursorPos, it would be possible to apply a 'calibration' procedure. When the MFD starts, you have to click at 1 or 2 crosses on the MFD screen, in order to determine the position of the MFD. I think after this calibration, a touch-screen MFD is possible (in default Orbiter-cockpit non panel mode). In the cases of VC or panel, the VESSEL2 HookClass could be used in order to get the relative mouse coords, so the calibration procedure only needs to be done once? Not sure about this.

I'll give it a try tomorrow.
 
Back
Top