Dialogs

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Dialogs

Post by pgriffin » Fri Oct 27, 2006 10:13 pm

I would like to present the appearance of a single dialog (my assumption is that this can't be done in a single dialog) in which the user presses a RadioButton and the dialog "repaints" with completely different input fields, and buttons....essentially a totally new dialog....

My strategy has been to create two almost identical dialogs and just swap them out in the exact same screen position each time the user changes the selection in the RadioGroup.

As ugly as it is.....Here is what I have.....

Code: Select all

vbstart

vbend

let>var1=
let>var2=
let>var3=
let>var4=
let>DataSource=Access

Dialog>DBDialog
   Caption=Access Details
   Width=366
   Height=371
   Top=CENTER
   Left=CENTER
   Max=0
   Edit=msEdit1,16,112,185,%var1%
   Edit=msEdit2,16,188,185,%var2%
   RadioGroup=msDataSrc,Data Source,24,8,185,65,Access%CRLF%Excel,0
   Label=Access Details,32,88,true
   Label=Access File Details,24,144,true
   Button=Close,24,272,75,25,2
EndDialog>DBDialog

Dialog>XLDialog
   Caption=XL Details
   Width=366
   Height=371
   Top=CENTER
   Left=CENTER
   Max=0
   Edit=msEdit1,16,112,185,%var3%
   Edit=msEdit2,16,168,185,%var4%
   RadioGroup=msDataSrc,Data Source,24,8,185,65,Access%CRLF%Excel,1
   Label=XL Details,24,80,true
   Label=File Details,24,144,true
   Button=Close,24,288,75,25,2
EndDialog>XLDialog

Label>Dialogs
// check to see which is the current default data source
// and display the corresponding dialog
if>DataSource=Access
   // check to see if the other dialog is open,then close it
   ifw>XL Details
      clo>XL Details
   endif>
   //make sure the inputs for the dialog are reset
   rda>DBDialog
   show>DBDialog
   label>ShowDB
   gda>DBDialog,dbr
   if>DBDialog.msDataSrc=Excel
         let>DataSource=Excel
         goto>Dialogs
   endif>
   if>dbr=2
      goto>ProgramEnd
   endif>
   goto>ShowDB
endif>
if>DataSource=Excel
   ifw>Access Details
       clo>Access Details
   endif>
   rda>XLDialog
   show>XLDialog
   label>ShowXL
   gda>XLDialog,xlr
   if>XLDialog.msDataSrc=Access
         let>DataSource=Access
		 rda>DBDialog
		 rda>XLDialog
         goto>Dialogs
   endif>
   if>xlr=2
      goto>ProgramEnd
   endif>
   goto>ShowXL
endif>
label>ProgramEnd


help!!!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Oct 27, 2006 10:25 pm

Hide/Show the objects. Requires a bit of API work - FindWindow and ShowWindow. Try this simple example:

Code: Select all

Dialog>Dialog1
   Caption=Test Dialog
   Width=445
   Height=250
   Top=206
   Left=148
   Button=Hide Button 2,56,40,75,25,10
   Button=Hide Button 1,56,88,75,25,20
EndDialog>Dialog1

OnEvent>DIALOG_EVENT,Dialog1,10,Button1
OnEvent>DIALOG_EVENT,Dialog1,20,Button2

Show>Dialog1
Label>loop
  Wait>0.02
Goto>loop

SRT>Button1
  LibFunc>user32,FindWindowA,dlgHwnd,TForm,Test Dialog
  LibFunc>User32,FindWindowExA,b1Hwnd,dlgHwnd,0,TBitBtn,Hide Button 2
  LibFunc>User32,FindWindowExA,b2Hwnd,dlgHwnd,0,TBitBtn,Hide Button 1
  LibFunc>User32,ShowWindow,r,b1Hwnd,0
  LibFunc>User32,ShowWindow,r,b2Hwnd,1
END>Button1

SRT>Button2
  LibFunc>user32,FindWindowA,dlgHwnd,TForm,Test Dialog
  LibFunc>User32,FindWindowExA,b1Hwnd,dlgHwnd,0,TBitBtn,Hide Button 2
  LibFunc>User32,FindWindowExA,b2Hwnd,dlgHwnd,0,TBitBtn,Hide Button 1
  LibFunc>User32,ShowWindow,r,b1Hwnd,1
  LibFunc>User32,ShowWindow,r,b2Hwnd,0
END>Button2
So developing this further you could have a set of objects that are hidden initially. Clicking on something will hide the visible set and show the hidden set.

Should add that this script uses the DIALOG_EVENT event handler introduced in V9. For earlier versions use a regular GetDialogAction check to determine which button was pressed.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Mon Oct 30, 2006 3:29 pm

Very nice!
Thanks for the script.
I had to add gda> to the loop to get it to work.


gda>Dialog1,result
if>result=10,Button2
if>result=20,Button1
if>result=2,Exit


Code: Select all

Dialog>Dialog1
   Caption=Test Dialog
   Width=445
   Height=250
   Top=206
   Left=148
   Button=Hide Button 2,56,40,75,25,10
   Button=Hide Button 1,56,88,75,25,20
EndDialog>Dialog1

OnEvent>DIALOG_EVENT,Dialog1,10,Button1
OnEvent>DIALOG_EVENT,Dialog1,20,Button2

Show>Dialog1
Label>loop
gda>Dialog1,result
if>result=10,Button2
if>result=20,Button1
if>result=2,Exit
  Wait>0.02
Goto>loop

SRT>Button1
  LibFunc>user32,FindWindowA,dlgHwnd,TForm,Test Dialog
  LibFunc>User32,FindWindowExA,b1Hwnd,dlgHwnd,0,TBitBtn,Hide Button 2
  LibFunc>User32,FindWindowExA,b2Hwnd,dlgHwnd,0,TBitBtn,Hide Button 1
  LibFunc>User32,ShowWindow,r,b1Hwnd,0
  LibFunc>User32,ShowWindow,r,b2Hwnd,1
  rda>Dialog1
END>Button1

SRT>Button2
  LibFunc>user32,FindWindowA,dlgHwnd,TForm,Test Dialog
  LibFunc>User32,FindWindowExA,b1Hwnd,dlgHwnd,0,TBitBtn,Hide Button 2
  LibFunc>User32,FindWindowExA,b2Hwnd,dlgHwnd,0,TBitBtn,Hide Button 1
  LibFunc>User32,ShowWindow,r,b1Hwnd,1
  LibFunc>User32,ShowWindow,r,b2Hwnd,0
  rda>Dialog1
END>Button2

label>Exit


User avatar
migro
Macro Veteran
Posts: 152
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Post by migro » Sun Jul 12, 2009 4:44 pm

Dear Marcus,

nice idea with the api-functions.

It works very well when using windows XP.
If used with windows Vista the specified dialog items won't hide.

Any idea what need to be changed to use the functionality also under Vista?
regards
migro

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sun Jul 12, 2009 6:14 pm

The API was always kind of flakey since the objects were not visible but could still be tabbed to and executed. With version 11 Marcus has introduced the SetDialogObjectVisible> function, which eliminates the tabbing issue and will undoubtedly work under Vista.

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=230
   Height=158
   Top=116
   Left=26
   Close=0
   Edit=msEdit1,49,44,121,
   Label=This is a demo,64,16
   Button=Exit,127,93,75,35,2
   Button=Toggle Exit%CRLF%Button,18,92,75,35,3
EndDialog>Dialog1

Show>dialog1
Let>hide=1
Label>Loop
GetDialogAction>dialog1,res1
If>res1=2
  Exit>0
EndIf
If>res1=3
  If>hide=1
    Let>hide=0
  Else
    Let>hide=1
  EndIF
  SetDialogObjectVisible>dialog1,msButton1,%hide%
  ResetDialogAction>Dialog1
EndIf
Wait>0.01
Goto>Loop

User avatar
migro
Macro Veteran
Posts: 152
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Post by migro » Fri Jul 17, 2009 1:19 am

Tanks Marcus for this new function (it suites perfect our needs) and thanks to JRL for the hint.
regards
migro

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts