XL 2016 ANNULÉ - VBA - Positionner UserForm aux limites de l'écran

Dudu2

XLDnaute Barbatruc
Bonjour à tous,

En positionnant un UserForm aux limites de l'écran, il reste toujours des marges, surtout dans l'axe des X.
Pour le vérifier il suffit de mettre UserForm.Left = 0 et UserForm.Top = 0 et on obtient ceci:

1658417623831.png


Alors je sais bien que si on fait un ActiveWindow.Left ou Application.Left d'un fenêtre Excel maximisée, on obtient un chiffre négatif (-4,4 points chez moi) que je n'ai d'ailleurs jamais compris. Mais cette fenêtre peut-être réduite. Donc quel est l'Objet VBA à utiliser pour retrouver ce chiffre négatif (-4,4) qui permettrait de supprimer la marge en X ?
 

Pièces jointes

  • VBA Position UserForm aux limites de l'écran.xlsm
    32.2 KB · Affichages: 7
Solution
Bonjour @patricktoulon,

Ok merci pour ton explication.
J'avais passé en revue tous les paramètres de GetSystemMetrics() sans succès.

Et c'est encore mieux, comme dans ce fichier, si on tient compte de la position de la Barre des Tâches (en bas, en haut, à gauche, à droite) qui reste toujours en 1er plan et masque la partie du UserForm qu'elle recouvre.

A noter que je suis allé chercher l'API pour la position de la Barre des Tâches car les paramètres de GetSystemMetrics() SM_CXFULLSCREEN et SM_CYFULLSCREEN qui sont sensés donner la taille de l'écran hors TaskBar n'ont pas donné le résultat escompté.

Dudu2

XLDnaute Barbatruc
En fait ces marges sont inhérentes au UserForm dans mon Windows 10.
Je me souviens maintenant de cette affaire lors de la création ancienne du fichier de ce sujet.
Donc tout va bien.
Si j'applique les mêmes corrections, valides pour Windows 10 (et plus ?):
VB:
TopBorderSize = 0.8
SideBorderSize = (UserForm1.Width - UserForm1.InsideWidth) / 2
BottomBorderSize = (UserForm1.Width - UserForm1.InsideWidth) / 2
ça se positionne visuellement parfaitement, mais Excellement incorrectement puisque la marge appartient au UserForm.

Edit: dans ce fichier j'ai appliqué les corrections sur les marges du UserForm et ça semble parfaitement cadré, sauf que pour Excel ça ne l'est pas puisque ces marges appartiennent au UserForm.
 

Pièces jointes

  • VBA Position UserForm aux limites de l'écran.xlsm
    33 KB · Affichages: 3
Dernière édition:

patricktoulon

XLDnaute Barbatruc
re
Bonjour @Dudu2 cette marge (+4) chez moi avec W 7) et propre a l'affichage selon le theme de windows et cela que ce soit W7,W10,W11
en fait quand on maximize la fenetre le cadre de la fenêtre se positionne en light frame et quand la fenêtre est en mode fenetrée c'est en mode thick frame sauf que dans W10 (et 11 je suppose) cette partie du cadre est invisible
donc pour info

Fonction GetSystemMetrics

Declare Function GetSystemMetrics Lib "user32" ( _
ByVal nIndex As Long) As Long
Versions :
. Windows 95/98 : Oui
. Windows NT : A partir de 3.1
. Windows 2000/XP : Oui et plus !!!!!!!


SM_ARRANGE56The flags that specify how the system arranged minimized windows. For more information, see the Remarks section in this topic.
SM_CLEANBOOT67The value that specifies how the system is started:
  • 0 Normal boot
  • 1 Fail-safe boot
  • 2 Fail-safe with network boot
A fail-safe boot (also called SafeBoot, Safe Mode, or Clean Boot) bypasses the user startup files.
SM_CMONITORS80The number of display monitors on a desktop. For more information, see the Remarks section in this topic.
SM_CMOUSEBUTTONS43The number of buttons on a mouse, or zero if no mouse is installed.
SM_CONVERTIBLESLATEMODE0x2003Reflects the state of the laptop or slate mode, 0 for Slate Mode and non-zero otherwise. When this system metric changes, the system sends a broadcast message via WM_SETTINGCHANGE with "ConvertibleSlateMode" in the LPARAM. Note that this system metric doesn't apply to desktop PCs. In that case, use GetAutoRotationState.
SM_CXBORDER5The width of a window border, in pixels. This is equivalent to the SM_CXEDGE value for windows with the 3-D look.
SM_CXCURSOR13The width of a cursor, in pixels. The system cannot create cursors of other sizes.
SM_CXDLGFRAME7This value is the same as SM_CXFIXEDFRAME.
SM_CXDOUBLECLK36The width of the rectangle around the location of a first click in a double-click sequence, in pixels. The second click must occur within the rectangle that is defined by SM_CXDOUBLECLK and SM_CYDOUBLECLK for the system to consider the two clicks a double-click. The two clicks must also occur within a specified time.
To set the width of the double-click rectangle, call SystemParametersInfo with SPI_SETDOUBLECLKWIDTH.
SM_CXDRAG68The number of pixels on either side of a mouse-down point that the mouse pointer can move before a drag operation begins. This allows the user to click and release the mouse button easily without unintentionally starting a drag operation. If this value is negative, it is subtracted from the left of the mouse-down point and added to the right of it.
SM_CXEDGE45The width of a 3-D border, in pixels. This metric is the 3-D counterpart of SM_CXBORDER.
SM_CXFIXEDFRAME7The thickness of the frame around the perimeter of a window that has a caption but is not sizable, in pixels. SM_CXFIXEDFRAME is the height of the horizontal border, and SM_CYFIXEDFRAME is the width of the vertical border.
This value is the same as SM_CXDLGFRAME.
SM_CXFOCUSBORDER83The width of the left and right edges of the focus rectangle that the DrawFocusRect draws. This value is in pixels.
Windows 2000: This value is not supported.
SM_CXFRAME32This value is the same as SM_CXSIZEFRAME.
SM_CXFULLSCREEN16The width of the client area for a full-screen window on the primary display monitor, in pixels. To get the coordinates of the portion of the screen that is not obscured by the system taskbar or by application desktop toolbars, call the SystemParametersInfo function with the SPI_GETWORKAREA value.
SM_CXHSCROLL21The width of the arrow bitmap on a horizontal scroll bar, in pixels.
SM_CXHTHUMB10The width of the thumb box in a horizontal scroll bar, in pixels.
SM_CXICON11The default width of an icon, in pixels. The LoadIcon function can load only icons with the dimensions that SM_CXICON and SM_CYICON specifies.
SM_CXICONSPACING38The width of a grid cell for items in large icon view, in pixels. Each item fits into a rectangle of size SM_CXICONSPACING by SM_CYICONSPACING when arranged. This value is always greater than or equal to SM_CXICON.
SM_CXMAXIMIZED61The default width, in pixels, of a maximized top-level window on the primary display monitor.
SM_CXMAXTRACK59The default maximum width of a window that has a caption and sizing borders, in pixels. This metric refers to the entire desktop. The user cannot drag the window frame to a size larger than these dimensions. A window can override this value by processing the WM_GETMINMAXINFO message.
SM_CXMENUCHECK71The width of the default menu check-mark bitmap, in pixels.
SM_CXMENUSIZE54The width of menu bar buttons, such as the child window close button that is used in the multiple document interface, in pixels.
SM_CXMIN28The minimum width of a window, in pixels.
SM_CXMINIMIZED57The width of a minimized window, in pixels.
SM_CXMINSPACING47The width of a grid cell for a minimized window, in pixels. Each minimized window fits into a rectangle this size when arranged. This value is always greater than or equal to SM_CXMINIMIZED.
SM_CXMINTRACK34The minimum tracking width of a window, in pixels. The user cannot drag the window frame to a size smaller than these dimensions. A window can override this value by processing the WM_GETMINMAXINFO message.
SM_CXPADDEDBORDER92The amount of border padding for captioned windows, in pixels.
Windows XP/2000: This value is not supported.
SM_CXSCREEN0The width of the screen of the primary display monitor, in pixels. This is the same value obtained by calling GetDeviceCaps as follows: GetDeviceCaps( hdcPrimaryMonitor, HORZRES).
SM_CXSIZE30The width of a button in a window caption or title bar, in pixels.
SM_CXSIZEFRAME32The thickness of the sizing border around the perimeter of a window that can be resized, in pixels. SM_CXSIZEFRAME is the width of the horizontal border, and SM_CYSIZEFRAME is the height of the vertical border.
This value is the same as SM_CXFRAME.
SM_CXSMICON49The recommended width of a small icon, in pixels. Small icons typically appear in window captions and in small icon view.
SM_CXSMSIZE52The width of small caption buttons, in pixels.
SM_CXVIRTUALSCREEN78The width of the virtual screen, in pixels. The virtual screen is the bounding rectangle of all display monitors. The SM_XVIRTUALSCREEN metric is the coordinates for the left side of the virtual screen.
SM_CXVSCROLL2The width of a vertical scroll bar, in pixels.
SM_CYBORDER6The height of a window border, in pixels. This is equivalent to the SM_CYEDGE value for windows with the 3-D look.
SM_CYCAPTION4The height of a caption area, in pixels.
SM_CYCURSOR14The height of a cursor, in pixels. The system cannot create cursors of other sizes.
SM_CYDLGFRAME8This value is the same as SM_CYFIXEDFRAME.
SM_CYDOUBLECLK37The height of the rectangle around the location of a first click in a double-click sequence, in pixels. The second click must occur within the rectangle defined by SM_CXDOUBLECLK and SM_CYDOUBLECLK for the system to consider the two clicks a double-click. The two clicks must also occur within a specified time.
To set the height of the double-click rectangle, call SystemParametersInfo with SPI_SETDOUBLECLKHEIGHT.
SM_CYDRAG69The number of pixels above and below a mouse-down point that the mouse pointer can move before a drag operation begins. This allows the user to click and release the mouse button easily without unintentionally starting a drag operation. If this value is negative, it is subtracted from above the mouse-down point and added below it.
SM_CYEDGE46The height of a 3-D border, in pixels. This is the 3-D counterpart of SM_CYBORDER.
SM_CYFIXEDFRAME8The thickness of the frame around the perimeter of a window that has a caption but is not sizable, in pixels. SM_CXFIXEDFRAME is the height of the horizontal border, and SM_CYFIXEDFRAME is the width of the vertical border.
This value is the same as SM_CYDLGFRAME.
SM_CYFOCUSBORDER84The height of the top and bottom edges of the focus rectangle drawn by DrawFocusRect. This value is in pixels.
Windows 2000: This value is not supported.
SM_CYFRAME33This value is the same as SM_CYSIZEFRAME.
SM_CYFULLSCREEN17The height of the client area for a full-screen window on the primary display monitor, in pixels. To get the coordinates of the portion of the screen not obscured by the system taskbar or by application desktop toolbars, call the SystemParametersInfo function with the SPI_GETWORKAREA value.
SM_CYHSCROLL3The height of a horizontal scroll bar, in pixels.
SM_CYICON12The default height of an icon, in pixels. The LoadIcon function can load only icons with the dimensions SM_CXICON and SM_CYICON.
SM_CYICONSPACING39The height of a grid cell for items in large icon view, in pixels. Each item fits into a rectangle of size SM_CXICONSPACING by SM_CYICONSPACING when arranged. This value is always greater than or equal to SM_CYICON.
SM_CYKANJIWINDOW18For double byte character set versions of the system, this is the height of the Kanji window at the bottom of the screen, in pixels.
SM_CYMAXIMIZED62The default height, in pixels, of a maximized top-level window on the primary display monitor.
SM_CYMAXTRACK60The default maximum height of a window that has a caption and sizing borders, in pixels. This metric refers to the entire desktop. The user cannot drag the window frame to a size larger than these dimensions. A window can override this value by processing the WM_GETMINMAXINFO message.
SM_CYMENU15The height of a single-line menu bar, in pixels.
SM_CYMENUCHECK72The height of the default menu check-mark bitmap, in pixels.
SM_CYMENUSIZE55The height of menu bar buttons, such as the child window close button that is used in the multiple document interface, in pixels.
SM_CYMIN29The minimum height of a window, in pixels.
SM_CYMINIMIZED58The height of a minimized window, in pixels.
SM_CYMINSPACING48The height of a grid cell for a minimized window, in pixels. Each minimized window fits into a rectangle this size when arranged. This value is always greater than or equal to SM_CYMINIMIZED.
SM_CYMINTRACK35The minimum tracking height of a window, in pixels. The user cannot drag the window frame to a size smaller than these dimensions. A window can override this value by processing the WM_GETMINMAXINFO message.
SM_CYSCREEN1The height of the screen of the primary display monitor, in pixels. This is the same value obtained by calling GetDeviceCaps as follows: GetDeviceCaps( hdcPrimaryMonitor, VERTRES).
SM_CYSIZE31The height of a button in a window caption or title bar, in pixels.
SM_CYSIZEFRAME33The thickness of the sizing border around the perimeter of a window that can be resized, in pixels. SM_CXSIZEFRAME is the width of the horizontal border, and SM_CYSIZEFRAME is the height of the vertical border.
This value is the same as SM_CYFRAME.
SM_CYSMCAPTION51The height of a small caption, in pixels.
SM_CYSMICON50The recommended height of a small icon, in pixels. Small icons typically appear in window captions and in small icon view.
SM_CYSMSIZE53The height of small caption buttons, in pixels.
SM_CYVIRTUALSCREEN79The height of the virtual screen, in pixels. The virtual screen is the bounding rectangle of all display monitors. The SM_YVIRTUALSCREEN metric is the coordinates for the top of the virtual screen.
SM_CYVSCROLL20The height of the arrow bitmap on a vertical scroll bar, in pixels.
SM_CYVTHUMB9The height of the thumb box in a vertical scroll bar, in pixels.
SM_DBCSENABLED42Nonzero if User32.dll supports DBCS; otherwise, 0.
SM_DEBUG22Nonzero if the debug version of User.exe is installed; otherwise, 0.
SM_DIGITIZER94Nonzero if the current operating system is Windows 7 or Windows Server 2008 R2 and the Tablet PC Input service is started; otherwise, 0. The return value is a bitmask that specifies the type of digitizer input supported by the device. For more information, see Remarks.
Windows Server 2008, Windows Vista and Windows XP/2000: This value is not supported.
SM_IMMENABLED82Nonzero if Input Method Manager/Input Method Editor features are enabled; otherwise, 0.
SM_IMMENABLED indicates whether the system is ready to use a Unicode-based IME on a Unicode application. To ensure that a language-dependent IME works, check SM_DBCSENABLED and the system ANSI code page. Otherwise the ANSI-to-Unicode conversion may not be performed correctly, or some components like fonts or registry settings may not be present.
SM_MAXIMUMTOUCHES95Nonzero if there are digitizers in the system; otherwise, 0.
SM_MAXIMUMTOUCHES returns the aggregate maximum of the maximum number of contacts supported by every digitizer in the system. If the system has only single-touch digitizers, the return value is 1. If the system has multi-touch digitizers, the return value is the number of simultaneous contacts the hardware can provide.
Windows Server 2008, Windows Vista and Windows XP/2000: This value is not supported.
SM_MEDIACENTER87Nonzero if the current operating system is the Windows XP, Media Center Edition, 0 if not.
SM_MENUDROPALIGNMENT40Nonzero if drop-down menus are right-aligned with the corresponding menu-bar item; 0 if the menus are left-aligned.
SM_MIDEASTENABLED74Nonzero if the system is enabled for Hebrew and Arabic languages, 0 if not.
SM_MOUSEPRESENT19Nonzero if a mouse is installed; otherwise, 0. This value is rarely zero, because of support for virtual mice and because some systems detect the presence of the port instead of the presence of a mouse.
SM_MOUSEHORIZONTALWHEELPRESENT91Nonzero if a mouse with a horizontal scroll wheel is installed; otherwise 0.
SM_MOUSEWHEELPRESENT75Nonzero if a mouse with a vertical scroll wheel is installed; otherwise 0.
SM_NETWORK63The least significant bit is set if a network is present; otherwise, it is cleared. The other bits are reserved for future use.
SM_PENWINDOWS41Nonzero if the Microsoft Windows for Pen computing extensions are installed; zero otherwise.
SM_REMOTECONTROL0x2001This system metric is used in a Terminal Services environment to determine if the current Terminal Server session is being remotely controlled. Its value is nonzero if the current session is remotely controlled; otherwise, 0.
You can use terminal services management tools such as Terminal Services Manager (tsadmin.msc) and shadow.exe to control a remote session. When a session is being remotely controlled, another user can view the contents of that session and potentially interact with it.
SM_REMOTESESSION0x1000This system metric is used in a Terminal Services environment. If the calling process is associated with a Terminal Services client session, the return value is nonzero. If the calling process is associated with the Terminal Services console session, the return value is 0. Windows Server 2003 and Windows XP: The console session is not necessarily the physical console. For more information, see WTSGetActiveConsoleSessionId.
SM_SAMEDISPLAYFORMAT81Nonzero if all the display monitors have the same color format, otherwise, 0. Two displays can have the same bit depth, but different color formats. For example, the red, green, and blue pixels can be encoded with different numbers of bits, or those bits can be located in different places in a pixel color value.
SM_SECURE44This system metric should be ignored; it always returns 0.
SM_SERVERR289The build number if the system is Windows Server 2003 R2; otherwise, 0.
SM_SHOWSOUNDS70Nonzero if the user requires an application to present information visually in situations where it would otherwise present the information only in audible form; otherwise, 0.
SM_SHUTTINGDOWN0x2000Nonzero if the current session is shutting down; otherwise, 0.
Windows 2000: This value is not supported.
SM_SLOWMACHINE73Nonzero if the computer has a low-end (slow) processor; otherwise, 0.
SM_STARTER88Nonzero if the current operating system is Windows 7 Starter Edition, Windows Vista Starter, or Windows XP Starter Edition; otherwise, 0.
SM_SWAPBUTTON23Nonzero if the meanings of the left and right mouse buttons are swapped; otherwise, 0.
SM_SYSTEMDOCKED0x2004Reflects the state of the docking mode, 0 for Undocked Mode and non-zero otherwise. When this system metric changes, the system sends a broadcast message via WM_SETTINGCHANGE with "SystemDockMode" in the LPARAM.
SM_TABLETPC86Nonzero if the current operating system is the Windows XP Tablet PC edition or if the current operating system is Windows Vista or Windows 7 and the Tablet PC Input service is started; otherwise, 0. The SM_DIGITIZER setting indicates the type of digitizer input supported by a device running Windows 7 or Windows Server 2008 R2. For more information, see Remarks.
SM_XVIRTUALSCREEN76The coordinates for the left side of the virtual screen. The virtual screen is the bounding rectangle of all display monitors. The SM_CXVIRTUALSCREEN metric is the width of the virtual screen.
SM_YVIRTUALSCREEN77The coordinates for the top of the virtual screen. The virtual screen is the bounding rectangle of all display monitors. The SM_CYVIRTUALSCREEN metric is the height of the virtual screen.
 

Dudu2

XLDnaute Barbatruc
Bonjour @patricktoulon,

Ok merci pour ton explication.
J'avais passé en revue tous les paramètres de GetSystemMetrics() sans succès.

Et c'est encore mieux, comme dans ce fichier, si on tient compte de la position de la Barre des Tâches (en bas, en haut, à gauche, à droite) qui reste toujours en 1er plan et masque la partie du UserForm qu'elle recouvre.

A noter que je suis allé chercher l'API pour la position de la Barre des Tâches car les paramètres de GetSystemMetrics() SM_CXFULLSCREEN et SM_CYFULLSCREEN qui sont sensés donner la taille de l'écran hors TaskBar n'ont pas donné le résultat escompté.
 

Pièces jointes

  • VBA Position UserForm aux limites de l'écran.xlsm
    35.4 KB · Affichages: 11

Statistiques des forums

Discussions
314 450
Messages
2 109 724
Membres
110 552
dernier inscrit
jasson