Solved

DC question

Posted on 2001-06-03
12
262 Views
Last Modified: 2013-11-20
i'm using ExtTextOut() to draw a rectangle and put string in it.
               pDC->SetBkColor(RGB(255,255,128));
               pDC->ExtTextOut(coordX ,coordY, ETO_CLIPPED, NULL, szText, NULL);

how do i change the font and the color to be like the tooltip ?
0
Comment
Question by:sedgwick
[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
  • 8
  • 4
12 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6150258
This should do the trick...


NONCLIENTMETRICS ncm;
CFont font,oldfont;

ncm.cnSize=sizeof(ncm);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(ncm),&ncm,0);

font.CreateFontIndirect(&ncm.lfStatusFont)

pDC->SetBkColor(GetSysColor(INFOBK));
pDC->SetTextColor(GetSysColor(INFOTEXT));
oldfont=pDC->SelectObject(font);
pDC->ExtTextOut(....)
pDC->SelectObject(oldfont);

0
 
LVL 42

Author Comment

by:sedgwick
ID: 6150287
robpitt:
my compiler doesn't familiar with INFOBK and INFOTEXT...?
0
 
LVL 42

Author Comment

by:sedgwick
ID: 6150288
ok got it, should be COLOR_INFOBK and COLOR_TEXT
0
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!

 
LVL 42

Author Comment

by:sedgwick
ID: 6150291
i get an error:
error C2582: 'CFont' : 'operator =' function is unavailable

in this line:
oldfont=pDC->SelectObject(font);

???

0
 
LVL 5

Expert Comment

by:robpitt
ID: 6150300
Try adding a "&" i.e.
   SelectObject(&font)



0
 
LVL 42

Author Comment

by:sedgwick
ID: 6150307
ok its working but one more question, how to add a black border?
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6150318
FrameRect
0
 
LVL 42

Author Comment

by:sedgwick
ID: 6150371
right but in FrameRect u need to give a rectangle but as u can see below i'm using ExtTextOut() which calculating the rect according to the length of the given string, the recrangle offset is the firsyt 2 arguments (coordX and coordY), so how can i retrieve this rectangle for the FrameRect?
0
 
LVL 42

Author Comment

by:sedgwick
ID: 6150393
u answer me that and u get 100 pts
0
 
LVL 42

Author Comment

by:sedgwick
ID: 6150413
u answer me that and u get 100 pts
0
 
LVL 5

Accepted Solution

by:
robpitt earned 100 total points
ID: 6150514
Okay heres some revised code in which I've used DrawText as this allows you to calculate the size of the text rectangle first...

//INITIALISATION
NONCLIENTMETRICS ncm;                    
ncm.cbSize=sizeof(ncm);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(ncm),&ncm,0);
font.CreateFontIndirect(&ncm.lfStatusFont);





 
   
//RENDERING
CFont *pOldFont;
CRect rect;

//Select font & colours
pDC->SetBkColor(GetSysColor(COLOR_INFOBK));
pDC->SetTextColor(GetSysColor(COLOR_INFOTEXT));
pOldFont=pDC->SelectObject(&font);

//Calculate size of text (doesn't draw the text)
rect.SetRect(x,y,0,0);
pDC->DrawText(szText,&rect,DT_CALCRECT|DT_NOPREFIX);    

//Draw framed rectangle of size 3 pixels larger than text rect
rect.InflateRect(3,3,3,3);
pDC->FillRect(&rect,CBrush::FromHandle(GetSysColorBrush(COLOR_INFOBK)));    
pDC->FrameRect(&rect,CBrush::FromHandle(GetSysColorBrush(COLOR_INFOTEXT)));
rect.DeflateRect(3,3,3,3);

//Finally draw the text rectangle    
pDC->DrawText(szText,&rect,DT_NOPREFIX);
pDC->SelectObject(pOldFont);
0
 
LVL 42

Author Comment

by:sedgwick
ID: 6151632
robpitt: thank u mate
0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

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