2

I have an mode that uses TComboBox.SelStart to indicate progress along the edit text string. In this mode I would like to make some kind of change to the edit caret, for example to widen it to 2 pixels or 'bold' it in some way to indicate this mode and to have it grab more attention. Is this possible?

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
Brian Frost
  • 13,334
  • 11
  • 80
  • 154
  • 1
    I don't know about delphi but win32's createcaret/showcaret/destroycaret let you easily assign a custom-size caret to an hwnd (the edit part of the combo) – Alex K. Sep 14 '12 at 10:48
  • I would custom-draw the ComboBox instead, then you can draw a real progress bar directly on the edit box, such as behind the text. – Remy Lebeau Sep 14 '12 at 22:40
  • @remy: That's an interesting idea.. Thanks – Brian Frost Sep 15 '12 at 16:59
  • I'm sorry guys, it seems that the answer and subsequent comments came in much later than the original question. And yes, I find SO excellent. I cant understand why I didn't see this traffic at the time. – Brian Frost Aug 16 '14 at 17:33

1 Answers1

3

Yes, as Alex mentioned in his comment, this can be done using API calls. Example:

procedure SetComboCaretWidth(ComboBox: TComboBox; Multiplier: Integer);
var
  EditWnd: HWND;
  EditRect: TRect;
begin
  ComboBox.SetFocus;
  ComboBox.SelStart := -1;
  Assert(ComboBox.Style = csDropDown);

  EditWnd := GetWindow(ComboBox.Handle, GW_CHILD);
  SendMessage(EditWnd, EM_GETRECT, 0, LPARAM(@EditRect));
  CreateCaret(EditWnd, 0,
              GetSystemMetrics(SM_CXBORDER) * Multiplier, EditRect.Height);
  ShowCaret(EditWnd);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetComboCaretWidth(ComboBox1, 4); // bold caret
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  SetComboCaretWidth(ComboBox1, 1); // default caret
end;
Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • Brian, does this answer your question? – Sertac Akyuz Nov 09 '12 at 12:08
  • I wonder why this question and answer had -1 and zero scores (Until I voted them up). This seems interesting to me. – Warren P Aug 11 '14 at 18:47
  • @Warren - Actually I'm the one who downvoted. With lack of any feedback, I assumed poster had lost any interest with any answer to the actual question asked (this is a late answer), in which case the question should better be deleted. Well, that was what I thought if I recall correctly. – Sertac Akyuz Aug 12 '14 at 02:45
  • Brian is still actively using the site. IT's too bad he doesn't accept answers, after 2 years. – Warren P Aug 13 '14 at 13:07
  • I'm sorry Sertac, I cant understand why I didn't see your answer at the time I had the issue. Thanks for your suggestion. – Brian Frost Aug 16 '14 at 17:35
  • @Brian - You're welcome. Probably I happened to post the answer later than when you had the issue, it might be why you missed it. – Sertac Akyuz Aug 21 '14 at 02:48