Solved

DC question

Posted on 2001-06-03
12
255 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

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 (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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