Msgbox centered on the window
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Msgbox centered on the window
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
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
Marco Turco
SOFTWARE XP LLP
- José Luis Sánchez
- Posts: 484
- Joined: Thu Oct 13, 2005 9:23 am
- Location: Novelda - Alicante - España
- Contact:
Re: Msgbox centered on the window
Use this code:
where oDlgInfo is your dialog and oApp():oWndMain the main window of the application.
Regards,
Code: Select all
ACTIVATE DIALOG oDlgInfo ;
ON INIT oDlgInfo:Center( oApp():oWndMain )
Regards,
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Re: Msgbox centered on the window
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.
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
Marco Turco
SOFTWARE XP LLP
- José Luis Sánchez
- Posts: 484
- Joined: Thu Oct 13, 2005 9:23 am
- Location: Novelda - Alicante - España
- Contact:
Re: Msgbox centered on the window
Marco,
I've the msgbox functions redefined based on dialogs, and for this runs ok in my programs.
Regards,
I've the msgbox functions redefined based on dialogs, and for this runs ok in my programs.
Regards,
- Massimo Linossi
- Posts: 474
- Joined: Mon Oct 17, 2005 10:38 am
- Location: Italy
Re: Msgbox centered on the window
Hello Josè.
I have the same problem of Marco. Is possible to see your functions ?
Thanks a lot.
Massimo
I have the same problem of Marco. Is possible to see your functions ?
Thanks a lot.
Massimo
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Msgbox centered on the window
Here there is some code that we could try to adapt to FWH:
http://vbnet.mvps.org/index.html?code/h ... centre.htm
http://vbnet.mvps.org/index.html?code/h ... centre.htm
- Massimo Linossi
- Posts: 474
- Joined: Mon Oct 17, 2005 10:38 am
- Location: Italy
Re: Msgbox centered on the window
It would be great.
Thanks Antonio.
Thanks Antonio.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Msgbox centered on the window
This is already working
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
#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
Here you have an example:
Code: Select all
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oWnd
DEFINE WINDOW oWnd
CenterMsgs()
ACTIVATE WINDOW oWnd ;
ON CLICK MsgInfo( "Hello world" )
return nil
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Msgbox centered on the window
In this version we are already able to move the Msg... window:
Still we need to get the handle of the parent window
Code: Select all
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() );
}
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Msgbox centered on the window
Ok, this one seems to be working fine
Still we need to implement a function to remove the hook.
Still we need to implement a function to remove the hook.
Code: Select all
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() );
}
Re: Msgbox centered on the window
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.
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
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() ); }
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)
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)
Re: Msgbox centered on the window
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
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
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
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
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
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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Msgbox centered on the window
Dutch,
I am using Windows 10
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
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() ); }
Re: Msgbox centered on the window
Hi,
Should we call CenterMsgs() function just in main window or should we call before every MsgInfo function?
Should we call CenterMsgs() function just in main window or should we call before every MsgInfo function?
Regards,
Hakan ONEMLI
Harbour & VS 2019 & FWH 20.12
Hakan ONEMLI
Harbour & VS 2019 & FWH 20.12
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Msgbox centered on the window
Hakan,
Just once at the beginning of your app.
And we should remove the hook before the app quits
Just once at the beginning of your app.
And we should remove the hook before the app quits