|
-
Jan 1st, 2006, 04:39 PM
#1
Thread Starter
Member
change the Color of XL Formula Bar
Hi all,
I am trying to change the Excel formula bar color to red and I am using the following code but unfortunately doesn't work:
Code :
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Function FillRect Lib "user32" _
(ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal _
lpsz2 As String) As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Sub ChangeFormulaBarColor()
Dim recto As RECT
Dim lngFrmBarHndle As Long
Dim lngFrmBarDC As Long
' Get the XL formula Bar window handle
lngFrmBarHndle = FindWindowEx(Application.hwnd, 0, "EXCEL<", vbNullString)
' Get its rectangle metrics
GetWindowRect lngFrmBarHndle, recto
' Get its window DC
lngFrmBarDC = GetDC(lngFrmBarHndle)
' Fill the Formula with Red Color
FillRect lngFrmBarDC, recto, &HFFFFFF + 1
' Release DC
ReleaseDC lngFrmBarHndle, lngFrmBarDC
End Sub
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Am I using the FillRect Function incorrectly ?
Regards.
-
Jan 1st, 2006, 05:02 PM
#2
Re: change the Color of XL Formula Bar
Your code basically looks ok but since your trying to do this on a third party program you will need to subclass it using a C++ dll. When your code fires the toolbar get repainted again from Excel, thus overwritting your color.
There is a codebank thread with an example of subclassing other programs in case your interested.[/color]
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 1st, 2006, 05:18 PM
#3
Thread Starter
Member
Re: change the Color of XL Formula Bar
 Originally Posted by RobDog888
Your code basically looks ok but since your trying to do this on a third party program you will need to subclass it using a C++ dll. When your code fires the toolbar get repainted again from Excel, thus overwritting your color.
There is a codebank thread with an example of subclassing other programs in case your interested.[/color]
Thanks for the prompt reply.
Is there any other solution apart from using the C dll ? Any other API functions\hacks that we can use in VB without having to resort to C or external DLLs ?
I have used the SetBKcolor API function before to achieve this but it doesn't work consistently : ie It only works when you deactivate the XL app and then reactivate it again !
Regards.
-
Jan 1st, 2006, 05:21 PM
#4
Re: change the Color of XL Formula Bar
Right, that is from the app not being subclased so you can intercept the WM_PAINT message. Thats when you would make the call to your procedure to paint the toolbar with the color you want.
I do not believe it is possible to do it in VB since you can not access another threads process without using a C++ dll.
Its not that hard using the dll. Here is the thread in question - http://www.vbforums.com/showthread.php?t=322261
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 1st, 2006, 05:30 PM
#5
Thread Starter
Member
Re: change the Color of XL Formula Bar
 Originally Posted by RobDog888
Right, that is from the app not being subclased so you can intercept the WM_PAINT message. Thats when you would make the call to your procedure to paint the toolbar with the color you want.
I do not believe it is possible to do it in VB since you can not access another threads process without using a C++ dll.
Its not that hard using the dll. Here is the thread in question - http://www.vbforums.com/showthread.php?t=322261
Thanks again,
Looks promising
I have never used any DLLs less so a C++ one ! ... however I'll give this a try and post back .
Regards.
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
|