Loading Bitmap into a CString

Posted on 2006-11-14
Last Modified: 2013-12-03
 i have two bitmaps which are basically "+" and "-"

I have to add them infront of a text to indicate if it can be expanded or contracted.

eg if i have word like Inbox is should appear " + Inbox" where + being the actual bitmap.

Is there any way is can load a bitmap in a CString by any chance.
I know that is i overload the CString class for this purpose i might be able to do it bit i am not sure how to go about doing that.

Any ideas.
Question by:jhav1594
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
  • 7
  • 6
LVL 86

Expert Comment

ID: 17939637
Why would you want to use a bitmap? Just use the corresponding letters, e.g.

CString text;

text = "+ " + text;
text = "- " + text;
LVL 39

Expert Comment

ID: 17940064
>>>> Is there any way is can load a bitmap in a CString by any chance.

You could store the bits of a bitmap to a CString. But if you would print it or draw it you never would get the bitmap printed or drawn but only binary rubbish. Look at the graphical output functions: you have a DrawText, MoveLine, BitBlt, ... for any kind of data there is a separate output function. So, if you need to associate a bitmap to a CString, you should make an association, e. g. by a new class:

class TextItem
     HBITMAP  bitmap;
     CString    text;
     // ....

Or, you folllow the advise of jkr and use the font characters +- instead of the bitmap.

Regards, Alex


Author Comment

ID: 17940275
i actually thought abt the idea from jkr, it does seem to be the most simple one.
How would i increase the font of the + and - so as to make it appear much bigger.
Independent Software Vendors: 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!

LVL 86

Expert Comment

ID: 17940339
>>How would i increase the font of the + and - so as to make it appear much bigger

You cannot have two different fonts in a seingle string, unfortunately. That would requre two text fields or a separate one for '+' or '-'. Then you can set a different font using 'CreateFontIndirect()' and 'SetFont()'


// define the logical parameters for the font
LogFont.lfHeight = -11; // size 8
LogFont.lfWidth = 0;
LogFont.lfEscapement = 0;
LogFont.lfOrientation = 0;
LogFont.lfWeight = FW_NORMAL;
LogFont.lfItalic = 0;
LogFont.lfUnderline = 0;
LogFont.lfStrikeOut = 0;
LogFont.lfCharSet = 0;
LogFont.lfOutPrecision = OUT_STRING_PRECIS;
LogFont.lfClipPrecision = CLIP_STROKE_PRECIS;
LogFont.lfQuality = DEFAULT_QUALITY;
LogFont.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
_tcscpy(LogFont.lfFaceName, _T("Lucida Sans Unicode"));
// create the associated font

CFont cf;


Author Comment

ID: 17940440
I have declared to CStrings

CString Plus = _T("+");
CString Minus = _T("-");

i just need to increase the font of each of those strings.

CreateFontIndirect(): i will call this to set the font params but how do i link the Plus and the Minus to that font.

LVL 86

Expert Comment

ID: 17940469
>>CreateFontIndirect(): i will call this to set the font params but how do i link the Plus and the Minus to that font.

Not at all. You'll create a font that way and assign it to a edit or static control that should resemble that sign, e.g.

CFont cf;
CString Plus = _T("+");






Author Comment

ID: 17940600
i am using the dundas software ultimate grid and in there i am trying to set the cell text

UGCELL cell.settext()

i got the part where u set the font size in cf but how do i am confused about assigning it to a edit ot static control.

this is what i have

CString Temp = Plus + ElementP->Name;

which gives me "+ Currency"   (eg)
LVL 86

Expert Comment

ID: 17940620
If you want to use different font sizes, you need to use different controls.

Author Comment

ID: 17940810
in that case, i am now trying to use unicode characters

this is what i am trying

wchar_t Plus = 2500 ( which is the unicode value in hex)
wchar_t Minus = 253C

since i need to add this to a CString, how should i go about doing this.
i.e how do i convert wchar_t into CString.

LVL 86

Accepted Solution

jkr earned 500 total points
ID: 17940983
If you need to use UNICODE, just compile your app with 'UNICODE' defined in your project options, then CString will support UNICODE and you can use it just like

CString Plus = _T("+");


CString Plus = L"+";

Author Comment

ID: 17941117
i cannot change the project options due to other reasons

Is this right

wchar_t * Plus = (wchar_t*)malloc(2);
*Plus = 0x2500;
wchar_t * Minus = (wchar_t*)malloc(2);
*Minus = 0x253C;

Let me know
LVL 86

Expert Comment

ID: 17941153
>>i cannot change the project options due to other reasons

Then just add

#define UNICODE

to the top of your "StdAfx.h", the effect will be the same.


wchar_t Plus = L'+';


wchar_t* Plus = L"+";

might be a little bit more straight foward.


Author Comment

ID: 17941252
but i dont want to use '+' . i want to use the symbol defined by the UNICODE (hex) 2500 and 253C as mentioned in MSWORD -> Insert -> Symbol

wchar_t * Minus = (wchar_t*)malloc(2);
*Minus = 0x253C;

the *Minus is just taking in '3C' and hence the result '<'
what do i do so that Minus takes in 253C

i am doing the following to convert it into CString

CString Temp.format("%c", *Minus);

LVL 86

Expert Comment

ID: 17941375
Well, then

wchar_t Plus = (wchar_t)0x2500;

wchar_t Minus = (wchar_t)0x253c;

should work.

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

707 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