|
-
Jul 14th, 2002, 02:47 PM
#1
Thread Starter
Hyperactive Member
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 {
}
-
Jul 14th, 2002, 03:28 PM
#2
PowerPoster
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++.
-
Jul 14th, 2002, 03:30 PM
#3
Thread Starter
Hyperactive Member
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 {
}
-
Jul 14th, 2002, 04:38 PM
#4
PowerPoster
You can try this (did work for me in VB but works in C++):
VB Code:
'IN THE MODULE
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
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
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_CTLCOLORBTN = &H135
Public oldwndproc As Long
Dim hbrush As Long
Public Function Subclass(hwnd As Long)
'Red background colour
hbrush = CreateSolidBrush(vbRed)
'Subclass the window
oldwndproc& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
End Function
Public Function Unsubclass(hwnd As Long)
'Remove the subclassing
SetWindowLong hwnd, GWL_WNDPROC, oldwndproc&
'Delete the background brush
DeleteObject hbrush
End Function
'Subclassed procedure
Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_CTLCOLORBTN Then
'Change the background colour of the button
WndProc = hbrush
End If
WndProc = CallWindowProc(oldwndproc&, hwnd&, Msg&, wParam&, lParam&)
End Function
'IN THE FORM
Private Sub Form_Load()
Subclass Me.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unsubclass Me.hwnd
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|