Ich habe ein Modul, wo beim Aufruf das gestartete Programm immer im Vordergrund bleibt (heißt modSubMain und ist in den Projekteigenschaften anstelle der Form Main als Startobjekt drinnen ist):
Option Explicit
Private Const WS_EX_TOPMOST As Long = &H8
Private Const WS_EX_NOACTIVATE As Long = &H8000000
Private Const GWL_EXSTYLE As Long = -20
Private Const GWL_WNDPROC As Long = -4
Private Const HWND_TOPMOST As Long = -1
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOACTIVATE As Long = &H10
Private Const SW_SHOWNOACTIVATE As Long = 4
Private Const WM_MOVING As Long = &H216
Private Const WM_ACTIVATE As Long = &H6
Private Const WM_ACTIVATEAPP As Long = &H1C
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal _
wParam As Long, ByVal lParam 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Sub 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)
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal _
nCmdShow As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef _
Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private tRect As RECT
Private lngStyle As Long
Private hFrmHwnd As Long
Private lngOldWndProc As Long
Sub Main()
Load frmMain '<- hier Deine Form
hFrmHwnd = frmMain.hwnd '<- hWnd von Deiner Form
Call ShowWindow(hFrmHwnd, SW_SHOWNOACTIVATE)
lngStyle = GetWindowLong(hFrmHwnd, GWL_EXSTYLE)
lngStyle = lngStyle Or WS_EX_NOACTIVATE Or WS_EX_TOPMOST
Call SetWindowLong(hFrmHwnd, GWL_EXSTYLE, lngStyle)
Call SetWindowPos(hFrmHwnd, HWND_TOPMOST, 60&, 200&, 0&, 0&, SWP_NOSIZE Or _
SWP_NOACTIVATE)
lngOldWndProc = SetWindowLong(hFrmHwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub Unhook()
Call SetWindowLong(hFrmHwnd, GWL_WNDPROC, lngOldWndProc)
End Sub
Private Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal _
wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_MOVING Then
Call CopyMemory(tRect, ByVal lParam, LenB(tRect))
Call SetWindowPos(hFrmHwnd, -1, tRect.Left, tRect.Top, tRect.Right - _
tRect.Left, tRect.Bottom - tRect.Top, 0&)
WindowProc = True
Exit Function
End If
If uMsg = WM_ACTIVATE Or uMsg = WM_ACTIVATEAPP Then
Call SetWindowPos(hFrmHwnd, HWND_TOPMOST, 60&, 200&, 0&, 0&, SWP_NOSIZE Or _
SWP_NOACTIVATE)
End If
WindowProc = CallWindowProc(lngOldWndProc, hwnd, uMsg, wParam, lParam)
End Function Leider bleiben auch die Comboboxen (sevText) im Hintergrund. Ich bin deswegen draufgekommen, wie ich die untersten Comboboxen angeklickt habe, die dann unter dem Programmfenster hervor guckten, aber in der Form waren die Einträge nicht sichtbar, weil ja die Form / das Programm sich immer im Vordergrund befindet.
Was bitte kann ich bewerkstelligen, damit die Comboboxen komplett angezeigt werden?
Beitrag wurde zuletzt am 26.02.24 um 22:51:40 editiert. |