procedure NomItemDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean); var LeftPos: Integer; TopPos: Integer; TextLength: Integer; Text: string; begin Text := (Sender as TMenuItem).Caption; if Selected then ACanvas.Brush.Color := clGreen else ACanvas.Brush.Color := clBlue; ACanvas.FillRect(ARect); ACanvas.Font.Color := clWhite; ACanvas.Font.Style := [fsBold]; // Draw right in the middle of the menu TopPos := ARect.Top + (ARect.Bottom - ARect.Top - ACanvas.TextHeight('W')) div 2; TextLength := Length(Text); if TextLength > (ARect.Right - ARect.Left) then LeftPos := ARect.Left + 3 else LeftPos := ARect.Left + (ARect.Right - ARect.Left - ACanvas.TextWidth(Text)) div 2; ACanvas.TextOut(LeftPos, TopPos, Text); end;
private procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; const SC_MonItem = WM_USER + 1; procedure TForm1.WMSysCommand(var Msg: TWMSysCommand); begin if Msg.CmdType = SC_MonItem then ShowMessage('Mon Message Menu Item') else inherited; end; procedure TForm1.Button1Click(Sender: TObject); var TempDC: Cardinal; MemoryDC: cardinal; BitmapDC: HBITMAP; RectDC: TRect; PenDC: HPEN; BrushDC: Cardinal; HFontDC: HFONT; nHeight: Integer; S: string; begin AppendMenu(GetSystemMenu(Handle, FALSE), MF_SEPARATOR, 0, ''); TempDC := GetDC(GetDesktopWindow); MemoryDC := CreateCompatibleDC(TempDC); BitmapDC := CreateCompatibleBitmap(TempDC, 80, 18); try S := 'Mon Item'; SelectObject(MemoryDC, BitmapDC); SetRect(RectDC, 0, 0, 80, 18); PenDC := CreatePen(PS_DOT, 1, RGB(0,128,0)); SelectObject(MemoryDC, PenDC); BrushDC := CreateSolidBrush(RGB(255,255,0)); SelectObject(MemoryDC, BrushDC); Rectangle(MemoryDC, RectDC.Left, RectDC.Top, RectDC.Right, RectDC.Bottom); nHeight := MulDiv(10, GetDeviceCaps(MemoryDC, LOGPIXELSY), 72); HFontDC := CreateFont(nHeight, 0, 0, 0, FW_BOLD, 0, 1, 0, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, 0, VARIABLE_PITCH, 'Arial'); SelectObject(MemoryDC, HFontDC); SetTextColor(MemoryDC, $000000FF); SetBkMode(MemoryDC, TRANSPARENT); TextOut(MemoryDC, 4, 2, PChar(S), Length(S)); AppendMenu(GetSystemMenu(Handle, FALSE), MF_BITMAP, SC_MonItem, PChar(BitmapDC)); finally DeleteObject(PenDC); DeleteObject(BrushDC); DeleteDC(MemoryDC); ReleaseDC(0, TempDC); end; end;
{Cette procedure permet la Colorisation Syntaxique du panneau des désignations et des périphériques - denis Bertin le 28.10.2019} procedure text_out_find(Paintdc:hdc; x,y:integer; apc,bpc:pchar; color:tcolorref); var p:pchar; pc:wutil.pc1024; Size:tsize; alpha:tcolorref; begin if not afficher_la_colorisation_syntaxique then exit; strcopy(pc,apc); p:=strpos(pc,bpc); if p<>nil then begin p^:=#0; GetTextExtentPoint(Paintdc,pc,strlen(pc),Size); if color=g_base.RGB_Vert then if woutil.global_bool_noir_ou_blanc then alpha:=settextcolor(Paintdc,color) else alpha:=settextcolor(Paintdc,g_base.RGB_Vert_foncer) else alpha:=settextcolor(Paintdc,color); textout(Paintdc,x+Size.cx,y,bpc,strlen(bpc)); settextcolor(Paintdc,alpha); end; end; {text_out_find} procedure text_out_color_number(Paintdc:hdc; x,y:integer; ficelle:string; color:tcolorref); var i:integer; {l'itérateur de boucle, il varie de '0' à '9', avec ord qui renvoie son ordre AsCii} local_apc:pc10; begin if not afficher_la_colorisation_syntaxique then exit; for i:=ord('0') to ord('9') do begin local_apc[0]:=chr(i); local_apc[1]:=chr(0); text_out_find_next(Paintdc,x,y,pchar(ficelle),local_apc,color); end; {for i} text_out_find_next(Paintdc,x,y,pchar(ficelle),'.',color); text_out_find_next(Paintdc,x,y,pchar(ficelle),',',color); end; {text_out_color_number} procedure text_out_find_next(Paintdc:hdc; x,y:integer; apc,bpc:pchar; color:tcolorref); var i:integer; p,q:pchar; pc:wutil.pc1024; Size:tsize; alpha:tcolorref; begin if not afficher_la_colorisation_syntaxique then exit; for i:=pred(strlen(apc)) downto 0 do begin strcopy(pc,apc); q:=@pc[i]; p:=strpos(q,bpc); if p<>nil then begin p^:=#0; alpha:=settextcolor(Paintdc,color); GetTextExtentPoint(Paintdc,pc,strlen(pc),Size); TextOut(Paintdc,x+Size.cx,y,bpc,strlen(bpc)); SetTextColor(Paintdc,alpha); end; end; end; {text_out_find_next}
Modifié le 10 août 2020 à 08:49
J'ai presque tout les éléments nécessaire en main, je me demande si en qualité de développeur et de conseilleur logiciel je peut vous citer avec votre pseudo sur mon site web, j'ai besoin de votre accord.