Solved

Loading Bitmap into a CString

Posted on 2006-11-14
14
416 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now