Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

gb2312 character set

Posted on 2001-06-05
8
Medium Priority
?
422 Views
Last Modified: 2013-12-03
I am trying to print some chinese characters within a static control.  The characters are in gb2312 format and are stored within a file.  The following code reads in the character but doesn't display the chinese character.

Anyone have any ideas ? I am using the win95 operating system.

     static CFont newfnt;
     CStatic* st=(CStatic*)GetDlgItem(IDC_MSG);
     
     CFont* fnt=st->GetFont();
     LOGFONT lf;

     fnt->GetLogFont(&lf);

     lf.lfCharSet=GB2312_CHARSET;
     strcpy(lf.lfFaceName ,"MS Song");

     newfnt.CreateFontIndirect(&lf);

     st->SetFont(&newfnt);

     FILE* fh;

     fh=fopen("c:\\temp\\test5.txt","rb");

     char buf[3];

     fread(buf,2,1,fh);
     
     buf[2]='\0';

     st->SetWindowText(buf);
0
Comment
Question by:ajh020797
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Expert Comment

by:BeyondWu
ID: 6158382
Have you installed the corresponding charset?
Which version OS are you using(English/Chinese)?
Have you tested st->SetWindowText("Chinese string") directly?
0
 

Author Comment

by:ajh020797
ID: 6160204
I am using an english version of windows 95, I have installed the microsoft simplified chinese language pack/ime.  I can view gb webpages ok, I can also enter chinese text using the ime within ie5 and word2000.  I have tried to enter chinese characters into visual studio directly but this doesn't seem to work.
0
 
LVL 1

Expert Comment

by:jizhang
ID: 6165063
I do not know if your MS Song font on Win95 is the same font as I used
on Windows NT.  The MS Song font I use  is unicode TTF GB2312
Chinese font.  You need to convert GB2312 codes to unicode first and
then reder with MS Song.

GB2312 are 2 BYTE 8bit codes, you may need to use unsigned char
or int array to store.

SetWindowsTextA may not work for 2 BYTE codes.

Ji.Zhang@nrc.ca
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 9

Expert Comment

by:BeyondWu
ID: 6166472
Try this:
lf.lfCharSet=GB2312_CHARSET;

lf.lfOutPrecision = OUT_TT_PRECIS;
lf.lfClipPrecision = CLIP_TT_ALWAYS;
lf.lfQuality = PROOF_QUALITY;
lf.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE | TMPF_TRUETYPE;

strcpy(lf.lfFaceName ,_T("MS Song"));
newfnt.CreateFontIndirect(&lf);

0
 

Author Comment

by:ajh020797
ID: 6169234
I tried the changes to the font but it doesn't seem to have worked.

I am led to believe that win95 is not a unicode based o/s so converting to unicode is not an option.  Win95 only supports MBCS.

MS Office, Outlook ecpress, and internet explorer all seem to be able to display gb2312 and big5 encoded text withuot any problem on my system.
0
 
LVL 1

Accepted Solution

by:
jizhang earned 1200 total points
ID: 6181635

Hi there,

SetFont() should work.

The problem is in SetWindowsText(), which only supports single byte codes.

You may set big font size like this:
       LOGFONT   lf;
       lf.lfHeight = 24;
       lf.lfWidth = 12;
  ..
     strcpy(lf.lfFaceName, _T("MS Song"));
       newfnt.CreateFontIndirect(&lf);
  ..
 GetDlgItem(IDC_MSG)->SetWindowText("abcde");
You will see the SetFont() works (lookat  the  font  face is MS Song).

>MS Office, Outlook ecpress, and internet explorer all seem to be able to display
>gb2312 and big5 encoded ..

  You can draw gb2312 with TextOutW() -- that I used to use on WinNT.
  Win95 has TextOutW function in English Env as well.

  for example,
  wchar_t stru[] = {0x4e2d, 0x6587};  // unicode {0x4e2d 0x6587} are gb2312 codes {0xd6d0 0xcec4}
  TextOutW( pDC)->m_hDC, 50, 50, stru, 2);
  that works in OnDraw() of CxxView.

 But it seems not work in dialog control:
 TextOutW( GetDlgItem(IDC_MSG)->GetDC()->m_hDC, 0,0, stru, 2);

 There is no SetWindowsTextW() in MFC English Env.
0
 

Author Comment

by:ajh020797
ID: 6187249
Thanks !! Finally I have a way to display these characters, all I need to do now if work out how to convert into unicode !
0
 
LVL 1

Expert Comment

by:jizhang
ID: 6187611

You need a table to convert from/to unicode/GB.

You may get my table gb2312.dat in uni03.zip at
http://www.zanmen.com/homepages/JiZhang/software/

gb2312.dat is ASCII file, which looks like:
....
f7e79e8b
f7e89e92
f7e993d6
f7ea9e9d
f7eb9e9f
f7ec9edb
f7ed9edc
...

read in  format   %4x%4x  to gb_tab(i), uni_tab(i)
translation:
   if you have a GB, then look up gb_tab() to get k, translate to the value in  uni_tab(k)

Besides, ASCII char set is a sub-set of GB, you may need to deal  with ascii
if you use mixed ascii+GB in your strings.


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question