?
Solved

DC question

Posted on 2001-06-03
12
Medium Priority
?
280 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

719 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