Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Chinese characters

Chinese characters

Scheduled Pinned Locked Moved C / C++ / MFC
c++designtoolstutorialquestion
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mortie42
    wrote on last edited by
    #1

    I'm writing a user interface with Visual C++ 6 on a computer with English as the working environment. I have Chinese script that I can see in Excel and RTF files. It uses a SimSun font. I want the same script to appear on a button using SetTitle. I compile successfully with UNICODE defined. However, I can't figure out how to get the characters into the code. Any ideas? ie wnd.SetTitle(_T("????")); Mortie

    W M 2 Replies Last reply
    0
    • M Mortie42

      I'm writing a user interface with Visual C++ 6 on a computer with English as the working environment. I have Chinese script that I can see in Excel and RTF files. It uses a SimSun font. I want the same script to appear on a button using SetTitle. I compile successfully with UNICODE defined. However, I can't figure out how to get the characters into the code. Any ideas? ie wnd.SetTitle(_T("????")); Mortie

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2

      I often have problems writing Chinese into my code using VC6, though for me each character takes up the space of 2. ie. the caret is able to position itself in the center of a character. It's annoying sometimes, especially when trying to edit the end of a line which has Chinese at the beginning. A work around I often use is to write the function in notepad or something similar, then copy the whole thing over to MSVC. I have just downloaded the 2005 edition, I hope this has been fixed.

      1 Reply Last reply
      0
      • M Mortie42

        I'm writing a user interface with Visual C++ 6 on a computer with English as the working environment. I have Chinese script that I can see in Excel and RTF files. It uses a SimSun font. I want the same script to appear on a button using SetTitle. I compile successfully with UNICODE defined. However, I can't figure out how to get the characters into the code. Any ideas? ie wnd.SetTitle(_T("????")); Mortie

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        You need to use escapes to put non-ASCII characters in source code. Figure out the Unicode code points of the characters, and do something like this: wnd.SetTitle(L"\x341f\x98bc")); (those are made-up values) --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        M 1 Reply Last reply
        0
        • M Michael Dunn

          You need to use escapes to put non-ASCII characters in source code. Figure out the Unicode code points of the characters, and do something like this: wnd.SetTitle(L"\x341f\x98bc")); (those are made-up values) --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          M Offline
          M Offline
          Mortie42
          wrote on last edited by
          #4

          Cool. Any hints on figuring out the code points. I could put the characters into a unicode configured text file, read the strings with a C++ program and print out the hex values. Is there an easier method or a utility available. Mortie42

          M 1 Reply Last reply
          0
          • M Mortie42

            Cool. Any hints on figuring out the code points. I could put the characters into a unicode configured text file, read the strings with a C++ program and print out the hex values. Is there an easier method or a utility available. Mortie42

            M Offline
            M Offline
            Michael Dunn
            wrote on last edited by
            #5

            Put them in a text file - use Notepad and save as Unicode (big endian) for ease of reading. Then open the file in VC in binary mode. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

            M 1 Reply Last reply
            0
            • M Michael Dunn

              Put them in a text file - use Notepad and save as Unicode (big endian) for ease of reading. Then open the file in VC in binary mode. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

              M Offline
              M Offline
              Mortie42
              wrote on last edited by
              #6

              I must be close but... Using your method (thanks), my hex values are \x62a4\x6797. But I get empty boxes. When I use \x2021, I get the double dagger symbol. My code is basically, ... CFont font1; font1.CreateFont(13,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,0,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|EF_DONTCARE,_T("SimSun") ); Button.SetFont(&font1, TRUE); Button.SetTitle(_L"\x62a4\x6797"); ... What am I missing? Mortie42

              M 1 Reply Last reply
              0
              • M Mortie42

                I must be close but... Using your method (thanks), my hex values are \x62a4\x6797. But I get empty boxes. When I use \x2021, I get the double dagger symbol. My code is basically, ... CFont font1; font1.CreateFont(13,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,0,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|EF_DONTCARE,_T("SimSun") ); Button.SetFont(&font1, TRUE); Button.SetTitle(_L"\x62a4\x6797"); ... What am I missing? Mortie42

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                You need to set the charset parameter correctly. For Chinese, there two - CHINESEBIG5_CHARSET and GB2312_CHARSET. One is simplified, one is traditional, I can never remember which is which. :-> --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                M 1 Reply Last reply
                0
                • M Michael Dunn

                  You need to set the charset parameter correctly. For Chinese, there two - CHINESEBIG5_CHARSET and GB2312_CHARSET. One is simplified, one is traditional, I can never remember which is which. :-> --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                  M Offline
                  M Offline
                  Mortie42
                  wrote on last edited by
                  #8

                  Hmmm. I tried both. I compile w/o warnings But I still get two squares and a dagger with (L"\x62a4\x6797\x2021"); . Any ideas? :confused: Mortie42 -- modified at 17:10 Friday 24th March, 2006

                  M 1 Reply Last reply
                  0
                  • M Mortie42

                    Hmmm. I tried both. I compile w/o warnings But I still get two squares and a dagger with (L"\x62a4\x6797\x2021"); . Any ideas? :confused: Mortie42 -- modified at 17:10 Friday 24th March, 2006

                    M Offline
                    M Offline
                    Michael Dunn
                    wrote on last edited by
                    #9

                    This works for me in a WTL dialog-based app

                    LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
                    {
                    CButton btn = GetDlgItem(IDOK);

                    m\_font.CreateFont ( -13, 0, 0, 0, FW\_NORMAL, false, false, false, CHINESEBIG5\_CHARSET, OUT\_DEFAULT\_PRECIS,
                                        CLIP\_DEFAULT\_PRECIS, DEFAULT\_QUALITY, DEFAULT\_PITCH|FF\_DONTCARE, \_T("SimSun") );
                    
                    btn.SetFont ( m\_font );
                    btn.SetWindowText ( L"\\x62a4\\x6797" );
                    

                    //...
                    }

                    The only change I made was the font size and char set params to CreateFont() --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                    M 1 Reply Last reply
                    0
                    • M Michael Dunn

                      This works for me in a WTL dialog-based app

                      LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
                      {
                      CButton btn = GetDlgItem(IDOK);

                      m\_font.CreateFont ( -13, 0, 0, 0, FW\_NORMAL, false, false, false, CHINESEBIG5\_CHARSET, OUT\_DEFAULT\_PRECIS,
                                          CLIP\_DEFAULT\_PRECIS, DEFAULT\_QUALITY, DEFAULT\_PITCH|FF\_DONTCARE, \_T("SimSun") );
                      
                      btn.SetFont ( m\_font );
                      btn.SetWindowText ( L"\\x62a4\\x6797" );
                      

                      //...
                      }

                      The only change I made was the font size and char set params to CreateFont() --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                      M Offline
                      M Offline
                      Mortie42
                      wrote on last edited by
                      #10

                      I think I have issues else where. I'm using an old copy of VisualC++6.0 on a new WinXP o/s. I copied the DLL's for Chinese; APPWZCHS.DLL AND APPWZCHT.DLL from disc to machine. I tried making a simple MFC dialog application using these. The dialog box in VC showed one set of gibberish while on compilation and execution, the resulting dialog box had rows of ?'s. I'm taking a break for the weekend but before I go, could you tell me which version of VC and o/s you used? Thx for all the help. PS WTL is ...? Mortie42

                      M 1 Reply Last reply
                      0
                      • M Mortie42

                        I think I have issues else where. I'm using an old copy of VisualC++6.0 on a new WinXP o/s. I copied the DLL's for Chinese; APPWZCHS.DLL AND APPWZCHT.DLL from disc to machine. I tried making a simple MFC dialog application using these. The dialog box in VC showed one set of gibberish while on compilation and execution, the resulting dialog box had rows of ?'s. I'm taking a break for the weekend but before I go, could you tell me which version of VC and o/s you used? Thx for all the help. PS WTL is ...? Mortie42

                        M Offline
                        M Offline
                        Michael Dunn
                        wrote on last edited by
                        #11

                        I'm using VC 6 on XP SP2. If you're on a fresh XP you probably don't have the east Asian language support installed. Control Panel-Regional and Language options-languages-Install files for east Asian languages. WTL: clickety[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                        W M 2 Replies Last reply
                        0
                        • M Michael Dunn

                          I'm using VC 6 on XP SP2. If you're on a fresh XP you probably don't have the east Asian language support installed. Control Panel-Regional and Language options-languages-Install files for east Asian languages. WTL: clickety[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                          W Offline
                          W Offline
                          Waldermort
                          wrote on last edited by
                          #12

                          Writing strings of Chinese in Hex format, urghh!!! It would be ok for very short items, but damn near impossible to read. I am using VC6, with windowsXP SP1, and the MS MultiLingual User Interface (English and Chinese version installed as one). I have no real problems writing chinese text into my code (without using ascii), or displaying it in the application. One point though, I never build Unicode, I always select MBCS. Try making a simple hello world app with a chinese string and play around with the settings until you get it right. If you have further problems I could give you a simple project to test.

                          M 1 Reply Last reply
                          0
                          • M Michael Dunn

                            I'm using VC 6 on XP SP2. If you're on a fresh XP you probably don't have the east Asian language support installed. Control Panel-Regional and Language options-languages-Install files for east Asian languages. WTL: clickety[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                            M Offline
                            M Offline
                            Mortie42
                            wrote on last edited by
                            #13

                            Thx :-D I had assumed that because I could see the Chinese glyphs in Excel, word and Notepad that all was well. Bad me. With the East Asian Languages set the glyphs appear. :) Mortie42

                            S 1 Reply Last reply
                            0
                            • W Waldermort

                              Writing strings of Chinese in Hex format, urghh!!! It would be ok for very short items, but damn near impossible to read. I am using VC6, with windowsXP SP1, and the MS MultiLingual User Interface (English and Chinese version installed as one). I have no real problems writing chinese text into my code (without using ascii), or displaying it in the application. One point though, I never build Unicode, I always select MBCS. Try making a simple hello world app with a chinese string and play around with the settings until you get it right. If you have further problems I could give you a simple project to test.

                              M Offline
                              M Offline
                              Mortie42
                              wrote on last edited by
                              #14

                              Hi waldermort please send me the project, I value any tips I can get. mmortimer47 at hot mail dot com Mortie42

                              1 Reply Last reply
                              0
                              • M Mortie42

                                Thx :-D I had assumed that because I could see the Chinese glyphs in Excel, word and Notepad that all was well. Bad me. With the East Asian Languages set the glyphs appear. :) Mortie42

                                S Offline
                                S Offline
                                Sheng Jiang
                                wrote on last edited by
                                #15

                                Use the String Table resource, don't put strings in code. My blogs: http://blog.joycode.com/jiangsheng http://blog.csdn.net/jiangsheng http://bloglines.com/public/jiangsheng Command what is yours Conquer what is not ---Kane

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups