Windows stops drawing my subclassed controls
-
Basic design info: Dialgo app, main window always up and one secondary dialog window can be broght up one at a time from the main window. Each window has a timer that updates based on data read from another computer. Most of the controls are buttons based on CButtonST. I use the m_MouseOnButton in the control to turn it on or off, thus this enables me to set the color and text on the button (is there a better way to do this????) Problem: After this program runs for awhile it stops drawing the CButtonST subclassed controls and some of the drop downs start displaying a "6" instead of the down arrow. All the static and straight Visual Studios controls don't seem to have this problem (they are alway visable). I've had this problem for quite some time now and have tried just about everything to make it go away. I thought that I was on to something when I slowed the timers and the problem took much longer to happen. So I figured that I was telling windows to draw too much. To many WM_PAINT messages, is this possible? Do VS controls have priority over subclassed controls? Does each item that has changed create a WM_PAINT message? Is this bad? Is there a better way? Thinking along these lines I went into the code for every page and made it so that the controls would only be changed if the data received from the other computer had changed, thus it stopped drawing every cycle of the timer. This seem to help as now it really takes a long time for the problem to show up, but when it does it doesn't go away until I re-start the application. This is my first VS MFC application and I've done it all with the help of this forum. So there is a good chance that maybe I overlooked something or am doing something that I shouldn't. Any help would be much appriciated!!!! Thanks!
-
Basic design info: Dialgo app, main window always up and one secondary dialog window can be broght up one at a time from the main window. Each window has a timer that updates based on data read from another computer. Most of the controls are buttons based on CButtonST. I use the m_MouseOnButton in the control to turn it on or off, thus this enables me to set the color and text on the button (is there a better way to do this????) Problem: After this program runs for awhile it stops drawing the CButtonST subclassed controls and some of the drop downs start displaying a "6" instead of the down arrow. All the static and straight Visual Studios controls don't seem to have this problem (they are alway visable). I've had this problem for quite some time now and have tried just about everything to make it go away. I thought that I was on to something when I slowed the timers and the problem took much longer to happen. So I figured that I was telling windows to draw too much. To many WM_PAINT messages, is this possible? Do VS controls have priority over subclassed controls? Does each item that has changed create a WM_PAINT message? Is this bad? Is there a better way? Thinking along these lines I went into the code for every page and made it so that the controls would only be changed if the data received from the other computer had changed, thus it stopped drawing every cycle of the timer. This seem to help as now it really takes a long time for the problem to show up, but when it does it doesn't go away until I re-start the application. This is my first VS MFC application and I've done it all with the help of this forum. So there is a good chance that maybe I overlooked something or am doing something that I shouldn't. Any help would be much appriciated!!!! Thanks!
It sounds to me like you are using up GDI resources and not freeing them. Have you done a Debug build and checked for memory leaks when your app closes? Also try the www.GlowCode.com demo, which does a good job of reporting leaks. There are probably other apps around which help you track leaks as well. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
It sounds to me like you are using up GDI resources and not freeing them. Have you done a Debug build and checked for memory leaks when your app closes? Also try the www.GlowCode.com demo, which does a good job of reporting leaks. There are probably other apps around which help you track leaks as well. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
I have been using the debugger and checked for memory leaks...haven't found any. I've also been watching the memory usage and CPU Time in the Windows Task Manager and the memory doesn't seem to change much and it doesn't just keep building...it uses some then it frees it when it's done. Thanks I'm going to give the GlowCode a shot. If I find the problem I'll let you all know... Thanks!
-
I have been using the debugger and checked for memory leaks...haven't found any. I've also been watching the memory usage and CPU Time in the Windows Task Manager and the memory doesn't seem to change much and it doesn't just keep building...it uses some then it frees it when it's done. Thanks I'm going to give the GlowCode a shot. If I find the problem I'll let you all know... Thanks!
DC and HANDLE leaks etc. won't show up as memory leaks, so you need other tools for these types of problems. I hope Glowcode helps you find the problem. Neville Franks, Author of ED for Windows. www.getsoft.com Make money with our new Affilate program
-
Basic design info: Dialgo app, main window always up and one secondary dialog window can be broght up one at a time from the main window. Each window has a timer that updates based on data read from another computer. Most of the controls are buttons based on CButtonST. I use the m_MouseOnButton in the control to turn it on or off, thus this enables me to set the color and text on the button (is there a better way to do this????) Problem: After this program runs for awhile it stops drawing the CButtonST subclassed controls and some of the drop downs start displaying a "6" instead of the down arrow. All the static and straight Visual Studios controls don't seem to have this problem (they are alway visable). I've had this problem for quite some time now and have tried just about everything to make it go away. I thought that I was on to something when I slowed the timers and the problem took much longer to happen. So I figured that I was telling windows to draw too much. To many WM_PAINT messages, is this possible? Do VS controls have priority over subclassed controls? Does each item that has changed create a WM_PAINT message? Is this bad? Is there a better way? Thinking along these lines I went into the code for every page and made it so that the controls would only be changed if the data received from the other computer had changed, thus it stopped drawing every cycle of the timer. This seem to help as now it really takes a long time for the problem to show up, but when it does it doesn't go away until I re-start the application. This is my first VS MFC application and I've done it all with the help of this forum. So there is a good chance that maybe I overlooked something or am doing something that I shouldn't. Any help would be much appriciated!!!! Thanks!
Try opening Task Manager and selecting the Processes tab. Open the View menu and choose 'Select Columns...'. Check the 'GDI objects' item. This will display a column for the number of GDI objects your application is using.
Software Zen:
delete this;
-
Try opening Task Manager and selecting the Processes tab. Open the View menu and choose 'Select Columns...'. Check the 'GDI objects' item. This will display a column for the number of GDI objects your application is using.
Software Zen:
delete this;
I went and checked the GDI objects on the task manager and found that when I close the secondary window that I just opened the GDI object count doesn't decrease by the amount that was taken and will continue to grow as I open and close the page. When I close the page I'm doing: DestroyWindow(); PostNcDestroy(); My objects on the page are created using: CButtonST Satus_RX; CButtonST Satus_DUP; CButtonST Satus_16F; CButtonST Satus_16R; etc..... Then in InitDialog() I subclass them using: Satus_RX.SubclassDlgItem(IDC_ALQ122_RX,this); Satus_DUP.SubclassDlgItem(IDC_ALQ122_DUP,this); Satus_16F.SubclassDlgItem(IDC_ALQ122_16F,this); Satus_16R.SubclassDlgItem(IDC_ALQ122_16R,this); Thus I'm under the impression that these will be delete with the window, am I wrong? What should I do now? Also, I was looking at CButtonST and it appears that if m_MouseOnButton = 1 then it will re-draw the item every time. I set the button to 1 as this is how I display info from the other computer. example: if the other computer is ON then I set the mouse button to 1 so that its text displays "Running" and the Color is Green. If the other computer is off then the button is set to 0 and displays "OFFLINE" and the button is colored Red. Is this the wrong way to handle this? Thanks for all the help guys. I've tried to download the GlowCode but haven't been able to yet....
-
I went and checked the GDI objects on the task manager and found that when I close the secondary window that I just opened the GDI object count doesn't decrease by the amount that was taken and will continue to grow as I open and close the page. When I close the page I'm doing: DestroyWindow(); PostNcDestroy(); My objects on the page are created using: CButtonST Satus_RX; CButtonST Satus_DUP; CButtonST Satus_16F; CButtonST Satus_16R; etc..... Then in InitDialog() I subclass them using: Satus_RX.SubclassDlgItem(IDC_ALQ122_RX,this); Satus_DUP.SubclassDlgItem(IDC_ALQ122_DUP,this); Satus_16F.SubclassDlgItem(IDC_ALQ122_16F,this); Satus_16R.SubclassDlgItem(IDC_ALQ122_16R,this); Thus I'm under the impression that these will be delete with the window, am I wrong? What should I do now? Also, I was looking at CButtonST and it appears that if m_MouseOnButton = 1 then it will re-draw the item every time. I set the button to 1 as this is how I display info from the other computer. example: if the other computer is ON then I set the mouse button to 1 so that its text displays "Running" and the Color is Green. If the other computer is off then the button is set to 0 and displays "OFFLINE" and the button is colored Red. Is this the wrong way to handle this? Thanks for all the help guys. I've tried to download the GlowCode but haven't been able to yet....
You shouldn't be calling
PostNcDestroy()
yourself; it's called by the framework. Child windows are deleted by Windows when their parent is deleted. I haven't usedCButtonST
. You might post/email a question to the author of the article it came from.
Software Zen:
delete this;
-
I went and checked the GDI objects on the task manager and found that when I close the secondary window that I just opened the GDI object count doesn't decrease by the amount that was taken and will continue to grow as I open and close the page. When I close the page I'm doing: DestroyWindow(); PostNcDestroy(); My objects on the page are created using: CButtonST Satus_RX; CButtonST Satus_DUP; CButtonST Satus_16F; CButtonST Satus_16R; etc..... Then in InitDialog() I subclass them using: Satus_RX.SubclassDlgItem(IDC_ALQ122_RX,this); Satus_DUP.SubclassDlgItem(IDC_ALQ122_DUP,this); Satus_16F.SubclassDlgItem(IDC_ALQ122_16F,this); Satus_16R.SubclassDlgItem(IDC_ALQ122_16R,this); Thus I'm under the impression that these will be delete with the window, am I wrong? What should I do now? Also, I was looking at CButtonST and it appears that if m_MouseOnButton = 1 then it will re-draw the item every time. I set the button to 1 as this is how I display info from the other computer. example: if the other computer is ON then I set the mouse button to 1 so that its text displays "Running" and the Color is Green. If the other computer is off then the button is set to 0 and displays "OFFLINE" and the button is colored Red. Is this the wrong way to handle this? Thanks for all the help guys. I've tried to download the GlowCode but haven't been able to yet....
Please let me know if you have any questions about using GlowCode, or about downloading an evaluation from www.glowcode.com/eval.htm. Barbara Shafer VP, Product Management Electric Software, Inc. ~ developer of GlowCode www.glowcode.com