Position of Window CENTER ?

Position of Window CENTER ?

Postby Jimmy » Sun Nov 13, 2022 12:56 pm

hi,

i do create Window
Code: Select all  Expand view
  DEFINE WINDOW oASKFORM FROM 0, 0 TO 270, 534 PIXEL
   ...
      @ 150, 010 BUTTON oButton_Start PROMPT "&OK" SIZE 100, 64 PIXEL OF oASKFORM ACTION ...
   ACTIVATE WINDOW oASKFORM CENTER

when ask for for Coordinate
Code: Select all  Expand view
  nTop0    := oParent:nTop
   nLeft0   := oParent:nLeft
   nWidth0  := oParent:nWidth
   nHeight0 := oParent:nHeight

   nTop     := oObj:nTop
   nLeft    := oObj:nLeft
   nWidth   := oObj:nWidth
   nHeight  := oObj:nHeight

i got
SNAPTOCTRL( 1800 ) nTop0 = 0 nLeft0 = 0 nWidth0 = 535 nHeight0 = 271
SNAPTOCTRL( 1801 ) nTop = 150 nLeft = 10 nWidth = 101 nHeight = 65

as you can see oASKFORM Coordinate are still 0, 0 .. but it is CENTER :!:

Question : how get Position when use CENTER :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Position of Window CENTER ?

Postby Antonio Linares » Sun Nov 13, 2022 8:10 pm

Dear Jimmy,

Before calling you code please do:

oParent:CoorsUpdate()
regards, saludos

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

Re: Position of Window CENTER ?

Postby Jimmy » Mon Nov 14, 2022 5:23 am

hi Antonio,
Antonio Linares wrote:oParent:CoorsUpdate()

thx,

i have try it but it does not work :(
still get 0,0

what i´m doing wrong
Code: Select all  Expand view
#include "FiveWin.ch"

PROCEDURE MAIN
LOCAL oWnd, oText_1, oBtn, cFilter := "*.*" + SPACE( 10 )
LOCAL cLog := cFileSetExt( ExeName(), "LOG" )

   FErase(cLog)

    DEFINE WINDOW oWnd FROM 0, 0 TO 150, 200 PIXEL TITLE "Test Snap2Ctrl"
      @ 010, 010 GET oText_1 VAR cFilter SIZE 160, 30 PIXEL OF oWnd
      @ 050, 010 BUTTON oBtn PROMPT "&OK" SIZE 160, 50 PIXEL ACTION( MsgInfo( cFilter ), oWnd:End() ) OF oWnd
#IFDEF __HMG__
   END WINDOW
#ENDIF

   // SetFocus() does not navigate Cursor to Position
   oText_1:Setfocus()
   // SnapToCtrl() should move Cursor to Position
   ACTIVATE WINDOW oWnd ON INIT SnapToCtrl( oWnd, oText_1 ) CENTER

   WinExec( "notepad.exe " + cLog )

RETURN


Code: Select all  Expand view
PROCEDURE SnapToCtrl( oParent, oObj )
LOCAL hWnd, nTop, nLeft, nWidth, nHeight, nCol, nRow
LOCAL nTop0, nLeft0, nWidth0, nHeight0

   oParent:CoorsUpdate()
   SysRefresh()

   hWnd := oObj:hWnd

   nTop0 := oParent:nTop
   nLeft0 := oParent:nLeft
   nWidth0 := oParent:nWidth
   nHeight0 := oParent:nHeight

   nTop := oObj:nTop
   nLeft := oObj:nLeft
   nWidth := oObj:nWidth
   nHeight := oObj:nHeight

   // Center of control
   nRow := nTop0 + nTop + ( nHeight0 / 2 )
   nCol := nLeft0 + nLeft + ( nWidth / 2 )

   SETCURSORPOS( nCol, nRow )

   oObj:Setfocus()

   FWLOG nTop0, nLeft0, nWidth0, nHeight0
   FWLOG nTop, nLeft, nWidth, nHeight
   FWLOG nCol, nRow
RETURN
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Position of Window CENTER ?

Postby Antonio Linares » Mon Nov 14, 2022 7:50 am

Dear Jimmy,

Please review this example:
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   @ 2, 2 BUTTON "Coors" SIZE 80, 20 ACTION XBrowser( { oWnd:nTop, oWnd:nLeft, oWnd:nWidth, oWnd:nHeight } )

   XBrowser( { oWnd:nTop, oWnd:nLeft, oWnd:nWidth, oWnd:nHeight } )

   ACTIVATE WINDOW oWnd CENTER

return nil
regards, saludos

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

Re: Position of Window CENTER ?

Postby Jimmy » Mon Nov 14, 2022 8:45 am

hi Antonio,

thx for Sample
i do understand now that INIT is "before" CENTER is made under Fivewin

so i have to use a "Workaround" with TIMER to "move" Cursor to "default" BUTTON -> next ACTION
Code: Select all  Expand view
#include "FiveWin.ch"
#define EM_SETSEL             0x00B1

PROCEDURE MAIN
LOCAL oWnd, oText_1, oBtn, cFilter := "*.*" + SPACE( 10 )
LOCAL oTimer

    DEFINE WINDOW oWnd FROM 0, 0 TO 150, 200 PIXEL TITLE "Test Snap2Ctrl"
      @ 010, 010 GET oText_1 VAR cFilter SIZE 160, 30 PIXEL OF oWnd
      oText_1:PostMsg( EM_SETSEL, 0, LEN( TRIM( cFilter ) ) )
      @ 050, 010 BUTTON oBtn PROMPT "&OK" SIZE 160, 50 PIXEL ACTION( MsgInfo( cFilter ), oWnd:End() ) OF oWnd
#IFDEF __HMG__
   END WINDOW
#ENDIF

   DEFINE TIMER oTimer INTERVAL 100 ACTION (SnapToCtrl( oWnd, oBtn , oTimer ), oTimer:End() )  OF oWnd
   ACTIVATE TIMER oTimer

   // SetFocus() does not navigate Cursor to Position
   oText_1:Setfocus()
   // SnapToCtrl() should move Cursor to Position
   // does not work at INIT
   ACTIVATE WINDOW oWnd ON INIT SnapToCtrl( oWnd, oBtn , oTimer ) CENTER

RETURN

PROCEDURE SnapToCtrl( oParent, oObj, oTimer )
LOCAL hWnd, nTop, nLeft, nWidth, nHeight, nCol, nRow, aRect
LOCAL nTop0, nLeft0, nWidth0, nHeight0

*   oParent:Setfocus()
*   oParent:Refresh()
*   oParent:CoorsUpdate()
*   SysRefresh()

   hWnd := oObj:hWnd

   nTop0 := oParent:nTop
   nLeft0 := oParent:nLeft
   nWidth0 := oParent:nWidth
   nHeight0 := oParent:nHeight

   nTop := oObj:nTop
   nLeft := oObj:nLeft
   nWidth := oObj:nWidth
   nHeight := oObj:nHeight

   // Center of control
   nRow := nTop0 + nTop + ( nHeight )
   nCol := nLeft0 + nLeft + ( nWidth / 2 )

   SETCURSORPOS( nCol, nRow )

   oObj:Setfocus()

RETURN
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Position of Window CENTER ?

Postby Antonio Linares » Mon Nov 14, 2022 9:28 am

Dear Jimmy,

if you use a dialog instead of a window, the cursor will go automatically to the first focusable control
regards, saludos

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

Re: Position of Window CENTER ?

Postby Jimmy » Mon Nov 14, 2022 11:05 am

hi Antonio,
Antonio Linares wrote:if you use a dialog instead of a window, the cursor will go automatically to the first focusable control

have change WINDOW to DIALOG and oWnd to oDlg but Result look total different :shock:
Image
what i´m doing wrong :?:
Code: Select all  Expand view
#include "FiveWin.ch"
#define EM_SETSEL             0x00B1

PROCEDURE MAIN
LOCAL oDlg, oText_1, oBtn, cFilter := "*.*" + SPACE( 10 )
LOCAL oTimer

    DEFINE DIALOG oDlg FROM 0, 0 TO 150, 200 PIXEL TITLE "Test Snap2Ctrl"
      @ 010, 010 GET oText_1 VAR cFilter SIZE 160, 30 PIXEL OF oDlg
      oText_1:PostMsg( EM_SETSEL, 0, LEN( TRIM( cFilter ) ) )
      @ 050, 010 BUTTON oBtn PROMPT "&OK" SIZE 160, 50 PIXEL ACTION( MsgInfo( cFilter ), oDlg:End() ) OF oDlg
#IFDEF __HMG__
   END DIALOG
#ENDIF
   ACTIVATE DIALOG oDlg CENTER
RETURN

you are right ... but that is NOT what i want

in Sample the Cursor is "in" GET (1st Control see "Marker") ... right ...
but Mouse-Cursor is not "over" BUTTON (for next ACTION) :idea:

what i do is to "move" Mouse-Cursor over BUTTON so i must not "move" my Mouse "to" BUTTON just "click"
please try my Workaround Sample (using TIMER) to "see" Effect

p.s. i use a Trackball because my wrist causes problems with the mouse after long use
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Position of Window CENTER ?

Postby Antonio Linares » Mon Nov 14, 2022 11:19 am

Dear Jimmy

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

#define EM_SETSEL             0x00B1

PROCEDURE MAIN

   local oDlg, oText_1, oBtn, cFilter := "*.*" + SPACE( 10 )

   DEFINE DIALOG oDlg FROM 0, 0 TO 150, 200 PIXEL TITLE "Test Snap2Ctrl"

   @ 010, 010 GET oText_1 VAR cFilter SIZE oDlg:nWidth - 120, 10 PIXEL OF oDlg

   @ 050, 010 BUTTON oBtn PROMPT "&OK" SIZE oDlg:nWidth - 120, 20 PIXEL ACTION( MsgInfo( cFilter ), oDlg:End() ) OF oDlg

   ACTIVATE DIALOG oDlg CENTER ON INIT ( oText_1:PostMsg( EM_SETSEL, 0, Len( Trim( cFilter ) ) ), oBtn:SetFocus(), .F. )

RETURN
regards, saludos

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

Re: Position of Window CENTER ?

Postby Jimmy » Mon Nov 14, 2022 12:24 pm

hi Antonio,

Ok, i have much to learn, thx

now it look OK but "handling" is not "exact" what i mean

a.) Use click "OK"
b.) User change "any" Selection (need Focus), most using TAB to navigate in a Window Form
and "click" while Mouse Cursor stay "over" BUTTON to "save"

so Mouse Cursor is not the same as SetFocus() to BUTTON

p.s. under DOS i have use F10 to "save" from any GET Position, later with Hot-Key

---

i want to simulate this Windows OS Setting in App
Image

please try my Workaround Sample how Mouse Cursor "move" to BUTTON
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Position of Window CENTER ?

Postby Antonio Linares » Mon Nov 14, 2022 2:39 pm

Dear Jimmy,

FWH SetCursorPos() lets you place the mouse pointer where desired:

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setcursorpos
regards, saludos

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

Re: Position of Window CENTER ?

Postby Jimmy » Mon Nov 14, 2022 3:10 pm

hi Antonio,
Antonio Linares wrote:FWH SetCursorPos() lets you place the mouse pointer where desired:

YES, this is what i´m doing in PROCEDURE SnapToCtrl() of 1st full Sample

but i must use a TIMER instead of INIT to call SnapToCtrl() while else i got wrong (Original) Position before CENTER
as i have a Workaround so no Problem any more
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 97 guests