WM_PAINT problem

Hi I have this function for my dialog box (it's a project based on
dialog box):
void CDialogBarCopy::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	dc.SetBkColor(RGB(212,208,200));
	dc.SetTextColor(RGB(255,0,0));
	CFont *m_Font1 = new CFont;
	m_Font1->CreatePointFont(260, "Garamond");
	dc.SelectObject(m_Font1);
	if(LecteurEnd == 1)
	{
		dc.TextOut(19, 37, "test");
	}
}

If I delete the if condition "if(LecteurEnd == 1)", this code work
good, but I want to do it just when my variable "LecteurEnd" is set to
1. When I set the variable to 1 I do this after:
SendMessage(WM_PAINT);
In debug step by step mode, I see that the function is executed and
also the line "dc.TextOut(19, 37, "test");" when the variable is set
to 1 but nothing print to the screen. Is there a solution?
thanks for help
0
3/5/2004 9:54:46 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
620 Views

Similar Articles

[PageSpeed] 24

"maxime" <maxime_phan@hotmail.com> skrev i en meddelelse
news:4cc9a89e.0403050154.73e04e56@posting.google.com...
> Hi I have this function for my dialog box (it's a project based on
> dialog box):
> void CDialogBarCopy::OnPaint()
> {
> CPaintDC dc(this); // device context for painting
>
> dc.SetBkColor(RGB(212,208,200));
> dc.SetTextColor(RGB(255,0,0));
> CFont *m_Font1 = new CFont;
> m_Font1->CreatePointFont(260, "Garamond");
> dc.SelectObject(m_Font1);
> if(LecteurEnd == 1)
> {
> dc.TextOut(19, 37, "test");
> }
> }
>
> If I delete the if condition "if(LecteurEnd == 1)", this code work
> good, but I want to do it just when my variable "LecteurEnd" is set to
> 1. When I set the variable to 1 I do this after:
> SendMessage(WM_PAINT);
> In debug step by step mode, I see that the function is executed and
> also the line "dc.TextOut(19, 37, "test");" when the variable is set
> to 1 but nothing print to the screen. Is there a solution?
> thanks for help

You should not yourself send WM_PAINT messages, that is for the framework to
do. Call Invalidate() instead, to have your thing repainted.

-- 
Bjarne Nielsen


0
3/5/2004 12:16:13 PM
maxime wrote:

> Hi I have this function for my dialog box (it's a project based on
> dialog box):
> void CDialogBarCopy::OnPaint() 
> {
> 	CPaintDC dc(this); // device context for painting
> 
> 	dc.SetBkColor(RGB(212,208,200));
> 	dc.SetTextColor(RGB(255,0,0));
> 	CFont *m_Font1 = new CFont;
> 	m_Font1->CreatePointFont(260, "Garamond");
> 	dc.SelectObject(m_Font1);
> 	if(LecteurEnd == 1)
> 	{
> 		dc.TextOut(19, 37, "test");
> 	}
> }
> 
> If I delete the if condition "if(LecteurEnd == 1)", this code work
> good, but I want to do it just when my variable "LecteurEnd" is set to
> 1. When I set the variable to 1 I do this after:
> SendMessage(WM_PAINT);
> In debug step by step mode, I see that the function is executed and
> also the line "dc.TextOut(19, 37, "test");" when the variable is set
> to 1 but nothing print to the screen. Is there a solution?
> thanks for help

Do not (ever) send or post WM_PAINT.  Only the operating system can do 
that properly.  When you do SendMessage(WM_PAINT) there is no clipping 
region established so your painting is clipped.

Call Invalidate() to cause a new WM_PAINT.

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp8856 (490)
3/5/2004 12:27:44 PM
I see many problems here.

First, you are using 'new' to create a temporary font, and I don't see where it is being
deleted. This is a fundamental mistake. You have even misused m_ to describe a local
variable, which means you should not be using these notations at all. Better to not use
them than to misuse them.

CFont font;
font.CreatePointFont(260, "Garamond");

(Note that this naively assumes Garamond is present and doesn't check to see what happens
if the font is missing!)

int save = dc.SaveDC();
dc.SelectObject(&font);
if(...)
   ...
dc.RestoreDC(save);

No new, and consequently no need to delete. Normally, you would htink you have to save the
old font so you can restore it (you can't delete a font that is actively selected), but
SaveDC/RestoreDC avoids the need for a lot of nonsensical variables.

Then you are doing SendMessage(WM_PAINT), which is guaranteed to fail, so there is no
question that this code could ever work. When you want a redraw, simply call Invalidate()
on the client area of the window (and it is usually a Bad Idea to paint on a dialog. Not
always, but usually. And almost always a mistake for a beginner)..

Overall, the best rule: if you think you need to do a SendMessage of a built-in Windows
message in MFC, and (a) it is NOT WM_CLOSE and (b) it is not a notification from a
custom-designed control to its parent, (meaning WM_COMMAND or WM_NOTIFY) then you are
almost certainly wrong. It is ALWAYS wrong to send WM_PAINT, WM_DESTROY, WM_SETFOCUS,
WM_KILLFOCUS and WM_NCDESTROY. These require very specific conditions to have occurred for
the kernel to send them, and the kernel has very specific expectations about how they will
behave. This is only a first-approximation heuristic, but it is right so close to100% of
the time that until you really understand Windows you can assume it is always correct.

				joe

On 5 Mar 2004 01:54:46 -0800, maxime_phan@hotmail.com (maxime) wrote:

>Hi I have this function for my dialog box (it's a project based on
>dialog box):
>void CDialogBarCopy::OnPaint() 
>{
>	CPaintDC dc(this); // device context for painting
>
>	dc.SetBkColor(RGB(212,208,200));
>	dc.SetTextColor(RGB(255,0,0));
>	CFont *m_Font1 = new CFont;
>	m_Font1->CreatePointFont(260, "Garamond");
>	dc.SelectObject(m_Font1);
>	if(LecteurEnd == 1)
>	{
>		dc.TextOut(19, 37, "test");
>	}
>}
>
>If I delete the if condition "if(LecteurEnd == 1)", this code work
>good, but I want to do it just when my variable "LecteurEnd" is set to
>1. When I set the variable to 1 I do this after:
>SendMessage(WM_PAINT);
>In debug step by step mode, I see that the function is executed and
>also the line "dc.TextOut(19, 37, "test");" when the variable is set
>to 1 but nothing print to the screen. Is there a solution?
>thanks for help

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
3/5/2004 10:29:34 PM
Reply:

Similar Artilces:

Mailbox quota problem
I mistakenly set the mailbox quota for a user's Exchange 2000 mailbox so that it would prevent them from sending and receiving mail if the mailbox was greater than 100 kb. (I had intended it to be 100 mb) On realizing my mistake, I immediately reset the limit to 100 mb Unfortunately, the user in question has been unable to send and receive mail since They tried emptying their mailbox (so that it would be less than 100 kb), but this hasn't helped Any ideas? ...

Signature block format problem
I have created a signature block (in HTML message format) which works well when I compose an email. The problem occurs when replying to an email. When I reply to an email, the sig block is distorted. For instance extra lines are added and the blue huperlinks dissapear which requires me to edit the sig block everytime I reply. A couple of times when I replied the sig block was not distorted and I believe this had to do with the message format I received (HTML?). Anybody know a solution to this frustrating problem? Thanks! Create your signature block using Outlook Rich Text as the mess...

Fewer normal template problems with Word 2000 or 2002?
I have enjoyed some things about Word 2007, but I keep having problems with macros and templates. I am wondering if (a) macros increase the likelihood of corrupting the normal template in 2007, or (b) if the older versions of Word had as many template problems. I have used Word in 2000, with Office 2003, and now with Office 2007 and I don't ever recall having as many problems as I've had with 2007. What I'm thinking is that if it is simply a macro problem causing corruption, I would simply use 2007 without the macros (they're nice but I can live without them). On the...

Subtract date problem
Hi there, I'm using SSRS 2008 I have period end like 1/19/2010 field and I want to generate -5 days (seperate textbox) from it like 1/15 1/16 1/17 1/18 1/19 I try =MyFileld.value - 1 and I got an error How do I sbtract day fron date field? I did also Month(myfield.value)&"/"&Day(myfield.value)-1 it works but this is not woks allways. Thanks Hi Oded > I have period end like 1/19/2010 field and I want to generate -5 days > (seperate textbox) from it like > 1/15 1/16 1/17 1/18 1/19 Is not that possible to do on the server side ,mean...

Problem with Remote Desktop Control and Excel
I have some Excel files at my work which I like to save on my local disk. Normally this goes well with "Save as" and then choosing my Macintosh disk. But with some files I get an error: Disk is full. Those files have a logo inside the Worksheet. When I compress the picture I can save the file on my disk as well. But it is all about sizes of 103 kb (uncompressed) and 34 kb (compressed) in this gigabyte age! So what is wrong with the logo? -- To mail me: look closely to my address ...

CComboBox problem #2
I have a perfectly fine working application (Ap1). And a 2nd application (Ap2), that i want to use one of the dialogs from Ap1 one in. So I copied the relevant data from Ap1.rc to Ap2.rc. Plus the class files for the dialog from Ap1. (i'm not sure of the correct way to copy over a dialog). Anyway, things appeared to be working fine.. Until in OnInitDlg() ((CComboBox*)GetDlgItem(IDC_FIXANG1))->SetCurSel(0); There is an unhandled exception: _AFXWIN_INLINE int CComboBox::SetCurSel(int nSelect) { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0); ...

QS2000 Auto-Increment Customer account number problem
I have a customer that is running QS2000, version 3.01N, and has for years had the option set in the INI file to auto-increment the account number when adding a new customer. Suddenly, a few weeks ago, the auto-increment stopped working and all the system will do now is try to assign the last new number that it assigned (and yes, it is assigned to a valid customer). I can't find anywhere in the tables where a "last new number used" is stored. I would appreciate any ideas on how to fix this so that it will start assigning the correct numbers again. I have already tried to repair ...

Problem adding items to Price List
When trying to add items to a price list, a product is selected from the list and then when attempting to enter a value in the UNIT field, a message appears: "You need to select a Product first." As far as I can tell, this is an endless loop and the price list cannot contain any items. Thanks for any help. ya, the product and pricing is not very intuitive AT ALL..........took me a while to figure out what was the exact process (not a straight line!)..... Make sure the product you're adding is properly filled out. Does it have a default unit? Also check your unit group, mak...

Data Migration Framework problems
Hi, Sorry to post this again, but I've been looking all over trying to solve this problem but no luck. I'm trying to migrate some data (Accounts, Contacts and Activities) to MS CRM 3.0 using the Data Migration Framework. I succeeded in migrating the Accounts and Contacts and just over 600 out of about 7000 activities (the activities are simple tasks associated with the accounts). I noticed that all the non-migrated activities have status set to "Completed". Moreover, when I change the status of those records to "In Progress" (just to test) some of them succeed. Doe...

Problems with images in email signatures
Our marketing dept. has requested that all employees use a html signature file that contains the company logo with a link to the website. However, lots of users are reporting that the image link shows up broken every once in a while and upon inspection I have noticed that outlook is changing the image link by adding outbind://35/ to the src attribute. The image link is an absolute URL that references a public web server so accessibility shouldn't be a problem. Anyone know a solution to this problem? Thanks Jason ...

Outlook 2007 Search Problem
I work at the Help Desk for a University. A client has called complaining that recently Outlook 2007's search bar started returning "bad results." For instance, if she searches for Smith, she'll get e- mails that were sent to Smith, or have Smith in the body, but not e- mails that are FROM Smith. She used to get better results. I pointed her to the advanced search feature (available in a sub-menu, or available right there when Instant Search is installed), and showed her how to search specific fields. She's still not satisfied, though. It used to work, she claims, and sh...

OWA
I have two front end servers with a NLB host name as Mail Two FE servers are members of this NLB I have one cluster exchange server Problem :- If I reboot one of the cluster servers then OWA stop working if I try to access using NLB host name But if I try direcly connecting my OWA to FE1 or FE2 then OWA works If I restart NLB then the NLB host can open OWA Anyone know what could be wrong ? ...

Exponential trend-line equation problem
Hello, I have made a exponential graph of below data set: x y 0,90498 14294225 0,88252 14361091 0,91054 14392452 0,89546 14463203 0,90225 14535720 0,93918 14754041 0,93624 14812708 0,92533 14922256 0,94256 15000374 0,94681 15049871 0,93819 15051332 0,93495 15188711 0,95299 15425517 The equation I get is: y = 6E+06e0,950x Microsoft (http://office.microsoft.com/en-us/excel-help/add-change-or- remove-a-trendline-in-a-chart-HP010007461.aspx) states that the exponential equation is written on this form: y = c*e^b*x where c and b are constants and e is the base of the ...

problem with report
hi all, i'm using the "insertion model" of ADO.NET to see my reports. this model is the desconnected model of NET. i have to create a dataset object (visual dataset schema), base my report on it and after: a form with a crystalreportviewer, configure its property "reportSource" this method requires code which fills the dataset of our SQL's data and pass it to our report with the "setdatasource" method. i haven't any problem with one table but when i try it with several tables, it's imposible have you got any idea? thanks a lot for your inter...

Interesting problem
I am using Outlook Express 6. I closed it. I installed Outlook XP, loaded it up, went to File -> Import and Export. I picked "Import Internet Mail and Addresses" -> Next -> I see only "Outlook Express 4.x, 5" Nothing about version 6, but I picked it anyway -> Next -> and then finally Finish. It started to import all of my emails and address book to Outlook. When it was done, I can see that *most* e-mails are added correctly, but a few of them has the today date. Received: Sun 11/01/2004 11:23 When I open the e-mail, it's showing the correct date, w...

ISA 2006-CRM Reports problem
Hi, we successfully upgrade CRM 3.0 to CRM 4.0. The migration was without any problems, everything is working fine. We configured IFD and we published CRM 4.0 through ISA 2006, CRM Web Access and MS Outlook CRM client is working but we have problems with CRM Reports. I received the error: Error Code: 500 Internal Server Error. The request was rejected by the HTTP filter. (12217). I read on MS Support Site that I have to uncheck “Verify normalization” and “Block high bit characters” on HTTPS listener on the Web published Rule o ISA Server. I did that but now I’m receiving another err...

Problem with printing continuous feed checks
Does anyone have experience with printing continuous feed checks? When the last check prints it printer does not "line feed" sufficiently for me to tear off the last check. I have been using Parsons Moneycounts for 13 years and it works flawlessly. The only problem is that, since it was invented pre-internet, it cannot download data from financial institutions. I figured I would move on the Money (or Quicken) to make use of the latest technology, but if I can't tear off my last check I'm not sure I like the trade off. Moneycounts has enough "line feeds" at the ...

#Name problem
While retriving data from a plugin. Instead of calculated values #Name appears in all cells. Thanks for the help Add-in? If the function is not available, it returns the #NAME? error ...Make sure you have installed and load the add-in and also you have spelled the function correctly. -- Jacob (MVP - Excel) "Senthil Ganesh" wrote: > While retriving data from a plugin. Instead of calculated values #Name > appears in all cells. > Thanks for the help ...

Problem access variable in On Format
Hi, I'm using Access via Office XP Pro. I am trying to format the Zip Code on the detail line of my report. I have tried the following lines of code in both the On Format event and the On Print event: If len([PostalCode]) > 5 Then : : end if or if len(Me.PostalCode) > 5 Then : : end if In both events and either code, I receive the error message: Access can't find the field 'PostalCode' referred to in your expression. If I put "PostalCode" as the source of the report's control...

Problem with spreadsheet
First and foremost, I'd like to thank the admins of this forum fo providing a place to discuss excel. It's a great forum !! I do have a problem however. I am in the midst of creating an excel spreadsheet that will have 52 pages (1 page/week) Now there will be several columns and rows with weekly statistics and year to date statistics. What I need to do is learn how to creat 52 separate pages within this worksheet (let's say for argument sake name each page the date..i.e -Jan 04.....Jan 11...etc) and have eac page populate the previous week's year to date values when I add...

Unable to display the folder.
Unable to display the folder. Microsoft Office Outlook could not access the specified folder location. Could not open the item. Try again. ------------- I dragged many of my folders from Outlook 2002 into the "My Documents" folder. Then I deleted the folders from Outlook 2002. (did so, so as to conserve size of outlook.pst file) Now in "My Documents", when i double click the folders so as to view the contents (emails), I get this error: "Unable to display the folder. Microsoft Office Outlook could not access the specified folder location. Could not open t...

Excel XP Nested If Function Problem
Using Excel XP to use nested IF function, I keep getting the "+" sign when clicking on the IF button to add a nested IF formula. I found that this creates incorrect False answers. I then have to manually change the "+" to a comma. How can I get Excel to display a comma between the formulas by default. And what is the difference between "+" and a comma when placed between nested IF formulas? -- a( : [|]=( DaffyD� A Duck With Tools Is A Duck To Be Reckoned With I'm not sure what the IF button is, but I could use ctrl-click and xl2002 put in a comma, then t...

Version 2000 vs 2003 Trendline Problem
My coworker has Office 2003 Professional Edition (11.8169.8172) SP3 and has one chart in Excel with two line graphs based on the months of the past year. She has a trendline visible on one of the series. She has tried repeatedly and unsuccessfully to have a trendline for BOTH series to indicate the upwards or downward trends over time. She saved the file and I opened it from our shared server. I have Office 2000 Professional. I was able to see the trendline for the second series AND not just once, but for every single attempt she made. (smirking) WHY is she unable to view the trendl...

Problems with "CommitFile" with EWF from Win XP embedded
Hello NG Maybe it's a little off-topic, but has anyone an idea, why the "EwfMgrCommitFile" Function does not seem to work? If I change a file, call the EwfMgrCommitFile function, I get a "successful" return code and everything seems to be OK, but if I restart the system, the file is old. Is there anything I forgot? Regards Eunet Eunet, Post your question to microsoft.public.windowsxp.embedded. If you don't get that NG from your news server use the msnews.microsoft.com server. I also suggest that you provide more information such as which mode of EWF you...

problem loading regular MFC dll written in VC++7 but loading from
Hi, I developed a dll in VS.Net 2003 (VC++) and am trying to use it in a system that loads this dll using simple LoadLibrary() and then calling a couple of exported C sytle functions. This system, call it loader, is written in VC++ 6. The problem i'm seeing is that if I run on my machine that has VS.Net2003 installed on it everything works fine but when i move to another machine where theres no VS enviroment my dll is not loaded by the loader. I cant see the error message from within the loader as i dont have access to the loader but the call to LoadLibrary fails for some reason. ...