Sign in to follow this  
Followers 0
Avix

Problem With HideWindow Code

4 posts in this topic

I'm trying to code this program which will hide the current window by pressing the hot keys defined. So if i have IE currently up and i want to hid it ill press F5 and if i want to hide another ill do the same. Than when i want to unhide the first one ill press f5 and so no so forth. Although this inst working. Anyone tell me why? And a way to optimize so it doesn't take 55% of the CPU? =/

Thanks!!!

#NoTrayIcon


while 1
HotKeySet("{F4}", "show")
HotKeySet("{F5}", "hide")
wend

Func show()

WinSetState("[current title]", "", @SW_SHOW)
EndFunc

Func hide()

WinSetState("[current title]", "", @SW_HIDE)
EndFunc

Share this post


Link to post
Share on other sites



Avix,

First, welcome to the AutoIt forums.

Where to start? A question, perhaps....

How does Autoit know which window to show when you press the HotKey to show it? I guarantee it will not be the "current title" as you have already hidden it and another window is now current! AutoIt cannot read your mind, however much we might like it to on occasion. :D

Basically, you need to store the handles and titles of the windows you are hiding and then, when you try to show them again, display a list of the hidden windows from which you can choose the one you want to show.

Look in the Help file under:

WinGetTitle - How to get the title of the active window

WinGetHandle - How to get the handle of that window

Dim - How to store the handle and title

GUICreate - How to make a GUI to display the

GUICtrlCreateCombo or GUICtrlCreateList - How to display the hidden window titles

GUICtrlRead - How to get the window chosen in the combo/list you have created

If all this sounds like Klingon, then I strongly recommend reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) - this will help you enormously. You should also try the excellent tutorials that you will find here and here.

Do NOT get disheartened - have a go at producing something yourself and, if you run into problems, post again. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

here you go, 0% CPU Usage.

#NoTrayIcon
global $old
Global $hidden = 0
HotKeySet("{F4}", "show")
HotKeySet("{F5}", "hide")
while 1
sleep(2000)
wend

Func show()
if $hidden = 1 Then
$hidden = 0
WinSetState($old, "", @SW_SHOW)
EndIf
EndFunc

Func hide()
if $hidden = 0 Then
$win = WinGetTitle(WinGetHandle(""))
$old = $win
$hidden = 1
WinSetState($win, "", @SW_HIDE)
EndIf
EndFunc

[center][/center][center]=][u][/u][/center][center][/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

this code will hide/show multiple windows.

This is untested, should work though.

Edit: Added more error checking.

#NoTrayIcon
dim $old[50]
Global $hidden = 0
$old[0] = 0
HotKeySet("{F4}", "show")
HotKeySet("{F5}", "hide")
while 1
sleep(2000)
wend

Func show()
if $old[0] > 0 Then
WinSetState($old[$old[0]], "", @SW_SHOW)
WinActivate($old[$old[0]])
$old[0]-=1
EndIf
EndFunc

Func hide()
if $old[0] < 49 Then
$win = WinGetTitle(WinGetHandle(""))
if $win <> "" Then
$old[0]+=1
$old[$old[0]] = $win
WinSetState($win, "", @SW_HIDE)
EndIf
EndIf
EndFunc
Edited by IchBistTod

[center][/center][center]=][u][/u][/center][center][/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0