WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Dialog Resize Demo


Notice: Dialog Resizing now supported, starting in WinBatch 2010B

Changes to the Dialog function and related functions

   Add two new dialog template variables MinWidth and MinHeight 
   that can be used to indicate the approximate minimum width and height of the dialog 
   window that can be set by dragging the dialog's boarders. The values are assumed 
   to be in dialog units and do not include the height of the title and menu bars. When 
   either of these variables is present in a dialog template, the dialog becomes re-sizable 
   by either directly dragging the dialog's boarder or by using the 'Size' system menu.

   Added new DialogProcOptions request code 17 that causes a call to a dialog's 
   user-defined-callback procedure when the dialog is resized, maximized, or restored from 
   maximized to normal size. 

   When the user-defined-callback is called with the resize request, the fifth parameter 
   to the user-defined-callback procedure contains a space delimited 
   list who's items represent the delta (change) in width and height of the dialog in dialog 
   units and can be either negative or positive numbers and the actual dialog width and height 
   in dialog units. The dialog height and width represent the internally maintained size of 
   the dialog's client area.  The client are is the area of a window used to display controls 
   and its size does not include the dialog window's borders, menu bar, nor title bar. 
   The data returned by the user-defined-callback is in this format:
   {delta_width} {delta_height} {actual_width} actual_height}
	


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; A demo on how to handel resize of a dialog
;; The Size of the dialog is saved into the registry
;; so when you start the progam again it remember the posistion.
;;
;; Made by Ola Ketil Siqveland
;; Date: 24 Jan. 2007
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Returns a window's styles
;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineFunction GetStyle(hWnd)
   user32 = StrCat(DirWindows(1),"user32.dll")
   GWL_STYLE = -16 ; offset for the Window Style value
   ret = DllCall(user32,long:"GetWindowLongA",long:hWnd,long:GWL_STYLE)
   Return ret
#EndFunction

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Sets a window's styles
;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineFunction SetStyle(hWnd, nstyle)
   user32 = StrCat(DirWindows(1),"user32.dll")
   GWL_STYLE = -16 ; offset for the Window Style value
   ret = DllCall(user32,long:"SetWindowLongA",long:hWnd,long:GWL_STYLE,long:nstyle)
   Return ret
#EndFunction

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set handle of control element  as 99 + tab order
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineSubRoutine Move_Sub_SysID_List_Rtn()
   si_pb_Mov_OK        = 100
   si_pb_Mov_Cance     = 101
   si_pb_Mov_Itembox   = 102
   si_pb_Mov_Check     = 103
   si_pb_Mov_Multi     = 104

   window1       = cWndByWndSpec("wb0wcdl3","WinBatch",2,100,101)
   wid_OK        = cWinIDConvert(cWndbyid(window1, si_pb_Mov_OK    ))
   wid_Cance     = cWinIDConvert(cWndbyid(window1, si_pb_Mov_Cance   ))
   wid_ItemBox   = cWinIDConvert(cWndbyid(window1, si_pb_Mov_Itembox  ))
   wid_Check     = cWinIDConvert(cWndbyid(window1, si_pb_Mov_Check     ))
   wid_Multi     = cWinIDConvert(cWndbyid(window1, si_pb_Mov_Multi   ))
#EndSubRoutine
;¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dialog Callback
;;;;;;;;;;;;;;;;;;;;;;;;;
#DefineSubRoutine MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_ID,rsvd1,rsvd2)


   MSG_INIT=0                ; The one-time initialization
   MSG_TIMER=1               ; Timer event
   MSG_BUTTONPUSHED=2        ; Pushbutton or Picturebutton
   MSG_RADIOPUSHED=3         ; Radiobutton clicked
   MSG_CHECKBOX=4            ; Checkbox clicked
   MSG_EDITBOX=5             ; Editbox or Multilinebox
   MSG_FILESELECT=6          ; Filelistbox
   WS_THICKFRAME=262144        ; Style adds sizing border.

   RET_DO_DEFAULT= -1        ; Continue with default processing for control

   Switch MyDialog_Message                         ; Switch based on Dialog Message type
      Case MSG_INIT                                ; Standard Initialization message

        ; Add System menus
        DialogProcOptions(MyDialog_Handle, MSG_BUTTONPUSHED, 1)  ; MSG_BUTTONPUSHED =2
        DialogProcOptions(MyDialog_Handle,1002, 4)               ; Same as IntControl (49, 1, 0, 0, 0)
        DialogProcOptions(MyDialog_Handle,MSG_TIMER, 1000)       ; Set 1000 millisecond mellom calbacks


        Move_Sub_SysID_List_Rtn()

         ; Add a "sizable" boarder.
         nStyle = GetStyle(MyDialog_Handle)
         nStyle = nStyle | WS_THICKFRAME
         SetStyle(MyDialog_Handle,nStyle)

         ;stratPos = @true
         wpos = WinPosition("Resize-demo")
         dwidth = (ItemExtract(3,wpos,","))-(ItemExtract(1,wpos,","))
         dheight= (ItemExtract(4,wpos,","))-(ItemExtract(2,wpos,","))
         w_save = dwidth
         h_save = dheight

         nr=0
         Return(RET_DO_DEFAULT)

     Case MSG_TIMER

         wpos = WinPosition("Resize-demo")
          x_b = ItemExtract(3,wpos,",")
          x_t = ItemExtract(1,wpos,",")
          y_b = ItemExtract(4,wpos,",")
          y_t = ItemExtract(2,wpos,",")
          dwidth = ItemExtract(3,wpos,",")-ItemExtract(1,wpos,",")
          dheight= ItemExtract(4,wpos,",")-ItemExtract(2,wpos,",")
          ;pause('%w_save% = %dwidth%','%h_save% = %dheight%')

          If (w_save != dwidth || h_save != dheight) Then
            Update_dialog_element()
          EndIf

         Return(RET_DO_DEFAULT)
     Case MSG_BUTTONPUSHED
        Switch MyDialog_ID
          Case 001    ; OK

             Return -2

          Case 002    ; Close buttom
              Return 9
         EndSwitch

   EndSwitch                                       ; MyDialog_Message
   Return(RET_DO_DEFAULT)
#EndFunction                                       ; End of Dialog Callback MyDialogCallbackProc



;============================================================
#DefineSubRoutine Update_dialog_element()

   ; Calculation of the position to the controlls in Winplace units
   DlgH = Int(Floor((y_b - y_t)/multiY)) - (WinMetrics(4)/hadj)     ; Get Dialog Height
   DlgW = Int(Floor((x_b - x_t)/multiX))         ;  Get Dialog Width
   DlgY = Int(Floor((Y_t)/multiY))
   DlgX = Int(Floor((X_T)/multiX))


TopButton    = Int(dheight -(WinMetrics(4)+5)*MultiY) ;  ; 475
LeftOK       = Int(dwidth/2 -(25+36)*MultiX)          ; 393
LeftCancel   = Int(dwidth/2 + 25*MultiX)              ; 410
LeftFilelist = 10
TopControls  = 10
LeftCheck    = LeftFilelist
TopCheck     = TopButton
LeftMulti    = Int(Dwidth/2 + 5)
FilelistH    = TopCheck - 20
FilelistW    = Int(Dwidth/2 - LeftFilelist - 5)
MultiH       = FilelistH
MultiW       = Int(Dwidth - 10)                  ;227

   ; To get units for the WinPlace multily dialog units mit multiX and multiY
   ; Winplace and Winpos use size 1000 x 1000 as windows-size

   WinPlace(LeftOK       ,TopButton     ,@NORESIZE  , @NORESIZE  ,wid_OK     )
   WinPlace(LeftCancel   ,TopButton     ,@NORESIZE  , @NORESIZE  ,wid_Cance  )
   WinPlace(LeftFilelist ,TopControls   ,FilelistW  , FilelistH  ,wid_ItemBox   )
   WinPlace(LeftCheck    ,TopCheck      ,@NORESIZE  , @NORESIZE  ,wid_Check      )
   WinPlace(LeftMulti    ,TopControls   ,MultiW     , MultiH     ,wid_Multi      )
   ;Pause(" InfoH=%InfoH% use_width=%use_width% ",'ListY=%ListY%  FotoW=%FotoW% FotoH=%FotoH%')

   w_save = dwidth
   h_save = dheight

Return
#EndSubRoutine
;***********************************************************************************************************


;============================================================
#DefineSubRoutine  CloseProgram()
   ; Find the dialog position in dialogunit
   DlgH = Int(Floor((y_b - y_t)/multiY)) - (WinMetrics(4)/hadj)     ; Get Dialog Height
   DlgW = Int(Floor((x_b - x_t)/multiX))         ;  Get Dialog Width
   DlgX =IntControl(75,1,0,0,0)                  ;  Get Dialog upperleft X
   DlgY =IntControl(75,2,0,0,0)                  ;  Get Dialog upperleft Y
   ;Pause(DlgX,DlgY)
   ;Pause('dlgx=%DlgX% DlgY=%dlgY%','Dlgw=%DlgW% DlgH=%DlgH%')
   newregkey= 'SOFTWARE\TestProgram\Settings'
   If ! RegExistValue(@REGMACHINE,'%newregkey%') Then
       key = RegCreateKey(@REGMACHINE,newregkey)
       RegCloseKey(key)
   EndIf
   regkey= 'SOFTWARE\TestProgram\Settings[DlgX]'
   RegSetEx(@REGMACHINE,regkey,DlgX,',',1)
   regkey= 'SOFTWARE\TestProgram\Settings[DlgY]'
   RegSetEx(@REGMACHINE,regkey,DlgY,',',1)
   regkey= 'SOFTWARE\TestProgram\Settings[DlgW]'
   RegSetEx(@REGMACHINE,regkey,DlgW,',',1)
   regkey= 'SOFTWARE\TestProgram\Settings[DlgH]'
   RegSetEx(@REGMACHINE,regkey,DlgH,',',1)


    ;FileDelete("ut.txt")
    Exit
Return
#EndSubRoutine
;*********************************************************************
 ;============================================================
#DefineSubRoutine StartDialog()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dialog Template
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`Resize-demo`
MyDialogX=DlgX
MyDialogY=DlgY
MyDialogWidth=DlgW
MyDialogHeight=DlgH
MyDialogNumControls=005
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

; Calculation of the position to the controlls in dialog units
TopButton    = DlgH - WinMetrics(12)/hadj -10   ;
LeftOK       = DlgW/2 - 25 - 36 ; 36 is the width of the button
LeftCancel   = DlgW/2 + 25
LeftItemlist = 10
TopControls  = 10
LeftCheck    = LeftItemlist
TopCheck     = TopButton
LeftMulti    = DlgW/2 + 5
ItemListH    = TopCheck - 20
ItemListW    = DlgW/2 - LeftItemlist - 5
MultiH       = ItemListH -5
MultiW       = DlgW - LeftMulti -10


MyDialog001=`%LeftOK%,%TopButton%,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`%LeftCancel%,%TopButton%,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`%LeftItemlist%,%TopControls%,%ItemListW%,%ItemListH%,ITEMBOX,ItemList,DEFAULT,DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`%LeftCheck%,%TopCheck%,044,012,CHECKBOX,MyVariable3,"Checkbox 1",1,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005=`%Leftmulti%,%TopControls%,%MultiW%,%MultiH%,MULTILINEBOX,Input,"Multiline edit 1",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

   If ( ButtonPushed == 9 ) Then CloseProgram()


 Return
#EndSubRoutine
;*********************************************************************

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Start of main program
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   AddExtender("wwctl44i.dll")
   IntControl(49,3,0,0,0)

   wadj = WinMetrics(-6)   ;pixel per horizontal dialog unit
   hadj = WinMetrics(-5)   ;pixel per vertical dialog unit

   ; Check if the dialog startvalue is saved in the register
   regkey1= 'SOFTWARE\TestProgram\Settings[DlgX]'
   regkey2= 'SOFTWARE\TestProgram\Settings[DlgY]'
   regkey3= 'SOFTWARE\TestProgram\Settings[Dlgw]'
   regkey4= 'SOFTWARE\TestProgram\Settings[DlgH]'
   reg1 = RegExistValue(@REGMACHINE,regkey1)
   reg2 = RegExistValue(@REGMACHINE,regkey2)
   If ((reg1 != 0) && (reg2 != 0) ) Then
      DlgX = RegQueryStr(@REGMACHINE,regkey1)
      DlgY = RegQueryStr(@REGMACHINE,regkey2)
      DlgW = RegQueryStr(@REGMACHINE,regkey3)
      DlgH = RegQueryStr(@REGMACHINE,regkey4)
      ;pause('DlgX=%DlgX% DlgY=%DlgY%','DlgH=%DlgH% DlgW=%DlgW%')
      screenwidth=WinMetrics(0) - (Dlgx * wadj)
      screenheight=WinMetrics(1) - (DlgY * hadj)
   Else
      DlgX =-1
      DlgY = -1
      screenwidth=WinMetrics(0)/2
      screenheight=WinMetrics(1)/2
      dialogunitswidth=screenwidth/WinMetrics(-6)
      dialogunitheight= (screenheight-WinMetrics(4)-WinMetrics(12))/WinMetrics(-5)
      Dlgw = dialogunitswidth
      DlgH = dialogunitheight
   EndIf
   multiX = (1000*wadj)/WinMetrics(0)
   MultiY = (1000*hadj)/WinMetrics(1)

   ItemList = StrCat('aprocot',@TAB,'apples',@TAB,'pears',@TAB,'oranges',@TAB,'grapes')

   ;message('%DlgX% %DlgY%','Width= %Dlg_width% Height= %Dlg_height%')
   StartDialog()


Exit

Article ID:   W16943
File Created: 2011:05:19:09:09:36
Last Updated: 2011:05:19:09:09:36