Control Dialog Width by ItemBox selection

Started by Jeremy Whilde, October 17, 2013, 11:07:42 AM

Previous topic - Next topic

Jeremy Whilde

How do you control a dialog width by selecting an item in an Itembox?

The following does not work. How can the required value be passed to the dialog?

W=153   ;Inital width
H=165

#DEFINEFUNCTION GetItemRange(Handle,DialogMessage,DialogControlID,param4,param5)

switch  (DialogMessage)
   case 0
      DialogProcOptions(Handle, 7, 1)           ;Item listbox selection changes.
      break
   case 7
      sSelection = DialogControlGet(Handle,3,6) ; Get selection for itembox control

      DialogControlSet(Handle,4,4,sSelection)      ; This works and passes text to control
        
      If sSelection == "Item - 6" then W = 388       ; ***This does not get passed to dialog?!***
      
      break
endswitch

return -1

#ENDFUNCTION


DefSelect="Item - 1"

:Start

MyVariable5 = StrCat("Item - 1",@TAB,"Item - 2",@TAB,"Item - 3",@TAB,"Item - 4",@TAB,"Item - 5",@TAB,"Item - 6")

MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`Items...`
MyDialogX=-1
MyDialogY=-1
MyDialogWidth=W
MyDialogHeight=H
MyDialogNumControls=004
MyDialogProcedure=`GetItemRange`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`033,139,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`089,139,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`065,067,058,046,ITEMBOX,MyVariable5,"%DefSelect%",DEFAULT,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`017,009,116,116,GROUPBOX,DEFAULT,"Inital Items:",DEFAULT,14,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

Thanks JW


Deana

You can get the dialogs current client area size using DialogProcOptions 1007 Get Client Area: Return internally maintained width and height of the dialog's client area in dialog-units as a space delimited list. The returned client area dimensions are the dialog's size not including the width and height of  borders, the height of the menu bar, nor the height of the title bar. The third parameter to DialogProcOptions must be set to -1 when using this request code.

However in order to get the dialog itself to dynamically resize you will need to redraw.





Deana F.
Technical Support
Wilson WindowWare Inc.

George Vagenas

Not sure how you get the dialog to redraw but this works.
Code (winbatch) Select
   case 7
      sSelection = DialogControlGet(Handle,3,6) ; Get selection for itembox control

      If sSelection == "Item - 6" then W = 388       ; ***This does not get passed to dialog?!***
      WP = winposition(wingetactive())
      pixHoriz = winmetrics(-6)
      newWidth = int(pixHoriz*388)
      WP = itemreplace(newWidth, 3, WP, ',')
      WinPlace( %WP%,  wingetactive() )
      break
Thanks

George

Deana

George thanks for sharing your solution. To answer the question, you can redraw the dialog by calling the Dialog function. If you want updated height and width then simply redefine those dialog variables then call the Dialog() function.
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

Here is an example the redraws the dialog with new height variables. Notice the use of DefineSubroutine

Code (winbatch) Select
#DEFINESubroutine GetItemRange(Handle,DialogMessage,DialogControlID,param4,param5)
   Switch DialogMessage
      case 0
         DialogProcOptions(Handle, 7, 1)           ;Item listbox selection changes.
         Return -1
      case 7
         sSelection = DialogControlGet(Handle,3,6) ; Get selection for itembox control
         DialogControlSet(Handle,4,4,sSelection)      ; This works and passes text to control
         Switch @True
            Case sSelection == "Item - 1"
               W = 188     
               H = 188             
               break
            Case sSelection == "Item - 2"
               W = 288       
               H = 288             
               break
            Case sSelection == "Item - 3"
               W = 388     
               H = 388             
               break
            Case sSelection == "Item - 4"
               W = 488     
               H = 488             
               break
            Case sSelection == "Item - 6"
               W = 588       
               H = 588             
               break 
            Case sSelection == "Item - 6"
               W = 688       
               H = 688             
               break
         Endswitch
         Return 999
   Endswitch
   Return -1
#EndSubroutine


W=153   ;Inital width
H=165

:Start
DefSelect="Item - 1"
MyVariable5 = StrCat("Item - 1",@TAB,"Item - 2",@TAB,"Item - 3",@TAB,"Item - 4",@TAB,"Item - 5",@TAB,"Item - 6")
MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`Items...`
MyDialogX=-1
MyDialogY=-1
MyDialogWidth=W
MyDialogHeight=H
MyDialogNumControls=004
MyDialogProcedure=`GetItemRange`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`033,139,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`089,139,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`065,067,058,046,ITEMBOX,MyVariable5,"%DefSelect%",DEFAULT,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`017,009,116,116,GROUPBOX,DEFAULT,"Inital Items:",DEFAULT,14,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")
if ButtonPushed == 999 then goto Start
Deana F.
Technical Support
Wilson WindowWare Inc.