SHELLING and TOPMOST question
Is it possible to make a Shelled pgm TopMost, when I am Shelling via a JPEG file ?
I show all my forms VBModal.
I have a wide form with a grid, listing lots of job records (the Job Register).
If user clicks on a row they get a form showing the details for that job record.
The detail form is similar in size to an A4 sheet of paper, in the sense that it -
- occupies the full height of the screen, but not the full width.
- when printed, it exactly matches the dimensions of the A4 sheet.
The user would like the ability to call up a view of scanned images which are also A4 dimension.
I can do that with this code -
VB Code:
Private Sub ShowScans()
Dim sPathAndFile As String
sPathAndFile = App.path & "\" & "Scan01.jpg"
LaunchFile sPathAndFile
End Sub
'IN BAS FILE
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
'Constant declarations
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Function LaunchFile(Filename As String, Optional WindowState As Integer, Optional Action As Integer) As Long
Dim retVal As Long
Dim LAction As String
'If window state is not specified, set to normal
If WindowState = 0 Then WindowState = SW_SHOWNORMAL
'Assign action
'If Action = 0 Then
LAction = "Open"
'Else
' LAction = "Print"
'End If
'Call the function
retVal = ShellExecute(0&, _
LAction, _
Filename, _
vbNullString, _
vbNullString, _
WindowState)
LaunchFile = retVal
End Function
This works, and the user can redimension the XP Windows Picture and Fax viewer so that it is occupying the left half of the screen. They can have my Job Form on the right.
The problem is
Somehow they should be able to have both visible at the same time.
At the moment, they can get that 'view', but the minute they click in my Job Form, the Win XP Picture viewer goes behind the other forms that my pgm has showing (the wider Job register grid, that the user used to get to the job Form).
I could make my Job Form TopMost(API call), but that does not prevent the Win XP Picture viewer going behind other forms.
I believe the best solution would be for me to make the Win XP Picture viewer, TopMost
If I had 'shelled' the Win XP Picture viewer direct, no doubt I could get the handle and make it TopMost.
With my approach above, I tried TopMosting the returned value, but that did not work (I didn't think it would).
I like my current approach, which just Shells the JPEG, as it just simply opens up the image in the user's default viewer (clean, simple, 'idiot proof' for this humble programmer).
Is it possible for me to make the default viewer topmost when I am opening it with my code above ?
Re: SHELLING and TOPMOST question
You can make just about any window TopMost. You can use the FindWindow API to get the windows handle.
Then you can use SetWindowLong to change the window style to TopMost.
Re: SHELLING and TOPMOST question
I am now 'Googling' to find FindWindow examples.
Thanks,
Re: SHELLING and TOPMOST question
You'll find an excellent reference at http://www.mentalis.org/apilist/apilist.php
All API List
Re: SHELLING and TOPMOST question
Forget Google, there are many examples on the Forums.
FindWindow
FindWindow 2
Re: SHELLING and TOPMOST question
Re: SHELLING and TOPMOST question
AppActivate will not make both windows visible at the same time. :(