MsgRun()-Question

MsgRun()-Question

Postby byte-one » Sat May 06, 2017 10:57 am

Is it possible the position of MsgRun() center on parent? Now is centered on Screen.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby Antonio Linares » Sat May 06, 2017 11:09 am

Günther,

We could add a new parameter to MsgRun()

function MsgRun( cCaption, cTitle, bAction, oWndParent )

and then in its code add this:
Code: Select all  Expand view
    IF cTitle == NIL
          DEFINE DIALOG oDlg OF oWndParent ;
               FROM 0,0 TO 3, Len( cCaption ) + 4 ;
               STYLE nOr( DS_MODALFRAME, WS_POPUP )
     ELSE
          DEFINE DIALOG oDlg OF oWndParent ;
               FROM 0,0 TO 4, Max( Len( cCaption ), Len( cTitle ) ) + 4 ;
               TITLE cTitle ;
               STYLE DS_MODALFRAME
     ENDIF
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: MsgRun()-Question

Postby byte-one » Sat May 06, 2017 12:33 pm

Antonio, that would be very helpful and should be default!!.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby Antonio Linares » Sun May 07, 2017 9:39 am

Finally implemented this way. It will be included in FWH 17.05

Code: Select all  Expand view
function MsgRun( cCaption, cTitle, bAction, oWndParent )

     LOCAL oDlg, nWidth, uReturn

     DEFAULT cCaption := "Please, wait...",;
             bAction  := { || WaitSeconds( 1 ) }

     IF cTitle == NIL
          DEFINE DIALOG oDlg ;
               FROM 0,0 TO 3, Len( cCaption ) + 4 ;
               STYLE nOr( DS_MODALFRAME, WS_POPUP )
     ELSE
          DEFINE DIALOG oDlg ;
               FROM 0,0 TO 4, Max( Len( cCaption ), Len( cTitle ) ) + 4 ;
               TITLE cTitle ;
               STYLE DS_MODALFRAME
     ENDIF

     oDlg:bStart := { || uReturn := Eval( bAction, oDlg ), oDlg:End(), SysRefresh() }
     oDlg:cMsg   := cCaption

     nWidth := oDlg:nRight - oDlg:nLeft

     ACTIVATE DIALOG oDlg ON PAINT oDlg:SayText( oDlg:cMsg ) ;
        ON INIT oDlg:Center( oWndParent )

return uReturn


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

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Move the window and left click on it"

   ACTIVATE WINDOW oWnd ;
      ON CLICK MsgRun( "MsgRun() messages are optionally centered", "In FWH 17.05", { || MsgInfo( "ok" ) }, oWnd )
   
return nil


Image
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: MsgRun()-Question

Postby byte-one » Sun May 07, 2017 10:36 am

Antonio, thanks!
Should also MsgInfo() centered on parent, if desired?
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby Antonio Linares » Sun May 07, 2017 2:43 pm

Not sure if we can:

http://stackoverflow.com/questions/6299797/c-how-to-center-messagebox

Code: Select all  Expand view
case WM_NOTIFY:{
  HWND X=FindWindow("#32770",NULL);
  if(GetParent(X)==H_frame){int Px,Py,Sx,Sy; RECT R1,R2;
    GetWindowRect(hwnd,&R1); GetWindowRect(X,&R2);
    Sx=R2.right-R2.left,Px=R1.left+(R1.right-R1.left)/2-Sx/2;
    Sy=R2.bottom-R2.top,Py=R1.top+(R1.bottom-R1.top)/2-Sy/2;
    MoveWindow(X,Px,Py,Sx,Sy,1);
  }
} break;
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: MsgRun()-Question

Postby byte-one » Sun May 07, 2017 7:43 pm

Antonio, for MsgRun() i use this code:
Code: Select all  Expand view
ACTIVATE DIALOG oDlg ON PAINT oDlg:SayText( oDlg:cMsg ) ;
    ON INIT WndCenter( oDlg:hWnd ,GetActiveWindow() )

So automatically center on the caller-window!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby Antonio Linares » Mon May 08, 2017 5:31 am

I think this is a better code:

ACTIVATE DIALOG oDlg ON PAINT oDlg:SayText( oDlg:cMsg ) ;
ON INIT oDlg:Center( oWndParent )

sometimes GetActiveWindow() may return a window that does not belong to our app
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: MsgRun()-Question

Postby byte-one » Wed May 10, 2017 9:31 am

Antonio, ok!
On my tests with this function, i noticed a different look if the STYLE nOr( DS_MODALFRAME, WS_POPUP ) or STYLE DS_MODALFRAME and the clausula GRADIENT are using.
It seems that the caption (and maybe also the msgbar) not included in the calculation of the client area!?

Code: Select all  Expand view
aGrad := {{0.5,CLR_HRED,CLR_WHITE},{0.5,CLR_WHITE,CLR_HRED}}
IF cTitle == NIL
    DEFINE DIALOG oDlg GRADIENT aGrad FONT oFont ;
        FROM 0,0 TO 3, Len( cCaption ) + 4 ;
        STYLE nOr( DS_MODALFRAME, WS_POPUP )
ELSE
    DEFINE DIALOG oDlg GRADIENT aGrad FONT oFont;
        FROM 0,0 TO 4, Max( Len( cCaption ), Len( cTitle ) ) + 4 ;
        TITLE cTitle ;
        STYLE DS_MODALFRAME
ENDIF
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby Antonio Linares » Wed May 10, 2017 4:08 pm

Günther,

Please provide a screenshot, 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: MsgRun()-Question

Postby byte-one » Thu May 11, 2017 9:11 am

Antonio, gradient should be half/half!
aGrad := {{0.5,METRO_ORANGE,CLR_WHITE},{0.5,CLR_WHITE,METRO_ORANGE}}

http://byte-one.com/snip_1.png
http://byte-one.com/snip_2.png
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby Antonio Linares » Thu May 11, 2017 10:20 am

Try it this way:

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

function Main()

   local oWnd

   SetDlgGradient( { {0.30,CLR_HRED,CLR_WHITE}, {0.70,CLR_WHITE,CLR_HRED} } )

   DEFINE WINDOW oWnd TITLE "Move the window and left click on it"

   ACTIVATE WINDOW oWnd ;
      ON CLICK MsgRun( "MsgRun() messages are optionally centered", "In FWH 17.05", { || MsgInfo( "ok" ) }, oWnd )
   
return nil


We may be changing the dimensions of the dialog once the brush has been created. Trying to find out where we do that.

Image
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: MsgRun()-Question

Postby byte-one » Sun May 14, 2017 7:02 pm

In METHOD Gradient( aGradColors ) CLASS TWindow should be respected the real client-area (without caption, etc..) not the height and width from full window/dialog
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby byte-one » Mon May 15, 2017 4:02 pm

I have changed the code in CLASS TWindow. It seems, now is better.

Code: Select all  Expand view
METHOD Gradient( aGradColors ) CLASS TWindow
   #define SM_CYCAPTION 4
   #define SM_CYFRAME   32
   
   local hDC, hBmp, hBmpOld, lCaption := lAnd(::nStyle,WS_CAPTION) .or. !lAnd(::nStyle,WS_POPUP), nHeight_korr := if(lCaption,GetSysMetrics( SM_CYCAPTION ),0) + GetSysMetrics( SM_CYFRAME )/2

   DEFAULT aGradColors := ::aGradColors

   if aGradColors == nil
      return nil
   endif

   hDC = CreateCompatibleDC( ::GetDC() )
   hBmp = CreateCompatibleBitMap( ::hDC, ::nWidth, ::nHeight - nHeight_korr )
   hBmpOld = SelectObject( hDC, hBmp )

   GradientFill( hDC, 0, 0, ::nHeight - nHeight_korr, ::nWidth, aGradColors )

   if ::oBrush != nil
      ::oBrush:End()
   endif

   ::oBrush = TBrush():New()
   ::oBrush:hBitmap = hBmp
   ::oBrush:hBrush = CreatePatternBrush( hBmp )

   SelectObject( hDC, hBmpOld )

   ::ReleaseDC()

return nil
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: MsgRun()-Question

Postby byte-one » Mon Jul 24, 2017 9:38 am

Now is respecting the real ClientArea!

Code: Select all  Expand view
  local hDC, hBmp, hBmpOld, aClient := GetClientRect(::hWnd), nHeight := aClient[3]-aClient[1], nWidth := aClient[4]-aClient[2]

   DEFAULT aGradColors := ::aGradColors

   if aGradColors == nil
      return nil
   endif

   hDC = CreateCompatibleDC( ::GetDC() )
   hBmp = CreateCompatibleBitMap( ::hDC, nWidth, nHeight )
   hBmpOld = SelectObject( hDC, hBmp )

   GradientFill( hDC, 0, 0, nHeight, nWidth, aGradColors )

   if ::oBrush != nil
      ::oBrush:End()
   endif

   ::oBrush = TBrush():New()
   ::oBrush:hBitmap = hBmp
   ::oBrush:hBrush = CreatePatternBrush( hBmp )

   SelectObject( hDC, hBmpOld )

   ::ReleaseDC()

return nil
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 56 guests