Click here to Skip to main content
15,900,258 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Using pointers with an array Pin
David Crow24-Sep-04 6:14
David Crow24-Sep-04 6:14 
GeneralRe: Using pointers with an array Pin
Bob Stanneveld15-Sep-04 10:20
Bob Stanneveld15-Sep-04 10:20 
GeneralRe: Using pointers with an array Pin
Tom Wright15-Sep-04 12:25
Tom Wright15-Sep-04 12:25 
GeneralRe: Using pointers with an array Pin
Antony M Kancidrowski16-Sep-04 2:22
Antony M Kancidrowski16-Sep-04 2:22 
GeneralRe: Using pointers with an array Pin
Bob Stanneveld16-Sep-04 4:33
Bob Stanneveld16-Sep-04 4:33 
GeneralRe: Using pointers with an array Pin
SandeepN15-Sep-04 15:14
SandeepN15-Sep-04 15:14 
GeneralRe: Using pointers with an array Pin
Muhammad Azam15-Sep-04 23:41
Muhammad Azam15-Sep-04 23:41 
GeneralCreating a Bitmap On The Fly Pin
#realJSOP15-Sep-04 6:44
professional#realJSOP15-Sep-04 6:44 
I'm trying to create a bitmap on the fly. Once the bitmap is created, it will be passed to a toolbar class (CodeJock's CXToolBar) to apply to a button. The following code snippet is what I have so far. It compiles but I haven't run it yet because I have some questions:

1) How close am I?

2) What am I missing?

3) Do I have to keep the bitmap around after I've passed it into the toolbar?

CString sText = "Test";

//setup the device context
CDC pDC;
pDC.CreateCompatibleDC((CDC*)::GetDC(NULL));
pDC.SetBkMode(TRANSPARENT);
pDC.SetTextColor(RGB(0,0,0));

// establish the size of the bitmap based on the length of the text
CRect bmpRect(0,0,0,0);
CSize sz = pDC.GetTextExtent(sText, sText.GetLength());
bmpRect.SetRect(0, 0, sz.cx + 4, 15);

// calculate the x pos that will allow the text to be drawn in the
// horizontal center of the bitmap
int nXPos = (int)((bmpRect.Width() - sz.cx) * 0.5);

// create the bitmap
CBitmap bmp;
bmp.CreateCompatibleBitmap(&pDC, bmpRect.Width(), bmpRect.Height());

pDC.SelectObject(&bmp);

// create the font
CFont bmpFont;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
strcpy(lf.lfFaceName,"Arial");
lf.lfQuality   = NONANTIALIASED_QUALITY; // may not want to use this
lf.lfHeight    = 8;
lf.lfWeight    = 100;
bmpFont.CreateFontIndirect(&lf);
CFont* pOldFont = pDC.SelectObject(&bmpFont);

// create a brush that uses the system button face color
CBrush bmpBrush;
bmpBrush.CreateSysColorBrush(COLOR_BTNFACE);
CBrush* pOldBrush = (CBrush*)pDC.SelectObject(&bmpBrush);

// draw the bitmap
pDC.Rectangle(&bmpRect);
pDC.TextOut(nXPos, 2, sText);

// release the resources
pDC.SelectObject(pOldBrush);
pDC.SelectObject(pOldFont);



------- sig starts

"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt

"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
GeneralRe: Creating a Bitmap On The Fly Pin
Michael Dunn15-Sep-04 9:24
sitebuilderMichael Dunn15-Sep-04 9:24 
GeneralTransparent Check Box in Dialog Pin
LukeV15-Sep-04 6:36
LukeV15-Sep-04 6:36 
GeneralHyperLink without mfc Pin
Paolo Ponzano15-Sep-04 6:06
Paolo Ponzano15-Sep-04 6:06 
GeneralRe: HyperLink without mfc Pin
Michael Dunn15-Sep-04 9:26
sitebuilderMichael Dunn15-Sep-04 9:26 
GeneralRe: HyperLink without mfc Pin
Paolo Ponzano15-Sep-04 20:51
Paolo Ponzano15-Sep-04 20:51 
GeneralRe: HyperLink without mfc Pin
Michael Dunn16-Sep-04 9:41
sitebuilderMichael Dunn16-Sep-04 9:41 
QuestionGetAdaptersAddresses IPv6 Where the problem is ?? Pin
Alpha Siera15-Sep-04 5:30
Alpha Siera15-Sep-04 5:30 
AnswerRe: GetAdaptersAddresses IPv6 Where the problem is ?? Pin
David Crow15-Sep-04 5:43
David Crow15-Sep-04 5:43 
GeneralRe: GetAdaptersAddresses IPv6 Where the problem is ?? Pin
Alpha Siera15-Sep-04 18:55
Alpha Siera15-Sep-04 18:55 
GeneralRe: GetAdaptersAddresses IPv6 Where the problem is ?? Pin
David Crow16-Sep-04 2:56
David Crow16-Sep-04 2:56 
GeneralRe: LinkedList Template - LNK2019 Pin
David Crow15-Sep-04 5:17
David Crow15-Sep-04 5:17 
GeneralRe: LinkedList Template - LNK2019 Pin
Milby00715-Sep-04 5:42
Milby00715-Sep-04 5:42 
GeneralGetDlgItem() in CFormView Pin
BlackDice15-Sep-04 5:07
BlackDice15-Sep-04 5:07 
GeneralRe: GetDlgItem() in CFormView Pin
RChin15-Sep-04 5:25
RChin15-Sep-04 5:25 
GeneralMFC ActiveX download progress Pin
AssemblySoft15-Sep-04 5:06
AssemblySoft15-Sep-04 5:06 
GeneralA dll that contains an executable. Pin
AssemblySoft15-Sep-04 5:02
AssemblySoft15-Sep-04 5:02 
GeneralRe: A dll that contains an executable. Pin
David Crow15-Sep-04 5:15
David Crow15-Sep-04 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.