Results 1 to 16 of 16

Thread: [VB6] CC6 Graphical Buttons

  1. #1

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    [VB6] CC6 Graphical Buttons

    We have "graphical style" command buttons, but they won't accept Common Controls 6 UxTheme adjustments. However I have found a way around this:

    Code:
    Option Explicit
    
    'Demonstrates using CommandButtons where Style = vbButtonStandard and
    'Picture = <some icon> along with a Common Controls 6 manifest to get
    '"graphical" buttons with CC6 styling and effects.
    '
    'Why do this?
    '
    'It can come in handy when you want to make a "toolbar" without the
    'need to deploy any toolbar OCX.  Just put them into a PictureBox,
    'UserControl, etc.
    '
    'And some people just like to have icons on buttons here and there.
    
    Private Const BM_SETIMAGE As Long = &HF7&
    Private Const IMAGE_ICON As Long = 1
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" ( _
        ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    
    Private Const GWL_STYLE As Long = -16&
    
    Private Enum BS_TEXTALIGN_STYLES
        [_BS_TEXTPOSMASK] = &HF00&
        'Note: the next two values seems to be swapped in winuser.h, or at least
        'have the opposite meaning when used with an icon, so I have swapped them:
        BS_RIGHT = &H100&
        BS_LEFT = &H200&
        'Note: the next two values seems to be swapped in winuser.h, or at least
        'have the opposite meaning when used with an icon, so I have swapped them:
        BS_BOTTOM = &H400&
        BS_TOP = &H800&
        BS_CENTER = &H300&
    End Enum
    
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongW" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long) As Long
    
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongW" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long
    
    Private Sub IconizeButton( _
        ByVal CommandButton As CommandButton, _
        Optional ByVal TextAlignment As BS_TEXTALIGN_STYLES = BS_BOTTOM)
        'Assumes the CommandButton has an icon as its Picture property.
        Dim NewStyle As Long
        
        With CommandButton
            NewStyle = GetWindowLong(.hWnd, GWL_STYLE) And Not [_BS_TEXTPOSMASK] Or TextAlignment
            SetWindowLong .hWnd, GWL_STYLE, NewStyle
            SendMessage .hWnd, BM_SETIMAGE, IMAGE_ICON, .Picture.Handle
        End With
    End Sub
    
    Private Sub Form_Load()
        IconizeButton cmdBurn
        IconizeButton cmdSave
        IconizeButton cmdSmiley
        IconizeButton cmdSomeButton, BS_CENTER
        IconizeButton cmdSubmit, BS_LEFT
    End Sub

    These buttons are larger than they need to be, and a normal toolbar would probably use smaller icons anyway:


    Name:  sshot1.png
Views: 9311
Size:  7.1 KB

    As it begins


    Name:  sshot2.png
Views: 6561
Size:  7.5 KB

    Tabbed to move focus, hovering mouse


    Name:  sshot3.png
Views: 6575
Size:  7.5 KB

    Just hovering


    I put my "toolbar buttons" within a PictureBox, but I haven't figured out how to theme that to look like a proper toolbar. Maybe the BackColor at least ought to be a different color? There are no borders but a Line control at the "bottom" of the PictureBox is standing in for one here.


    Requirements

    Should work on Windows XP or later. Reports say no on XP though.

    Tested, working on Windows 10, Windows 7, Windows Server 2008 R2.

    IDE runs of course look clunky and the icons don't show, but if you apply a CC6 manifest to the IDE that might not happen. I haven't tried this since I don't use an IDE manifest for theming.
    Attached Files Attached Files
    Last edited by dilettante; Jun 17th, 2017 at 03:53 PM.

  2. #2
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: [VB6] CC6 Graphical Buttons

    win7 test is ok.

  3. #3

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] CC6 Graphical Buttons

    Quote Originally Posted by xxdoc123 View Post
    win7 test is ok.
    Thanks, good to know.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,671

    Re: [VB6] CC6 Graphical Buttons

    In XP SP3 the icons don't show up.

  5. #5

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] CC6 Graphical Buttons

    Thanks, more useful info.

    I wonder if somebody can get them to work? There were a lot of things that got fixed and improved in the Longhorn development process though, so I'd expect Vista to work ok.

  6. #6

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] CC6 Graphical Buttons

    I took another run at this and found a way to get at theme colors. Not as important as the icons, but i raised the point so I figured I should follow through after I found an answer.

    Quite a bit more code, though not a ton, but I won't post it inline. If anyone really cares they can download the source.

    Clunky enough to be worth moving to a separate class or static module, and for a toolbar it makes more sense to create a UserControl instead of using a PictureBox. I didn't do any of that here though, it is all inline within the Form module.


    Name:  sshot.png
Views: 5533
Size:  7.6 KB


    This was very helpful, though hardly a cookbook:

    Custom Controls in Win32 API: Visual Styles
    Attached Files Attached Files

  7. #7
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [VB6] CC6 Graphical Buttons

    On XP, the effect of CC6 Graphical Buttons is as follows:
    Attached Images Attached Images  
    Last edited by dreammanor; Jun 11th, 2017 at 10:00 AM.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] CC6 Graphical Buttons

    For those still using XP, if someone could verify that the button has the proper style bits set, that may or may not be helpful.

    For example, in dilettante's code...
    Code:
    If (NewStyle And &H40) Then Debug.Print "Button has BS_ICON style bit"
    If (NewStyle And &H80) Then Debug.Print "Button has BS_BITMAP style bit"
    Oh, and another thing... If the button has no text, I'm guessing the icon will show in XP?
    Last edited by LaVolpe; Jun 11th, 2017 at 11:50 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] CC6 Graphical Buttons

    Good point.

    See the table under Remarks at BM_SETIMAGE message that shows the result of different combinations.

    Edit:

    That seems odd too, because getting only the text doesn't seem possible according to that table if BM_SETIMAGE was sent.

    Or maybe XP is just not described there, since MSDN says:

    Minimum supported client: Windows Vista [desktop apps only]
    Last edited by dilettante; Jun 11th, 2017 at 12:38 PM.

  10. #10
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [VB6] CC6 Graphical Buttons

    Quote Originally Posted by LaVolpe View Post
    For those still using XP, if someone could verify that the button has the proper style bits set, that may or may not be helpful.

    For example, in dilettante's code...
    Code:
    If (NewStyle And &H40) Then Debug.Print "Button has BS_ICON style bit"
    If (NewStyle And &H80) Then Debug.Print "Button has BS_BITMAP style bit"
    Oh, and another thing... If the button has no text, I'm guessing the icon will show in XP?
    LaVolpe, I've tested it in dilattante's IconizeButton procedure on XP, and the results are as follows:

    (NewStyle And & H40) = False
    (NewStyle And & H80) = False

  11. #11
    Hyperactive Member
    Join Date
    Feb 2014
    Posts
    294

    Re: [VB6] CC6 Graphical Buttons

    I am not sure whether this is relevant... has it got to do with comctl32.dll v6.1 or higher is required for picture and caption?

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] CC6 Graphical Buttons

    Quote Originally Posted by dreammanor View Post
    LaVolpe, I've tested it in dilattante's IconizeButton procedure on XP, and the results are as follows:

    (NewStyle And & H40) = False
    (NewStyle And & H80) = False
    Easy enough to test then for XP users: Ensure NewStyle includes &H40, i.e.,
    Code:
    NewStyle = GetWindowLong(.hWnd, GWL_STYLE) And Not [_BS_TEXTPOSMASK] Or TextAlignment or &H40
    However, setting that style after the button is created may not take effect
    Edited: I assume you used a common controls v6 manifest?
    Last edited by LaVolpe; Jun 15th, 2017 at 03:15 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13
    Hyperactive Member
    Join Date
    Feb 2014
    Posts
    294

    Re: [VB6] CC6 Graphical Buttons

    I believe comctl32.dll ver6.1 is not available in WinXP.

  14. #14

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [VB6] CC6 Graphical Buttons

    If you check older versions of MSDN:

    BM_SETIMAGE

    Requirements :

    Windows NT/2000/XP: Included in Windows NT 4.0 and later.
    Windows 95/98/Me: Included in Windows 95 and later.
    So that suggests there is something about VB6 Command buttons that is incompatible with BM_SETIMAGE on XP, since the message itself is valid there.

    If you look at the current article (link in post #9 above that nobody seems to have read) in Remarks there you will see that you DO NOT want those style bits set.


    What may be making this work for Vista+ is that a lot of changes were made to UxTheme.dll and the Win32 controls that make use of it (which of course goes far beyond comctl32.dll itself). Win32 controls defined in other system DLLs check the version of comctl32.dll that is loaded to decide how to behave themselves.

    In any case this works on Windows 10, Windows 7, and Windows Server 2008 R2.

    I don't have any Vista machines running and Vista died last month anyway. XP has been dead for over 3 years, leave it buried.

  15. #15
    Member Dragokas's Avatar
    Join Date
    Aug 2015
    Location
    Ukraine on fire (country of slaves)
    Posts
    750

    Re: [VB6] CC6 Graphical Buttons

    Tested. Looks fine on Vista.
    Malware analyst, VirusNet developer, HiJackThis+ author || my CodeBank works

  16. #16
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6] CC6 Graphical Buttons

    If you look at the current article (link in post #9 above that nobody seems to have read) in Remarks there you will see that you DO NOT want those style bits set.
    Depends on intent, no? If only icon is wanted, no text, then BS_ICON is required per that article. But point taken if text + icon/bitmap is desired.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Click Here to Expand Forum to Full Width