Results 1 to 10 of 10

Thread: Change style of command button to graphical during run time?

  1. #1

    Thread Starter
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 2002
    Location
    Near, Very Near
    Posts
    340

    Change style of command button to graphical during run time?

    Greetings Every1,
    I want to set the Style property of Command Button to Graphical i.e., 1 during run time using the SetLongWindow API. But I dont know how? Plz help...
    If Not VB Then Exit
    ------------------------------------------------
    visit me @ http://mzubair.50g.com/

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Why do you have to set it at run time?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 2002
    Location
    Near, Very Near
    Posts
    340
    I'm developing a subclassing control and it can catch the WM_DRAWITEM msg only for graphical style buttons(owner buttons). Got the picture...
    If Not VB Then Exit
    ------------------------------------------------
    visit me @ http://mzubair.50g.com/

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Is it even possible? I only ask because its a read only property at
    runtime. There must be some other things that will get affected
    by tring to change the button stlye during run time?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 2002
    Location
    Near, Very Near
    Posts
    340
    yeah rob, its possible, but i just cant remember the constant to be supplied to SetLongWindow...
    If Not VB Then Exit
    ------------------------------------------------
    visit me @ http://mzubair.50g.com/

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    VB Code:
    1. ' ##ENUMERATION_DESCRIPTION ButtonControlStyles - Style bits that modify the appearance
    2. Public Enum ButtonControlStyles
    3.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_PUSHBUTTON - A standard style push button
    4.     BS_PUSHBUTTON = &H0
    5.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_DEFPUSHBUTTON - A default push button
    6.     BS_DEFPUSHBUTTON = &H1
    7.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_CHECKBOX - A checkbox type button
    8.     BS_CHECKBOX = &H2
    9.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_AUTOCHECKBOX - A check box that deselects others in the same group when selected
    10.     BS_AUTOCHECKBOX = &H3
    11.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_RADIOBUTTON - A radio (option) button
    12.     BS_RADIOBUTTON = &H4
    13.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_3STATE - A checkbox that can be dimmed when disabled
    14.     BS_3STATE = &H5
    15.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_AUTO3STATE - A check box that can be dimmed and that deselects others in the same group when selected
    16.     BS_AUTO3STATE = &H6
    17.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_GROUPBOX - The button is a button group control
    18.     BS_GROUPBOX = &H7
    19.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_USERBUTTON - No longer used.
    20.     BS_USERBUTTON = &H8
    21.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_AUTORADIOBUTTON - A radio button that deselects others in the same group when selected
    22.     BS_AUTORADIOBUTTON = &H9
    23.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_OWNERDRAW - The button owner is responsible for drawing it
    24.     BS_OWNERDRAW = &HB
    25.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_LEFTTEXT - For check boxes this makes the check box on the left hand side of the text
    26.     BS_LEFTTEXT = &H20
    27.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_TEXT - Button has text
    28.     BS_TEXT = &H0
    29.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_ICON - Button contains an icon image
    30.     BS_ICON = &H40
    31.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_BITMAP - Button contains a bitmap (i.e is graphical)
    32.     BS_BITMAP = &H80
    33.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_LEFT - Left align the button text
    34.     BS_LEFT = &H100
    35.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_RIGHT - Right align the button text
    36.     BS_RIGHT = &H200
    37.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_CENTER - Center (horizontally) the button text
    38.     BS_CENTER = &H300
    39.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_TOP - Top align the button text
    40.     BS_TOP = &H400
    41.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_BOTTOM - Bottom align the button text
    42.     BS_BOTTOM = &H800
    43.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_VCENTER - Vertically centre the button text
    44.     BS_vCENTER = &HC00
    45.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_PUSHLIKE - Makes a checkbox style button behave as a push button
    46.     BS_PUSHLIKE = &H1000
    47.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_MULTILINE - Button text wraps if it is too long for a single line
    48.     BS_MULTILINE = &H2000
    49.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_NOTIFY - Send notification messages to the button owner
    50.     BS_NOTIFY = &H4000
    51.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_FLAT - Draws the button in the flat style
    52.     BS_FLAT = &H8000
    53.     ' ##ENUMERATION_MEMBER_DESCRIPTION BS_RIGHTBUTTON - For check boxes this makes the check box on the right hand side of the text
    54.     BS_RIGHTBUTTON = &H20
    55. End Enum
    56.  
    57. ' ##ENUMERATION_DESCRIPTION ButtonControlMessages - Predefined windows messages that are specifically to do with controls derived from the BUTTON class
    58. Public Enum ButtonControlMessages
    59.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_GETCHECK - Sent to return the check box state (checked or unchecked)
    60.     BM_GETCHECK = &HF0
    61.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_SETCHECK - Sent to set the check box state (checked or unchecked)
    62.     BM_SETCHECK = &HF1
    63.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_GETSTATE - Sent to return the button control state
    64.     BM_GETSTATE = &HF2
    65.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_SETSTATE - Sent to set the button control state
    66.     BM_SETSTATE = &HF3
    67.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_SETSTYLE - Sent to set the new button style of this button
    68.     BM_SETSTYLE = &HF4
    69.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_CLICK - Simulates the user clicking this button
    70.     BM_CLICK = &HF5
    71.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_GETIMAGE - Sent to get the picture displayed by this button, if it is a graphical style button
    72.     BM_GETIMAGE = &HF6
    73.     ' ##ENUMERATION_MEMBER_DESCRIPTION BM_SETIMAGE - Sent to set the picture displayed by this button, if it is a graphical style button
    74.     BM_SETIMAGE = &HF7
    75. End Enum
    76.  
    77. Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As ButtonControlMessages, ByVal wParam As Long, ByVal lParam As Long) As Long
    78. Private Declare Function GetWindowLongApi Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

  7. #7

    Thread Starter
    Hyperactive Member toughcoder's Avatar
    Join Date
    Nov 2002
    Location
    Near, Very Near
    Posts
    340
    thanx Merrion, guess i cud use them...
    If Not VB Then Exit
    ------------------------------------------------
    visit me @ http://mzubair.50g.com/

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Hey, I was looking for how to align a buttons text and there the
    const. is for right align. So sendmessagelong should be able to
    change the alignment of a button like this?

    VB Code:
    1. SendMessageLong btn.hwnd, BS_RIGHT, 0&, 0&
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    Use GetWindowLong to get the current window style.
    Then AND this with WS_RIGHT
    Then use Sendmessage(hwnd, WM_SETSTYLE, new style, True)

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Thanks, i'll try it out.

    Sorry for piggy-backing on your thread toughcoder!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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