+ Reply to Thread
Results 1 to 3 of 3

Recuded or increased UserForm without the cross button

Hybrid View

  1. #1
    Registered User
    Join Date
    06-05-2019
    Location
    France
    MS-Off Ver
    2013
    Posts
    3

    Recuded or increased UserForm without the cross button

    Hello everyone,

    I would like to have an UserForm that can be reduced or increased as desired. So I searched on the net and I found a code to display these buttons, which works perfectly.

    But, first complication, I already had a code that allowed me to delete the cross, because I want to force the user to click o a button to close the UF, and therefore this code hides me these buttons to reduce and increase UF. So I have to comment this code to be able to have the buttons that are displayed, but then the cross is present.

    So I would like to hide or delete this button "cross", but I admit that it is a more complex code than usual and I do not know how to modify it to achieve my purposes.

    I would also like, if possible, to hide or delete the button that displays in the UF in full screen.

    Here are my codes:

    Module to remove the cross:
    Private Const mcGWL_STYLE = (-16)
    Private Const mcWS_SYSMENU = &H80000
    
    'Windows API calls to handle windows
    Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
    
    #If Win64 Then
        Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" ( _
            ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _
            ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #Else
        Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" ( _
            ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _
            ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #End If
    
    Public Sub RemoveCloseButton(objForm As Object)
        Dim lngStyle As LongPtr
        Dim lngHWnd As LongPtr
    
        Dim lpClassName As String
        lpClassName = vbNullString
        If Val(Application.Version) >= 9 Then
           lpClassName = "ThunderDFrame"
        Else
           lpClassName = "ThunderXFrame"
        End If
    
        lngHWnd = FindWindow(lpClassName, objForm.Caption)
        lngStyle = GetWindowLongPtr(lngHWnd, mcGWL_STYLE)
    
        If lngStyle And mcWS_SYSMENU > 0 Then
            SetWindowLongPtr lngHWnd, mcGWL_STYLE, (lngStyle And Not mcWS_SYSMENU)
        End If
    End Sub

    Module to add buttons:


    Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Const GWL_STYLE As Long = (-16)  'The offset of a window's style
    Private hwnd, IStyle
    Public Sub AjoutBtn(F As Object)
        hwnd = FindWindow(vbNullString, F.Caption)
        IStyle = GetWindowLong(hwnd, GWL_STYLE) Or &H70000
        SetWindowLong hwnd, GWL_STYLE, IStyle
    End Sub


    In the Initialize of the UF:


        AjoutBtn Me
        
        RemoveCloseButton Me

    Many thanks in advance to those who will try to help me!

    PS : Sorry if I made English's mistakes, I'm not English !

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Recuded or increased UserForm without the cross button

    Simplest way to work around that issue, is to show the "x" button, but cancel close when user presses that button.

    Ex:
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        If CloseMode = vbFormControlMenu Then
            MsgBox "This button is disabled, use Commandbutton name to close."
            Cancel = True
        End If
    End Sub
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    06-05-2019
    Location
    France
    MS-Off Ver
    2013
    Posts
    3

    Re: Recuded or increased UserForm without the cross button

    Thanks for your answer CK76

    Currently, I use this method for my UF. But I did not manage to apply it to the increased button.

    1559739214-capture.jpg

    I don't know if what I ask is possible, it's more for aesthetics and not to make the user want to click but I search and I ask, do we ever know!

    Thanks again for your quick reply !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 08-31-2017, 12:16 PM
  2. Replies: 1
    Last Post: 01-31-2016, 05:54 AM
  3. Call userform 1 from userform 2 allowing to open workbook 1 clicking button 1
    By FMontana in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2015, 02:29 AM
  4. [SOLVED] Userform code fails when the userform is called from a custom ribbon button
    By klonbeck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 03:00 PM
  5. Login form cross button problem
    By saiyan x in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-23-2013, 09:49 AM
  6. Userform Option Button to Show/Hide Another Option Button on same Userform
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2010, 09:44 AM
  7. Looping procedure calls userform; how to exit loop (via userform button)?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1