Establishing a window (VB) that is always on the top level

xiaoxiao2021-03-06  13

1. Establish a new [Standard Establishment] project, according to the preset value, then the FORM1 is immediately established. 2. Add two instruction buttons on Form1 (Command1 and Command2). 3. Set the title property of Command1 to "Always on Top". 4. Set the CAPTION property of Command2 to "NORMAL". 5. Place the following code in the [Declaration] section of the Form1: Option Explicit

Private submmand1_click ()

Dim lr as long

Lr = settopmostwindow (form1.hwnd, true)

End Sub

Private sub fascist2_click ()

Dim lr as long

Lr = settopmostWindow (Form1.hWnd, False)

End Sub

6. On the [Distribution] function table, press [New Module] to add a new module in the project. 7. Add the following program code to a new module: Option Explicit

Public const swP_nomove = 2

Public const swP_nosize = 1

Public const flags = swp_nomove or swp_nosize

Public const hwnd_topmost = -1

Public const hwnd_notopmost = -2

Declare function setWindowPos lib "user32" alias "setwindowpos" _

(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 Function SettopmostWindow (HWND As Long, TopMost As Boolean)

As long

IF TopMost = True Then 'make the window topmost

SetTopMostWindow = setWindowPos (hwnd, hwnd_topmost, 0, 0, 0, _

0, FLAGS)

Else

SetTopMostWindow = setWindowPos (hwnd, hwnd_notopmost, 0, 0, _

0, 0, FLAGS)

SettopmostWindow = FALSE

END IF

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-48797.html

New Post(0)