Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unicode String with CStatic using Multi-byte Charset in MFC

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

688 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