Loading Bitmap into a CString

Hi ALL.
 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.
jhav1594Asked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
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("+");

or

CString Plus = L"+";
0
 
jkrCommented:
Why would you want to use a bitmap? Just use the corresponding letters, e.g.

CString text;

text = "+ " + text;
text = "- " + text;
0
 
itsmeandnobodyelseCommented:
>>>> 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;
public:
     // ....
};

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

Regards, Alex

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
jhav1594Author Commented:
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.
thanks
0
 
jkrCommented:
>>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()'

LOGFONT LogFont;

// 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;

cf.CreateFontIndirect(&cf);
0
 
jhav1594Author Commented:
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.

0
 
jkrCommented:
>>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("+");

//...

cf.CreateFontIndirect(&cf);

pStatic->SetFont(&cf);

pStatic->SetText(Plus);

0
 
jhav1594Author Commented:
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)
0
 
jkrCommented:
If you want to use different font sizes, you need to use different controls.
0
 
jhav1594Author Commented:
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.

Thanks'
0
 
jhav1594Author Commented:
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
Thanks
0
 
jkrCommented:
>>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.

BTW,

wchar_t Plus = L'+';

or

wchar_t* Plus = L"+";

might be a little bit more straight foward.

0
 
jhav1594Author Commented:
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);

0
 
jkrCommented:
Well, then

wchar_t Plus = (wchar_t)0x2500;

wchar_t Minus = (wchar_t)0x253c;

should work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.