+ Reply to Thread
Results 1 to 7 of 7

Userform with logo and without closebtn

  1. #1
    Klaus Heinrich
    Guest

    Userform with logo and without closebtn

    Hi folks,

    I am not an VBA expert and found some code snips in the net.
    First one hides the close button in user forms, second one sets
    individual logo in the menu bar of the user form. Maybe any
    one can help me combine this code snips ot at least help to
    understand, what the coding does:

    The declaration of lib "user32" is the same in both cases.
    Only difference:

    Private Const GWL_STYLE As Long = -16
    Private Const WS_SYSMENU As Long = &H80000

    Private hWndForm As Long
    Private bCloseBtn As Boolean

    Private Sub UserForm_Initialize()
    ' Find handle depending on Excel Version

    If Val(Application.Version) >= 9 Then
    hWndForm = FindWindow("ThunderDFrame", Me.Caption)
    Else
    hWndForm = FindWindow("ThunderXFrame", Me.Caption)
    End If

    bCloseBtn = False
    SetUserFormStyle <-- this is the sub which hides the close button
    End Sub

    Private Sub SetUserFormStyle()
    ' Hide close button in userform
    Dim frmStyle As Long

    If hWndForm = 0 Then Exit Sub

    frmStyle = GetWindowLong(hWndForm, GWL_STYLE)

    If bCloseBtn Then
    frmStyle = frmStyle Or WS_SYSMENU
    Else
    frmStyle = frmStyle And Not WS_SYSMENU
    End If

    SetWindowLong hWndForm, GWL_STYLE, frmStyle
    DrawMenuBar hWndForm
    End Sub

    Until here it works fine. Now I want to add some lines as follows:

    hIcon = Image3.Picture
    SendMessage hWndForm, &H80, True, hIcon
    SendMessage hWndForm, &H80, False, hIcon
    frm = GetWindowLong(hWndForm, -20)
    frm = frm And Not &H1
    SetWindowLong hWndForm, -20, frm

    DrawMenuBar hWndForm

    I do not understand the meaning of the lines, but I am sure
    that some commands overwrite the other.
    Is there any way to combine this snips ?

    Thanks in advandced

    Regards

    Klaus

  2. #2
    Michel Pierron
    Guest

    Re: Userform with logo and without closebtn

    Hi Klaus Heinrich,
    You can try:
    Private Declare Function FindWindow& Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName$ _
    , ByVal lpWindowName$)
    Private Declare Function SendMessage& Lib "user32" _
    Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg& _
    , ByVal wParam&, lParam As Any)
    Private Declare Function RemoveMenu& Lib "user32" _
    (ByVal hMenu&, ByVal nPosition&, ByVal wFlags&)
    Private Declare Function GetSystemMenu& Lib "user32" _
    (ByVal hWnd&, ByVal bRevert&)

    Private Sub UserForm_Initialize()
    Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption)
    SendMessage hWnd, &H80, 0, ByVal Image3.Picture.Handle
    RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    End Sub

    Regards,
    MP

    "Klaus Heinrich" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > Hi folks,
    >
    > I am not an VBA expert and found some code snips in the net.
    > First one hides the close button in user forms, second one sets
    > individual logo in the menu bar of the user form. Maybe any
    > one can help me combine this code snips ot at least help to
    > understand, what the coding does:
    >
    > The declaration of lib "user32" is the same in both cases.
    > Only difference:
    >
    > Private Const GWL_STYLE As Long = -16
    > Private Const WS_SYSMENU As Long = &H80000
    >
    > Private hWndForm As Long
    > Private bCloseBtn As Boolean
    >
    > Private Sub UserForm_Initialize()
    > ' Find handle depending on Excel Version
    >
    > If Val(Application.Version) >= 9 Then
    > hWndForm = FindWindow("ThunderDFrame", Me.Caption)
    > Else
    > hWndForm = FindWindow("ThunderXFrame", Me.Caption)
    > End If
    >
    > bCloseBtn = False
    > SetUserFormStyle <-- this is the sub which hides the close button
    > End Sub
    >
    > Private Sub SetUserFormStyle()
    > ' Hide close button in userform
    > Dim frmStyle As Long
    >
    > If hWndForm = 0 Then Exit Sub
    >
    > frmStyle = GetWindowLong(hWndForm, GWL_STYLE)
    >
    > If bCloseBtn Then
    > frmStyle = frmStyle Or WS_SYSMENU
    > Else
    > frmStyle = frmStyle And Not WS_SYSMENU
    > End If
    >
    > SetWindowLong hWndForm, GWL_STYLE, frmStyle
    > DrawMenuBar hWndForm
    > End Sub
    >
    > Until here it works fine. Now I want to add some lines as follows:
    >
    > hIcon = Image3.Picture
    > SendMessage hWndForm, &H80, True, hIcon
    > SendMessage hWndForm, &H80, False, hIcon
    > frm = GetWindowLong(hWndForm, -20)
    > frm = frm And Not &H1
    > SetWindowLong hWndForm, -20, frm
    >
    > DrawMenuBar hWndForm
    >
    > I do not understand the meaning of the lines, but I am sure
    > that some commands overwrite the other.
    > Is there any way to combine this snips ?
    >
    > Thanks in advandced
    >
    > Regards
    >
    > Klaus




  3. #3
    Klaus Heinrich
    Guest

    Re: Userform with logo and without closebtn

    Hi Michel,

    thank you very much. It works fine, although I don't know what realy
    happens with this code. The X-button does not dissappear but is grey
    and not active, which is allright for me.
    I use it with Excel 2003.

    Thanks again and have a nice weekend

    Regards Klaus

    Michel Pierron schrieb:

    >Hi Klaus Heinrich,
    >You can try:
    >Private Declare Function FindWindow& Lib "user32" _
    >Alias "FindWindowA" (ByVal lpClassName$ _
    >, ByVal lpWindowName$)
    >Private Declare Function SendMessage& Lib "user32" _
    >Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg& _
    >, ByVal wParam&, lParam As Any)
    >Private Declare Function RemoveMenu& Lib "user32" _
    >(ByVal hMenu&, ByVal nPosition&, ByVal wFlags&)
    >Private Declare Function GetSystemMenu& Lib "user32" _
    >(ByVal hWnd&, ByVal bRevert&)
    >
    >Private Sub UserForm_Initialize()
    >Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption)
    >SendMessage hWnd, &H80, 0, ByVal Image3.Picture.Handle
    >RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    >End Sub
    >
    >Regards,
    >MP
    >
    >"Klaus Heinrich" <[email protected]> a écrit dans le message de news:
    >[email protected]...
    >
    >
    >>Hi folks,
    >>
    >>I am not an VBA expert and found some code snips in the net.
    >>First one hides the close button in user forms, second one sets
    >>individual logo in the menu bar of the user form. Maybe any
    >>one can help me combine this code snips ot at least help to
    >>understand, what the coding does:
    >>
    >>The declaration of lib "user32" is the same in both cases.
    >>Only difference:
    >>
    >>Private Const GWL_STYLE As Long = -16
    >>Private Const WS_SYSMENU As Long = &H80000
    >>
    >>Private hWndForm As Long
    >>Private bCloseBtn As Boolean
    >>
    >>Private Sub UserForm_Initialize()
    >>' Find handle depending on Excel Version
    >>
    >> If Val(Application.Version) >= 9 Then
    >> hWndForm = FindWindow("ThunderDFrame", Me.Caption)
    >> Else
    >> hWndForm = FindWindow("ThunderXFrame", Me.Caption)
    >> End If
    >>
    >> bCloseBtn = False
    >> SetUserFormStyle <-- this is the sub which hides the close button
    >>End Sub
    >>
    >>Private Sub SetUserFormStyle()
    >>' Hide close button in userform
    >> Dim frmStyle As Long
    >>
    >> If hWndForm = 0 Then Exit Sub
    >>
    >> frmStyle = GetWindowLong(hWndForm, GWL_STYLE)
    >>
    >> If bCloseBtn Then
    >> frmStyle = frmStyle Or WS_SYSMENU
    >> Else
    >> frmStyle = frmStyle And Not WS_SYSMENU
    >> End If
    >>
    >> SetWindowLong hWndForm, GWL_STYLE, frmStyle
    >> DrawMenuBar hWndForm
    >>End Sub
    >>
    >>Until here it works fine. Now I want to add some lines as follows:
    >>
    >> hIcon = Image3.Picture
    >> SendMessage hWndForm, &H80, True, hIcon
    >> SendMessage hWndForm, &H80, False, hIcon
    >> frm = GetWindowLong(hWndForm, -20)
    >> frm = frm And Not &H1
    >> SetWindowLong hWndForm, -20, frm
    >>
    >> DrawMenuBar hWndForm
    >>
    >>I do not understand the meaning of the lines, but I am sure
    >>that some commands overwrite the other.
    >>Is there any way to combine this snips ?
    >>
    >>Thanks in advandced
    >>
    >>Regards
    >>
    >>Klaus
    >>
    >>

    >
    >
    >
    >


  4. #4
    Michel Pierron
    Guest

    Re: Userform with logo and without closebtn

    Re Klaus Heinrich,
    It is normal; if you want to have an icon, you cannot remove the totality
    of the system menu.
    MP

    "Klaus Heinrich" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > Hi Michel,
    >
    > thank you very much. It works fine, although I don't know what realy
    > happens with this code. The X-button does not dissappear but is grey
    > and not active, which is allright for me.
    > I use it with Excel 2003.
    >
    > Thanks again and have a nice weekend
    >
    > Regards Klaus
    >
    > Michel Pierron schrieb:
    >
    > >Hi Klaus Heinrich,
    > >You can try:
    > >Private Declare Function FindWindow& Lib "user32" _
    > >Alias "FindWindowA" (ByVal lpClassName$ _
    > >, ByVal lpWindowName$)
    > >Private Declare Function SendMessage& Lib "user32" _
    > >Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg& _
    > >, ByVal wParam&, lParam As Any)
    > >Private Declare Function RemoveMenu& Lib "user32" _
    > >(ByVal hMenu&, ByVal nPosition&, ByVal wFlags&)
    > >Private Declare Function GetSystemMenu& Lib "user32" _
    > >(ByVal hWnd&, ByVal bRevert&)
    > >
    > >Private Sub UserForm_Initialize()
    > >Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption)
    > >SendMessage hWnd, &H80, 0, ByVal Image3.Picture.Handle
    > >RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    > >End Sub
    > >
    > >Regards,
    > >MP
    > >
    > >"Klaus Heinrich" <[email protected]> a écrit dans le message de news:
    > >[email protected]...
    > >
    > >
    > >>Hi folks,
    > >>
    > >>I am not an VBA expert and found some code snips in the net.
    > >>First one hides the close button in user forms, second one sets
    > >>individual logo in the menu bar of the user form. Maybe any
    > >>one can help me combine this code snips ot at least help to
    > >>understand, what the coding does:
    > >>
    > >>The declaration of lib "user32" is the same in both cases.
    > >>Only difference:
    > >>
    > >>Private Const GWL_STYLE As Long = -16
    > >>Private Const WS_SYSMENU As Long = &H80000
    > >>
    > >>Private hWndForm As Long
    > >>Private bCloseBtn As Boolean
    > >>
    > >>Private Sub UserForm_Initialize()
    > >>' Find handle depending on Excel Version
    > >>
    > >> If Val(Application.Version) >= 9 Then
    > >> hWndForm = FindWindow("ThunderDFrame", Me.Caption)
    > >> Else
    > >> hWndForm = FindWindow("ThunderXFrame", Me.Caption)
    > >> End If
    > >>
    > >> bCloseBtn = False
    > >> SetUserFormStyle <-- this is the sub which hides the close button
    > >>End Sub
    > >>
    > >>Private Sub SetUserFormStyle()
    > >>' Hide close button in userform
    > >> Dim frmStyle As Long
    > >>
    > >> If hWndForm = 0 Then Exit Sub
    > >>
    > >> frmStyle = GetWindowLong(hWndForm, GWL_STYLE)
    > >>
    > >> If bCloseBtn Then
    > >> frmStyle = frmStyle Or WS_SYSMENU
    > >> Else
    > >> frmStyle = frmStyle And Not WS_SYSMENU
    > >> End If
    > >>
    > >> SetWindowLong hWndForm, GWL_STYLE, frmStyle
    > >> DrawMenuBar hWndForm
    > >>End Sub
    > >>
    > >>Until here it works fine. Now I want to add some lines as follows:
    > >>
    > >> hIcon = Image3.Picture
    > >> SendMessage hWndForm, &H80, True, hIcon
    > >> SendMessage hWndForm, &H80, False, hIcon
    > >> frm = GetWindowLong(hWndForm, -20)
    > >> frm = frm And Not &H1
    > >> SetWindowLong hWndForm, -20, frm
    > >>
    > >> DrawMenuBar hWndForm
    > >>
    > >>I do not understand the meaning of the lines, but I am sure
    > >>that some commands overwrite the other.
    > >>Is there any way to combine this snips ?
    > >>
    > >>Thanks in advandced
    > >>
    > >>Regards
    > >>
    > >>Klaus
    > >>
    > >>

    > >
    > >
    > >
    > >




  5. #5
    Klaus Heinrich
    Guest

    Re: Userform with logo and without closebtn

    Hi Michel,

    optimizing my code I declared APIs in general module now and reduced
    form initalization to the following lines:

    Private Sub UserForm_Initialize()
    Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption)
    Image3.Visible = False ' hide image3 on form
    SendMessage hWnd, &H80, 0, ByVal Image3.Picture.Handle
    RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    End Sub

    If I want to use a sub like this and call it during initialization of
    several forms
    I can not use "Me" but I have to transmitt it to the sub. How can
    I do this ?

    Sub ChangeMenuBar()
    Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption) <----
    Image3.Visible = False ' hide image3 on form
    SendMessage hWnd, &H80, 0, ByVal Image3.Picture.Handle
    RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    End Sub



    Thanks

    Klaus
    Michel Pierron schrieb:

    >Re Klaus Heinrich,
    >It is normal; if you want to have an icon, you cannot remove the totality
    >of the system menu.
    >MP
    >
    >


  6. #6
    Michel Pierron
    Guest

    Re: Userform with logo and without closebtn

    Hi Klaus,
    To make simple, in a standard module:
    Private Declare Function FindWindow& Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName$ _
    , ByVal lpWindowName$)
    Private Declare Function SendMessage& Lib "user32" _
    Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg& _
    , ByVal wParam&, lParam As Any)
    Private Declare Function RemoveMenu& Lib "user32" _
    (ByVal hMenu&, ByVal nPosition&, ByVal wFlags&)
    Private Declare Function GetSystemMenu& Lib "user32" _
    (ByVal hWnd&, ByVal bRevert&)

    Private Sub ChangeMenuBar(frm As Object)
    Dim hWnd&, hIcon&
    With frm
    ..Image3.Visible = False
    hWnd = FindWindow(vbNullString, .Caption)
    hIcon = .Image3.Picture.Handle
    SendMessage hWnd, &H80, 0, ByVal hIcon
    RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    ..Show
    End With
    End Sub

    Sub UserForm1Show()
    On Error Resume Next
    Call ChangeMenuBar(UserForm1)
    End Sub

    Sub UserForm2Show()
    On Error Resume Next
    Call ChangeMenuBar(UserForm2)
    End Sub

    Regards,
    MP


    "Klaus Heinrich" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > Hi Michel,
    >
    > optimizing my code I declared APIs in general module now and reduced
    > form initalization to the following lines:
    >
    > Private Sub UserForm_Initialize()
    > Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption)
    > Image3.Visible = False ' hide image3 on form
    > SendMessage hWnd, &H80, 0, ByVal Image3.Picture.Handle
    > RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    > End Sub
    >
    > If I want to use a sub like this and call it during initialization of
    > several forms
    > I can not use "Me" but I have to transmitt it to the sub. How can
    > I do this ?
    >
    > Sub ChangeMenuBar()
    > Dim hWnd&: hWnd = FindWindow(vbNullString, Me.Caption) <----
    > Image3.Visible = False ' hide image3 on form
    > SendMessage hWnd, &H80, 0, ByVal Image3.Picture.Handle
    > RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    > End Sub
    >
    >
    >
    > Thanks
    >
    > Klaus
    > Michel Pierron schrieb:
    >
    > >Re Klaus Heinrich,
    > >It is normal; if you want to have an icon, you cannot remove the

    totality
    > >of the system menu.
    > >MP
    > >
    > >




  7. #7
    Klaus Heinrich
    Guest

    Re: Userform with logo and without closebtn

    Hi Michel,

    it works very fine in deed. Thank you very much !
    I've learned lots from this.

    Best regards Klaus

    Michel Pierron schrieb:

    >Hi Klaus,
    >To make simple, in a standard module:
    >Private Declare Function FindWindow& Lib "user32" _
    >Alias "FindWindowA" (ByVal lpClassName$ _
    >, ByVal lpWindowName$)
    >Private Declare Function SendMessage& Lib "user32" _
    >Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg& _
    >, ByVal wParam&, lParam As Any)
    >Private Declare Function RemoveMenu& Lib "user32" _
    >(ByVal hMenu&, ByVal nPosition&, ByVal wFlags&)
    >Private Declare Function GetSystemMenu& Lib "user32" _
    >(ByVal hWnd&, ByVal bRevert&)
    >
    >Private Sub ChangeMenuBar(frm As Object)
    >Dim hWnd&, hIcon&
    >With frm
    >.Image3.Visible = False
    >hWnd = FindWindow(vbNullString, .Caption)
    >hIcon = .Image3.Picture.Handle
    >SendMessage hWnd, &H80, 0, ByVal hIcon
    >RemoveMenu GetSystemMenu(hWnd, 0), &HF060, 0
    >.Show
    >End With
    >End Sub
    >
    >Sub UserForm1Show()
    >On Error Resume Next
    >Call ChangeMenuBar(UserForm1)
    >End Sub
    >
    >Sub UserForm2Show()
    >On Error Resume Next
    >Call ChangeMenuBar(UserForm2)
    >End Sub
    >
    >Regards,
    >MP
    >
    >



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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