开发者

How to use ASCII Art symbols in Message Dialogs of Unicode-by-default Delphi XE Applications

I have searched subject offers, but Did not manage to get right one ...

Sorry if I am mistaking. If so, please point to correct Question here.

Okay, back to business. Situation: I am using ShowMessage() as simple "Status Briefing" provider for some events in Application:

procedure SatusBriefingDialog();
begin
  if Sender = SomeObject then 
  begin
    Application.NormalizeToMosts;
    MessageDlg(Handle, PChar('The_string_that_forms_nice_informative_window / dialog'));
  开发者_如何学编程  Application.RestoreTopMosts;
  end;
end;

Now, I want to polish it, therefore I want to use extended ascii table, but, I cannot choose best way to access them. Maybe I just don't know that magical function ...

Here is approach that uses OEMToANSI / OEMToChar and vice-verse functions: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20381022.html . I tried them with no luck, probobly because of:

Syntax from EDN / MS-Help

BOOL OemToChar( LPCSTR lpszSrc, LPTSTR lpszDst );

Parameters

lpszSrc [in] Pointer to a null-terminated string of characters from the OEM-defined character set.

lpszDst [out] Pointer to the buffer for the translated string.

If the OemToChar function is being used as an ANSI function, the string can be translated in place by setting the lpszDst parameter to the same address as the lpszSrc parameter. This cannot be done if OemToChar is being used as a wide-character function.

What I need is Char(Ord(170)); , Char(Ord(180)); and Char(Ord(190)) - http://www.asciitable.com/. Obviously, with default WInXP codepage I cannot use them. Now, I google a bit and found this solution:


FormShow Event Code:

procedure TMain.FormShow(Sender: TObject);
var
   i : longint;
begin
  re.Font.Name := 'Terminal';
  re.Font.Size := 9;
//seems that charset must be set last
  re.Font.Charset := OEM_CHARSET;
  re.DefAttributes.Name := 'Terminal';
  re.DefAttributes.Size := 9;
  re.DefAttributes.Charset := OEM_CHARSET;
  re.SelectAll;
  re.SelAttributes := re.DefAttributes;
//turn off richedit's auto font switching...
  i := SendMessage(re.Handle, EM_GETLANGOPTIONS, 0, 0);
  i := i and not IMF_AUTOFONT;
  SendMessage(re.Handle, EM_SETLANGOPTIONS, 0, i);
end;

Also these Fonts will display correctly >> Courier New Lucida Console MS Mincho


Now, the question is - what would be best way to say Windows Dialogs (API) to use OEM charset withing procedure that triggers ShowMessage(); ? Overriding ShowMessage(); ? Inheriting some richedit features? Various OwnerDraw() or WndProc() approaches ... too many options, but ... which ... I am confused. :(

Help me to choose and point to, of course, subjectively most effective and most code-less solution.


IF you're using a UNICODE version of Delphi, stop thinking about ASCII art in terms of ASCII chars. Every single one of those box-drawing chars has an UNICODE code point. Your Delphi's editor is perfectly capable of working with the codes directly, you can safely use them in your pascal source files.

Here's an example:

procedure TForm20.Button1Click(Sender: TObject);
begin
  ShowMessage(
     '┌─────────────────────────────────────────────┐'#13#10 +
     '│ You have UNICODE DELPHI, you may now write  │'#13#10 +
     '│ this without any problems. Just copy-paste  │'#13#10 +
     '│ the chars you need from the wikipedia page. │'#13#10 +
     '└─────────────────────────────────────────────┘'
  );
end;

How did I write that? VERY easy: Open up this page http://en.wikipedia.org/wiki/Box-drawing_characters and copy-paste the box drawing characters that you need. That's right, you copy paste the actual char (the right-angled lines, the horizontal lines, the vertical lines, whatever you need) - you don't need to care about the Unicode code points themselves.

Now of course, making those characters properly show up the display is a different matter: You need an fixed-point font to do that. AFAIK you can't get an fixed-font point with ShowMessage, you'll need to write your own version of ShowMessage...


If I understand you correctly then you want to use some of the box drawing characters, which are in the Unicode range 2500-257F. So you just need to show a message with Unicode text. If you are on Delphi 2009 or later it's very simple, you just insert the characters into your string:

procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  s := 'Test ' + #$2523;
  MessageBox(Handle, PChar(s), nil, MB_OK);
end;

Even if you were on an earlier version of Delphi you could still call the Unicode variant of for example the MessageBox() function, by using MessageBoxW() and passing it a WideString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜