Change "System Menu Item" to Bold Style + Change S

Just starting out? Need help? Post your questions and find answers here.
User avatar
Alireza
Enthusiast
Enthusiast
Posts: 143
Joined: Sat Aug 16, 2008 2:02 pm
Location: Iran

Change "System Menu Item" to Bold Style + Change S

Post by Alireza »

Hi All
I do bunlge to change "System Menu Item" to Bold Style + Change Size
but result is false.
Masters, please help me.
Thanks in Advanced.

Code: Select all

Procedure SysMenuAdd(hwnd, ret, nPos.l, flage, Text.s)
; English forum: http://www.purebasic.fr/english/viewtopic.php?p=70325#70325 
; Author: GreenGiant (updated for PB 4.00 by edel)
; Date:  26. September 2004 
; OS: Windows 
; Demo: No 
SystemMenu = GetSystemMenu_(hwnd, #False)
      #MIIM_STATE=1 
      #MFS_DEFAULT=4096 
      bold.MENUITEMINFO 
      bold\cbSize=SizeOf(bold) 
      bold\fMask=#MIIM_STATE 
      bold\fState=#MFS_DEFAULT 
      SetMenuItemInfo_(SystemMenu,7,#True,bold) ;2 specifies the item to be made bold
  
  InsertMenu_(SystemMenu, nPos, #MF_BYPOSITION	| flage	, ret, @Text)
  DrawMenuBar_(hwnd)
       
  ProcedureReturn retA = ret
EndProcedure
;##################################################################################################

OpenWindow(0, 0, 0, 200, 200, "Box", #PB_Window_SystemMenu | #PB_Window_ScreenCentered, PID) And CreateGadgetList(WindowID(0)) 

SysMenuAdd(WindowID(Window_0), 10000, 7, #MFS_DEFAULT,"            About")



Repeat 
    ev = WaitWindowEvent() 
Until ev = #PB_Event_CloseWindow
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It seems that in a system menu only one item can be made bold - and that is reserved for the 'close' item. One way around this is to remove the close item and add your own and then add your new item!

Code: Select all

Procedure SysMenuAdd(hWnd, menuHwnd, ret, nPos.l, flage, Text.s) 
      #MIIM_STATE=1 
      #MFS_DEFAULT=4096 
      bold.MENUITEMINFO 
      bold\cbSize=SizeOf(bold) 
      bold\fMask=#MIIM_STATE 
      bold\fState=#MFS_DEFAULT
  InsertMenu_(menuHwnd, nPos, #MF_BYPOSITION   | flage   , ret, @Text) 
  SetMenuItemInfo_(menuHwnd,7,#True,bold) ;2 specifies the item to be made bold 
  DrawMenuBar_(hwnd) 
        
  ProcedureReturn retA = ret 
EndProcedure 
;################################################################################################## 

OpenWindow(0, 0, 0, 200, 200, "Box", #PB_Window_SystemMenu | #PB_Window_ScreenCentered, PID)
CreateGadgetList(WindowID(0))

SystemMenu = GetSystemMenu_(WindowID(0), #False) 
  RemoveMenu_(systemmenu,6,#MF_DISABLED|#MF_BYPOSITION) 
  InsertMenu_(SystemMenu, 6, #MF_BYPOSITION, #SC_CLOSE, @"Close") 

SysMenuAdd(WindowID(0), SystemMenu, 10000, 7, #MFS_DEFAULT,"            About") 


Repeat 
    ev = WaitWindowEvent() 
Until ev = #PB_Event_CloseWindow
I may look like a mule, but I'm not a complete ass.
User avatar
Alireza
Enthusiast
Enthusiast
Posts: 143
Joined: Sat Aug 16, 2008 2:02 pm
Location: Iran

Thanks man

Post by Alireza »

WoW, Mr.srod it's a fantastic, Thanks man.
Only there is a prob with CloseButton Disabling .
I hope that you have a trick for it.
Thanks a lot man.

Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Okay scrap that crappy code! :wink:

The following effectively places the text 'About' on top of the 'Close' item and adds a new item for close. A few tricks are then needed to differentiate between the user wishing to close the window and utilise the 'about' option etc.

I'm in a real rush right now so I can't search for what I feel must be a better way - there has to be a much better solution than this! The code below uses a lot of 'hard coding' of menu items etc. which you would need to change if altering the menu even more. It also assumes that there is a window caption present.

Code: Select all

Procedure.l Callback(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_SYSCOMMAND
      If wParam = #SC_CLOSE
        ypos = lparam>>16&$ffff - WindowY(0)
        If ypos > GetSystemMetrics_(#SM_CYCAPTION	)
          Debug "About clicked!"
          result = 0
        EndIf
      ElseIf wParam = 6
        SendMessage_(hWnd, #WM_CLOSE, 0, 0)
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0, 0, 0, 200, 200, "Box", #PB_Window_SystemMenu | #PB_Window_ScreenCentered, PID) 
CreateGadgetList(WindowID(0)) 

SystemMenu = GetSystemMenu_(WindowID(0), #False) 
  InsertMenu_(SystemMenu, 6, #MF_BYPOSITION, 6, @"Close") 
  bold.MENUITEMINFO 
  bold\cbSize=SizeOf(bold) 
  bold\fMask=#MIIM_TYPE
  bold\fType = #MFT_STRING
  bold\dwTypeData = @"About"
  SetMenuItemInfo_(systemmenu,7,#True,bold) ;2 specifies the item to be made bold 
SetWindowCallback(@Callback())


Repeat 
    ev = WaitWindowEvent() 
Until ev = #PB_Event_CloseWindow
I may look like a mule, but I'm not a complete ass.
User avatar
Alireza
Enthusiast
Enthusiast
Posts: 143
Joined: Sat Aug 16, 2008 2:02 pm
Location: Iran

Post by Alireza »

Image


Ok, I try again in freuqently and i'm understand that why your explanation is true utterly.
If 'Bold' be Imputed to Word "Close", we have not prob,
But 'Bold' is Impute to "#SC_CLOSE" ! then i think that can't Own both non Word "Close" and CloseButton simultaneous.
But your trick is very very nice and desirable.
thanks man
I'm sorry really for tack busy you.
Image
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Code: Select all

;...Get menu font info
ncm.NONCLIENTMETRICS
ncm\cbSize = SizeOf(ncm)
SystemParametersInfo_(#SPI_GETNONCLIENTMETRICS, 0, @ncm, 0)
menuFont$ = PeekS(@ncm\lfMenuFont\lfFacename)
hdc = CreateDC_(@"DISPLAY", 0, 0, 0) 
logPixSY = GetDeviceCaps_(hdc, #LOGPIXELSY) 
DeleteDC_(hdc) 
menuFontSize = -(ncm\lfMenuFont\lfHeight * 72) / logPixSY   
myFont = LoadFont(0, menuFont$, menuFontSize , #PB_Font_Bold)

Procedure SysMenuAdd(win, mPos.l) 
  SystemMenu = GetSystemMenu_(WindowID(win), #False) 
  result = InsertMenu_(SystemMenu, mPos - 1, #MF_BYPOSITION | #MF_OWNERDRAW, mPos, #MF_OWNERDRAW) 
  If result
    DrawMenuBar_(WindowID(win)) 
  EndIf
  ProcedureReturn result
EndProcedure 

Procedure WinCallback(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_DRAWITEM
      If wParam = 0
        *dis.DRAWITEMSTRUCT = lParam
        If *dis\CtlType = #ODT_MENU And *dis\itemID = 8
          menuNormalBg = GetSysColorBrush_(#COLOR_MENU)
          menuSelectBg = GetSysColorBrush_(#COLOR_HIGHLIGHT)
          menuNormalText = GetSysColor_(#COLOR_MENUTEXT)
          menuSelectText = GetSysColor_(#COLOR_HIGHLIGHTTEXT)
          textColor = GetTextColor_(*dis\hdc)
          If *dis\itemState & #ODS_SELECTED
            SetTextColor_(*dis\hdc, menuSelectText)
            brush = menuSelectBg
          Else
            SetTextColor_(*dis\hdc, menuNormalText)
            brush = menuNormalBg
          EndIf
          ;...Fill our menu item background
          FillRect_(*dis\hdc, *dis\rcItem, brush)
          ;...Adjust text margin
          leftMargin = GetSystemMetrics_(#SM_CXMENUSIZE) + 4
          *dis\rcItem\left + leftMargin
          ;...Get default bk mode
          bkMode = GetBkMode_(*dis\hdc)
          ;...Set to transparent if needed
          If bkMode <> #TRANSPARENT
            SetBkMode_(*dis\hdc, #TRANSPARENT)
          EndIf
          ;...Select our font into the dc
          oldFont = SelectObject_(*dis\hdc, FontID(0))
          ;...Draw the menu item text
          DrawText_(*dis\hdc, "&About", 6, *dis\rcItem, #DT_VCENTER)
          ;...Set dc back to defaults
          SetBkMode_(*dis\hdc, bkMode)
          SetTextColor_(*dis\hdc, textColor)
          SelectObject_(*dis\hdc, oldFont)
        EndIf
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 200, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  SetWindowCallback(@WinCallback())
  SysMenuAdd(0, 8) 
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow
EndIf
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

After that rose, all that's left is some obscure male bonding ritual... poor Sparkie...

:shock:
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

It's none of my business what goes on between those 2. I just post and run :P
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Not that there's anything wrong with that... :lol:
BERESHEIT
User avatar
Alireza
Enthusiast
Enthusiast
Posts: 143
Joined: Sat Aug 16, 2008 2:02 pm
Location: Iran

Post by Alireza »

@Sparkie
WoW, sir it's very more than What i aspire it... .
I would do send a flower-Pic here, but Perhaps in some Culture this action is Despicable .
but I'm very leal to you, Thanks a lot man. Image
Q:
In srod method is a way to coll a ting (srod used Debug), in your method has like act?

@blueznl
Please don't make rumor, its a thank only, however don't will glue this talks to srod & i both. Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Aye, Sparkie's ownerdrawn menu item is a better way by far. :)

Now, what exactly have these guys been insinuating? Is our secret out? Damn it! :wink:
I may look like a mule, but I'm not a complete ass.
Olli
Addict
Addict
Posts: 1238
Joined: Wed May 27, 2020 12:26 pm

Re: Change "System Menu Item" to Bold Style + Change S

Post by Olli »

Hello !

Is there any updates for Win 10/11 ?
Post Reply