Solved

Unicode String with CStatic using Multi-byte Charset in MFC

Posted on 2012-03-27
3
760 Views
Last Modified: 2012-03-29
How do I display a Unicode string in a CStatic Control in MFC when the project has to compile with the Multi-byte Char Set.

Alternatively, can changing the language of windows or some other method give me the correct character set?


Also, can some please tell me where the MFC section is listed in the Topic selector? I know it's listed as being in Programming->System Programming->Win OS Dev->MFC. But 'System Programming' does not show up in the Topic Selector.
0
Comment
Question by:microwhat
[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 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 200 total points
ID: 37773714
You won't be able to do that with a 'regular' CStatic, but if you derive from it and add a method that sets UNICODE text via the corresponding Windows API, that might work. E.g.

class CMyStatic : public CStatic
{
  public:

    BOOL SetUnicodeText(LPCWSTR pszText)
    {
        return SetWindowTextW(m_hWnd,pszText);
    }
}

Open in new window


Oh, and the MFC Zone is here: http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/

See also the link on top of the C++ page ;o)
0
 
LVL 34

Accepted Solution

by:
sarabande earned 300 total points
ID: 37781222
SetWindowTextW only could work if you were using a UNICODE font for the control.

if SetWindowTextW doesn't work you might try making a owner draw control - for example an owner-drawn listbox - and write the unicode text by calling DrawTextW in the OnDrawItem callback function. you could select a UNICODE font to the device context by calling SelectFont before writing Text.
the OnDrawItem was called for each line of the listbox, so you would need to do the line wrap yourself, for example by calling GetTextExtentPoint32W.

Sara
0
 

Author Closing Comment

by:microwhat
ID: 37782907
Jkr, im talking about when Asking a question. I wasn't able to find the MFC section in the Topic Selector.

Although I won't be testing the solution as we have decided to just convert the project to Unicode. The suggested methods look sound.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

615 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