Results 1 to 4 of 4

Thread: how to set button color background and text?

  1. #1

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461

    how to set button color background and text?

    how would i set the background color and text of a pushbutton WITH ONLY API!!!!!!! has to be api becuase i need it for a nother project that isnt vb.
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Is it C++? You'll have to subclass your window (change its procedure to your own) and then you'll recieve a WM_CTLCOLORBTN message where you can return the background colour (as HBRUSH) to change the background colour to whatever you want.
    BTW, you'll already be handling your window's messages in C++.
    Baaaaaaaaah

  3. #3

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    asm actully, if youy can give me some vb code to do this i can convert it to asm.
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You can try this (did work for me in VB but works in C++):

    VB Code:
    1. 'IN THE MODULE
    2.  
    3. Option Explicit
    4.  
    5. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    6. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    7. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    8. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    9. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    10. Public Const GWL_WNDPROC = (-4)
    11. Public Const WM_CTLCOLORBTN = &H135
    12.  
    13. Public oldwndproc As Long
    14. Dim hbrush As Long
    15.  
    16. Public Function Subclass(hwnd As Long)
    17. 'Red background colour
    18. hbrush = CreateSolidBrush(vbRed)
    19. 'Subclass the window
    20. oldwndproc& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
    21. End Function
    22. Public Function Unsubclass(hwnd As Long)
    23. 'Remove the subclassing
    24. SetWindowLong hwnd, GWL_WNDPROC, oldwndproc&
    25. 'Delete the background brush
    26. DeleteObject hbrush
    27. End Function
    28.  
    29. 'Subclassed procedure
    30. Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    31.  
    32. If Msg = WM_CTLCOLORBTN Then
    33. 'Change the background colour of the button
    34. WndProc = hbrush
    35. End If
    36.  
    37. WndProc = CallWindowProc(oldwndproc&, hwnd&, Msg&, wParam&, lParam&)
    38. End Function
    39.  
    40.  
    41. 'IN THE FORM
    42. Private Sub Form_Load()
    43. Subclass Me.hwnd
    44. End Sub
    45.  
    46. Private Sub Form_Unload(Cancel As Integer)
    47. Unsubclass Me.hwnd
    48. End Sub
    Baaaaaaaaah

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