Page 1 of 1
Change Notepad's menu title background color?
Posted: Mon Apr 24, 2023 12:08 pm
by BarryG
I'm wondering if there's any way to change a third-party window's menu title background color? Like change Notepad's menu titles to have a red background? I can get the menu handle, but haven't been able to change the colors yet. Any tips?
Re: Change Notepad's menu background color?
Posted: Sun Apr 30, 2023 5:18 pm
by firace
Have you tried tweaking this code (by luis):
Code: Select all
#MIM_BACKGROUND = 2
#MIM_APPLYTOSUBMENUS = $80000000 ; added
Structure myMENUINFO Align #PB_Structure_AlignC ; added
cbSize.l
fMask.l
dwStyle.l
cyMax.l
hbrBack.i ; changed to HBRUSH, handle size -> pointer size
dwContextHelpId.l
*dwMenuData ; changed to ULONG_PTR -> http://msdn.microsoft.com/en-us/library/windows/desktop/aa384255%28v=vs.85%29.aspx
EndStructure
Debug SizeOf(myMENUINFO)
hMenuBrushBG = CreateSolidBrush_(RGB(255,255,0))
With mi.myMENUINFO
\cbSize = SizeOf(myMENUINFO)
\fMask = #MIM_BACKGROUND | #MIM_APPLYTOSUBMENUS ; added
\hbrBack = hMenuBrushBG
EndWith
If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateMenu(0, WindowID(0))
MenuTitle("MenĂ¼ 1")
MenuItem(1,"Item 1")
MenuTitle("MenĂ¼ 2")
MenuItem(2,"Item 2")
EndIf
Debug SetMenuInfo_(MenuID(0), mi)
DrawMenuBar_(WindowID(0))
Repeat
EventID=WaitWindowEvent()
If EventID=#PB_Event_CloseWindow
DeleteObject_(hMenuBrushBG)
Quit=1
EndIf
Until Quit=1
EndIf
Re: Change Notepad's menu title background color?
Posted: Mon May 01, 2023 3:10 am
by BarryG
Sorry, I actually meant the menu title background color of a third-party menu, not the drop-down menus itself. Edited my post to clarify.
I looked at luis' code but don't see how that would be applied to a third-party window like Notepad?
Re: Change Notepad's menu title background color?
Posted: Mon May 01, 2023 5:18 am
by AZJIO
Code: Select all
EnableExplicit
#MIM_MAXHEIGHT = $1
#MIM_BACKGROUND = $2
#MIM_HELPID = $4
#MIM_MENUDATA = $8
#MIM_STYLE = $10
#MIM_APPLYTOSUBMENUS = $80000000
#MNS_NOCHECK = $80000000
; #MNS_CHECKORBMP = $4000000
Structure myMENUINFO Align #PB_Structure_AlignC ; added
cbSize.l
fMask.l
dwStyle.l
cyMax.l
hbrBack.i ; changed to HBRUSH, handle size -> pointer size
dwContextHelpId.l
*dwMenuData ; changed to ULONG_PTR -> http://msdn.microsoft.com/en-us/library/windows/desktop/aa384255%28v=vs.85%29.aspx
EndStructure
Structure ResStr
s.s
r.s
slen.i
rlen.i
hwnd.l
match.l
type.l
instance.l
EndStructure
Enumeration
#Title
#Class
EndEnumeration
; https://www.purebasic.fr/english/viewtopic.php?t=80897
; Finding Window
Procedure.l enumChildren(hwnd.l, *s.ResStr)
Static n.l = 0
If hwnd
Select *s\type
Case 0
GetWindowText_(hwnd, @*s\r, *s\rlen)
Case 1
GetClassName_(hwnd, @*s\r, *s\rlen)
EndSelect
Select *s\match
Case 0
If *s\r = *s\s
n + 1
If n = *s\instance
n = 0
Debug *s\r
*s\hwnd = hwnd
ProcedureReturn 0
EndIf
EndIf
Case 1
If Left(*s\r, *s\slen) = *s\s
n + 1
If n = *s\instance
n = 0
Debug *s\r
*s\hwnd = hwnd
ProcedureReturn 0
EndIf
EndIf
Case 2
If FindString(*s\r, *s\s, 1, #PB_String_NoCase)
n + 1
If n = *s\instance
n = 0
Debug *s\r
*s\hwnd = hwnd
ProcedureReturn 0
EndIf
EndIf
EndSelect
ProcedureReturn 1
EndIf
n = 0
ProcedureReturn 0
EndProcedure
; type
; 0 - Title
; 1 - Class
; match
; 0 - exact match
; 1 - match from start
; 2 - the word occurs in the title
Procedure.l WinGetHandle(hwnd, text.s, instance = 1, type = 0, match = 0)
Protected s.ResStr
s\rlen = 256
s\r = Space(s\rlen)
s\s = text
s\slen = Len(text)
s\match = match
s\type = type
s\instance = instance
EnumChildWindows_(hwnd, @enumChildren(), @s)
ProcedureReturn s\hwnd
EndProcedure
Define hwnd, hMenu, hSubMenu, Count
Define hMenuBrushBG
Define mi.myMENUINFO
Define i
RunProgram("Notepad")
Delay(1000)
; End
hwnd = WinGetHandle(0, "Notepad", 1, #Class, 1) ; Properties
Debug Hex(hwnd)
If hwnd
hMenu = GetMenu_(hwnd)
Debug Hex(hMenu)
Count = GetMenuItemCount_(hMenu)
; hSubMenu = GetSubMenu_(hMenu, 0)
; Debug Hex(hSubMenu)
Else
End
EndIf
; https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor
; only For cached brushes, i.e. system ones
hMenuBrushBG = GetSysColorBrush_(#COLOR_INFOBK)
; With mi
; \cbSize = SizeOf(myMENUINFO)
; \fMask = #MIM_BACKGROUND | #MIM_HELPID | #MIM_MAXHEIGHT | #MIM_MENUDATA | #MIM_STYLE
; EndWith
;
; GetMenuInfo_(hMenu, mi)
With mi
\cbSize = SizeOf(myMENUINFO)
; \fMask = #MIM_BACKGROUND ; hSubMenu
\fMask = #MIM_BACKGROUND | #MIM_APPLYTOSUBMENUS | #MIM_STYLE ; hwnd
\hbrBack = hMenuBrushBG
\dwStyle = #MNS_NOCHECK ; Remove if not needed (removes the field for the icon)
EndWith
; For i = 0 To Count - 1
; hSubMenu = GetSubMenu_(hMenu, i)
; SetMenuInfo_(hSubMenu, mi)
; Next
SetMenuInfo_(hMenu, mi)
; DrawMenuBar_(hwnd)
Re: Change Notepad's menu title background color?
Posted: Mon May 01, 2023 6:10 am
by BarryG
Thanks, getting close! I will see if I can work out the menu titles themselves now (unless you know a quick way?).
Re: Change Notepad's menu title background color?
Posted: Mon May 01, 2023 6:29 am
by AZJIO
There is a GetMenuBarInfo function and a MENUBARINFO structure, but there are no elements in it that could change the background color.
If you try to access it as a menu item, then in the MENUITEMINFO structure there is also no way to set a color.
I usually look at
AutoIt3 help and then look in the "Include" folder for the function files to understand how they are made and remake them in PureBasic. But also looking in "CodeArchiv".
Re: Change Notepad's menu title background color?
Posted: Mon May 01, 2023 7:16 am
by BarryG
Checking AutoIt sources is a good tip! Thanks; will have to start doing that. I often look at AutoHotkey scripts as well when I need help, or search StackOverflow.