Msgbox centered on the window

Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: Msgbox centered on the window

Post by Horizon »

Antonio Linares wrote:Hakan,

Just once at the beginning of your app.

And we should remove the hook before the app quits
How?

what about the my error result of 15.06?
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Msgbox centered on the window

Post by Antonio Linares »

Hakan,

http://forums.fivetechsupport.com/viewt ... 14#p179714

I am going to review how to implement it
regards, saludos

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

Re: Msgbox centered on the window

Post by Antonio Linares »

This is the final version to be included in FWH 15.07:

Please call UNHOOKWINDOWSHOOKEX() before exiting the app

Code: Select all

static HHOOK hHook = NULL;

static void CenterWindowOnParent( HWND hChildWnd )
{
   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 );            
   }        
    
   return 0; // allow normal processing
}

HINSTANCE GetInstance( void );

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

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

HB_FUNC( UNHOOKWINDOWSHOOKEX )
{
   if( hHook )
   {    
      hb_retl( UnhookWindowsHookEx( hHook ) );
      hHook = NULL;
   }        
   else
      hb_retl( 0 ); 
}

//------------------------------------------------------------------------//
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Massimo Linossi
Posts: 474
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: Msgbox centered on the window

Post by Massimo Linossi »

You're great !!!
Compliments
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Msgbox centered on the window

Post by Antonio Linares »

These new functions have been already included in FWH 15.06 build 2 that it is available for download :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
groiss
Posts: 206
Joined: Tue Sep 01, 2009 7:55 am
Location: Plasencia - ESPAÑA

Re: Msgbox centered on the window

Post by groiss »

Antonio:
Y ¿ Cómo se podría conseguir la versión 7 del borland c?. Debe tener truco porque por mas que la busco por embarcadero no la consigo.
Gracias.
Saludos
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Msgbox centered on the window

Post by Antonio Linares »

Te acabo de enviar un email con las indicaciones
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Patricio Avalos Aguirre
Posts: 1028
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile
Contact:

Re: Msgbox centered on the window

Post by Patricio Avalos Aguirre »

hola Antonio favor enviarme el link
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Msgbox centered on the window

Post by nageswaragunupudi »

Mr Antonio

What if window.prg has an EXIT PROCEDURE calling UNHOOKWINDOWSHOOKEX() ?
Regards

G. N. Rao.
Hyderabad, India
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Msgbox centered on the window

Post by Antonio Linares »

Yes, thats an option too
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply