如何在程序窗口显示国际音标æʌəɔεʃθʒðŋ

x363635334 2014-03-11 11:10:31
æʌəɔεʃθʒðŋ 这些在浏览器中很好使,以UTF-8存入记事本后打开也显示良好,
但用fread读入字符串后TextOutA和TextW只见汉字和韩文
...全文
222 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
x363635334 2014-03-12
  • 打赏
  • 举报
回复
不行,下载亲测各种字体配合字符集, 要么是中文要么是朝鲜文要么就是黑方框 这么难么
赵4老师 2014-03-12
  • 打赏
  • 举报
回复
TextOutW显示什么决定于之前SelectObject了什么Font 仅供参考:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = FALSE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
void ShowTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

    if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = TRUE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;

    system("color F0");
    system("cls");
    HideTheCursor();
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, 0             , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,10,L"你好",2);
    DeleteObject(hfont);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, JOHAB_CHARSET , 0, 0, 0, 0, "Arial Unicode MS");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,80,L"\xb7f0\xb7f0\xb2dd\xb2dd",4);
    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    ShowTheCursor();
    return 0;
}
赵4老师 2014-03-12
  • 打赏
  • 举报
回复
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;
    wchar_t ws[11];
    SIZE sz;

    ws[ 0]=0x00E6;
    ws[ 1]=0x028C;
    ws[ 2]=0x0259;
    ws[ 3]=0x0254;
    ws[ 4]=0x03B5;
    ws[ 5]=0x0283;
    ws[ 6]=0x03B8;
    ws[ 7]=0x0292;
    ws[ 8]=0x00F0;
    ws[ 9]=0x014B;
    ws[10]=0;

    system("color F0");
    system("cls");
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET  , 0, 0, 0, 0, "MS Mincho");
    SelectObject(hdc,hfont);
    GetTextExtentPoint32W(hdc,ws,10,&sz);
    Rectangle(hdc,10-2,80-1,10+sz.cx+2,80+sz.cy+1);
    TextOutW(hdc,10,80,ws,10);
    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    return 0;
}
赵4老师 2014-03-12
  • 打赏
  • 举报
回复
GetTextExtentPoint32 The GetTextExtentPoint32 function computes the width and height of the specified string of text. BOOL GetTextExtentPoint32( HDC hdc, // handle to device context LPCTSTR lpString, // pointer to text string int cbString, // number of characters in string LPSIZE lpSize // pointer to structure for string size ); Parameters hdc Handle to the device context. lpString Pointer to the string of text. The string does not need to be zero-terminated, since cbString specifies the length of the string. cbString Specifies the number of characters in the string. lpSize Pointer to a SIZE structure in which the dimensions of the string are to be returned. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks The GetTextExtentPoint32 function uses the currently selected font to compute the dimensions of the string. The width and height, in logical units, are computed without considering any clipping. Because some devices kern characters, the sum of the extents of the characters in a string may not be equal to the extent of the string. The calculated string width takes into account the intercharacter spacing set by the SetTextCharacterExtra function. Windows CE: The GetTextExtentPoint32 function is identical to the GetTextExtentPoint function. QuickInfo Windows NT: Requires version 3.5 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 2.0 or later. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows and Windows NT. See Also Fonts and Text Overview, Font and Text Functions, SetTextCharacterExtra, SIZE
x363635334 2014-03-12
  • 打赏
  • 举报
回复
谢谢大神,看来这10个编码才对; 新问题出现了,如何随时算出后半句该输出的位置 因为'i'和'w'非等宽啊 TEXTMETRIC tm; GetTextMetrics(hDC,&tm); 里面好像只有平均宽度,不现实啊 GetTextExtent是MFC的吧,不想用
赵4老师 2014-03-12
  • 打赏
  • 举报
回复
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
HWND WINAPI GetConsoleWindow();
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;
    wchar_t ws[11];

    ws[ 0]=0x00E6;
    ws[ 1]=0x028C;
    ws[ 2]=0x0259;
    ws[ 3]=0x0254;
    ws[ 4]=0x03B5;
    ws[ 5]=0x0283;
    ws[ 6]=0x03B8;
    ws[ 7]=0x0292;
    ws[ 8]=0x00F0;
    ws[ 9]=0x014B;
    ws[10]=0;

    system("color F0");
    system("cls");
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);
    hfont = CreateFont(48, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET  , 0, 0, 0, 0, "MS Mincho");
    SelectObject(hdc,hfont);
    TextOutW(hdc,10,80,ws,10);
    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    return 0;
}
x363635334 2014-03-11
  • 打赏
  • 举报
回复
æ 编码是C3A6 忙 编码是C3A6 所以TextOutA显示汉字了 TextOutW还是韩文呢

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧