PC Review


Reply
Thread Tools Rate Thread

Close Common Dialog from hookproc

 
 
david epsom dot com dot au
Guest
Posts: n/a
 
      17th Sep 2003
I am trying to send a message to a FileOpen dialog, to tell it to close, as
suggested here:
http://msdn.microsoft.com/library/de...FNHookProc.asp

I am using :
Call PostMessage(GetParent(hwnd), WM_COMMAND, IDABORT, 0)
this didn't work either:
Call PostMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_CLOSE, 0)

hwnd is the handle to the child dialog (using the default template),
and GetParent(hwnd) is the handle to the dialog.

When I post the message, nothing happens.

FWIW, using (hwnd) closes the parent application : using
GetParent(GetParent(hwnd), (which correctly returns the hwnd of the parent
application) locks up the dialog and the parent application.

(I want this to work like the File|Get External Data|Import dialog in
MSAccess: I want to close the dialog when the ODBC file type is selected. I
am trapping the CFileDialog::OnTypeChange event)

Any suggestions?

(david)


 
Reply With Quote
 
 
 
 
Randy Birch
Guest
Posts: n/a
 
      17th Sep 2003
Try something along the line of ...

Case WM_NOTIFY

Dim notify As OFNOTIFY
Dim hWndTargetBtn As Long

Call CopyMemory(notify, ByVal lParam, Len(notify))

Select Case notify.hdr.code

Case CDN_SELCHANGE

hwndParent = GetParent(hwnd)
hWndTargetBtn = GetDlgItem(hwndParent, IDOK)

If <WHATEVER> Then

If hWndTargetBtn <> 0 Then

'simulate a mouse click on the button
Call PutFocus(hWndTargetBtn)
Call PostMessage(hWndTargetBtn, WM_LBUTTONDOWN,
0, ByVal 0&)
Call PostMessage(hWndTargetBtn, WM_LBUTTONUP, 0,
ByVal 0&)
Call PostMessage(hWndTargetBtn, WM_LBUTTONDOWN,
0, ByVal 0&)
Call PostMessage(hWndTargetBtn, WM_LBUTTONUP, 0,
ByVal 0&)
Debug.Print "should have closed", hWndTargetBtn

End If

End If

.... where the " If <WHATEVER> " test is your code to ensure an actual file
name has been selected.


'------------------------
Public Const IDOK = 1
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202

Public Const CDN_FIRST As Long = -601
Public Const CDN_SELCHANGE As Long = (CDN_FIRST - &H1)
Public Const CDN_TYPECHANGE As Long = (CDN_FIRST - &H6)

Public Const WM_NOTIFY As Long = &H4E&

Public Type NMHDR
hWndFrom As Long
idfrom As Long
code As Long
End Type

Public Type OFNOTIFY
hdr As NMHDR
ofnPtr As Long ' OPENFILENAMEPTR
pszFile As Long
End Type


Public Declare Function GetDlgItem Lib "user32" _
(ByVal hDlg As Long, _
ByVal nIDDlgItem As Long) As Long

Public Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Long) As Long

Public Declare Function PutFocus Lib "user32" _
Alias "SetFocus" _
(ByVal hwnd As Long) As Long

Public Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)


--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.


"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
news:(E-Mail Removed)...
: I am trying to send a message to a FileOpen dialog, to tell it to close,
as
: suggested here:
:
http://msdn.microsoft.com/library/de...FNHookProc.asp
:
: I am using :
: Call PostMessage(GetParent(hwnd), WM_COMMAND, IDABORT, 0)
: this didn't work either:
: Call PostMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_CLOSE, 0)
:
: hwnd is the handle to the child dialog (using the default template),
: and GetParent(hwnd) is the handle to the dialog.
:
: When I post the message, nothing happens.
:
: FWIW, using (hwnd) closes the parent application : using
: GetParent(GetParent(hwnd), (which correctly returns the hwnd of the parent
: application) locks up the dialog and the parent application.
:
: (I want this to work like the File|Get External Data|Import dialog in
: MSAccess: I want to close the dialog when the ODBC file type is selected.
I
: am trapping the CFileDialog::OnTypeChange event)
:
: Any suggestions?
:
: (david)
:
:


 
Reply With Quote
 
david epsom dot com dot au
Guest
Posts: n/a
 
      17th Sep 2003
Cool!

(david)

"Randy Birch" <rgb at mvps dot org> wrote in message
news:(E-Mail Removed)...
> Try something along the line of ...
>
> Case WM_NOTIFY
>
> Dim notify As OFNOTIFY
> Dim hWndTargetBtn As Long
>
> Call CopyMemory(notify, ByVal lParam, Len(notify))
>
> Select Case notify.hdr.code
>
> Case CDN_SELCHANGE
>
> hwndParent = GetParent(hwnd)
> hWndTargetBtn = GetDlgItem(hwndParent, IDOK)
>
> If <WHATEVER> Then
>
> If hWndTargetBtn <> 0 Then
>
> 'simulate a mouse click on the button
> Call PutFocus(hWndTargetBtn)
> Call PostMessage(hWndTargetBtn, WM_LBUTTONDOWN,
> 0, ByVal 0&)
> Call PostMessage(hWndTargetBtn, WM_LBUTTONUP,

0,
> ByVal 0&)
> Call PostMessage(hWndTargetBtn, WM_LBUTTONDOWN,
> 0, ByVal 0&)
> Call PostMessage(hWndTargetBtn, WM_LBUTTONUP,

0,
> ByVal 0&)
> Debug.Print "should have closed", hWndTargetBtn
>
> End If
>
> End If
>
> ... where the " If <WHATEVER> " test is your code to ensure an actual file
> name has been selected.
>
>
> '------------------------
> Public Const IDOK = 1
> Public Const WM_LBUTTONDOWN = &H201
> Public Const WM_LBUTTONUP = &H202
>
> Public Const CDN_FIRST As Long = -601
> Public Const CDN_SELCHANGE As Long = (CDN_FIRST - &H1)
> Public Const CDN_TYPECHANGE As Long = (CDN_FIRST - &H6)
>
> Public Const WM_NOTIFY As Long = &H4E&
>
> Public Type NMHDR
> hWndFrom As Long
> idfrom As Long
> code As Long
> End Type
>
> Public Type OFNOTIFY
> hdr As NMHDR
> ofnPtr As Long ' OPENFILENAMEPTR
> pszFile As Long
> End Type
>
>
> Public Declare Function GetDlgItem Lib "user32" _
> (ByVal hDlg As Long, _
> ByVal nIDDlgItem As Long) As Long
>
> Public Declare Function PostMessage Lib "user32" _
> Alias "PostMessageA" _
> (ByVal hwnd As Long, _
> ByVal wMsg As Long, _
> ByVal wParam As Long, lParam As Long) As Long
>
> Public Declare Function PutFocus Lib "user32" _
> Alias "SetFocus" _
> (ByVal hwnd As Long) As Long
>
> Public Declare Sub CopyMemory Lib "kernel32" _
> Alias "RtlMoveMemory" _
> (Destination As Any, _
> Source As Any, _
> ByVal Length As Long)
>
>
> --
>
> Randy Birch
> MVP Visual Basic
> http://www.mvps.org/vbnet/
> Please respond only to the newsgroups so all can benefit.
>
>
> "david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
> news:(E-Mail Removed)...
> : I am trying to send a message to a FileOpen dialog, to tell it to close,
> as
> : suggested here:
> :
>

http://msdn.microsoft.com/library/de...FNHookProc.asp
> :
> : I am using :
> : Call PostMessage(GetParent(hwnd), WM_COMMAND, IDABORT, 0)
> : this didn't work either:
> : Call PostMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_CLOSE, 0)
> :
> : hwnd is the handle to the child dialog (using the default template),
> : and GetParent(hwnd) is the handle to the dialog.
> :
> : When I post the message, nothing happens.
> :
> : FWIW, using (hwnd) closes the parent application : using
> : GetParent(GetParent(hwnd), (which correctly returns the hwnd of the

parent
> : application) locks up the dialog and the parent application.
> :
> : (I want this to work like the File|Get External Data|Import dialog in
> : MSAccess: I want to close the dialog when the ODBC file type is

selected.
> I
> : am trapping the CFileDialog::OnTypeChange event)
> :
> : Any suggestions?
> :
> : (david)
> :
> :
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
common dialog Joel Allen Microsoft Outlook VBA Programming 1 9th Apr 2009 02:36 PM
common dialog "C:\Program\Common" and after rebbot =?Utf-8?B?LS0tLW5pa29zIDQwMDAtLS0t?= Windows XP General 2 19th Mar 2006 10:43 PM
Common Dialog Box SecretCharacter Microsoft Access Forms 3 28th Dec 2004 06:12 AM
MS Common Dialog box Mark Microsoft Access Form Coding 1 17th Aug 2004 01:51 PM
Re: Common Dialog? Kevin Spencer Microsoft ASP .NET 2 23rd Jan 2004 07:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:28 PM.