Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Unicode String with CStatic using Multi-byte Charset in MFC

Posted on 2012-03-27
3
Medium Priority
?
782 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 800 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 35

Accepted Solution

by:
sarabande earned 1200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

972 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