Solved

Unicode String with CStatic using Multi-byte Charset in MFC

Posted on 2012-03-27
3
712 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
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 32

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

758 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now