Move DialogBox

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
srvet_claudio
Posts: 1919
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 25 times
Been thanked: 95 times
Contact:

Move DialogBox

Post by srvet_claudio » Wed Jan 29, 2014 12:53 am

Hi all,
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

Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
esgici
Posts: 4282
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 166 times
Been thanked: 61 times
Contact:

Post by esgici » Wed Jan 29, 2014 1:24 am

Thanks Dr. :)

Very nice :arrow:

Viva HMG :D
Viva INTERNATIONAL HMG :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest