Solved

Unicode String with CStatic using Multi-byte Charset in MFC

Posted on 2012-03-27
3
725 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 33

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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.

821 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