Fenster soll im vordergrund bleiben..wie?

hallo,

wie schaff ich es, das ein fenster immer im vordergrund bleibt und erst weggeht wenn ich den zurück-button auf dem fenster geklickt habe?!?!
jetz is es so, dass wenn ich neben das fenster A auf das dahinterliegende fenster B klicke, fenster B über dem fenster A is.

ähm, kommt noch einer mit mit meinem wirr-warr hier?!?! :wink:

axl

Hi Axl,

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

Const SWP\_NOSIZE = &H1
Const SWP\_NOMOVE = &H2
Const SWP\_SHOWWINDOW = &H40
Const HWND\_NOTOPMOST = -2
Const HWND\_TOPMOST = -1

' Set a form always on the top.
'
' the form can be specified as a Form or object
' or through its hWnd property
' If OnTop=False the always on the top mode is de-activated.

Sub SetAlwaysOnTopMode(hWndOrForm As Variant, Optional ByVal OnTop As Boolean = \_
 True)
 Dim hWnd As Long
 ' get the hWnd of the form to be move on top
 If VarType(hWndOrForm) = vbLong Then
 hWnd = hWndOrForm
 Else
 hWnd = hWndOrForm.hWnd
 End If
 SetWindowPos hWnd, IIf(OnTop, HWND\_TOPMOST, HWND\_NOTOPMOST), 0, 0, 0, 0, \_
 SWP\_NOMOVE Or SWP\_NOSIZE Or SWP\_SHOWWINDOW
End Sub

Aufruf mit

Call SetAlwaysOnTopMode(Me.hWnd, True)

Gruß
Christian

Hi,

da ich jetzt nicht genau weiß, ob du das nur für dein eigenes internes Programm benötigst oder nicht, aber das generelle In-den-Vordergrund-Stellen schon gepostet wurde, poste ich hier mal die Möglichkeit, wie du in deinem eigenem Programm die Fenster in den Vordergrund stellen kannst.

Beispiel:
Erstelle 2 Forms.
Schreib folgenden Code in Form1

Sub Form_Load()
form2.show ,form1
End Sub

Jetzt hast du die 2. Form im Vordergrund. Wenn du jetzt auf Form1 klickst, dann bleibt immer noch die 2. Form im Vordergrund.

Du kannst jetzt das ganze noch modal öffnen, dann bleibt kannst du im Code solange in Form 1 warten bis Form2 geschlossen ist

Beispiel

Sub Form_Load()
form2.show vbmodal, form1
msgbox „Hallo“
End Sub

Erst wenn form2 geschlossen wird erscheint die Messagebox.

Hoffe, es hilft dir weiter

greetz

Mario