OVH Cloud OVH Cloud

GWL_STYLE pour SetWindowLong (macro mp-RéductibleApp.xls)

2 réponses
Avatar
Baudolino
Bonjour,
Dans la macro mp-R=E9ductibleApp.xls de Michel Pierron, le param=E8tre
GWL_STYLE de la fonction API SetWindowLong est =E9gal =E0 : &H84CA0080,
ce qui correspond vraisemblablement =E0 une combinaison de constantes
parmi celles-ci :
WS_BORDER =3D #800000,
WS_CAPTION =3D #C00000,
WS_CHILD =3D #40000000,
WS_CHILDWINDOW =3D #40000000,
WS_CLIPCHILDREN =3D #2000000,
WS_CLIPSIBLINGS =3D #4000000,
WS_DISABLED =3D #8000000,
WS_DLGFRAME =3D #400000,
WS_GROUP =3D #20000,
WS_HSCROLL =3D #100000,
WS_ICONIC =3D #20000000,
WS_MAXIMIZE =3D #1000000,
WS_MAXIMIZEBOX =3D #10000,
WS_MINIMIZE =3D #20000000,
WS_MINIMIZEBOX =3D #20000,
WS_OVERLAPPED =3D 0,
WS_OVERLAPPEDWINDOW =3D #CF0000,
WS_POPUP =3D #80000000,
WS_POPUPWINDOW =3D #80880000,
WS_SIZEBOX =3D #40000,
WS_SYSMENU =3D #80000,
WS_TABSTOP =3D #10000,
WS_THICKFRAME =3D #40000,
WS_TILED =3D 0,
WS_TILEDWINDOW =3D #CF0000,
WS_VISIBLE =3D #10000000,
WS_VSCROLL =3D #200000,
Le but de l'appel =E0 la fonction API =E9tant de faire apparaitre un
bouton de r=E9duction dans le formulaire, la constante WS_MINIMIZEBOX =3D
#20000 =E9tait indiqu=E9e. On obtient le m=EAme r=E9sultat avec la valeur :
&H84CA0080. A quoi correspond cette valeur ?
Merci d'avance pour votre =E9clairage.
Cordialement,

2 réponses

Avatar
Michel Pierron
Bonjour Baudolino;
Voici le détail pour la détermination du style:

Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)

Private Declare Function GetWindowLong& Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd&, ByVal nIndex&)

Private Declare Function SetWindowLong& Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd&, ByVal nIndex& _
, ByVal wNewWord&)

Private Sub UserForm_Initialize()
Const WS_MINIMIZEBOX = &H20000
Const GWL_STYLE = (-16) ' Basic style
Dim wLong&, hWnd&
hWnd = FindWindow(vbNullString, Me.Caption)

' ----------------------------
' Détermination du style de base
wLong = GetWindowLong(hWnd, GWL_STYLE)
Cells(1, 1) = "&H" & Hex(wLong)
Cells(1, 3) = "Basic style"
' Ajout du bouton de réduction
wLong = wLong Or WS_MINIMIZEBOX
Cells(2, 1) = "&H" & Hex(wLong)
Cells(2, 3) = "With minimize button"
SetWindowLong hWnd, GWL_STYLE, wLong
' ----------------------------

' Ajout du bouton de réduction directement
' sans étape intermédiaire (valeur en cellule "A2")
'SetWindowLong hWnd, -16, &H84CA0080
End Sub

MP


"Baudolino" a écrit dans le message de news:

Bonjour,
Dans la macro mp-RéductibleApp.xls de Michel Pierron, le paramètre
GWL_STYLE de la fonction API SetWindowLong est égal à : &H84CA0080,
ce qui correspond vraisemblablement à une combinaison de constantes
parmi celles-ci :
WS_BORDER = #800000,
WS_CAPTION = #C00000,
WS_CHILD = #40000000,
WS_CHILDWINDOW = #40000000,
WS_CLIPCHILDREN = #2000000,
WS_CLIPSIBLINGS = #4000000,
WS_DISABLED = #8000000,
WS_DLGFRAME = #400000,
WS_GROUP = #20000,
WS_HSCROLL = #100000,
WS_ICONIC = #20000000,
WS_MAXIMIZE = #1000000,
WS_MAXIMIZEBOX = #10000,
WS_MINIMIZE = #20000000,
WS_MINIMIZEBOX = #20000,
WS_OVERLAPPED = 0,
WS_OVERLAPPEDWINDOW = #CF0000,
WS_POPUP = #80000000,
WS_POPUPWINDOW = #80880000,
WS_SIZEBOX = #40000,
WS_SYSMENU = #80000,
WS_TABSTOP = #10000,
WS_THICKFRAME = #40000,
WS_TILED = 0,
WS_TILEDWINDOW = #CF0000,
WS_VISIBLE = #10000000,
WS_VSCROLL = #200000,
Le but de l'appel à la fonction API étant de faire apparaitre un
bouton de réduction dans le formulaire, la constante WS_MINIMIZEBOX #20000 était indiquée. On obtient le même résultat avec la valeur :
&H84CA0080. A quoi correspond cette valeur ?
Merci d'avance pour votre éclairage.
Cordialement,
Avatar
Baudolino
Merci beaucoup !
Donc, GWL_STYLE est égal à la valeur du Basic style combiné,
éventuellement, avec certaines constantes. J'essaie de maitriser les
règles d'assemblage de ces valeurs mais j'ai un peu de mal ! D'une
part, je ne comprends pas la fonction des opérateurs OR, AND ou AND
NOT et d'autre part, je suis surpris par certains résultats. J'ai donc
converti les valeurs en décimal sans y voir assez clair. Pouvez-vous
m'aider ?

J'ai prolongé votre code pour tester plusieurs situations (je ne sais
pas vous transférer mon fichier). Voici le code (questions dans la
dernière partie) :

Private Declare Function FindWindow& Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$)

Private Declare Function GetWindowLong& Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd&, ByVal nIndex&)

Private Declare Function SetWindowLong& Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd&, ByVal nIndex& _
, ByVal wNewWord&)

Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long

Private Sub UserForm_Initialize()
Const WS_MINIMIZEBOX = &H20000
Const GWL_STYLE = (-16) ' Basic style
Const WS_TEST2 = &HFFF7FFFF
Const WS_TEST3 = &H10000
Const WS_TEST4 = &HFF77FFFF
Const WS_TEST5 = &HC00000
Dim wLong&, wLong0&, wLong2&, wLong3&, wLong4&, wLong5&, hwnd&

hwnd = FindWindow(vbNullString, Me.Caption)

' ----------------------------
' Détermination du style de base
wLong = GetWindowLong(hwnd, GWL_STYLE)
wLong0 = wLong
wLong2 = wLong
wLong3 = wLong
wLong4 = wLong
wLong5 = wLong
Cells(3, 1) = Hex(wLong)
Cells(3, 5) = "Basic style"
' Cas 1 : Ajout du bouton de réduction
wLong = wLong Or WS_MINIMIZEBOX ''''''' OR
'Cells(4, 1) = Hex(wLong)
Cells(4, 2) = Hex(WS_MINIMIZEBOX)
Cells(4, 3) = Hex(wLong)
Cells(4, 5) = "With minimize button"
' Cas 2 : Suppression des boutons de fermeture et d'agrandissement
Cells(5, 1) = Hex(wLong2)
Cells(5, 5) = "Basic style"
wLong2 = wLong2 And WS_TEST2 ''''''' AND
Cells(6, 2) = Hex(WS_TEST2)
Cells(6, 3) = Hex(wLong2)
Cells(6, 5) = "Sans boutons (ferm & aggran)"
' Cas 3 : Suppression du bouton d'agrandissement
Cells(7, 1) = Hex(wLong3)
Cells(7, 5) = "Basic style"
wLong3 = wLong3 And Not WS_TEST3 ''''''' AND NOT
Cells(8, 2) = Hex(WS_TEST3)
Cells(8, 3) = Hex(wLong3)
Cells(8, 5) = "Sans bouton d'agrandissement"
' Cas 4 : Suppression de tous les boutons
Cells(9, 1) = Hex(wLong4)
Cells(9, 5) = "Basic style"
wLong4 = wLong4 And WS_TEST4 ''''''' AND
Cells(10, 2) = Hex(WS_TEST4)
Cells(10, 3) = Hex(wLong4)
Cells(10, 5) = "Sans aucun bouton"
' Cas 5 : Suppression de la barre de titre
Cells(11, 1) = Hex(wLong5)
Cells(11, 5) = "Basic style"
wLong5 = wLong5 And Not WS_TEST5 ''''''' AND NOT
Cells(12, 2) = Hex(WS_TEST5)
Cells(12, 3) = Hex(wLong5)
Cells(12, 5) = "Sans barre de titre"
' Choix du style de fenêtre
Select Case InputBox("0 à 5 pour choisir le style")
Case "0"
SetWindowLong hwnd, GWL_STYLE, wLong0
' 84C80080 - cas standard
Case "1"
SetWindowLong hwnd, GWL_STYLE, wLong
' 84CA0080 - ok
Case "2"
SetWindowLong hwnd, GWL_STYLE, wLong2
' 84C00080 - pourquoi les 2 boutons disparaissent-ils ?
Case "3"
SetWindowLong hwnd, GWL_STYLE, wLong3
' 84C80080 - égal au cas standard. Pourquoi ?
Case "4"
SetWindowLong hwnd, GWL_STYLE, wLong4
' 84400080 - voisin du cas 2 mais bords droits. Pourquoi ?
Case "5"
SetWindowLong hwnd, GWL_STYLE, wLong5
' 84080080 - ok (AND NOT = soustraction)
DrawMenuBar hwnd ''''''' MAJ de la barre
Case Else
End Select
' ----------------------------
End Sub

Private Sub CommandButton1_Click()
Unload UserForm1
End Sub

En vous remerciant par avance !
Cordialement,