如何在默认 Unicode Delphi XE 应用程序的消息对话框中使用 ASCII Art 符号
我已经搜索了主题报价,但未能找到正确的报价...
抱歉,如果我弄错了。如果是这样,请在此处指出正确的问题。
好吧,回到正题。情况:我使用 ShowMessage() 作为应用程序中某些事件的简单“状态简报”提供程序:
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;
现在,我想完善它,因此我想使用 扩展 ascii 表,但是,我无法选择访问它们的最佳方式。也许我只是不知道那个神奇的函数...
这是使用 OEMToANSI / OEMToChar 和反之函数的方法: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20381022.html 。我尝试过,但没有成功,可能是因为:
语法来自 EDN / MS-帮助
BOOL OemToChar( LPCSTR lpszSrc, LPTSTR lpszDst );
参数
lpszSrc [in] 指向a的指针 以空字符结尾的字符串 来自 OEM 定义的字符集。
lpszDst [out] 指向缓冲区的指针 对于翻译后的字符串。
如果 OemToChar 函数被用作 ANSI函数,字符串可以是 通过设置翻译到位 lpszDst 参数指向同一地址 作为 lpszSrc 参数。 这不能 如果 OemToChar 被用作 宽字符函数。
我需要的是 Char(Ord(170)); , Char(Ord(180));和 Char(Ord(190)) - http://www.asciitable.com/。显然,使用默认的 WInXP 代码页我无法使用它们。现在,我谷歌了一下,找到了这个解决方案:
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 those Fonts will displayright >> 快递新 露西达控制台 MS Mincho
现在的问题是 - 在触发 ShowMessage() 的过程中使用 OEM 字符集的 Windows 对话框 (API) 的最佳方式是什么? ?重写 ShowMessage(); ?继承一些richedit功能?各种 OwnerDraw() 或 WndProc() 方法...太多选项,但是...其中...我很困惑。 :(
当然,帮助我选择并指出主观上最有效且最无代码的解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 UNICODE 版本的 Delphi,请停止考虑 ASCII 字符方面的 ASCII 艺术。这些方框图字符中的每一个都有一个 UNICODE 代码点。您的 Delphi 编辑器完全能够直接使用这些代码,您可以在您的 pascal 源文件中安全地使用它们。
这是一个例子:
我是怎么写的?非常简单:打开此页面 http://en.wikipedia.org/wiki/Box- Drawing_characters 并复制粘贴您需要的框绘图字符。没错,您复制粘贴实际的字符(直角线、水平线、垂直线,无论您需要什么)——您不需要关心 Unicode 代码点本身。
当然,现在让这些字符正确显示在显示屏上是另一回事:您需要定点字体来做到这一点。 AFAIK 您无法使用
ShowMessage
获得固定字体点,您需要编写自己的ShowMessage
版本...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:
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 ofShowMessage
...如果我理解正确,那么您想要使用一些方框图字符,这些字符位于 Unicode 范围
2500-257F
。所以你只需要显示一条带有 Unicode 文本的消息。如果您使用的是 Delphi 2009 或更高版本,则非常简单,只需将字符插入到字符串中即可:即使您使用的是早期版本的 Delphi,您仍然可以调用 Unicode 变体,例如
MessageBox()
函数,通过使用 < code>MessageBoxW() 并向其传递一个WideString
。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:Even if you were on an earlier version of Delphi you could still call the Unicode variant of for example the
MessageBox()
function, by usingMessageBoxW()
and passing it aWideString
.