Msgbox centered on the window

Re: Msgbox centered on the window

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

Re: Msgbox centered on the window

Postby Antonio Linares » 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: Select all  Expand view
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
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Msgbox centered on the window

Postby Massimo Linossi » Mon Jul 20, 2015 4:15 pm

You're great !!!
Compliments
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 » Mon Jul 20, 2015 4: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Msgbox centered on the window

Postby groiss » Mon Jul 20, 2015 4: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
groiss
 
Posts: 224
Joined: Tue Sep 01, 2009 7:55 am
Location: Plasencia - ESPAÑA

Re: Msgbox centered on the window

Postby Antonio Linares » Mon Jul 20, 2015 5:16 pm

Te acabo de enviar un email con las indicaciones
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: Msgbox centered on the window

Postby Patricio Avalos Aguirre » Tue Jul 21, 2015 7: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
User avatar
Patricio Avalos Aguirre
 
Posts: 1060
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile

Re: Msgbox centered on the window

Postby nageswaragunupudi » Tue Jul 21, 2015 9:38 am

Mr Antonio

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10639
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Msgbox centered on the window

Postby Antonio Linares » Tue Jul 21, 2015 11:46 am

Yes, thats an option too
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

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 40 guests