 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Wed May 19, 2010 9:28 pm Post subject: |
|
|
| jaco0646 wrote: | | I'd like to not have to flash the window open just to get its handle. Any thoughts? |
| Code: | winGet, tmHwnd, ID, Windows Task Manager
msgbox % tmHwnd |
edit:
or
| Code: | setformat, integerfast, H
msgbox % tmHwnd:=dllCall("FindWindow", str, "#32770", str, "Windows Task Manager") |
_________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Wed May 19, 2010 11:04 pm Post subject: |
|
|
I forgot to note earlier that to make Task Manager minimize to the tray, go to the Options menu and check Hide When Minimized.
I had also forgotten to detect hidden windows. | Code: | DetectHiddenWindows, On
Run, taskmgr.exe,,Min,PID
WinWait, ahk_pid %PID%
DisableCloseButton(WinExist())
DisableCloseButton(hWnd) {
hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE)
nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu)
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-1,"Uint","0x400")
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-2,"Uint","0x400")
DllCall("DrawMenuBar","Int",hWnd)
} |
This code works about 50% of the time. The other half, the button is not disabled even though the handle is found. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Wed May 19, 2010 11:53 pm Post subject: |
|
|
| jaco0646 wrote: | | Task Manager. I like to keep it running in the tray for the real-time CPU usage graph. |
Nice Idea! Here is my version
- without DetectHiddenWindows
- without compromising Ctrl+Alt+Del functionality
| Code: | #NoTrayIcon
#SingleInstance, Force
If !TaskManID := DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager" ) {
Run, taskmgr.exe,,Hide
While ! TaskManID := DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager" )
Sleep 20
} Else {
TaskManID := DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager" )
WinHide, ahk_id %TaskManID%
}
DisableCloseButton( TaskManID )
Return ; // End of auto-execute section /
^!Del:: ; Ctrl+Alt+Del will toggle Hide/Show state for 'Windows Task Manager'
DllCall( "ShowWindow"
, UInt, TaskManID := DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager" )
, UInt, !DllCall( "IsWindowVisible", UInt,TaskManID ) )
Return
^!x::ExitApp, % DllCall( "ShowWindow", UInt,TaskManID, UInt,1 )
DisableCloseButton( hWnd ) {
hSysMenu := DllCall( "GetSystemMenu", UInt,hWnd, Int,0 )
nCnt := DllCall( "GetMenuItemCount", UInt,hSysMenu )
DllCall( "RemoveMenu", UInt,hSysMenu, UInt,nCnt-1, UInt,0x400 )
DllCall( "RemoveMenu", UInt,hSysMenu, UInt,nCnt-2, UInt, 0x400 )
DllCall( "DrawMenuBar", UInt,hWnd )
} |
Last edited by SKAN on Thu May 20, 2010 12:10 am; edited 1 time in total |
|
| Back to top |
|
 |
MasterFocus
Joined: 08 Apr 2009 Posts: 3035 Location: Rio de Janeiro - RJ - Brasil
|
Posted: Wed May 19, 2010 11:59 pm Post subject: |
|
|
| SKAN wrote: | | Code: | Run, taskmgr.exe,,Hide,PID
WinWait, ahk_pid %PID% |
|
Did you mean TaskManID? _________________ "Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried."
Antonio França
My stuff: Google Profile |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu May 20, 2010 12:11 am Post subject: |
|
|
| MasterFocus wrote: | | Did you mean TaskManID? |
No.. But I overlooked the fact that WinWait would require DetectHiddenWindows. Code altered..
Thanks. |
|
| Back to top |
|
 |
TLM
Joined: 21 Aug 2006 Posts: 2926 Location: The Shell
|
Posted: Thu May 20, 2010 12:13 am Post subject: |
|
|
| SKAN wrote: | | Code: | | DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager" ) |
| Hi SKAN is there any difference between FindWindow and FindWindowA other than ANSI?
Also
Does this inverse work for all function calls to dll?
BTW after running the updated version, my taskmanager does not come back if I close it from the tray  _________________
paradigm.shift:=(•_•)┌П┐RTFM||^.*∞ |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu May 20, 2010 12:31 am Post subject: |
|
|
| TLM wrote: | | SKAN wrote: | | Code: | | DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager" ) |
| Hi SKAN is there any difference between FindWindow and FindWindowA other than ANSI? |
There is no function named FindWindow() exported in user32.dll
AutoHotkey appends the 'A' for you - automatically. Sweet!
| Quote: | | Does this inverse work for all function calls to dll? |
Yes. You may use triple toggle like !!! Function() if you strictly require a BOOLEAN.
| Quote: | BTW after running the updated version, my taskmanager does not come back if I close it from the tray  |
Use SHELLHOOK. |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Thu May 20, 2010 12:37 am Post subject: |
|
|
This seems to be 100% reliable after limited testing. | Code: | #NoTrayIcon
Run, taskmgr.exe,,Min
While ! TaskManID := DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager")
Sleep 20
DisableCloseButton( TaskManID )
DisableCloseButton( hWnd ) {
hSysMenu := DllCall( "GetSystemMenu", UInt,hWnd, Int,0 )
nCnt := DllCall( "GetMenuItemCount", UInt,hSysMenu )
DllCall( "RemoveMenu", UInt,hSysMenu, UInt,nCnt-1, UInt,0x400 )
DllCall( "RemoveMenu", UInt,hSysMenu, UInt,nCnt-2, UInt, 0x400 )
DllCall( "DrawMenuBar", UInt,hWnd )
} | Why does the loop work, when WinWait fails? |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu May 20, 2010 1:09 am Post subject: |
|
|
| jaco0646 wrote: | | Why does the loop work, when WinWait fails? |
WinWait would require DetectHiddenWindows On, I guess. |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Thu May 20, 2010 1:14 am Post subject: |
|
|
Yep, I've remembered that now. Here's my test script. The message box should never show. | Code: | ;#NoTrayIcon
DetectHiddenWindows, On
Run, taskmgr.exe,,Min,PID
WinWait, ahk_pid %PID%
h1 := WinExist()
h2 := DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager")
If (h1 = h2)
DisableCloseButton(h1)
Else MsgBox,% h1 "`n" h2
DisableCloseButton(hWnd) {
hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE)
nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu)
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-1,"Uint","0x400")
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-2,"Uint","0x400")
DllCall("DrawMenuBar","Int",hWnd)
} | But intermittently, WinExist() returns a handle and DllCall() returns 0. In these cases, it seems that WinWait has not waited long enough; but then how is WinExist() working  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu May 20, 2010 1:35 am Post subject: |
|
|
| jaco0646 wrote: | | The message box should never show. |
It never shows..
Does the following produce different result?
| Code: | DetectHiddenWindows, On
Run, taskmgr.exe,,Min,PID
WinWait, ahk_pid %PID%
h1 := WinExist( "Windows Task Manager ahk_class #32770" )
h2 := DllCall("FindWindowA", Str,"#32770", Str,"Windows Task Manager")
If (h1 = h2)
DisableCloseButton(h1)
Else MsgBox,% h1 "`n" h2 |
|
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Thu May 20, 2010 2:08 am Post subject: |
|
|
| That code is about 90% reliable for me (I ran it 50 times and it failed on 5). Here's the strange thing: I never got a message box, even on the 5 that failed to disable the button. When I don't pass a parameter to WinExist() I get a message box every time it fails (and it fails more often). |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Thu May 20, 2010 3:28 am Post subject: |
|
|
| TLM wrote: | | Does this inverse work for all function calls to dll? | It works for any expression, not just function calls.
| SKAN wrote: | | AutoHotkey appends the 'A' for you - automatically. Sweet! | If you omit the 'A', the script will also work on the Unicode build of AutoHotkey_L, which appends 'W' instead of 'A'.
| Quote: | | You may use triple toggle like !!! Function() if you strictly require a BOOLEAN. | You may also use !!!!!!!!! Function(), but ! Function() will give the same result faster. |
|
| Back to top |
|
 |
Trente Guest
|
Posted: Wed May 26, 2010 5:30 pm Post subject: Re: How to enable Drag for a Static Control ? |
|
|
| SKAN wrote: |
How to enable Drag for a Static Control ?
http://www.autohotkey.com/forum/viewtopic.php?p=123732#123732
| Code: | Loop 6
Gui, Add, Picture, Icon%A_Index% gControlMove, User32.dll
Gui, Add, Text, w200 h30 +0x201 +Border gControlMove, Static Text Control
Gui, Show, w400 h300, Click'N'Drag the Icons!
Return
ControlMove:
MouseGetPos,,,,sHwnd, 2
PostMessage, 0x112,0xF012,0,,ahk_id %sHwnd% ; [ WM_SYSCOMMAND+SC_MOVE ]
Winset,Redraw,,ahk_id %sHwnd% ; Thanks to adamrgolf
Return |
Related Post: How to enable Drag for a GUI without a Titlebar ?
|
SKAN, I have a few questions for you about this wonderful snippet of code...
1. How can I distinguish between the drag action, and a click action? And since it seems that all dragable images would have the same action code, is there a way to reference the variable of whichever image was clicked?
2. If I drag an image passing completely over another one, there are no glitches. But if I let go of the drag while one image is on top of another, then as soon as I drag that top image away, it retains whatever portion of the bottom image it was covering. I have to click that top image a second time in order to clear that. Is there a way to fix that visual glitch? |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Wed May 26, 2010 6:11 pm Post subject: |
|
|
in its most simplistic form
| Code: | #InstallMouseHook
SetTimer,mouse,10
mouse:
if !drag := GetKeyState("LButton", "P")
ToolTip % "Mouse Up"
Else ToolTip % "Holding down"
Return |
_________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|