Hide and show objects in custom dialog [Script Tip]

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

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

Hide and show objects in custom dialog [Script Tip]

Post by Rain » Thu Feb 08, 2007 3:28 pm

To hide the objects in a custom dialog move them by using MoveWindow>Object Name*,-5000,-5000
To show them move them back to correct position by using MoveWindow>Object Name*,CORRECT_X_POS,CORRECT_Y_POS

Code: Select all

Dialog>Dialog1
   Caption=Hide and Show Objects
   Width=392
   Height=216
   Top=CENTER
   Left=CENTER
   Max=1
   Min=1
   Close=1
   Resize=1
   Button=Button 1,8,8,121,25,10
   Button=Button 2,8,40,121,25,10
   Edit=msEdit1,8,80,121,My Edit
   Memo=MyMemo,144,8,97,97,My Memo
   CheckBox=msCheckBox1,Check This,8,112,97,False
   ListBox=msListBox1,248,8,121,97,Option 1%CRLF%Option 2
   ComboBox=msComboBox1,8,136,121,Option 1%CRLF%Option 2
   RadioGroup=msRadioGroup1,Select,144,112,97,49,Select 1%CRLF%Select 2,0
   ProgressBar=msProgressBar1,248,128,121,17,0
EndDialog>Dialog1

Show>Dialog1
//Hide objects by moving them to a negative position
MoveWindow>Button 1*,-5000,-5000
MoveWindow>Button 2*,-5000,-5000
MoveWindow>My Edit*,-5000,-5000
MoveWindow>My Memo*,-5000,-5000
MoveWindow>Check This*,-5000,-5000
MoveWindow>msListBox1*,-5000,-5000
MoveWindow>Option *,-5000,-5000
MoveWindow>Select*,-5000,-5000
MoveWindow>msProgressBar1*,-5000,-5000
Label>Show_Hide_Loop
Wait>1
GetDialogAction>Dialog1,r
if>r=2,Exit
//Show objects by moving them back to the correct position
MoveWindow>Button 1*,8,8
MoveWindow>Button 2*,8,40
MoveWindow>My Edit*,8,80
MoveWindow>My Memo*,144,8
MoveWindow>Check This*,8,112
MoveWindow>msListBox1*,248,8
MoveWindow>Option *,8,136
MoveWindow>Select*,144,112
MoveWindow>msProgressBar1*,248,128
Wait>1
GetDialogAction>Dialog1,r
if>r=2,Exit
//Hide objects by moving them to a negative position
MoveWindow>Button 1*,-5000,-5000
MoveWindow>Button 2*,-5000,-5000
MoveWindow>My Edit*,-5000,-5000
MoveWindow>My Memo*,-5000,-5000
MoveWindow>Check This*,-5000,-5000
MoveWindow>msListBox1*,-5000,-5000
MoveWindow>Option *,-5000,-5000
MoveWindow>Select*,-5000,-5000
MoveWindow>msProgressBar1*,-5000,-5000
Goto>Show_Hide_Loop
Label>Exit
I hope someone finds this useful

Rain

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

Post by Marcus Tettmar » Thu Feb 08, 2007 3:57 pm

Or use the Win32 API ShowWindow function as described here:
http://www.mjtnet.com/forum/viewtopic.php?t=3363
Last edited by Marcus Tettmar on Thu Feb 08, 2007 5:55 pm, edited 1 time in total.
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
JRL
Automation Wizard
Posts: 3504
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Feb 08, 2007 5:43 pm

Interesting discussion. Rain's concept is easy to grasp. I like it :)

Marcus, your code in the link you provided needs to be reposted with HTML disabled.

I have a related question.
If a dialog object is moved to any position outside the boundary of the dialog it is no longer visible on the screen. Is there any possibility that there is an API function that could make an object visible even though its position is outside the boundary of the dialog?

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

Post by Marcus Tettmar » Thu Feb 08, 2007 5:57 pm

Link will be fine now - it wasn't the code - just the board trying to highlight the word "showwindow" and thereby inserting html around it. It's not clever enough to realise it can't do that to code sections.

>Is there any possibility that there is an API function that
>could make an object visible even though its position is
>outside the boundary of the dialog?

Only by changing it's position, or increasing the size of the dialog to reveal it. API functions can do either of those.
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
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Feb 08, 2007 6:47 pm

Hi Rain,

Cool concept, I found a few odd things with it though:
  • - if you click the triangle for the dropdown, the choices don't get hidden, just the original field
    - if you click into the Edit field (text = My Edit) you get a blinking cursor in there, all is well, then if you hit the backspace key four times or more, the Edit field will no longer hide
    - Start the macro, highlight all text in the Edit field, now while the elements are all hidden, tap the delete key to delete the text and... the whole field seems to be gone, it does not get redisplayed with the other fields.
Again, just some oddities that perhaps have answers. Thanks for sharing this useful technique. :)
Last edited by jpuziano on Thu Apr 09, 2009 8:39 pm, edited 1 time in total.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by JRL » Thu Feb 08, 2007 7:13 pm

it wasn't the code - just the board trying to highlight the word "showwindow" and thereby inserting html around it. It's not clever enough to realise it can't do that to code sections.
That explains why the code is sometimes unusable when I find it by searching. From now on I'll remove the search text from the location bar and refresh the page without it.

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

Post by JRL » Fri Aug 03, 2007 10:21 pm

So I've been thinking about this for 6 months and finally got to try eliminating extraneous buttons from ERP windows we use at work. Just trying to make things a little more efficient. It looks great, the buttons are not visible, I'm feeling like there might be hope for the week to close on a positive.

Showing off what I have accomplished to a co-worker and he says, "great, that will eliminate tabbing through all those extra buttons"....

Funny... I hadn't tried tabbing. What I found is that the buttons still exist whether you use Rain's move-em-off-the-screen technique, or the libfunc technique from Scripts and Tips. When you tab through the window the focus still goes to those invisible dialog objects and, the objects still function because they still exist.

My question is:
Is there any way to close or disable these objects?

I have also tried CloseWindow> which makes the object disappear but you can still tab to the "closed" object. And I tried the gray out technique discussedhere with similar results, a button turns gray but still functions when you tab to it and press enter.

Any ideas?

Thanks,
Dick

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

Post by Marcus Tettmar » Sun Aug 05, 2007 9:35 am

Use the EnableWindow API function.
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 » Sun Aug 05, 2007 2:19 pm

Hi JRL,

Two examples that work for me on Windows XP SP2.

This example will disable button 3 and render it useless when the button is in “focusâ€Â

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

Post by JRL » Mon Aug 06, 2007 1:53 pm

Marcus and Rain,
Thanks for the suggestions but I had already tried EnableWindow. It does cause the specified object to become insensitive to mouse activity and in a Macro Scheduler dialog a disabled button will not function when focused and enter is pressed. Unfortunately the ERP software displays different behavior. In the ERP software the button is insensitive to mouse activity but can still be focused by tabbing to it (though it does not appear focused) and will execute when enter is pressed.

Even in the Macro Scheduler dialog examples provided by Rain, The tab key still goes to the object. The object does not show that it is focused and pressing enter does not appear to perform any activity, but you still need to press tab three times to cycle through the three buttons. Imagine that there are 20 disabled buttons and 2 enabled buttons, you'd need to press tab 22 times to get through all of them. I want to press tab 2 times. I want to turn what I deem extraneous into digital waste and zap it into data bit heaven.

I've modified Rain's second example to demonstrate my problem. Even though you can't see four of the buttons when they are "disabled", you still have to press tab 5 times to get to the last button.

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=207
   Height=270
   Top=178
   Left=507
   Max=1
   Min=1
   Close=1
   Resize=1
   Button=Activate,64,16,75,25,100
   Button=Disable,64,48,75,25,200
   Button=Disabled1,24,80,153,25,300
   Button=Disabled2,24,112,153,25,400
   Button=Disabled3,24,144,153,25,500
   Button=Disabled4,24,176,153,25,600
   Button=Tab to Here,24,208,153,25,700
EndDialog>Dialog1

show>Dialog1

GetWindowHandle>Dialog1,dlgHwnd
LibFunc>user32,FindWindowExA,edtHwnd1,dlgHwnd,0,TBitBtn,Disabled1
LibFunc>user32,FindWindowExA,edtHwnd2,dlgHwnd,0,TBitBtn,Disabled2
LibFunc>user32,FindWindowExA,edtHwnd3,dlgHwnd,0,TBitBtn,Disabled3
LibFunc>user32,FindWindowExA,edtHwnd4,dlgHwnd,0,TBitBtn,Disabled4
LibFunc>user32,EnableWindow,nowt,edtHwnd1,0
LibFunc>user32,EnableWindow,nowt,edtHwnd2,0
LibFunc>user32,EnableWindow,nowt,edtHwnd3,0
LibFunc>user32,EnableWindow,nowt,edtHwnd4,0
LibFunc>User32,ShowWindow,r,edtHwnd1,0
LibFunc>User32,ShowWindow,r,edtHwnd2,0
LibFunc>User32,ShowWindow,r,edtHwnd3,0
LibFunc>User32,ShowWindow,r,edtHwnd4,0

label>start
rda>Dialog1

label>loop
wait>0.01
gda>Dialog1,r
if>r=100,ActivateButton
if>r=200,DisableButton
if>r=300,TestButton
if>r=400,TestButton
if>r=500,TestButton
if>r=600,TestButton
if>r=700,TestButton
if>r=2,2
goto>loop

label>TestButton
mdl>Button is Active
goto>start

label>ActivateButton
let>Dialog1.msButton2=Active1
let>Dialog1.msButton3=Active2
let>Dialog1.msButton4=Active3
let>Dialog1.msButton5=Active4
rda>Dialog1
LibFunc>user32,EnableWindow,nowt,edtHwnd1,1
LibFunc>user32,EnableWindow,nowt,edtHwnd2,1
LibFunc>user32,EnableWindow,nowt,edtHwnd3,1
LibFunc>user32,EnableWindow,nowt,edtHwnd4,1
LibFunc>User32,ShowWindow,r,edtHwnd1,1
LibFunc>User32,ShowWindow,r,edtHwnd2,1
LibFunc>User32,ShowWindow,r,edtHwnd3,1
LibFunc>User32,ShowWindow,r,edtHwnd4,1
goto>start

label>DisableButton
let>Dialog1.msButton2=Disabled1
let>Dialog1.msButton3=Disabled2
let>Dialog1.msButton4=Disabled3
let>Dialog1.msButton5=Disabled4
rda>Dialog1
LibFunc>user32,EnableWindow,nowt,edtHwnd1,0
LibFunc>user32,EnableWindow,nowt,edtHwnd2,0
LibFunc>user32,EnableWindow,nowt,edtHwnd3,0
LibFunc>user32,EnableWindow,nowt,edtHwnd4,0
LibFunc>User32,ShowWindow,r,edtHwnd1,0
LibFunc>User32,ShowWindow,r,edtHwnd2,0
LibFunc>User32,ShowWindow,r,edtHwnd3,0
LibFunc>User32,ShowWindow,r,edtHwnd4,0
goto>start

label>2

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