Page 1 of 1

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

Posted: Sun Aug 31, 2008 7:45 am
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

Posted: Sun Aug 31, 2008 10:29 am
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

Thanks man

Posted: Sun Aug 31, 2008 11:41 am
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

Posted: Sun Aug 31, 2008 12:22 pm
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

Posted: Sun Aug 31, 2008 1:31 pm
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

Posted: Sun Aug 31, 2008 4:20 pm
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

Posted: Sun Aug 31, 2008 4:28 pm
by blueznl
After that rose, all that's left is some obscure male bonding ritual... poor Sparkie...

:shock:

Posted: Sun Aug 31, 2008 4:30 pm
by Sparkie
It's none of my business what goes on between those 2. I just post and run :P

Posted: Sun Aug 31, 2008 4:57 pm
by netmaestro
Not that there's anything wrong with that... :lol:

Posted: Sun Aug 31, 2008 7:26 pm
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

Posted: Sun Aug 31, 2008 8:48 pm
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:

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

Posted: Sun Jul 30, 2023 6:50 am
by Olli
Hello !

Is there any updates for Win 10/11 ?