Taille USER inférieur à 99

ericTA

XLDnaute Occasionnel
Bonjour à tous,

Il y a t il un moyen de réduire la largeur (Width) d'un USER en dessous de 99 ?

Merci d'avance

Eric
 

Staple1600

XLDnaute Barbatruc
Re : Taille USER inférieur à 99

Bonsoir à tous

Avec les API, oui , mais dans quel but ??
Code:
Option Explicit
Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
Private Declare Function SetWindowPos Lib "user32.dll" (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 Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2

Private Sub UserForm_Click()
Dim hwnd As Long
Dim lngWidth As Long
Dim lngHeight As Long
lngWidth = 45
lngHeight = 45
hwnd = GetActiveWindow()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, lngWidth, lngHeight, SWP_NOMOVE
End Sub

PS: Si on teste avec moins de 45, seul la croix rouge apparait.
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : Taille USER inférieur à 99

[...SUITE...]

Une version plus aboutie (grâce un emprunt à Leith Roth)
NB: Test OK sur Excel 2013 32 bits.
Ps: Pour fermer, l'userform il suffit de cliquer dessus.
DANS UN MODULE STANDARD
VB:
'Written: August 01, 2009
'Author:  Leith Ross
'Summary: Removes the Titlebar and thick border around a UserForm.
'Returns the Window Handle of the Window that is accepting User input.
 Public Declare Function GetForegroundWindow Lib "user32.dll" () As Long

 Private Declare Function GetWindowLong _
   Lib "user32.dll" _
     Alias "GetWindowLongA" _
       (ByVal hwnd As Long, ByVal nIndex As Long) As Long
               
 Private Declare Function SetWindowLong _
  Lib "user32.dll" _
    Alias "SetWindowLongA" _
      (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Sub RemoveFrame()
Dim Bitmask As Long
Dim hwnd As Long
Dim WindowStyle As Long
Const GWL_STYLE As Long = (-16)
Const WS_DLGFRAME As Long = &H400000
hwnd = GetForegroundWindow
WindowStyle = GetWindowLong(hwnd, GWL_STYLE)
Bitmask = WindowStyle And (Not WS_DLGFRAME)
Call SetWindowLong(hwnd, GWL_STYLE, Bitmask)
End Sub

DANS LE CODE DE L'USERFOM
VB:
Option Explicit
Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
Private Declare Function SetWindowPos Lib "user32.dll" (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 Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2

Private Sub UserForm_Activate()
Dim hwnd As Long
Dim lngWidth As Long
Dim lngHeight As Long
RemoveFrame
lngWidth = 25
lngHeight = 25
hwnd = GetActiveWindow()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, lngWidth, lngHeight, SWP_NOMOVE
End Sub
Private Sub UserForm_Click()
Unload Me
End Sub
 

Discussions similaires

  • Résolu(e)
Microsoft 365 Taille UserForm
Réponses
3
Affichages
355
Réponses
12
Affichages
332

Statistiques des forums

Discussions
312 330
Messages
2 087 339
Membres
103 524
dernier inscrit
Smile1813