Visual Basic always on top

demmy86

Level-2
Beiträge
202
Reaktionspunkte
0
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo zusammen!
Ich versuche mit Visual Basic eine always on top Anwendung zu erstellen,
d.h. sobald ich die Anwendung starte soll das Fenster immer oben auf sein!
Ich bekomm es aber irgendwie nicht hin.
Hat jemand eine Beispielanwendung die er mir zukommen lassen könnte?
MfG
 
Ist nicht direkt sondern nur mit Win32-API-Aufrufen möglich.
In einem normalen Modul (*.bas) deklarieren:
Code:
Public Const SWP_SHOWWINDOW = &H40
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

Public 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
und in dem Hauptfenster aufrufen:

Code:
SetWindowPos Me.hwnd, HWND_TOPMOST, Left \ Screen.TwipsPerPixelX, Top \ Screen.TwipsPerPixelY, Width \ Screen.TwipsPerPixelX, Height \ Screen.TwipsPerPixelY, SWP_SHOWWINDOW
 
Zuviel Werbung?
-> Hier kostenlos registrieren
Hallo!
Danke erst mal!
Also der Aufruf im Modul hat funktioniert, nur bekomme ich beim Aufruf in der Form eine Fehlermeldung!

Mit welchem Befehl muss ich das denn aufrufen? gibt es da einen bestimmten?

gruß
 
Welcher Aufruf im Modul? Dies sind nur Deklarationen, damit VB die Konstanten und Funktionen kennt. Danach einfach im Load-Ergeignis der gewünschten Form SetWindowPos wie angegeben aufrufen.
Wenn schon Fehlermeldungen erwähnt werden, dann auch bitte den Code dazu und die genaue Fehlermeldung einstellen. Die Glaskugeln sind leider gerade aus. Ach ja, um Ärger mit Kollege Vierlagig zu vermeiden, beim Beispiel-Code immer schön die Code-Tags verwenden.
 
Hi also wie du schon gemerkt haben solltest hab ich nicht soo die Ahnung von Visual Basic ich versuch mich da momentan ein wenig rein zu arbeiten!
Also nun noch mal zu meinem Problem:
Also ich denke das ich díe Deklaration nun richtig gesetzt hab! aber wo platziere ich jetzt den Aufruf?

Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]
Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SWP_SHOWWINDOW = &H40
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] HWND_TOP = 0
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] HWND_TOPMOST = -1
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] HWND_NOTOPMOST = -2
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Declare[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SetWindowPos [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Lib[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"user32"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] hwnd [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] hWndInsertAfter [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] X [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Y [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] cx [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] cy [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] wFlags [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Long
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub
End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE][/COLOR][/SIZE]

Egal wie ich es versucht habe! ich hab immer eine Fehlermeldung erhalten!
 
Zuviel Werbung?
-> Hier kostenlos registrieren
welches vb nutzt du?
du hast den 1sten code ins form kopiert. das ist falsch

im projekt ein 'modul' hinzufügen
dort den 1.sten code einfügen.

im form den code anzeigen lassen.
im linken auswahlfeld das form anwählen. im rechten load
dort den 2.ten code einfügen.

fertig

wie reiner schon erwähnt... welchen fehler. hellseher sind wir hier nicht
 
Zuletzt bearbeitet:
hallo,
ich benutze Microsoft Visual Basic Express Edition.

also ich komme bis zu dem Teil: "im form den code anzeigen lassen"
ich hab den jetzt Code der form geöffnent, aber nun komm ich nicht so recht weiter mit deinen Angaben.

das mit den Fehlermeldungen: es sind zu viele! laut dem Programm würde gar nichts stimmen!

Könnte mir jemand das mal als Projekt erstellen und mir zukommen lassen.
Das wäre super!
Ich versteh einfach nicht wieso das nicht funktioniert.
danke schon mal!
 
der code funzt unter .net nicht.

hier ist das ohne code möglich.
in den eigenschaften der form TopMost auf true setzen.

geht natürlich auch im code
PHP:
Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
 
  ' Form in den Vordergrund
  Me.TopMost = True
End Sub
 
Tja, mein Code funktioniert nur unter VB 6 (und wahrscheinlich älter). Und für Fragen in der Zukunft: VB .net ist nicht VB und grundsätzlich anders zu behandeln.
 
OK vielen Dank! Das wusste ich nicht, dass es da unterschiede gibt!
Wo wir gerade dabei waren!
Könntet ihr mir noch eine Möglichkeit nennen eine bereits laufende Anwendung in den Vordergrund zu holen?
 
Zurück
Oben