Having two screens how i get in what display are my mouse?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Having two screens how i get in what display are my mouse?

Post by dkaip »

I have two screens and the main is with number 1, not 0.
My mouse is in 0 screen. How i can get ScreenDX and ScreenDY sizes from screen that mouse are?

Code: Select all

    //Get Display Count
    const size_t DisplayCount = wxDisplay::GetCount();
    switch (DisplayCount)
    {
//This is the case when there is only one monitor
    case 1:
    {
        wxDisplay display(0);
        wxRect screen = display.GetGeometry();

        ScreenDX=screen.width;
        ScreenDY=screen.height;
    }
    break;

//This is the case when there are two monitor
    case 2:
    {
        wxDisplay display(1);
        wxRect screen = display.GetGeometry();

        ScreenDX=screen.width;
        ScreenDY=screen.height;
    }
    break;
    }


PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Having two screens how i get in what display are my mouse?

Post by PB »

It should be easy, see the display sample: all you need is to obtain the display index from the mouse position.

For example, in your mouse event handler you do something like this

Code: Select all

void SomeWindow::MouseEventHandler(wxMouseEvent& event)
{
    const wxPoint ptScreen = ClientToScreen(event.GetPosition());
    const int displayIndex = wxDisplay::GetFromPoint(ptScreen);

    if ( displayIndex != wxNOT_FOUND )
    {
        wxDisplay display(displayIndex);

        // do something with the display
    }
}
If you cannot use the mouse handler, you can use wxGetMousePosition() to obtain the current mouse position, already in screen coordinates.
Post Reply