Re: [Help] At wit's end about zOrder and API
From: alpine (alpine_don'tsendspam_at_mvps.org)
Date: 01/27/05
- Next message: Veign: "Re: [Help] At wit's end about zOrder and API"
- Previous message: Karl E. Peterson: "Re: Monitor position in dual mode"
- In reply to: Patrick Pirtle: "[Help] At wit's end about zOrder and API"
- Next in thread: Patrick Pirtle: "Re: [Help] At wit's end about zOrder and API"
- Reply: Patrick Pirtle: "Re: [Help] At wit's end about zOrder and API"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 27 Jan 2005 10:36:51 -0700
>From your description, it sounds like Window(1) and Window(2) are from
different applications which sounds like a mess. ;-)
Have you thought about dumping the TOPMOST thing and setting Window(1)
as the owner of Window(2) and Window(2) as the owner of your userform?
(You would, of course, have to clean up properly to keep things from
exploding when the other two apps shut down)
HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
On Thu, 27 Jan 2005 09:13:59 -0800, "Patrick Pirtle" <pap at skilling
dot com> wrote:
>I've been trying to use the helpful advice I've received from a number
>of people on threads in this forum to create an app (actually w/VBA,
>not
>VB) within a CADD program. The program opens two windows, and
>we have each of them them positioned on a separate monitor. I'll
>refer
>to these windows as "Window(1)" and "Window(2)."
>
>When my app starts, Window(1) owns my form. What I'm *trying*
>to do is make my form act like BOTH Window(1) and Window(2)
>are its owners. The code below shows what I've come up with that
>"kind of" works. I'm using a timer to move my form to the top.
>
>Using this, if one of the windows has focus, and you change focus to
>the other one, my app pops to the front. Good.
>
>If you minimize one of the windows, my app may disappear, but
>pops quickly back up if the other window has focus. Good.
>
>The CADD program is constantly opening other dialog boxes, some
>of which display temporarily and disappear if the user doesn't
>mouseover
>them. If Window(2) owns my form, each time one of these temporary
>dialogs opens, my form disappears and reappears. This only happens
>with Window(2). This is driving my users crazy. BAD!!
>
>Any suggestions for how I can polish these problems out? TIA for
>all your help and suggestions.
>
>****************************************************
>Form code
>****************************************************
>Private Sub UserForm_Initialize()
> Dim hWndForm As Long
>
> 'Get the userform's window handle
> hWndForm = FindWindow("ThunderDFrame", Me.Caption)
>
> 'change the uElapse parameter as needed. It should be high enough
> ' to bring the form to the top without any apparent delay, but
>low
> ' enough that it doesn't slow down other processes.
> 'SetTimer hWndForm, 0, uElapse, AddressOf TimerProc
> SetTimer hWndForm, 0, 750, AddressOf TimerProc
>End Sub
>
>
>****************************************************
>Main module code
>****************************************************
>'============================DECLARATIONS=====================================
>Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
> (ByVal lpClassName As String, ByVal lpWindowName As String) As
>Long
>Private Declare Function GetFocus Lib "user32" () As Long
>Private Declare Function GetForegroundWindow Lib "user32" () As Long
>Private Declare Function GetWindowText Lib "user32" Alias
>"GetWindowTextA" (ByVal hWnd As Long, _
> ByVal lpString As String, ByVal cch As Long) As Long
>Private Declare Function IsIconic Lib "user32.dll" (ByVal hWnd As
>Long) As Long
>Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, _
> ByVal wCmd As Long) As Long
>Private Declare Function SetWindowLong Lib "user32" _
> Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long,
>_
> ByVal dwNewLong As Long) As Long
>Private Declare Function 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) As Long
>
>Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long,
>ByVal nIDEvent As Long) As Long
>Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long,
>ByVal nIDEvent As Long, _
> ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
>
>Public hWndOwnr As Long
>Public hWndForm As Long
>
>'============================CONSTANTS========================================
>Private Const GWL_HWNDPARENT = (-8)
>Private Const GW_OWNER = 4
>
>Private Const HWND_TOPMOST = 0
>' Private Const HWND_TOPMOST = -1
>
>Private Const SWP_NOACTIVATE = &H10
>Private Const SWP_NOSIZE = &H1
>Private Const SWP_NOMOVE = &H2
>Private Const SWP_SHOWWINDOW = &H40
>
>'============================SUBROUTINES======================================
>
>Public Sub TimerProc(ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal
>uElapse As Long, _
> ByVal lpTimerFunc As Long)
> Dim hWndFocus As Long
> Dim wndFocusCap As String
> Dim wndFocusCapTrim As String
> Dim hNewWndOwner As Long
> Dim captionOrig As String
> Dim captionTrim As String
> Dim newCaptionTrim As String
>
> hWndFocus = GetForegroundWindow()
> wndFocusCap = String(500, Chr$(0))
> GetWindowText hWndFocus, wndFocusCap, 500
> wndFocusCapTrim = Left(wndFocusCap, InStr(1, wndFocusCap, Chr$(0),
>vbTextCompare) - 1)
>
> 'Find the handle of this form using it's caption
> hWndForm = FindWindow("ThunderDFrame", frm_MKA_001.Caption)
>
> 'Get this form's owner using this form's handle
> hWndOwnr = GetWindow(hWndForm, GW_OWNER)
>
> 'Create a string buffer to hold the owner's caption
> captionOrig = String(500, Chr$(0))
>
> 'Fill in the caption
> GetWindowText hWndOwnr, captionOrig, 500
>
> 'Trim all the chr$(0) characters off the right end of the caption
> captionTrim = Left(captionOrig, InStr(1, captionOrig, Chr$(0),
>vbTextCompare) - 1)
>
> 'Construct the new owner window caption based on the current
>owner's caption
> Select Case Right(captionTrim, 3)
> Case "(1)"
> newCaptionTrim = Left(captionTrim, Len(captionTrim) - 3) +
>"(2)"
> Case "(2)"
> newCaptionTrim = Left(captionTrim, Len(captionTrim) - 3) +
>"(1)"
> Case Else 'Only (1) MicroStation window is open
> Exit Sub
> End Select
>
> 'locate the new owner window using the constructed caption
> hNewWndOwner = FindWindow(vbNullString, newCaptionTrim)
>
>'******* 'Don't RE-bring to front if the window with focus is
>simply a CADD
>'******* 'child window like the Tool Settings dialog box
>'******* 'If
>'******* 'Else
> 'Switch owners if:
> ' - EITHER MicroStation window has focus, and
> ' - The focused uSTN window is NOT the current owner
> If (Left(wndFocusCapTrim, Len(captionTrim) - 3) =
>Left(captionTrim, Len(captionTrim) - 3)) And _
> (wndFocusCapTrim <> captionTrim) Then
>
> SetWindowLong hWndForm, GWL_HWNDPARENT, hNewWndOwner
> SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or
>SWP_NOSIZE Or _
> SWP_SHOWWINDOW Or SWP_NOACTIVATE
> End If
>'******* 'End If
>
>End Sub
>
>
>
- Next message: Veign: "Re: [Help] At wit's end about zOrder and API"
- Previous message: Karl E. Peterson: "Re: Monitor position in dual mode"
- In reply to: Patrick Pirtle: "[Help] At wit's end about zOrder and API"
- Next in thread: Patrick Pirtle: "Re: [Help] At wit's end about zOrder and API"
- Reply: Patrick Pirtle: "Re: [Help] At wit's end about zOrder and API"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|