GetDesktopWindow() on dual monitor system.

GetDesktopWindow() on dual monitor system.

Postby byron.hopp » Wed Sep 25, 2024 6:46 pm

When I ask for the desktop windows on my dual monitor system I get the main monitor by GetWndRect( GetDesktopWindows() ). Is there a way to the the second or n monitors as well. I am trying to display multiple dialogs across the screens for a scheduling app and need to know how far I can go to the right.
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: GetDesktopWindow() on dual monitor system.

Postby Antonio Linares » Thu Sep 26, 2024 3:05 am

Dear Byron,

monitors.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   EnumDisplayMonitors( { | nMonitor, hMonitor, hdcMonitor, lPrimary, aMonitorRect, aMonitorRectInfo, aWorkRect | ;
                          XBrowser( { "nMonitor" => nMonitor,;
                                      "hMonitor" => hMonitor,;
                                      "hdcMonitor" => hdcMonitor,;
                                      "lPrimary" => lPrimary,;
                                      "aMonitorRect" => aMonitorRect,;
                                      "aMonitorRectInfo" => aMonitorRectInfo,;  
                                      "aWorkRect" => aWorkRect } ), .T. } )  // .T. continue to next monitor
return nil

#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>
#include <hbapiitm.h>

static int iMonitorCount;

static BOOL CALLBACK MonitorEnumProc( HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData )
{
    MONITORINFOEX mi;

    if( iMonitorCount >= MAX_MONITORS )
    {
       return FALSE;  // Stop enumeration if we've reached the maximum
    }

    mi.cbSize = sizeof( MONITORINFOEX );
   
    if( GetMonitorInfo( hMonitor, ( LPMONITORINFO ) &mi ) )
    {
       PHB_ITEM pMonitorCount   = hb_itemPutNL( NULL, ++iMonitorCount );
       PHB_ITEM pHandleMonitor  = hb_itemPutPtr( NULL, hMonitor );
       PHB_ITEM phdcMonitor     = hb_itemPutPtr( NULL, hdcMonitor );
       PHB_ITEM prctMonitor     = hb_itemArrayNew( 4 );
       PHB_ITEM pIsPrimary      = hb_itemPutL( NULL, ( mi.dwFlags & MONITORINFOF_PRIMARY) != 0 );
       PHB_ITEM prctMonitorInfo = hb_itemArrayNew( 4 );
       PHB_ITEM prctWork        = hb_itemArrayNew( 4 );

       PHB_ITEM pMonitorLeft    = hb_itemPutNL( NULL, lprcMonitor->left );
       PHB_ITEM pMonitorTop     = hb_itemPutNL( NULL, lprcMonitor->top );
       PHB_ITEM pMonitorBottom  = hb_itemPutNL( NULL, lprcMonitor->bottom );
       PHB_ITEM pMonitorRight   = hb_itemPutNL( NULL, lprcMonitor->right );

       PHB_ITEM pMonitorInfoLeft   = hb_itemPutNL( NULL, mi.rcMonitor.left );
       PHB_ITEM pMonitorInfoTop    = hb_itemPutNL( NULL, mi.rcMonitor.top );
       PHB_ITEM pMonitorInfoBottom = hb_itemPutNL( NULL, mi.rcMonitor.bottom );
       PHB_ITEM pMonitorInfoRight  = hb_itemPutNL( NULL, mi.rcMonitor.right );

       PHB_ITEM pWorkLeft   = hb_itemPutNL( NULL, mi.rcWork.left );
       PHB_ITEM pWorkTop    = hb_itemPutNL( NULL, mi.rcWork.top );
       PHB_ITEM pWorkBottom = hb_itemPutNL( NULL, mi.rcWork.bottom );
       PHB_ITEM pWorkRight  = hb_itemPutNL( NULL, mi.rcWork.right );

       hb_itemArrayPut( prctMonitor, 1, pMonitorLeft );
       hb_itemArrayPut( prctMonitor, 2, pMonitorTop );
       hb_itemArrayPut( prctMonitor, 3, pMonitorBottom );
       hb_itemArrayPut( prctMonitor, 4, pMonitorRight );

       hb_itemArrayPut( prctMonitorInfo, 1, pMonitorInfoLeft );
       hb_itemArrayPut( prctMonitorInfo, 2, pMonitorInfoTop );
       hb_itemArrayPut( prctMonitorInfo, 3, pMonitorInfoBottom );
       hb_itemArrayPut( prctMonitorInfo, 4, pMonitorInfoRight );

       hb_itemArrayPut( prctWork, 1, pWorkLeft );
       hb_itemArrayPut( prctWork, 2, pWorkTop );
       hb_itemArrayPut( prctWork, 3, pWorkBottom );
       hb_itemArrayPut( prctWork, 4, pWorkRight );

       hb_evalBlock( ( PHB_ITEM ) dwData, pMonitorCount, pHandleMonitor, phdcMonitor, pIsPrimary, prctMonitor,
                     prctMonitorInfo, prctWork, NULL );

       hb_itemRelease( pMonitorLeft );
       hb_itemRelease( pMonitorTop );
       hb_itemRelease( pMonitorBottom );
       hb_itemRelease( pMonitorRight );

       hb_itemRelease( pMonitorInfoLeft );
       hb_itemRelease( pMonitorInfoTop );
       hb_itemRelease( pMonitorInfoBottom );
       hb_itemRelease( pMonitorInfoRight );

       hb_itemRelease( pWorkLeft );
       hb_itemRelease( pWorkTop );
       hb_itemRelease( pWorkBottom );
       hb_itemRelease( pWorkRight );

       hb_itemRelease( prctWork );
       hb_itemRelease( prctMonitorInfo );
       hb_itemRelease( prctMonitor );
       hb_itemRelease( pIsPrimary );
       hb_itemRelease( phdcMonitor );
       hb_itemRelease( pHandleMonitor );
       hb_itemRelease( pMonitorCount );
    }
   
    return hb_parl( -1 );  // .T. continue enumeration
}

HB_FUNC( ENUMDISPLAYMONITORS )
{
   iMonitorCount = 0;
   hb_retl( EnumDisplayMonitors( NULL, NULL, MonitorEnumProc, ( LPARAM ) hb_param( 1, HB_IT_BLOCK ) ) );    
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetDesktopWindow() on dual monitor system.

Postby byron.hopp » Thu Sep 26, 2024 3:30 am

Mr. Rao told me to try FW_VirtualScreen(), but I don't know if it works for more than two screens (I only have 2) . However I cannot successfully link my app with EnumDisplayMonitors() the linker can't find it. I did find several mentions of this function when googling the WinAPI for multiple monitors.
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: GetDesktopWindow() on dual monitor system.

Postby Antonio Linares » Thu Sep 26, 2024 4:11 am

I have edited my previous answer with an example to test, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetDesktopWindow() on dual monitor system.

Postby Antonio Linares » Thu Sep 26, 2024 4:17 am

Minor editing again on the example code
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetDesktopWindow() on dual monitor system.

Postby Antonio Linares » Thu Sep 26, 2024 4:19 am

Final minor editing :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetDesktopWindow() on dual monitor system.

Postby Antonio Linares » Thu Sep 26, 2024 4:22 am

Please let me know if it helps you or if you need something else.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GetDesktopWindow() on dual monitor system.

Postby byron.hopp » Thu Sep 26, 2024 5:26 pm

Works perfectly. Do you know the difference between aWorkRect vs (aMonitorRectInfo or aMonitorRect), this is more like what I saw on line I just had no idea how to implement the code. Thanks,
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 64 guests