Solved

DC question

Posted on 2001-06-03
12
221 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

12 Experts available now in Live!

Get 1:1 Help Now