Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created May 12, 2015 21:29
Show Gist options
  • Select an option

  • Save tmplinshi/4f371090cea46fe7afcc to your computer and use it in GitHub Desktop.

Select an option

Save tmplinshi/4f371090cea46fe7afcc to your computer and use it in GitHub Desktop.
; Usage: Gui_NoActivate(GuiHwnd)
Gui_NoActivate(wParam:="", lParam:="", msg:="", hwnd:="") {
static WM_NCLBUTTONDOWN := 0xA1
, WM_NCMOUSEMOVE := 0xA0
, WS_EX_NOACTIVATE := 0x08000000
, pre_hForegroundWnd
If (msg = WM_NCLBUTTONDOWN) {
pre_hForegroundWnd := DllCall("GetForegroundWindow")
WinSet, ExStyle, -%WS_EX_NOACTIVATE%, ahk_id %hwnd%
DllCall("SetForegroundWindow", "Uint", hwnd)
}
Else If (msg = WM_NCMOUSEMOVE) {
If !pre_hForegroundWnd || GetKeyState("LButton", "P")
Return
WinSet, ExStyle, +%WS_EX_NOACTIVATE%, ahk_id %hwnd%
DllCall("SetForegroundWindow", "Uint", pre_hForegroundWnd)
pre_hForegroundWnd := ""
}
Else If !msg {
Gui, +LastFound
WinSet, ExStyle, +%WS_EX_NOACTIVATE%
OnMessage(WM_NCLBUTTONDOWN, A_ThisFunc)
OnMessage(WM_NCMOUSEMOVE, A_ThisFunc)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment