AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Detect Open/Save dialog

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
majkinetor



Joined: 24 May 2006
Posts: 4511
Location: Belgrade

PostPosted: Tue Jun 06, 2006 7:25 am    Post subject: Detect Open/Save dialog Reply with quote

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


Code:

#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
   }
}

_________________
Back to top
View user's profile Send private message
joetazz



Joined: 23 Dec 2009
Posts: 3
Location: Dallas, TX

PostPosted: Sun Feb 21, 2010 1:05 pm    Post subject: tweak to run without Hotkey? Reply with quote

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

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


Any help would be much appreciated!
Regards,
Joe
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 4511
Location: Belgrade

PostPosted: Sun Feb 21, 2010 1:21 pm    Post subject: Reply with quote

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.
_________________
Back to top
View user's profile Send private message
derRaphael



Joined: 23 Nov 2007
Posts: 841
Location: ~/.

PostPosted: Sun Feb 21, 2010 3:16 pm    Post subject: Reply with quote

i felt that this log time ago written script somehow fits into this topic

Code:
#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
Back to top
View user's profile Send private message
joetazz



Joined: 23 Dec 2009
Posts: 3
Location: Dallas, TX

PostPosted: Tue Feb 23, 2010 1:46 am    Post subject: Showing details in open/close windows Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group