Click here to Skip to main content
15,888,286 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
econy17-Mar-14 4:09
econy17-Mar-14 4:09 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
Chris Losinger17-Mar-14 4:21
professionalChris Losinger17-Mar-14 4:21 
NewsRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
econy17-Mar-14 4:30
econy17-Mar-14 4:30 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
Chris Losinger17-Mar-14 5:02
professionalChris Losinger17-Mar-14 5:02 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
econy17-Mar-14 5:06
econy17-Mar-14 5:06 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
econy17-Mar-14 5:19
econy17-Mar-14 5:19 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
Chris Losinger17-Mar-14 5:34
professionalChris Losinger17-Mar-14 5:34 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
econy17-Mar-14 16:11
econy17-Mar-14 16:11 
Hi, I wrote snippet code to test.
first, I put a Static text in the dialog box, from the resource file:
IDD_ECHOBUTTONEVENT_DIALOG DIALOGEX 0, 0, 320, 200
...
BEGIN
...
     LTEXT           "Static",IDC_STATIC_TXT1,89,59,98,26
...
END


In Ontimer():
C++
CRect outRect;
CStatic* pTxt1Static;
pTxt1Static = (CStatic*)GetDlgItem(IDC_STATIC_TXT1);
pTxt1Static->GetWindowRect(&outRect);
ScreenToClient(&outRect);
InvalidateRect(&outRect);
UpdateData(FALSE);


In OnPaint():
C++
if (IsIconic()) {
...
}
else
{
	CRect outRect;
	CStatic* pTxt1Static;
	pTxt1Static = (CStatic*)GetDlgItem(IDC_STATIC_TXT1);
	pTxt1Static->GetWindowRect(&outRect);
	ScreenToClient(&outRect);

	CPaintDC dc(pTxt1Static); 
	//dc.SetTextColor(RGB(255,255,255));
	dc.SetTextColor(RGB(255,0,0));
	dc.SetBkMode(TRANSPARENT);
		
	dc.DrawText(_T("My Test"),&outRect,DT_CENTER|DT_VCENTER);
		
	CDialogEx::OnPaint();
}


But, the string "My Test" 's position is not at same position of Static text(IDC_STATIC_TXT1).
offset I guess is about 50 to 100 pixel.

And if I change CPaintDC dc(pTxt1Static) to CPaintDC dc(this), I got nothing, even I stretch the dialog
box to double, triple size.

If I don't use ScreenToClient(&outRect) in OnTimer(), and OnPaint(), I can see "My Test" string, but, need to stretch the dialog;
I set break point, pTxt1Static->GetWindowRect(&outRect); give :
tagRECT = {top=309 bottom=351 left=577 right=724}

run to ScreenToClient(&outRect); give:
tagRECT = {top=96 bottom=138 left=134 right=281}

Could you please help me to see what is the reason?
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
Chris Losinger18-Mar-14 1:41
professionalChris Losinger18-Mar-14 1:41 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
Chris Losinger18-Mar-14 1:44
professionalChris Losinger18-Mar-14 1:44 
GeneralRe: MFC CreateCompatibleDC(), Drawtext() no display Pin
econy18-Mar-14 2:26
econy18-Mar-14 2:26 
QuestionMFC set Control color question [Solved] Pin
econy16-Mar-14 11:13
econy16-Mar-14 11:13 
AnswerRe: MFC set Control color question Pin
CPallini16-Mar-14 22:29
mveCPallini16-Mar-14 22:29 
GeneralRe: MFC set Control color question Pin
econy17-Mar-14 1:58
econy17-Mar-14 1:58 
GeneralRe: MFC set Control color question Pin
CPallini17-Mar-14 2:52
mveCPallini17-Mar-14 2:52 
QuestionCompiling DLL - what is the sequence of compilation? SOLVED Pin
Vaclav_16-Mar-14 8:53
Vaclav_16-Mar-14 8:53 
AnswerRe: Compiling DLL - what is the sequence of compilation? Pin
Richard MacCutchan16-Mar-14 23:11
mveRichard MacCutchan16-Mar-14 23:11 
GeneralRe: Compiling DLL - what is the sequence of compilation? Pin
Vaclav_17-Mar-14 3:47
Vaclav_17-Mar-14 3:47 
GeneralRe: Compiling DLL - what is the sequence of compilation? Pin
Gisle Vanem17-Mar-14 4:00
Gisle Vanem17-Mar-14 4:00 
GeneralRe: Compiling DLL - what is the sequence of compilation? Pin
Richard MacCutchan17-Mar-14 4:16
mveRichard MacCutchan17-Mar-14 4:16 
GeneralRe: Compiling DLL - what is the sequence of compilation? Pin
Vaclav_17-Mar-14 7:42
Vaclav_17-Mar-14 7:42 
GeneralRe: Compiling DLL - what is the sequence of compilation? Pin
Richard MacCutchan17-Mar-14 7:54
mveRichard MacCutchan17-Mar-14 7:54 
QuestionDrawText() blinking problem Pin
econy15-Mar-14 1:36
econy15-Mar-14 1:36 
AnswerRe: DrawText() blinking problem Pin
PJ Arends15-Mar-14 6:07
professionalPJ Arends15-Mar-14 6:07 
GeneralRe: DrawText() blinking problem Pin
econy15-Mar-14 6:33
econy15-Mar-14 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.