Solved

Loading Bitmap into a CString

Posted on 2006-11-14
14
430 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
Technology Partners: 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

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Chrome color inconsistency 2 95
Eclipse IDE - Cannot copy/paste from console output 8 373
No module found pypyodbc, 3 53
Coding for the first time 9 95
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…
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…
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.
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.

738 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