Msgbox centered on the window

Msgbox centered on the window

Postby Marco Turco » Sun Nov 06, 2011 3: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Msgbox centered on the window

Postby José Luis Sánchez » Mon Nov 07, 2011 7:34 am

Use this code:

Code: Select all  Expand view  RUN
  ACTIVATE DIALOG oDlgInfo ;
      ON INIT oDlgInfo:Center( oApp():oWndMain )


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

Regards,
User avatar
José Luis Sánchez
 
Posts: 556
Joined: Thu Oct 13, 2005 9:23 am
Location: Novelda - Alicante - España

Re: Msgbox centered on the window

Postby Marco Turco » 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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Msgbox centered on the window

Postby José Luis Sánchez » Tue Nov 08, 2011 9:26 pm

Marco,
I've the msgbox functions redefined based on dialogs, and for this runs ok in my programs.
Regards,
User avatar
José Luis Sánchez
 
Posts: 556
Joined: Thu Oct 13, 2005 9:23 am
Location: Novelda - Alicante - España

Re: Msgbox centered on the window

Postby Massimo Linossi » Sun Jul 19, 2015 3:22 pm

Hello Josè.
I have the same problem of Marco. Is possible to see your functions ?
Thanks a lot.
Massimo
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: Msgbox centered on the window

Postby Antonio Linares » Sun Jul 19, 2015 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Msgbox centered on the window

Postby Massimo Linossi » Sun Jul 19, 2015 6:13 pm

It would be great.
Thanks Antonio.
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: Msgbox centered on the window

Postby Antonio Linares » Sun Jul 19, 2015 10:27 pm

This is already working

Code: Select all  Expand view  RUN

#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: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Msgbox centered on the window

Postby Antonio Linares » Sun Jul 19, 2015 11:05 pm

In this version we are already able to move the Msg... window:

Code: Select all  Expand view  RUN
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Msgbox centered on the window

Postby Antonio Linares » 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: Select all  Expand view  RUN
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() );
}
 


Image
regards, saludos

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

Re: Msgbox centered on the window

Postby dutch » Mon Jul 20, 2015 3: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: Select all  Expand view  RUN
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() );
}
 


Image
Regards,
Dutch

FWH 19.01 / 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)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Msgbox centered on the window

Postby ukoenig » Mon Jul 20, 2015 6: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

Image

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

Image

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 :)
Last edited by ukoenig on Mon Jul 20, 2015 12:16 pm, edited 1 time in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Msgbox centered on the window

Postby Antonio Linares » Mon Jul 20, 2015 7: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: Select all  Expand view  RUN
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() );
}
 


Image
regards, saludos

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

Re: Msgbox centered on the window

Postby Horizon » Mon Jul 20, 2015 9: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.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Msgbox centered on the window

Postby Antonio Linares » Mon Jul 20, 2015 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 47 guests