Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Detect Open/Save dialog


  • Please log in to reply
4 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
This script will write a message when you pres WIN + N with Open/Save dialog active. You can use it to write Open/Save dialog enhacers.

Functions:

DialogWindowActive()
Returns true if Open/Save dialog is active

IsDialog (HWND)
Returns true if handle represents Open/Save dialog


#n::
 if (DialogWindowActive())
   MsgBox Open/Save dialog detected

return

DialogWindowActive()
{	
	WinGet, active_hwnd, ID, A
	{
		if ( IsDialog( active_hwnd ) )
			return 1
		else 
			return 0
	}	

	return 0
}

;------------------------------------------------------------------------------------------------

IsDialog(dlg)
{

	local toolbar, edit, combo, button

	toolbar := FindWindowExID(dlg, "ToolbarWindow32", "0x440")	  ;windows XP
	if (toolbar = "0")
		toolbar := FindWindowExID(dlg, "ToolbarWindow32", "0x001")  ;windows 2k

	edit   := FindWindowExID(dlg, "Edit", "0x480")			; edit field
	combo  := FindWindowExID(dlg, "ComboBoxEx32", "0x47C")	; comboboxex field
	button := FindWindowExID(dlg, "Button", "0x001")		; second button


	if (toolbar && (combo || edit) && button) 
		return 1
	else
		return 0
}


;------------------------------------------------------------------------------------------------
; Iterate through controls with the same class, find the one with ctrlID and return its handle
; Used for finding a specific control on a dialog

FindWindowExID(dlg, className, ctrlId)
{
	local ctrl, id

	ctrl = 0
	Loop
	{
		ctrl := DllCall("FindWindowEx", "uint", dlg, "uint", ctrl, "str", className, "uint", 0 )
		if (ctrlId = "0")
		{
			return ctrl
		}

		if (ctrl != "0")
		{
			id := DllCall( "GetDlgCtrlID", "uint", ctrl )
			if (id = ctrlId) 
				return ctrl				
		}
		else 
			return 0
	}
}

Posted Image

Joe Glines
  • Members
  • 118 posts
  • Last active: Jan 24 2016 03:08 PM
  • Joined: 23 Dec 2009
Windows drives me crazy that I cannot always have my Open/Close dialogues set to details. I've adapted the code to work when I press Win+N however I'd love to be able to skip this step.

I'm sure this is very easy to do however I'm very new to AHK & programming.

BTW- here is what I've put at the front. Probably a much slicker way to do this however it is simple, stable, and works

#n::
 if (DialogWindowActive())
;   MsgBox Open/Save dialog detected
 Send, !i
 Send, {TAB}{Left}{SPACE}D
return

Any help would be much appreciated!
Regards,
Joe

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
As a newbeee, You could set a timer that checks for dialog existance every 500 ms. There is faster solution using hooks but its not trivial.
Posted Image

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
i felt that this log time ago written script somehow fits into this topic

#Persistent
SetTimer, testWindow, 100

testWindow:
  ActiveHWND  := WinActive("A")
  TargetClass := "Notepad"
  
  WinGetClass, CurrentClass, ahk_id %ActiveHWND%

  If (CurrentClass="#32770")
  {
	 ; Gets the owner's hWnd
    OwnerHWND   := DllCall("GetWindow","UInt",ActiveHWND,"UInt",4)
	 
    WinGetClass, parentClass, ahk_id %OwnerHWND%
    WinGetTitle, parentTitle, ahk_id %OwnerHWND%
	 
    If (parentClass = TargetClass)
    {
      ToolTip, % "Dialog Window from " parentTitle " found"
    }
  }
   else
  {
    ToolTip
  }
return

this particular window checks the current topmost window and queries its parent window handle. then the hwnd is checked against a predefined window class and a lil tooltip is displayed.

the reason why i posted it here, is that the described technique shows how to query for a dialogues parent and do any checks so this might be used additionally to the functions presented by majkinetor.

greets
dR

Edit: The window to check against in this sample is notepads' dlgs

All scripts, unless otherwise noted, are hereby released under CC-BY

Joe Glines
  • Members
  • 118 posts
  • Last active: Jan 24 2016 03:08 PM
  • Joined: 23 Dec 2009
I ended up doing something that works for 90% of the cases, doesn't have much overhead and is super-simple

; DETAILS IN OPEN
~^o::
Send, !i
Send, {TAB}{Left}{SPACE}D
return

; DETAILS IN CLOSE
~^s::
Send, !i
Send, {TAB}{Left}{SPACE}D
return