ACTIVATE DIALOG oDlgInfo ;
ON INIT oDlgInfo:Center( oApp():oWndMain )
#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 nil
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() );
}
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.
- Code: Select all Expand view RUN
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.
- Code: Select all Expand view RUN
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() );
}
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 47 guests