Zum Zeitpunkt der Erstellung Ihres VB Projektes legen
Sie für jede verwendete Form die BorderStyle Eigenschaft fest.
0=Kein / 1=Fest Einfach / 2=Änderbar / 3=Fester Dialog .....Ich denke, dies deck wohl den allergrößten Teil der Projekte ab,
was aber, wenn Sie zur Laufzeit diese Auswahl ändern wollen oder es dem User überlassen
möchten, ob er eine Titelzeile möchte oder nicht?
Wie immer nutzen Sie dann den vorgestellten Tipp.
1.
Dazu ist erstmal etwas Deklaration notwendig, denn wir bedienen uns wiedermal der
API.
Allgemein/Deklarationen
Const GWL_STYLE = (-16)
Const SW_HIDE = 0
Const SW_SHOW = 5
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOZORDER = &H4
Const SWP_NOACTIVATE = &H10
Const SWP_DRAWFRAME = &H20
Const WS_CAPTION = &HC00000
Const WS_SYSMENU = &H80000
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 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
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal
nCmdShow As Long) As Long
Dim m_ObjHWND As Long
Dim m_Style As WSStyle
Private Type WSType
wsRemove As Long
wsAdd As Long
End Type
Dim WSS() As WSType
Public Enum WSStyle
wsNONE = 0
wsCAPTION_BUTTON = 1
wsCAPTION = 2
End Enum
2.
Allgemein/ModifyStyle
Desweiteren benötigen Sie noch eine Funktion
Private Function ModifyStyle(ByVal hwnd As Long, ByVal dwRemove As Long, ByVal dwAdd As
Long, ByVal nFlags As Long, ByVal bRefresh As Boolean) As Boolean
Dim dwStyle As Long
Dim dwNewStyle As Long
Dim nStyleOffset As Long
nStyleOffset = GWL_STYLE
dwStyle = GetWindowLong(hwnd, nStyleOffset)
dwNewStyle = (dwStyle And (Not dwRemove)) Or dwAdd
If dwStyle = dwNewStyle Then
ModifyStyle = False
Exit Function
End If
If bRefresh Then
ShowWindow hwnd, SW_HIDE
End If
SetWindowLong hwnd, nStyleOffset, dwNewStyle
If bRefresh Then
ShowWindow hwnd, SW_SHOW
End If
If nFlags <> 0 Then
SetWindowPos hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOZORDER Or
SWP_NOACTIVATE Or nFlags
End If
ModifyStyle = True
End Function
3.
Fügen Sie nun einen Commandbutton (Command1) Ihrer Form hinzu und erstellen Sie zwei
Kopien davon (Index 0 bis 2).
4.
Form_Load
'ohne Titel
ReDim Preserve WSS(0)
WSS(0).wsAdd = 0
WSS(0).wsRemove = WS_CAPTION Or WS_SYSMENU
'normal
ReDim Preserve WSS(1)
WSS(1).wsAdd = WS_CAPTION Or WS_SYSMENU
WSS(1).wsRemove = 0
'nur Titel
ReDim Preserve WSS(2)
WSS(2).wsAdd = WS_CAPTION
WSS(2).wsRemove = WS_SYSMENU
Command1(0).Caption = "Normal"
Command1(1).Caption = "ohne Titelleiste"
Command1(2).Caption = "nur Titelleiste"
5.
Die Aktionen
Command_Click(Index as Integer)
Dim wAdd As Long, wRem As Long
If index = 0 Then
wAdd = WSS(1).wsAdd
wRem = WSS(1).wsRemove
ElseIf index = 1 Then
wAdd = WSS(0).wsAdd
wRem = WSS(0).wsRemove
ElseIf index = 2 Then
wAdd = WSS(2).wsAdd
wRem = WSS(2).wsRemove
End If
ModifyStyle Form1.hwnd, wRem, wAdd, SWP_DRAWFRAME, False
'Form1 = Name der zu modifizierenden Form
6.
Sie können nun Ihr Projekt testen und zur Laufzeit die BorderStyle Eigenschaft der Form
festlegen. |