?
Solved

Loading Bitmap into a CString

Posted on 2006-11-14
14
Medium Priority
?
437 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:jhav1594
[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
  • 7
  • 6
14 Comments
 
LVL 86

Expert Comment

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

CString text;

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

Expert Comment

by:itsmeandnobodyelse
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;
public:
     // ....
};

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

Regards, Alex

0
 

Author Comment

by:jhav1594
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.
thanks
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:jkr
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()'

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
 

Author Comment

by:jhav1594
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.

0
 
LVL 86

Expert Comment

by:jkr
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("+");

//...

cf.CreateFontIndirect(&cf);

pStatic->SetFont(&cf);

pStatic->SetText(Plus);

0
 

Author Comment

by:jhav1594
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)
0
 
LVL 86

Expert Comment

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

Author Comment

by:jhav1594
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.

Thanks'
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 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("+");

or

CString Plus = L"+";
0
 

Author Comment

by:jhav1594
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
Thanks
0
 
LVL 86

Expert Comment

by:jkr
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.

BTW,

wchar_t Plus = L'+';

or

wchar_t* Plus = L"+";

might be a little bit more straight foward.

0
 

Author Comment

by:jhav1594
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);

0
 
LVL 86

Expert Comment

by:jkr
ID: 17941375
Well, then

wchar_t Plus = (wchar_t)0x2500;

wchar_t Minus = (wchar_t)0x253c;

should work.
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

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 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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses

649 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