FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Msgbox centered on the window
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Msgbox centered on the window
Posted: Sun Nov 06, 2011 03:39 PM

Hi all,
I need to center the msgbox (example: Msginfo, MsgNoYes etc.) automatically on my windows instead of the screen.
I tried SetCenterOnParent(.t.) but this runs only for dialogs.

Any solution ? Thanks in advance

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 564
Joined: Thu Oct 13, 2005 09:23 AM
Re: Msgbox centered on the window
Posted: Mon Nov 07, 2011 07:34 AM
Use this code:

Code (fw): Select all Collapse
   ACTIVATE DIALOG oDlgInfo ;
      ON INIT oDlgInfo:Center( oApp():oWndMain )


where oDlgInfo is your dialog and oApp():oWndMain the main window of the application.

Regards,
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Msgbox centered on the window
Posted: Tue Nov 08, 2011 12:53 PM

Hi José,
your solution runs only with dialogs not with the msgbox functions.
The only running solution I have found is to make new function dialogs based for the msgbox functions.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 564
Joined: Thu Oct 13, 2005 09:23 AM
Re: Msgbox centered on the window
Posted: Tue Nov 08, 2011 09:26 PM

Marco,
I've the msgbox functions redefined based on dialogs, and for this runs ok in my programs.
Regards,

Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Msgbox centered on the window
Posted: Sun Jul 19, 2015 03:22 PM

Hello Josè.
I have the same problem of Marco. Is possible to see your functions ?
Thanks a lot.
Massimo

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Sun Jul 19, 2015 05:56 PM
Here there is some code that we could try to adapt to FWH:

http://vbnet.mvps.org/index.html?code/hooks/messageboxhookcentre.htm
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Msgbox centered on the window
Posted: Sun Jul 19, 2015 06:13 PM

It would be great.
Thanks Antonio.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Sun Jul 19, 2015 10:27 PM
This is already working

Code (fw): Select all Collapse
#pragma BEGINDUMP

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

LRESULT CALLBACK MsgBoxHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
   if( nCode == HCBT_ACTIVATE )
   {
      HWND hWndMsgBox = wParam;
      
      SetWindowText( hWndMsgBox, "It works" );      
   }        
    
   return 0; // allow normal processing
}

HINSTANCE GetInstance( void );

HB_FUNC( CENTERMSGS )
{
   hb_retptr( ( void * ) SetWindowsHookEx( WH_CBT,  
                                MsgBoxHookProc, GetInstance(), 
                                GetCurrentThreadId() ) );
}

#pragma ENDDUMP


Now we need to find a way to locate the active window. I guess that the idea is to set this for the entire app.

Here you have an example:
Code (fw): Select all Collapse
#include "FiveWin.ch"

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

function Main()

   local oWnd

   DEFINE WINDOW oWnd
   
   CenterMsgs()
    
   ACTIVATE WINDOW oWnd ;
      ON CLICK  MsgInfo( "Hello world" )
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Sun Jul 19, 2015 11:05 PM
In this version we are already able to move the Msg... window:

Code (fw): Select all Collapse
static HHOOK hHook = NULL;

LRESULT CALLBACK MsgBoxHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
   if( nCode < 0 )  // do not process message 
        return CallNextHookEx( hHook, nCode, wParam, lParam ); 

   if( nCode == HCBT_CREATEWND )
   {
      HWND hWndMsgBox = wParam; 
      char cn[ 200 ];
            
      GetClassName( hWndMsgBox, cn, 199 );      

      if( cn[ 0 ] == '#' &&
          cn[ 1 ] == '3' &&
          cn[ 2 ] == '2' &&
          cn[ 3 ] == '7' &&
          cn[ 4 ] == '7' &&
          cn[ 5 ] == '0' &&
          cn[ 6 ] == 0 )
      {     
         ( ( CBT_CREATEWND * ) lParam )->lpcs->x = 50;
         ( ( CBT_CREATEWND * ) lParam )->lpcs->y = 50;
      }             
   }        
   
   return 0; // allow normal processing
}

HINSTANCE GetInstance( void );

HB_FUNC( CENTERMSGS )
{
   hHook = SetWindowsHookEx( WH_CBT,  
                             MsgBoxHookProc, GetInstance(), 
                             GetCurrentThreadId() );
}


Still we need to get the handle of the parent window
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Sun Jul 19, 2015 11:53 PM
Ok, this one seems to be working fine :-)

Still we need to implement a function to remove the hook.

Code (fw): Select all Collapse
static HHOOK hHook = NULL;

static void CenterWindowOnParent( HWND hChildWnd, LPARAM lParam )
{
   HWND hParent = GetParent( hChildWnd );
   RECT rcChild, rcParent;
   int cxChild, cyChild, cxParent, cyParent;

   GetWindowRect( hChildWnd, &rcChild );
   GetWindowRect( hParent, &rcParent );

   cxChild = rcChild.right - rcChild.left;
   cyChild = rcChild.bottom - rcChild.top;
   cxParent = rcParent.right - rcParent.left;
   cyParent = rcParent.bottom - rcParent.top;
   
   SetWindowPos( hChildWnd, NULL, 
               rcParent.left + ( cxParent - cxChild ) / 2, 
                 rcParent.top + ( cyParent - cyChild ) / 2, 0, 0, 0x15 );       
}

LRESULT CALLBACK MsgBoxHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
   if( nCode < 0 )  // do not process message 
        return CallNextHookEx( hHook, nCode, wParam, lParam ); 

   if( nCode == HCBT_ACTIVATE )
   {
      HWND hWndMsgBox = ( HWND ) wParam;    
      char cn[ 200 ];
            
      GetClassName( hWndMsgBox, cn, 199 );      

      if( cn[ 0 ] == '#' &&
          cn[ 1 ] == '3' &&
          cn[ 2 ] == '2' &&
          cn[ 3 ] == '7' &&
          cn[ 4 ] == '7' &&
          cn[ 5 ] == '0' &&
          cn[ 6 ] == 0 )
         CenterWindowOnParent( hWndMsgBox, lParam );            
   }        
    
   return 0; // allow normal processing
}

HINSTANCE GetInstance( void );

HB_FUNC( CENTERMSGS )
{
   hHook = SetWindowsHookEx( WH_CBT,  
                             MsgBoxHookProc, GetInstance(), 
                             GetCurrentThreadId() );
}


regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 03:48 AM
Dear Antonio,

The theme (Dialog, MsgBox) is so nice. Is this Win8 theme or standard screen? If so, can we make it the screen on other Windows version such as Win7 or WinXP.
Antonio Linares wrote:Ok, this one seems to be working fine :-)

Still we need to implement a function to remove the hook.

Code (fw): Select all Collapse
static HHOOK hHook = NULL;

static void CenterWindowOnParent( HWND hChildWnd, LPARAM lParam )
{
   HWND hParent = GetParent( hChildWnd );
   RECT rcChild, rcParent;
   int cxChild, cyChild, cxParent, cyParent;

   GetWindowRect( hChildWnd, &rcChild );
   GetWindowRect( hParent, &rcParent );

   cxChild = rcChild.right - rcChild.left;
   cyChild = rcChild.bottom - rcChild.top;
   cxParent = rcParent.right - rcParent.left;
   cyParent = rcParent.bottom - rcParent.top;
   
   SetWindowPos( hChildWnd, NULL, 
               rcParent.left + ( cxParent - cxChild ) / 2, 
                 rcParent.top + ( cyParent - cyChild ) / 2, 0, 0, 0x15 );       
}

LRESULT CALLBACK MsgBoxHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
   if( nCode < 0 )  // do not process message 
        return CallNextHookEx( hHook, nCode, wParam, lParam ); 

   if( nCode == HCBT_ACTIVATE )
   {
      HWND hWndMsgBox = ( HWND ) wParam;    
      char cn[ 200 ];
            
      GetClassName( hWndMsgBox, cn, 199 );      

      if( cn[ 0 ] == '#' &&
          cn[ 1 ] == '3' &&
          cn[ 2 ] == '2' &&
          cn[ 3 ] == '7' &&
          cn[ 4 ] == '7' &&
          cn[ 5 ] == '0' &&
          cn[ 6 ] == 0 )
         CenterWindowOnParent( hWndMsgBox, lParam );            
   }        
    
   return 0; // allow normal processing
}

HINSTANCE GetInstance( void );

HB_FUNC( CENTERMSGS )
{
   hHook = SetWindowsHookEx( WH_CBT,  
                             MsgBoxHookProc, GetInstance(), 
                             GetCurrentThreadId() );
}


Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 06:20 AM
I needed a solution, to display different messages
on any defined position and with any style ( color,brush, gradient, font, icon .... )

the sample shows a message displayed on left upper corner on button-action



MYMSGBOX( .T., { 100, 50, 100, 300 }, ; // .F. = center
"< " + ALLTRIM(STR( nMenge1 )) + " > Patient(en) mit" + CRLF + ;
"< " + ALLTRIM(STR( nMenge2 )) + " > Verordnungen geprüft " + CRLF + ;
" " + CRLF + ;
"< " + ALLTRIM(STR( nMenge3 )) + " > Fehler gefunden", ;
{"&Weiter"}, "VERORDNUNGS-PRÜFUNG", "A", 1, ;
{{ nDColorB, nDColorB, nDColorB, nDColorB }}, , , , ;
oFontSys, aVal[27], c_Pfad1 + "Info1.bmp" )


YES / NO centered



DO WHILE nOpt = 0
nOpt := MYMSGBOX( .F., { 10, 10, 100, 300 }, ;
"Wollen Sie den Monat : " + cNach + CRLF + ;
"neu aufbauen ?", ;
{"&Aufbau","A&bbruch"}, ;
"MONATSÜBERNAHME", ;
"O", 1, ;
{{ nDColorB, nDColorB, nDColorB, nDColorB }}, , , , ;
oFontSys, aVal[27], c_Pfad1 + "Sort.bmp" )
ENDDO

IF nOpt = 1
....
....


best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 07:35 AM
Dutch,

I am using Windows 10 :-)

dutch wrote:Dear Antonio,

The theme (Dialog, MsgBox) is so nice. Is this Win8 theme or standard screen? If so, can we make it the screen on other Windows version such as Win7 or WinXP.
Antonio Linares wrote:Ok, this one seems to be working fine :-)

Still we need to implement a function to remove the hook.

Code (fw): Select all Collapse
static HHOOK hHook = NULL;

static void CenterWindowOnParent( HWND hChildWnd, LPARAM lParam )
{
   HWND hParent = GetParent( hChildWnd );
   RECT rcChild, rcParent;
   int cxChild, cyChild, cxParent, cyParent;

   GetWindowRect( hChildWnd, &rcChild );
   GetWindowRect( hParent, &rcParent );

   cxChild = rcChild.right - rcChild.left;
   cyChild = rcChild.bottom - rcChild.top;
   cxParent = rcParent.right - rcParent.left;
   cyParent = rcParent.bottom - rcParent.top;
   
   SetWindowPos( hChildWnd, NULL, 
               rcParent.left + ( cxParent - cxChild ) / 2, 
                 rcParent.top + ( cyParent - cyChild ) / 2, 0, 0, 0x15 );       
}

LRESULT CALLBACK MsgBoxHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
   if( nCode < 0 )  // do not process message 
        return CallNextHookEx( hHook, nCode, wParam, lParam ); 

   if( nCode == HCBT_ACTIVATE )
   {
      HWND hWndMsgBox = ( HWND ) wParam;    
      char cn[ 200 ];
            
      GetClassName( hWndMsgBox, cn, 199 );      

      if( cn[ 0 ] == '#' &&
          cn[ 1 ] == '3' &&
          cn[ 2 ] == '2' &&
          cn[ 3 ] == '7' &&
          cn[ 4 ] == '7' &&
          cn[ 5 ] == '0' &&
          cn[ 6 ] == 0 )
         CenterWindowOnParent( hWndMsgBox, lParam );            
   }        
    
   return 0; // allow normal processing
}

HINSTANCE GetInstance( void );

HB_FUNC( CENTERMSGS )
{
   hHook = SetWindowsHookEx( WH_CBT,  
                             MsgBoxHookProc, GetInstance(), 
                             GetCurrentThreadId() );
}


regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 09:23 AM

Hi,

Should we call CenterMsgs() function just in main window or should we call before every MsgInfo function?

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 09:35 AM

Hakan,

Just once at the beginning of your app.

And we should remove the hook before the app quits

regards, saludos

Antonio Linares
www.fivetechsoft.com