Alpha_AI
asked on
how do i get the caption of the currently highlighted menuitem in a popupmenu?
how do i get the caption of the currently highlighted menuitem in a popupmenu?
I have a popupmenu and in it is menuitems added dynamically, i want to know how to get the caption of the menuitem while on mouseover or on the menuitem currently highlighted.
i dont want to know of the caption when you click on the item, i want to know the caption when i am on mouse over on the item.
and put the caption in the form1.caption.
any clues?
Ben
I have a popupmenu and in it is menuitems added dynamically, i want to know how to get the caption of the menuitem while on mouseover or on the menuitem currently highlighted.
i dont want to know of the caption when you click on the item, i want to know the caption when i am on mouse over on the item.
and put the caption in the form1.caption.
any clues?
Ben
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Do you know how to get the width of the popupmenu.
You see my menuitems are dynamic so the length of the caption in the menuitem determines the width of the popupmenu
I saw the function
procedure TForm2.SomeMenuItem_Measur eItem(Send er: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
begin
Width := 140;
end;
and i realise that width contains the length of the last str in the menu item but if the length of that last item
is the shortest then i cant use width .
i need to know the longest menuitem caption and i guess there must be a way to just get the width.
You see my menuitems are dynamic so the length of the caption in the menuitem determines the width of the popupmenu
I saw the function
procedure TForm2.SomeMenuItem_Measur
var Width, Height: Integer);
begin
Width := 140;
end;
and i realise that width contains the length of the last str in the menu item but if the length of that last item
is the shortest then i cant use width .
i need to know the longest menuitem caption and i guess there must be a way to just get the width.
I know how to get the width of teh text in teh menu item...
canvas.textwidth (it uses the canvas font to determine the dimensions)
eg.
width := ACanvas.TextWidth( TMenuItem(sender).Caption ); // + any buffer for the checkmark/image of course
height := ACanvas.TextHeight(TMenuIt em(sender) .Caption);
canvas.textwidth (it uses the canvas font to determine the dimensions)
eg.
width := ACanvas.TextWidth( TMenuItem(sender).Caption ); // + any buffer for the checkmark/image of course
height := ACanvas.TextHeight(TMenuIt
ASKER
ok you dont know how to make the blue highlighter while you hover reappear do you?
Ben
Ben
it does highlight on mine.
see this portion
if Selected then
begin
ACanvas.Brush.Color := clHighlight;
see this portion
if Selected then
begin
ACanvas.Brush.Color := clHighlight;
ASKER
it doesnt on mine, what am i doing wrong?
procedure TForm1.SomeMenuItem_1DrawI tem(Sender : TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
var
ImgID: integer;
HoverText : string;
position : integer;
GetTheNumberString : string;
GetTheNumber : integer;
Node : PVirtualNode;
Data : PNodeData;
begin
if Selected then
begin
ACanvas.Brush.Color := clHighlight;
Form1.Caption := StringReplace(TMenuItem(se nder).Capt ion, '&', '', [rfReplaceAll]); // or just use hint
hovertext := Form1.Caption;
Position := Pos(')',hovertext); // if copy of real version has a '(' in it then run this small function
if Position = 3 then
begin
GettheNumberString := AnsiMidStr(hovertext,2,1); //Extract the number out cos we need it for duplicate custom names, this way each custom name is unique by a number.
GetTheNumber := strtoint(GetTheNumberStrin g);
Delete(hovertext,1,4);
end;
if Position = 4 then
begin
GettheNumberString := AnsiMidStr(hovertext,2,2); //Extract the number out cos we need it for duplicate custom names, this way each custom name is unique by a number.
GetTheNumber := strtoint(GetTheNumberStrin g);
Delete(hovertext,1,5);
end;
Node := FindNodeByID1(vtClips,hove rtext);
if Node <> nil then
begin
Data := vtClips.GetNodeData(Node);
Form7.Caption := Data^.DictionaryWord;
Form7.PageControl1.Pages[0 ].Caption := Data^.DictionaryWord;
Form7.RichEdit1.Text := Data^.Type1;
end;
end
else
begin
ACanvas.Brush.Color := clMenu;
Form1.Caption := '';
ARect.Left := 4;
ACanvas.FillRect(ARect);
DrawText(ACanvas.Handle, PChar( TMenuItem(sender).Caption) , -1, ARect, DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_NOCLIP);
end;
end;
procedure TForm1.SomeMenuItem_1DrawI
ARect: TRect; Selected: Boolean);
var
ImgID: integer;
HoverText : string;
position : integer;
GetTheNumberString : string;
GetTheNumber : integer;
Node : PVirtualNode;
Data : PNodeData;
begin
if Selected then
begin
ACanvas.Brush.Color := clHighlight;
Form1.Caption := StringReplace(TMenuItem(se
hovertext := Form1.Caption;
Position := Pos(')',hovertext); // if copy of real version has a '(' in it then run this small function
if Position = 3 then
begin
GettheNumberString := AnsiMidStr(hovertext,2,1);
GetTheNumber := strtoint(GetTheNumberStrin
Delete(hovertext,1,4);
end;
if Position = 4 then
begin
GettheNumberString := AnsiMidStr(hovertext,2,2);
GetTheNumber := strtoint(GetTheNumberStrin
Delete(hovertext,1,5);
end;
Node := FindNodeByID1(vtClips,hove
if Node <> nil then
begin
Data := vtClips.GetNodeData(Node);
Form7.Caption := Data^.DictionaryWord;
Form7.PageControl1.Pages[0
Form7.RichEdit1.Text := Data^.Type1;
end;
end
else
begin
ACanvas.Brush.Color := clMenu;
Form1.Caption := '';
ARect.Left := 4;
ACanvas.FillRect(ARect);
DrawText(ACanvas.Handle, PChar( TMenuItem(sender).Caption)
end;
end;
ASKER
yeah i removed the end; at the bottom and put it underneath Form1.Caption := ''; and then it worked :-)
THanks heaps
Ben
THanks heaps
Ben
ASKER
Do you know how make it appear?
Ben