|
-
Dec 16th, 2000, 07:46 PM
#1
Thread Starter
Fanatic Member
How do I make a window modal that was opened using Shell Execute? I'm using the following code that I found on VB-World to display a property box for files, but I would like the property window to be modal when it opens up or at least cancel the window when it losses focus. The flag may already be listed in the code and I'm just missing it. Thanks:
Code:
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400
Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Sub ShowProps(FileName As String, OwnerhWnd As Long)
Dim SEI As SHELLEXECUTEINFO
Dim r As Long
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or _
SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
.hwnd = OwnerhWnd
.lpVerb = "properties"
.lpFile = FileName
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
r = ShellExecuteEX(SEI)
End Sub
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Dec 16th, 2000, 09:04 PM
#2
Frenzied Member
Just set ít's position with SetWindowPos API:
Code:
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Sub Form_Activate()
SetWindowPos r, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Did that help?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Dec 16th, 2000, 10:31 PM
#3
Thread Starter
Fanatic Member
Not really, what I really need is for the properties window to be modal so that my application can not regain focus until it is cancelled out.
Or if I could get it to cancel when it loses focus would work too. Thanks anyway.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Dec 17th, 2000, 04:25 AM
#4
Fanatic Member
How about a Timer control combine with Jop's code.
Chemically Formulated As:
Dr. Nitro
-
Dec 17th, 2000, 07:13 AM
#5
Frenzied Member
I have bad news for ya.
This window doesn't seem to react like any other 'normal' window.
The thing I experienced is that it doesn't receive the WM_KILLFOCUS msg when losing focus (like any other window), but only when it's closed.
Therefore we cannot intercept the message and respond to it (cancel it in our case).
Also, I wasn't able to find any constants that'll show it Modal (SE_, SEE_, SW_ were all without succes), but it doesn't matter because the window doesn't seem to accept this parameters anyway (the .nShow doesn't seem to care whatever you pass it, it shows it default.)
Anyway, if you're interested how I tried to fix it, here's the code I used to intercept the WM_KILLFOCUS msg:
In a module:
Code:
Option Explicit
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400
Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const GWL_WNDPROC = (-4)
Private Const WM_KILLFOCUS = &H8
Dim PrevProc As Long
Public Sub Hook(Wnd As Long)
PrevProc = SetWindowLong(Wnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook(Wnd As Long)
SetWindowLong Wnd, GWL_WNDPROC, PrevProc
End Sub
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
If uMsg = WM_KILLFOCUS Then
Debug.Print "FOCUS KILLED"
End If
End Function
Public Sub ShowProps(FileName As String, OwnerhWnd As Long)
Dim SEI As SHELLEXECUTEINFO
Dim r As Long
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or _
SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
.hwnd = OwnerhWnd
.lpVerb = "properties"
.lpFile = FileName
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
r = ShellExecuteEX(SEI)
End Sub
In a form:
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private lProp&
Private Sub Form_Load()
ShowProps "c:\jop\hehe.txt", Me.hwnd 'open the dialog.
lProp = FindWindow("StubWindow32", vbNullString) 'find the handle of the window
If lProp <> 0 Then Hook lProp 'if found, subclass it
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook lProp 'stop the subclassing
End Sub
Maybe you can make something of it
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Dec 17th, 2000, 09:11 PM
#6
You may also want to check out the SetSysModalWindow API function. (Not sure if it works)
Code:
Private Declare Function SetSysModalWindow Lib "User" _
(ByVal hWnd As Integer) As Integer
'Private Declare Function SetSysModalWindow Lib "User32" _
'(ByVal hWnd As Integer) As Integer
-
Dec 18th, 2000, 09:52 AM
#7
Frenzied Member
hmm Matthew, where did you get that function?
I think someone's fooling you,
First of all, the Entry doesn't exists in my User32 (i don't have a user.dll)
and second, most of the time, hWnd's are Long integers, so I don't get it mate 
I think this should be the Good declration then
Code:
Private Declare Function SetSysModalWindow Lib "User" _
(ByVal hWnd As Long) As Long
hmm maybe it's new in win2k or winME or something?
Anyone ever heard of this call? I don't 
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Dec 18th, 2000, 11:17 AM
#8
Lively Member
-
Dec 18th, 2000, 12:16 PM
#9
Frenzied Member
Ah that cleared things up (that it's absolete)
thanks Corey.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|