AutoHotkey Community

It is currently May 27th, 2012, 4:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Detect Open/Save dialog
PostPosted: June 6th, 2006, 8:25 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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
   }
}

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 21st, 2010, 2:05 pm 
Offline

Joined: December 23rd, 2009, 4:53 pm
Posts: 3
Location: Dallas, TX
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 2:21 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2010, 4:16 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
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

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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 23rd, 2010, 2:46 am 
Offline

Joined: December 23rd, 2009, 4:53 pm
Posts: 3
Location: Dallas, TX
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group