How to make desktop gadgets these days? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
william_ahk
Posts: 598
Joined: 03 Dec 2018, 20:02

How to make desktop gadgets these days?

Post by william_ahk » 23 Jul 2024, 00:47

I tried this and it kind of works. The issue is that when I go Show Desktop (or Win+D) it would disappear. I guess it's not finding the right desktop window?

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
G := Gui("-Caption +ToolWindow")
G.AddText("w300 h200", "Test Gadget")
G.Show("NoActivate")
SetAsDesktopGadget(G.Hwnd)

SetAsDesktopGadget(hWindow) {
	DetectHiddenWindows 1
	SendMessage(0x052C, 0, 0, , "ahk_id " WinExist("ahk_class Progman"))
	For Window in WinGetList("ahk_class WorkerW") {
	} Until !DllCall("FindWindowEx", "Ptr", Window, "Ptr", 0, "Str", "SHELLDLL_DefView", "UPtr", 0, "Ptr")
	&& hWorkerW := Window
	DllCall("SetWindowLongPtr", "Ptr", hWindow, "Int", -8, "Ptr", hWorkerW, "Ptr")
	DllCall("SetWindowPos", "uint", hWindow, "uint", hWorkerW, "int", 0, "int", 0, "int", 0, "int", 0, "uint", 0x13)
}

teadrinker
Posts: 4542
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to make desktop gadgets these days?  Topic is solved

Post by teadrinker » 23 Jul 2024, 03:54

Code: Select all

#Requires AutoHotkey v2.0

G := Gui("-Caption +ToolWindow")
G.AddText("w300 h200", "Test Gadget")
G.Show("NoActivate")
SetGuiOnDesktop(G, 300, 300)

SetGuiOnDesktop(guiObj, x, y) {
    static GW_CHILD := 5, HWND_BOTTOM := 1, flags := (SWP_SHOWWINDOW := 0x40) | (SWP_NOACTIVATE := 0x10) | (SWP_NOSIZE := 0x1)
    hOwner := DllCall('GetWindow', 'Ptr', WinExist('ahk_class WorkerW') || WinExist('ahk_class Progman'), 'Int', GW_CHILD, 'UInt')
    guiObj.Opt('+Owner' . hOwner)
    DllCall('SetWindowPos', 'Ptr', guiObj.Hwnd, 'Ptr', HWND_BOTTOM, 'Int', x, 'Int', y, 'Int', 0, 'Int', 0, 'UInt', flags)
}

william_ahk
Posts: 598
Joined: 03 Dec 2018, 20:02

Re: How to make desktop gadgets these days?

Post by william_ahk » 23 Jul 2024, 04:39

teadrinker wrote:
23 Jul 2024, 03:54

Code: Select all

[...]
Thanks teadrinker, once again you are maintaining the state of GUI in AHK! :thumbup:

Why not use SWP_NOMOVE though? Are there performance considerations, function design?

Code: Select all

SetGuiOnDesktop(GuiObj) {
    Static GW_CHILD := 5, HWND_BOTTOM := 1, Flags := (SWP_SHOWWINDOW := 0x40) | (SWP_NOACTIVATE := 0x10) | (SWP_NOSIZE := 0x1) | (SWP_NOMOVE := 0x2)
    hOwner := DllCall("GetWindow", "Ptr", WinExist("ahk_class WorkerW") || WinExist("ahk_class Progman"), "Int", GW_CHILD, "UInt")
    GuiObj.Opt("+Owner" . hOwner)
    DllCall("SetWindowPos", "Ptr", GuiObj.Hwnd, "Ptr", HWND_BOTTOM, "Int", 0, "Int", 0, "Int", 0, "Int", 0, "UInt", Flags)
}

teadrinker
Posts: 4542
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to make desktop gadgets these days?

Post by teadrinker » 23 Jul 2024, 06:56

If you don't need to specify coordinates, you can use it.

User avatar
kunkel321
Posts: 1262
Joined: 30 Nov 2015, 21:19

Re: How to make desktop gadgets these days?

Post by kunkel321 » 23 Jul 2024, 09:12

Cool script! I think this one does similar things. viewtopic.php?f=83&t=89979
name := "ste(phen|ve) kunkel"

e-t-l
Posts: 4
Joined: 19 Aug 2024, 01:48
Contact:

Re: How to make desktop gadgets these days?

Post by e-t-l » 19 Aug 2024, 02:00

teadrinker wrote:
23 Jul 2024, 03:54

Code: Select all

#Requires AutoHotkey v2.0

G := Gui("-Caption +ToolWindow")
G.AddText("w300 h200", "Test Gadget")
G.Show("NoActivate")
Will this only work for AHK GUI windows, or can it be modified to make any window stay visible on the desktop (so it ignores Win+D, etc)? I have a different program that creates a desktop gadget experiencing the same problem.

teadrinker
Posts: 4542
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to make desktop gadgets these days?

Post by teadrinker » 19 Aug 2024, 02:56

You can try this:

Code: Select all

#Requires AutoHotkey v2.0

hwnd := WinExist('ahk_class Notepad')
SetWindowOnDesktop(hwnd, 300, 300)

SetWindowOnDesktop(hwnd, x, y) {
    static GW_CHILD := 5, HWND_BOTTOM := 1, GWLP_HWNDPARENT := -8
         , flags := (SWP_SHOWWINDOW := 0x40) | (SWP_NOACTIVATE := 0x10) | (SWP_NOSIZE := 0x1)
    hOwner := DllCall('GetWindow', 'Ptr', WinExist('ahk_class WorkerW') || WinExist('ahk_class Progman'), 'Int', GW_CHILD, 'UInt')
    DllCall('SetWindowLong' . (A_PtrSize = 4 ? '' : 'Ptr'), 'Ptr', hwnd, 'Int', GWLP_HWNDPARENT, 'Ptr', hOwner)
    DllCall('SetWindowPos', 'Ptr', hwnd, 'Ptr', HWND_BOTTOM, 'Int', x, 'Int', y, 'Int', 0, 'Int', 0, 'UInt', flags)
}
I don't know if this will work with all windows.

Post Reply

Return to “Ask for Help (v2)”