Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change the color font of menu label
#1
Is it possible to change the color of the font of the label of a menu item? Any advice much appreciated.
#2
In Properties you can set text color of all items and the selected item. In other cases need to create owner-draw menu, much work.
#3
Thank you for this advice. Actually I mean changing color for a particular label. I understand an idea about drawing a menu is give in topic (Function dlg_menu_draw) :

Enable/Disable/Rename

I am working on it. However, I envisage difficulty in finding how to change the color. Any advice is mostly welcome.
#4
Really much work. Need to store item text/id/color in array, get menu DC, calculate text width, detect is themed or not, get theme handle, calculate text rectangle, draw background, draw text, draw all differently when themed or not, use different colors for normal/selected/disabled state, draw separators differently, process WM_MENUCHAR (menu item selection with keys).

Minimal example.
Function dlg_menu_draw2
Code:
Copy      Help
out

;optionally add icons
SetThreadMenuIcons "100=0 101=34 102=2" "$qm$\il_qm.bmp" 1

str dd=
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 8 8 48 14 "Popup menu"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0 0 0 0 0 0 0 0 0 sub.GetMenuDef)) ret


#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,
,case WM_MEASUREITEM
,sel wParam
,,case 0
,,sub.MeasureMenuItem hDlg +lParam
,,ret DT_Ret(hDlg 1)
,
,case WM_DRAWITEM
,sel wParam
,,case 0
,,sub.DrawMenuItem hDlg +lParam
,,ret DT_Ret(hDlg 1)
ret
;messages2
sel wParam
,case 3 ;;Popup menu
,int i=ShowMenu(sub.GetMenuDef hDlg)
,
,case IDOK
,case IDCANCEL
ret 1


#sub GetMenuDef
function~

str md=
;BEGIN MENU
;>&File
;,&New :100 0x100 0x0 Cn
;,&Open :101 0x100 0x0 Co
;,&Save :102 0x100 0x0 Cs
;,Save &As... :103 0x100
;,-
;,>&Recent :0 0x100
;,,not implemented :190 0x0 0x3
;,,<
;,-
;,E&xit :2 0x100 0x0 AF4
;,<
;&Help :901
;END MENU
ret md


#sub MeasureMenuItem
function hDlg MEASUREITEMSTRUCT&m

BSTR b="Menu item text" ;;this should be retrieved from array that you create before showing menu
SIZE z
GetTextExtentPoint32W(sub.GetMenuDC b b.len &z)
m.itemWidth=z.cx
m.itemWidth+24 ;;add space for icon or checkbox
if(m.itemHeight<18) m.itemHeight=18 ;;icon height + 2 pixels between icons


#sub DrawMenuItem
function hDlg DRAWITEMSTRUCT&d

int hdc=d.hDC
RECT r=d.rcItem
int selected(d.itemState&ODS_SELECTED) disabled(d.itemState&ODS_DISABLED)

FillRect hdc &r iif(selected COLOR_HIGHLIGHT COLOR_MENU)+1

;this code gets default text color. Change it if need other color.
int col=-1
if(disabled) col=GetSysColor(COLOR_GRAYTEXT)
else if(selected) col=GetSysColor(COLOR_HIGHLIGHTTEXT)
else col=GetSysColor(COLOR_MENUTEXT)

SetTextColor(hdc col)
SetBkMode(hdc TRANSPARENT)

BSTR b="Menu item text" ;;this should be retrieved from array that you create before showing menu

r.left+24 ;;add space for icon or checkbox, which you can draw here or use SetThreadMenuIcons
r.top+1

DrawTextW(hdc b b.len &r DT_END_ELLIPSIS)


#sub GetMenuDC
function#

;Returns DC to measure menu item text width.

POINT-- m ;;x=DC, y=oldFont
if m.x=0
,NONCLIENTMETRICSW nc.cbSize=sizeof(nc)
,SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, nc.cbSize, &nc, 0);
,int font=CreateFontIndirectW(&nc.lfMenuFont)
,m.x=CreateCompatibleDC(0)
,m.y=SelectObject(m.x font)
,atend sub.__DeleteMenuDC &m
ret m.x

#sub __DeleteMenuDC
function POINT&m
DeleteObject SelectObject(m.x m.y)
DeleteDC m.x
#5
If need a popup menu without submenus, use ShowDropdownListSimple. Then also can add icons.

Macro Macro2365
Code:
Copy      Help
str csv=
F
;-1,,8
;One
;Two,,8
;Three,,,,0x80ff
;Four,,,,,0xffE0C0

int i
if(0=1&ShowDropdownListSimple(csv i)) ret
out i
#6
Thank you very much indeed, for all this useful information. I will try it, I think it is worthwhile. Best regards.
#7
I used SetThreadMenuIcons to add icons to labels. I experienced overlapping (over-striking). Then I left-padded label stings with a few spaces. It worked. However, I am not sure this is the proper way to do it.

Function dlg_menu_draw_Color
Code:
Copy      Help
str- Label=
;;;;;;;Line0
;;;;;;;Line1
;;;;;;;Line2
#8
Let me ask one additional question. I understand that using QM Menu Editor you may produce either menu bars (run with ShowDialog) or popupmenus (run with ShowMenu). Is it possible to run the present item as popup menu?
#9
Try dlg_menu_draw2 new version.
#10
Thank you, once more!
#11
Dear Gintaras, Have a nice day!
I am sorry if bothering, however I cannot avoid two more questions :

1. When I click on 3, then menu appears and variable "i" gets the proper value for this menu item. Nevertheless, the relevant menu value (for example 100) does not work, probably because "i" does not convey its value to wParam. Let me add that if this same menu item is invoked through menu label "File" it is working properly.

Your advice is mostly welcome.

2. If I wanted to invoke menu sub.GetMenuDef directly, without showing the main dialogue, then I thought to include in WM_INITDIALOG
Quote:but+ id(3, hDlg)

Could you please comment on it?
#12
This is the solution I gave to both above inquiries. It works. I wonder whether it is best practice.

Function dlg_menu_draw2_Menu
Code:
Copy      Help
sel wParam
,case 3 ;;Popup menu
,int i=ShowMenu(sub.GetMenuDef hDlg)
,out i
,sel i
,,case 100
,,out 100
,,case 101
,,out 101
,end
,
,case 100
,out 100
,
,case IDOK
,case IDCANCEL
#13
If need WM_COMMAND from ShowMenu, use TPM_RETURNCMD, see ShowMenu help. Or goto messages2.
#14
Thank you, but I am afraid your advice is not very clear to me. What I actually do is getting the return value as shown in the above example. Could you please elaborate your advice, upon your availability.
#15
This is what it came out finally. Any advice/comment is mostly welcome.

Function MenuDraw_FilMngmnt
Code:
Copy      Help
str si.getmacro(getopt(itemid) 1)
str caller.getmacro(getopt(itemid 1) 1);err    caller=si
if ideb; min 0; err out "<>%s : <open ''%s /%i''>%s</open> - Called by : %s" NowT si _error.place si caller

;http://www.quickmacros.com/forum/viewtopic.php?p=31268

str simglo
int i

IStringMap MenuItems._create
lpstr s=
;100 _|I. Select Folder
;101 0|Explorer Folder|GetSetFlashFol(0)
;102 1|Folder in Registry|GetSetFlashFol(1)
;103 2|Display Folder in Registry|Display_Clip(1)
;104 3|Working Folder|GetSetFlashFol(2)
;105 4|Display Working Folder|Display_Clip(2)
;106 5|Downloads Folder|GetSetFlashFol(3)
;107 6|Image Files Folder|GetSetFlashFol(9 F"{MyTemp}\png")
;108 7|Icons Folder|GetSetFlashFol(9 "C:\Documents and Settings\S.E.Simopoulos\My Documents\Local Settings\sysman\icons\Ico")
;109 8|Τύπος
;110 8|Τύπος|GetSetFlashFol(9 "S:\SESdoc\ΕΜΠ-Πρυτανεία\Δημόσιες Σχέσεις\ΜΜΕ\Τύπος")
;111 9|Καθημερινή - Α.Λ.|FilTagDatim(0); GetSetFlashFol(9 "S:\SESdoc\ΕΜΠ-Πρυτανεία\Δημόσιες Σχέσεις\ΜΜΕ\Τύπος\Καθημερινή\Λακασάς Α")
;112 10|ETE IB Statement|SaveETEIBMF
;113 11|Financial Folders
;114 12|Μισθός - Σύνταξη |GetSetFlashFol(9 "S:\SESdoc\Lykaio\ΕΜΠ\ΣΕΣ\Μισθολογικά")
;115 13|Σύνταξη ΤΣΜΕΔΕ |GetSetFlashFol(9 "S:\SESdoc\Lykaio\ΕΜΠ\ΣΕΣ\Ασφαλιστικά\ΤΣΜΕΔΕ\Συνταξιοδοτικά\Παραστατικά")
;116 14|ΔΕΗ-Παγκράτι|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Κατοικία\ΔΕΗ\%ThisYear%")
;117 15|ΔΕΗ-Πόρτο Ράφτη|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Πόρτο-Ράφτη\ΔΕΗ")
;118 16|Ανω - 5012|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Πόρτο-Ράφτη\ΔΕΗ\706012935012_Ανω")
;119 17|Κάτω - 4018|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Πόρτο-Ράφτη\ΔΕΗ\706015064018_Κάτω")
;120 18|Πηγάδι - 4016|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Πόρτο-Ράφτη\ΔΕΗ\706015524016_Πηγάδι")
;121 19|ΕΥΔΑΠ|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Κατοικία\ΕΥΔΑΠ")
;122 15|Υδρευση Π-Ρ|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Πόρτο-Ράφτη\Υδρευση")
;123 20|Cosmote 6977784222|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Τηλέφωνα\Πάροχοι\Cosmote\6977784222\%ThisYear%")
;124 21|Πόρτο-Ράφτη 78080|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Τηλέφωνα\Πάροχοι\ΟΤΕ\78080")
;125 22|Wind|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Τηλέφωνα\Πάροχοι\Wind)
;126 23|Wind 1.29810627-6932229428-71370|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Τηλέφωνα\Πάροχοι\Wind\1.29810627-71370-2229428\%ThisYear%")
;127 24|Wind 1.30837977-6978996600-7013157|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Τηλέφωνα\Πάροχοι\Wind\1.30837977-7013157-6978996600\%ThisYear%")
;128 25|Wind 1.30837875-6936939289-7019090|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Τηλέφωνα\Πάροχοι\Wind\1.30837875-7019090-ΧΕΣ Mob\%ThisYear%")
;129 26|Ασφάλιστρα Αυτοκινήτου|GetSetFlashFol(9 "S:\SESdoc\Προσωπικά\Αυτοκίνητα\IMT5317\Ασφάλεια")
;130 27|Κίνηση-082 Ετους|GetSetFlashFol(9 "%SESdoc%\Προσωπικά\Banks\ETE\Κίνηση\%ThisYear%")
;131 28|Display Current Path Length|CheckPathLength
;132 29|Display File Length|CheckFileOELength
;133 30|Display Current Folder|_s=OEMConstructComboPath; Task_Message _s 0 0xFF0000
;134 31|Display Current File|DisplayCurrentFile
;135 32|File tag Date|Paste_Date
;136 33|File tag Time|Paste_Date_Time
;137 34|Check File Length|Report_SavedF
;138 35|Shrink File Length|Shrink_SavedF
;139 36|Display Files Management Toolbar|OpSavMisc(win())
;140 _|II. FileSystem Routines
;141 _|III. Filename Modification Routines
;142 _|IV. Filename Length Routines
;143 _|V. Other

MenuItems.AddList(s)
IStringMap- label._create; label.Flags=1
IStringMap- qmi._create; label.Flags=1


ARRAY(str) arr ak av
MenuItems.GetAll(ak av)
int j
for(i 0 ak.len)
,j=tok(av[i] arr 3 "|" 0x2000)
,if j<2
,,_s=F"Tok error on key {ak[i]} - {av[i]}  - Caller : <open>{caller}</open> "
,,min 0; err out "<>%s : <open ''%s /%i''>%s</open> - %s" NowT si _error.place si _s
,,mac "Warning_QM" si 0
,,end

,if StrCompare(arr[0] "_")<>0; simglo.formata(F"{ak[i]}={arr[0]} ")
,label.Add(ak[i] arr[1])
,if j=3; qmi.Add(ak[i] arr[2])

;out simglo
simglo.rtrim
;simglo.left(simglo 261)
;out simglo

SetThreadMenuIcons simglo "$my qm$\imagelists\FilMngmnt.bmp" 1


str dd=
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;3 Button 0x54032000 0x0 8 8 48 14 "Popup menu"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040308 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0 0 0 0 0 0 0 0 0 sub.GetMenuDef)) ret


#sub DlgProc

function# hDlg message wParam lParam

str si.getmacro(getopt(itemid) 1)
str caller.getmacro(getopt(itemid 1) 1);err    caller=si
if ideb; min 0; err out "<>%s : <open ''%s /%i''>%s</open> - Called by : %s" NowT si _error.place si caller


sel message
,case WM_INITDIALOG
,but+ id(3, hDlg)
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,
,case WM_MEASUREITEM
,sel wParam
,,case 0
,,sub.MeasureMenuItem hDlg +lParam
,,ret DT_Ret(hDlg 1)
,
,case WM_DRAWITEM
,sel wParam
,,case 0
,,sub.DrawMenuItem hDlg +lParam
,,ret DT_Ret(hDlg 1)
ret
;messages2
;OutWinMsg message wParam lParam
IStringMap- qmi

sel wParam
,case 3 ;;Popup menu
,int i=ShowMenu(sub.GetMenuDef hDlg)

,lpstr v=qmi.Get(F"{i}")
,outt F"{i} | {v}"
,if(v)
,,RunTextAsFunction2(v)
,else
,,_s=F"Value not found for key {i}  - Caller : <open>{caller}</open> "
,,min 0; err out "<>%s : <open ''%s /%i''>%s</open> - %s" NowT si _error.place si _s
,,mac "Warning_QM" si 0
,,end
,
,end
,
,
,case IDOK
,case IDCANCEL
ret 1


#sub GetMenuDef
function~

str md=
;BEGIN MENU
;I. Select Folder : 100 0x100 0x3
;Explorer Folder : 101 0x100 0x0
;Folder in Registry : 102 0x100 0x0
;Display Folder in Registry : 103 0x100 0x0
;Working Folder : 104 0x100 0x0
;Display Working Folder : 105 0x100 0x0
;Downloads Folder : 106 0x100 0x0
;Image Files Folder : 107 0x100 0x0
;Icons Folder : 108 0x100 0x0
;>Τύπος  : 109 0x100
;,Τύπος : 110 0x100 0x0
;,Καθημερινή - Α.Λ. : 111 0x100 0x0
;<
;ETE IB Statement : 112 0x100 0x0
;>Financial Folders : 113 0x100 0x0
;Μισθός - Σύνταξη : 114 0x100 0x0
;Σύνταξη ΤΣΜΕΔΕ : 115 0x100 0x0
;-
;ΔΕΗ-Παγκράτι : 116 0x100 0x0
;ΔΕΗ-Πόρτο Ράφτη : 117 0x100 0x0
;Ανω - 5012 : 118 0x100 0x0
;Κάτω - 4018 : 119 0x100 0x0
;Πηγάδι - 4016 : 120 0x100 0x0
;-
;ΕΥΔΑΠ : 121 0x100 0x0
;Υδρευση Π-Ρ : 122 0x100 0x0
;-    
;Cosmote 6977784222 : 123 0x100 0x0
;Πόρτο-Ράφτη 78080 : 124 0x100 0x0
;-
;Wind  : 125 0x100 0x0
;Wind 1.29810627-6932229428-71370 : 126 0x100 0x0
;Wind 1.30837977-6978996600-7013157 : 127 0x100 0x0
;Wind 1.30837875-6936939289-7019090 : 128 0x100 0x0
;-
;Ασφάλιστρα Αυτοκινήτου : 129 0x100 0x0
;-
;Κίνηση-082 Ετους : 130 0x100 0x0
;<
;-
;II. : 140 0x100 0x3
;Display Current Path Length : 131 0x100 0x0
;Display File Length : 132 0x100 0x0
;Display Current Folder : 133 0x100 0x0
;Display Current File : 134 0x100 0x0
;-
;III. : 141 0x100 0x3
;File tag Date : 135 0x100 0x0
;File tag Time : 136 0x100 0x0
;-
;IV. : 142 0x100 0x3
;Check File Length : 137 0x100 0x0
;Shrink File Length : 138 0x100 0x0
;-
;V. : 143 0x100 0x3
;Display Files Management Toolbar : 139 0x100 0x0
;END MENU

ret md


#sub MeasureMenuItem
function hDlg MEASUREITEMSTRUCT&m

m.itemWidth=200 ;;there are several API functions to get string width, for example GetTextExtentPoint32W
m.itemWidth+24 ;;add space for icon or checkbox
;if(m.itemHeight<18) m.itemHeight=18 ;;icon height + 2 pixels between icons
if(m.itemHeight<24) m.itemHeight=24 ;;icon height + 2 pixels between icons

#sub DrawMenuItem
function hDlg DRAWITEMSTRUCT&d

str si.getmacro(getopt(itemid) 1)
str caller.getmacro(getopt(itemid 1) 1);err    caller=si
if ideb; min 0; err out "<>%s : <open ''%s /%i''>%s</open> - Called by : %s" NowT si _error.place si caller

IStringMap- label

int hdc=d.hDC
RECT r=d.rcItem
int selected(d.itemState&ODS_SELECTED) disabled(d.itemState&ODS_DISABLED)

FillRect hdc &r iif(selected COLOR_HIGHLIGHT COLOR_MENU)+1

;this code gets default text color. Change it if need other color.
int col=-1
int color

if d.itemID=103 ; color=475617
if d.itemID=105 ; color=108031
if(disabled)
;,col=GetSysColor(COLOR_GRAYTEXT)
;,https://msdn.microsoft.com/en-us/library/windows/desktop/ms724371(v=vs.85).aspx
,col=GetSysColor(COLOR_HOTLIGHT)
else
,if(selected)
,,col=GetSysColor(COLOR_HIGHLIGHTTEXT)
,else
,,col=iif(color color GetSysColor(COLOR_MENUTEXT))

SetTextColor(hdc col)
SetBkMode(hdc TRANSPARENT)

BSTR b
lpstr v=label.Get(F"{d.itemID}")
if(v)
,b=v
else
,_s=F"Value not found for key {d.itemID}  - Caller : <open>{caller}</open> "
,min 0; err out "<>%s : <open ''%s /%i''>%s</open> - %s" NowT si _error.place si _s
,mac "Warning_QM" si 0
,end

;BSTR b="Menu item text" ;;this should be retrieved from array that you create before showing menu

r.left+24 ;;add space for icon or checkbox, which you can draw here or use SetThreadMenuIcons
r.top+1


DrawTextW(hdc b b.len &r DT_END_ELLIPSIS)
#16
I have written a routine (function) to convert any menu to "smart-menu" (including colors etc.).


Attached Files
.qml   SmartMenu.qml (Size: 16 KB / Downloads: 359)
#17
When calculating the string width, I get slighter higher values in MeasureMenuItem than in DrawMenuItem> I would appreciate it if you could kindly comment on it. I use the following statements in these sub-functions :

Function MeasureMenuItem
Code:
Copy      Help
,int hdc=GetDC(hDlg)
;,out F"{s} - {hdc}"
,int c=s.lenu
,SIZE sz
,_i=GetTextExtentPoint32(hdc, s, c, &sz)
,out F"{s} - {_i} - {c} - {sz.cx} - {sz.cy}"

Function DrawMenuItem
Code:
Copy      Help
int c=s.lenu
SIZE sz
int hdc=d.hDC
_i=GetTextExtentPoint32(hdc, s, c, &sz)
out F"{s} - {_i} - {c} - {sz.cx} - {sz.cy}"

Many thanks in advance.
#18
To create common menu DC I use this algorithm. Maybe a better way exist.

Get NONCLIENTMETRICSW with SystemParametersInfoW(SPI_GETNONCLIENTMETRICS...);
From its lfMenuFont create font with CreateFontIndirectW.
Create DC with CreateCompatibleDC and select the font with SelectObject.
#19
Added to dlg_menu_draw2.
#20
Thank you. Actually, this makes my life easier!

Now tested. It is perfect!
#21
Thanks for this interesting thread.

SSimop, there are several 'unknown identifiers' like:

ideb
NowT
Warning_QM
GVarOut
LVarOut

Thank you, SSimop and Gintaras for sharing that info.
Regards.
#22
Dear AlexZ,

Thank you for your interest regarding this thread. Your questions are dealt with as it follows:

1. ideb is a global variable initialised in init2 for debugging purposes. Usually, its value is zero.

2. NowT is a simple time output routine. It may be modified according to the user's preferences. I have included it in an updated version of SmartMenu.qml above.

3. Warning_QM is a routine which outputs audio/screen messages in the case of error. It may be modified according to the user's preferences. I have included it in an updated version of SmartMenu.qml above.

4. GVarOut and LVarOut are routines called in a sample menu routine I included for demo purposes. They have nothing to do with this thread. They have to be replaced by the end user, which writes his own menu routine.

Please do not hesitate to ask any further questions. Let me add that I am writing computer software since 1968, under almost all operating systems, mainly for data acquisition and processing. I must admit that Quick Macros is the best platform, from every point of view, to my opinion. Congratulations are due to Gintaras for this perfect product, further to those for the present thread.
#23
Thank you for an interesting topic, especially the "Smart Menu".
I have a questiong though:
I have a sample menu like this:
Menu SmartMenu_Sample
Code:
Copy      Help
My Smart Menu * d:\ico\star.ico
-
> Control Panel * d:\ico\supernova.ico
,Administrative Tools :mac "Administrative_Tools" * d:\ico\supernova.ico
,Date and Time :mac "Date_and_Time" * d:\ico\supernova.ico
,Device Manager :mac "Device_Manager" * d:\ico\supernova.ico
<
-
>Utils * d:\ico\gear.ico
,Autotext :mac "My_Autotext" * d:\ico\gear.ico
,Backup My Data :mac "Backup My Data" * d:\ico\gear.ico
,Compare 2 Macros :mac "Compare 2 Macros" * d:\ico\gear.ico
<
I notice there is a trail of "* d" at the end of each menu item. How could you get rid of that?
#24
Thank you for your interest. It is probably a bug. I will investigate it thoroughly and I will let you know accordingly. I am sorry for this inconvenience.
#25
The bug is due to the column (Smile after d:\ico\... etc. It is my bug. Actually, I always use symbolic links for icons, and I missed this case. I will correct it as soon as possible and I will upload a new version. Many thanks for your comment.
#26
It is now corrected and updated. I would welcome any further comments.
#27
Thank you very much. It works fine now.
I have other questions:
- What make up the color number at the end when you want to add color to an item?
- Besides coloring each item with different color, could you make an item bold or italic too?
#28
1. You can help on QM colors by using lemma "color" in QM.
Colors in QM are defined as BGR
0x000000 - black
0xFFFFFF - white
0x0000FF - red
0x00FF00 - green
0xFF0000 - blue
0x00FFFF - yellow (red+green)
0xC0C0C0 - gray
0x808080 - dark gray
0x008000 - dark green

You may get int values for other colors using any relevant layered product, for example "colopicker"

2. I am working on changing font characteristics (bold & italic). I will report any outcome.
#29
Thanks for the examples on color input.
#30
Another, simple Color Dialog routine can be found in :

Simple ColorDialog

I attach, herewith a short routine I have written to simplify the use of this color dialog :
Function My_Color_Dialog
Code:
Copy      Help
str si.getmacro(getopt(itemid) 1)
if ideb; out "%s : %s" NowT si
int col
str s

;g1
if(ColorDialog(col s))
,;out "0x%06X" col
,;out s
,s.format("0x%06X" col)
,_s="Selected color string in Clipboard - Colors in QM are defined as BGR"
,
,Task_Message _s 0 col 1
,_s.from("Selected BGR-QM color code :[][]" s "[][]Continue ?")
,int i=mes(_s si "YN")
,s.setclip
,beeS 300 300
else
,ret
if i=89; goto g1

I have found the following version somewhere in the forum, I am afraid I do not remember where :

Function ColorDialog
Code:
Copy      Help
;/
function# int&colorInt [str&colorStr] [hwndOwner]

;Shows Color dialog.
;Returns 1 on OK, 0 on Cancel.

;colorInt - receives color value in format 0xBBGGRR.
;colorStr - receives color formatted as string.
;hwndOwner (QM 2.3.4) - handle of owner window or 0.

;EXAMPLE
;int col
;if(ColorDialog(col))
,;out "0x%X" col


type ___MYCOLORS ft c[16]
___MYCOLORS+ ___mycolors
if(___mycolors.ft=0) ___mycolors.ft=1; for(_i 0 16) ___mycolors.c[_i]=0xa0a0a0

CHOOSECOLOR cc.lStructSize=sizeof(CHOOSECOLOR)
cc.hWndOwner=hwndOwner
cc.flags=CC_FULLOPEN | CC_RGBINIT
cc.lpCustColors=&___mycolors.c
cc.rgbResult=0xa0a0a0
if(!ChooseColor(&cc)) 0; ret
if(&colorInt) colorInt=cc.rgbResult
if(&colorStr) colorStr.format("0x%X" cc.rgbResult)
0
ret 1


Forum Jump:


Users browsing this thread: 1 Guest(s)