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
Marco Turco
SOFTWARE XP LLP
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
ACTIVATE DIALOG oDlgInfo ;
ON INIT oDlgInfo:Center( oApp():oWndMain )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.
Marco,
I've the msgbox functions redefined based on dialogs, and for this runs ok in my programs.
Regards,
Hello Josè.
I have the same problem of Marco. Is possible to see your functions ?
Thanks a lot.
Massimo
It would be great.
Thanks Antonio.
#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#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oWnd
DEFINE WINDOW oWnd
CenterMsgs()
ACTIVATE WINDOW oWnd ;
ON CLICK MsgInfo( "Hello world" )
return nilstatic 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() );
}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() );
}Antonio Linares wrote:Ok, this one seems to be working fine
Still we need to implement a function to remove the hook.
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() ); }


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.
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() ); }
Hi,
Should we call CenterMsgs() function just in main window or should we call before every MsgInfo function?
Hakan,
Just once at the beginning of your app.
And we should remove the hook before the app quits