FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Program open on the second monitor
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Program open on the second monitor
Posted: Tue Dec 09, 2025 08:07 AM

Hi,

A second large monitor is connected to the laptop. At startup, my program opens on the laptop screen. How do I make the program open on the second large monitor at startup ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Program open on the second monitor
Posted: Tue Dec 09, 2025 11:24 AM

To make your program open on the second large monitor at startup, you can use FiveWin's multi-monitor support functions. Here are the main approaches:

Quick Solution

Add the IN 2 clause to your ACTIVATE WINDOW or ACTIVATE DIALOG command:

Code (harbour): Select all Collapse
ACTIVATE WINDOW oWnd IN 2
// or
ACTIVATE DIALOG oDlg IN 2

Detailed Options

1. Using Monitor Number in ACTIVATE

The ACTIVATE WINDOW and ACTIVATE DIALOG commands support an IN clause that accepts a monitor number or object 0-cite-0 . Monitor 2 refers to the second monitor.

2. Using FW_GetMonitor() Function

Get the second monitor object and pass it to the activate command:

Code (harbour): Select all Collapse
ACTIVATE WINDOW oWnd IN FW_GetMonitor(2)

The FW_GetMonitor() function returns a TMonitor object for the specified monitor 0-cite-1 .

3. Setting Default Monitor with FW_SetMonitor()

Use FW_SetMonitor() to set the default monitor for all subsequent windows:

Code (harbour): Select all Collapse
FW_SetMonitor(2)  // Set second monitor as default
ACTIVATE WINDOW oWnd  // Will open on second monitor

FW_SetMonitor() sets a static monitor that's used by default for all windows 0-cite-2 .

4. Centering on Specific Monitor

To center the window on the second monitor:

Code (harbour): Select all Collapse
ACTIVATE WINDOW oWnd CENTERED IN 2

The TWindow:Activate() method handles the monitor parameter and centers the window if requested 0-cite-3 .

Monitor Detection

You can check how many monitors are available:

Code (harbour): Select all Collapse
nMonitors := FW_ActiveMonitors()  // Returns number of active monitors

FW_ActiveMonitors() uses GetSysMetrics( SM_CMONITORS ) to get the count 0-cite-4 .

Notes

  • If the second monitor is not available, the window will default to the primary monitor
  • Monitor numbering starts at 1 (primary monitor is typically 1)
  • The TMonitor class provides methods like Center() and Move() for positioning windows 0-cite-5
  • All these functions are located in source/function/getsysin.prg and the monitor handling is integrated into the TWindow:Activate() method in source/classes/window.prg

Wiki pages you might want to explore:

Citations

File: whatsnew.txt (L538-540)

Code (text): Select all Collapse
* Enhanced multi-monitor support:
  ACTIVATE WINDOW/DIALOG [CENTERED] IN onMonitor
  onMonitor can be number of the monitor or monitor object.

File: source/function/getsysin.prg (L427-428)

Code (text): Select all Collapse
function FW_ActiveMonitors()
return GetSysMetrics( SM_CMONITORS )

File: source/function/getsysin.prg (L438-452)

Code (text): Select all Collapse
function FW_SetMonitor(...)

   static oMonitor

   local oRet

   oRet  := oMonitor
   if PCOUNT() > 0
      oMonitor := HB_ExecFromArray( "FW_GETMONITOR", HB_AParams() )
      if oMonitor:lPrimary
         oMonitor  := nil
      endif
   endif

return oRet

File: source/function/getsysin.prg (L456-486)

Code (text): Select all Collapse
function FW_GetMonitor( nRow, nCol )  // POINT r,c [OR] nMonitor, [or] oWnd/hWnd No params: primary monitor

   local aInfo, oMonitor, nMax

   if nRow == nil .and. nCol == nil
      oMonitor   := TMonitor():New( MonitorInfoFromRC( 20, 20 ) )
   elseif HB_ISNUMERIC( nRow ) .and. HB_ISNUMERIC( nCol )
      aInfo       := MonitorInfoFromRC( nRow, nCol )
      if !Empty( aInfo )
         oMonitor := TMonitor():New( aInfo )
      endif
   elseif PCount() == 1
      if HB_ISOBJECT( nRow ) .and. nRow:IsKindOf( "TWINDOW" )
         nRow     := nRow:hWnd
      endif
      if ValType( nRow ) != "N"
         nRow     := 1
      endif
      if IsWindow( nRow )
         aInfo    := MonitorInfoFromRC( nRow )
         if aInfo != nil
            oMonitor := TMonitor():New( aInfo )
         endif
      else
         nMax  := Max( 1, Min( nRow, FW_ActiveMonitors() ) )
         oMonitor := FW_GetAllMonitors()[ nMax ]
      endif

   endif

return oMonitor

File: source/function/getsysin.prg (L563-584)

Code (text): Select all Collapse
CLASS TMonitor STATIC FROM TRect

   DATA ClientRect
   DATA lPrimary

   METHOD New( aInfo ) CONSTRUCTOR
   METHOD Move( oWnd )
   METHOD Center( oWnd )
   METHOD Row( r )   INLINE ( ::nTop  + r )
   METHOD Col( c )   INLINE ( ::nLeft + c )

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( aInfo ) CLASS TMonitor

   ::Super:New( aInfo[ 1 ], aInfo[ 2 ], aInfo[ 3 ], aInfo[ 4 ] )
   ::ClientRect:= TRect():New( aInfo[ 5 ], aInfo[ 6 ], aInfo[ 7 ], aInfo[ 8 ] )
   ::lPrimary  := aInfo[ 9 ]

return Self

File: source/classes/window.prg (L1038-1170)

Code (text): Select all Collapse
METHOD Activate( cShow, bLClicked, bRClicked, bMoved, bResized, bPainted,;
                 bKeyDown, bInit, bUp, bDown, bPgUp, bPgDown,;
                 bLeft, bRight, bPgLeft, bPgRight, bValid, bDropFiles,;
                 bLButtonUp, lCentered, oMonitor ) CLASS TWindow

   local oVScroll, oHScroll

   DEFAULT cShow := "NORMAL", lCentered := .F.

   ( bMoved, bResized, bKeyDown, bInit, bLButtonUp )

   ::nResult     = nil
   ::lValidating = .f.

   DEFAULT oMonitor := FW_SetMonitor()
   if oMonitor != nil
      if HB_ISNUMERIC( oMonitor )
         oMonitor := FW_GetMonitor( oMonitor )
      elseif !( HB_ISOBJECT( oMonitor ) .and. ( oMonitor:IsKindOf( "TMONITOR" ) .or. oMonitor:IsKindOf( "TWINDOW" ) ) )
         oMonitor := nil
      endif
   endif

   if bValid != nil
      ::bValid = bValid
   endif

   if bDropFiles != nil
      ::bDropFiles = bDropFiles
      DragAcceptFiles( ::hWnd, .t. )
   endif

   if bPainted != nil
      if ::IsKindof( "TMDIFRAME" )            // for "CLASS MyApp FROM TMdiFrame"
         ::oWndClient:bPainted = bPainted
      else
         ::bPainted  = bPainted
      endif
   endif

   if bLClicked != nil
      if ::IsKindof( "TMDIFRAME" )
         ::oWndClient:bLClicked = bLClicked
      else
         ::bLClicked = bLClicked
      endif
   endif

   if bRClicked != nil
      if ::IsKindof( "TMDIFRAME" )
         ::oWndClient:bRClicked = bRClicked
      else
         ::bRClicked = bRClicked
      endif
   endif

   // For WS_VSCROLL and WS_HSCROLL styles

   if ::IsKindof( "TMDIFRAME" )
      oVScroll = ::oWndClient:oVScroll
      oHScroll = ::oWndClient:oHScroll
   else
      oVScroll = ::oVScroll
      oHScroll = ::oHScroll
   endif

   if oVScroll != nil       // When using VSCROLL clause
      if bUp != nil
         oVScroll:bGoUp = bUp
      else
         if ::IsKindof( "TMDIFRAME" )
            oVScroll:bGoUp = { || ScrollWindow( ::oWndClient:hWnd, 0, 20, 0, GetClientRect( ::oWndClient:hWnd ) ) }
         endif
      endif
      if bDown != nil
         oVScroll:bGoDown = bDown
      else
         if ::IsKindof( "TMDIFRAME" )
            oVScroll:bGoDown = { || ScrollWindow( ::oWndClient:hWnd, 0, -20, 0, GetClientRect( ::oWndClient:hWnd ) ) }
         endif
      endif
      if bPgUp != nil
         oVScroll:bPageUp = bPgUp
      endif
      if bPgDown != nil
         oVScroll:bPageDown = bPgDown
      endif
   endif

   if oHScroll != nil       // When using HSCROLL clause
      if bLeft != nil
         oHScroll:bGoUp = bLeft
      else
         if ::IsKindof( "TMDIFRAME" )
            oHScroll:bGoUp = { || ScrollWindow( ::oWndClient:hWnd, 20, 0, 0, GetClientRect( ::oWndClient:hWnd ) ), ReleaseCapture() }
         endif
      endif
      if bRight != nil
         oHScroll:bGoDown = bRight
      else
         if ::IsKindof( "TMDIFRAME" )
            oHScroll:bGoDown = { || ScrollWindow( ::oWndClient:hWnd, -20, 0, 0, GetClientRect( ::oWndClient:hWnd ) ), ReleaseCapture() }
         endif
      endif
      if bPgLeft != nil
         oHScroll:bPageUp = bPgLeft
      endif
      if bPgRight != nil
         oHScroll:bPageDown = bPgRight
      endif
   endif

   ::AEvalWhen()

   if ! lWRunning()
      SetWndApp( ::hWnd )
   endif

   if ::bInit != nil
      Eval( ::bInit, Self )
   endif

   ::Resize( 0, ::nWidth, ::nHeight )

   if lCentered
      if oMonitor == nil
         ::Center()
      else
         WndCenterEx( ::hWnd, oMonitor )
      endif
   elseif oMonitor != nil .and. oMonitor:IsKindOf( "TMONITOR" )
      oMonitor:Move( Self )
   endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Program open on the second monitor
Posted: Tue Dec 09, 2025 06:09 PM

Thank you, Antonio!

Continue the discussion