Solved

DC question

Posted on 2001-06-03
12
240 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 66
Shell script to login to remote m/c and execute commands 10 78
scoreUp challenge 14 57
firstChar challenge 13 110
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

862 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now