This a demo as move a dialog box in the screen.
I hope it is useful.
Best regards,
Claudio.
Code: Select all
// HMG Demo: Move Dialog Box
// (c) 2014, by Dr. Claudio Soto , srvet@adinet.com.uy , http://srvet.blogspot.com
#include "hmg.ch"
#include "common.ch"
#xtranslate SET DIALOGBOX [ROW <nRow>] [COL <nCol>] [[<lCenter:CENTER>] [OF <Form>]] => ;
_HMG_DialogBoxProperty ( <nRow>, <nCol>, <.lCenter.>, <Form>, .T.)
FUNCTION MAIN
DEFINE WINDOW Form_1 ;
AT 100,100 ;
WIDTH 700 HEIGHT 500 ;
TITLE 'Move Dialog Box' ;
MAIN
@ 50,350 BUTTON Button_1 CAPTION "Dlg Move1" ACTION (( SET DIALOGBOX CENTER OF Form_1.Button_1.HANDLE ) ,;
MsgInfo ("Hello","Dlg Move"),;
SET DIALOGBOX )
@ 150,100 BUTTON Button_2 CAPTION "Dlg Move2" ACTION (( SET DIALOGBOX CENTER ) ,;
MsgInfo ("Hello","Dlg Move"),;
SET DIALOGBOX )
@ 250,100 BUTTON Button_3 CAPTION "Dlg Move3" ACTION (( SET DIALOGBOX ROW 50 COL 30 ) ,;
MsgInfo ("Hello","Dlg Move"),;
SET DIALOGBOX )
@ 350,100 BUTTON Button_4 CAPTION "Dlg NoMove" ACTION MsgInfo ("Hello","Dlg NoMove" )
END WINDOW
CREATE EVENT PROCNAME _HMG_DialogBoxProcedure()
ACTIVATE WINDOW Form_1
RETURN NIL
FUNCTION _HMG_DialogBoxProperty ( nRow, nCol, lCenter, Form, lSet )
STATIC _HMG_DialogBoxPosSizeInfo
IF ValType (_HMG_DialogBoxPosSizeInfo) <> "A"
_HMG_DialogBoxPosSizeInfo := ARRAY (4)
ENDIF
IF lSet == NIL .OR. lSet == .T.
_HMG_DialogBoxPosSizeInfo [1] := nCol
_HMG_DialogBoxPosSizeInfo [2] := nRow
_HMG_DialogBoxPosSizeInfo [3] := lCenter
_HMG_DialogBoxPosSizeInfo [4] := IF (ValType ( Form ) == "C", GetFormHandle ( Form ), Form )
ELSE
nCol := _HMG_DialogBoxPosSizeInfo [1]
nRow := _HMG_DialogBoxPosSizeInfo [2]
lCenter := _HMG_DialogBoxPosSizeInfo [3]
Form := _HMG_DialogBoxPosSizeInfo [4]
ENDIF
RETURN NIL
FUNCTION _HMG_DialogBoxProcedure()
LOCAL nRow, nCol, lCenter, Width, Height, aPos := ARRAY (4)
LOCAL hWndParent, hWnd := GetActiveWindow()
#define WM_WINDOWPOSCHANGING 70
IF EventMSG () == WM_WINDOWPOSCHANGING .AND. GetClassName ( hWnd ) == "#32770" // The class name for a dialog box is --> #32770
_HMG_DialogBoxProperty ( @nRow, @nCol, @lCenter, @hWndParent, .F. )
IF ValType (lCenter) == "L" .AND. lCenter == .T.
IF Valtype (hWndParent) <> "N"
hWndParent := GetParent(hWnd)
ENDIF
GetWindowRect(hWndParent, aPos)
Width := aPos [3] - aPos [1]
Height := aPos [4] - aPos [2]
nCol := aPos [1] + ( Width - GetWindowWidth (hWnd) ) /2
nRow := aPos [2] + ( Height - GetWindowHeight(hWnd) ) /2
ENDIF
IF nRow <> NIL .OR. nCol <> NIL
DEFAULT nCol TO GetWindowCol ( hWnd )
DEFAULT nRow TO GetWindowRow ( hWnd )
#define SWP_NOOWNERZORDER 0x0200
#define SWP_NOMOVE 0x0002
#define SWP_NOSIZE 0x0001
SetWindowPos ( hWnd, 0, nCol, nRow, 0, 0, SWP_NOOWNERZORDER + SWP_NOSIZE)
ENDIF
ENDIF
RETURN NIL
#pragma BEGINDUMP
#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"
#include <windows.h>
#include "hbapi.h"
HB_FUNC ( GETCLASSNAME )
{
HWND hWnd = (HWND) hb_parnl (1);
TCHAR ClassName [1024];
GetClassName ( hWnd, ClassName, sizeof (ClassName) / sizeof (TCHAR) );
HMG_retc ( ClassName );
}
#pragma ENDDUMP