FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Msgbox centered on the window
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 09:38 AM
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 & 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 10:00 AM

Hakan,

viewtopic.php?p=179714#p179714

I am going to review how to implement it

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 10:26 AM
This is the final version to be included in FWH 15.07:

Please call UNHOOKWINDOWSHOOKEX() before exiting the app

Code (fw): Select all Collapse
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
Posts: 512
Joined: Mon Oct 17, 2005 10:38 AM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 04:15 PM

You're great !!!
Compliments

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 04:34 PM

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
Posts: 234
Joined: Tue Sep 01, 2009 07:55 AM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 04:57 PM

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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Mon Jul 20, 2015 05:16 PM

Te acabo de enviar un email con las indicaciones

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1074
Joined: Fri Oct 07, 2005 01:56 PM
Re: Msgbox centered on the window
Posted: Tue Jul 21, 2015 07:36 AM

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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Msgbox centered on the window
Posted: Tue Jul 21, 2015 09:38 AM

Mr Antonio

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Msgbox centered on the window
Posted: Tue Jul 21, 2015 11:46 AM

Yes, thats an option too

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion