Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Repainting of dialog box takes time.

Repainting of dialog box takes time.

Scheduled Pinned Locked Moved C / C++ / MFC
question
24 Posts 6 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R R jeev K R

    Create a test application that using CBitmapButton class. Use the above code in that application and continuously use that application. Check the usage in Task Manager... It will help you to find the memory leak is from CBitmapButton ...

    L Offline
    L Offline
    Le rner
    wrote on last edited by
    #13

    if i use application without CBitmapButton code,its still behave like this.

    R 1 Reply Last reply
    0
    • L Le rner

      if i use application without CBitmapButton code,its still behave like this.

      R Offline
      R Offline
      R jeev K R
      wrote on last edited by
      #14

      That means, the problem is not from the CBitmapButton. Now check your dialog skinning code.Just like commenting the code for coloring the dialog or controls. This way you can find out the exact problem...

      L 1 Reply Last reply
      0
      • R R jeev K R

        That means, the problem is not from the CBitmapButton. Now check your dialog skinning code.Just like commenting the code for coloring the dialog or controls. This way you can find out the exact problem...

        L Offline
        L Offline
        Le rner
        wrote on last edited by
        #15

        i use this for color

        CBrush m_brush;
        m_brush.CreateSolidBrush(RGB(241,244,250));//in OnInitDialog

        HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
        {
        HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

        switch (nCtlColor)
        {
        	case CTLCOLOR\_EDIT:
        		pDC->SetTextColor(RGB(0,0,0));
        		pDC->SetBkColor(RGB(255,255,255));
        		return hbr;
        
        	case CTLCOLOR\_STATIC:			
        		LOGBRUSH logbrush;
        		m\_brush.GetLogBrush( &logbrush );
        		pDC->SetTextColor(RGB(0,0,0));
        		pDC->SetBkColor(logbrush.lbColor);
        		return m\_brush;
        		
        
        	case CTLCOLOR\_BTN:
        	case CTLCOLOR\_MSGBOX:
        	case CTLCOLOR\_DLG:
        		return m\_brush;
        	
        	default:
        		return m\_brush;
        }
        

        }

        BOOL CTest::OnEraseBkgnd(CDC *pDC)
        {
        CPen myPen,hpenOld;
        CRect rect;
        GetClientRect(&rect);
        for(int i=0;i<rect.bottom;)
        { myPen.CreatePen(PS_SOLID,1,RGB(241,244,250));
        pDC->SelectObject(&myPen);
        pDC->MoveTo(0,i);
        pDC->LineTo(rect.right,i);
        i++;
        myPen.DeleteObject();
        }
        return 1
        }

        R M 2 Replies Last reply
        0
        • L Le rner

          actully i dont know how can i detected memory leak in application, so how can i know memory leak occur from CBitmapButton or not.

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #16

          Could you post your BitmapButton.cpp here ? :)

          Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition

          L 1 Reply Last reply
          0
          • E Eugen Podsypalnikov

            Could you post your BitmapButton.cpp here ? :)

            Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition

            L Offline
            L Offline
            Le rner
            wrote on last edited by
            #17

            CBitmapButton is a Visual studio class.

            E 1 Reply Last reply
            0
            • L Le rner

              i use this for color

              CBrush m_brush;
              m_brush.CreateSolidBrush(RGB(241,244,250));//in OnInitDialog

              HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
              {
              HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

              switch (nCtlColor)
              {
              	case CTLCOLOR\_EDIT:
              		pDC->SetTextColor(RGB(0,0,0));
              		pDC->SetBkColor(RGB(255,255,255));
              		return hbr;
              
              	case CTLCOLOR\_STATIC:			
              		LOGBRUSH logbrush;
              		m\_brush.GetLogBrush( &logbrush );
              		pDC->SetTextColor(RGB(0,0,0));
              		pDC->SetBkColor(logbrush.lbColor);
              		return m\_brush;
              		
              
              	case CTLCOLOR\_BTN:
              	case CTLCOLOR\_MSGBOX:
              	case CTLCOLOR\_DLG:
              		return m\_brush;
              	
              	default:
              		return m\_brush;
              }
              

              }

              BOOL CTest::OnEraseBkgnd(CDC *pDC)
              {
              CPen myPen,hpenOld;
              CRect rect;
              GetClientRect(&rect);
              for(int i=0;i<rect.bottom;)
              { myPen.CreatePen(PS_SOLID,1,RGB(241,244,250));
              pDC->SelectObject(&myPen);
              pDC->MoveTo(0,i);
              pDC->LineTo(rect.right,i);
              i++;
              myPen.DeleteObject();
              }
              return 1
              }

              R Offline
              R Offline
              R jeev K R
              wrote on last edited by
              #18

              I cant find any problem in your code... Any way just comment your code in the OnEraseBkgnd and try to sort out the problem... If the problem is still there then we can avoid this one also from the problem list...

              1 Reply Last reply
              0
              • L Le rner

                CBitmapButton is a Visual studio class.

                E Offline
                E Offline
                Eugen Podsypalnikov
                wrote on last edited by
                #19

                OK :) Do you have the following in all used *.cpp ?

                #ifdef _DEBUG
                #define new DEBUG_NEW
                #endif

                What output comes now after the exiting ?

                Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition

                L 1 Reply Last reply
                0
                • E Eugen Podsypalnikov

                  OK :) Do you have the following in all used *.cpp ?

                  #ifdef _DEBUG
                  #define new DEBUG_NEW
                  #endif

                  What output comes now after the exiting ?

                  Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition

                  L Offline
                  L Offline
                  Le rner
                  wrote on last edited by
                  #20

                  yes i add this in all *.cpp

                  'Test.exe': Loaded 'C:\Windows\System32\ntdll.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\kernel32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\user32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\gdi32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\advapi32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\rpcrt4.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\msimg32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\comdlg32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\msvcrt.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\shlwapi.dll'
                  'Test.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18005_none_5cb72f96088b0de0\comctl32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\shell32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\winspool.drv'
                  'Test.exe': Loaded 'C:\Windows\System32\oledlg.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\ole32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\oleaut32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\winmm.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\oleacc.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\imm32.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\msctf.dll'
                  'Test.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.6002.18005_none_9e50b396ca17ae07\GdiPlus.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\lpk.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\usp10.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\uxtheme.dll'
                  'Test.exe': Loaded 'C:\Windows\System32\dwmapi.dll'
                  'Test.exe': Unloaded 'C:\Windows\System32\dwmapi.dll'
                  Detected memory leaks!
                  Dumping objects ->
                  {235} normal block at 0x00286728, 145 bytes long.
                  Data: < % d > C0 25 C9 01 64 00 00 00 80 00 00 00 01 00 00 00
                  {227} normal block at 0x002866D8, 20 bytes long.
                  Data: < % > C0 25 C9 01 03 00 00 00 03 00 00 00 01 00 00 00
                  {226} normal block at 0x00286640, 85 bytes long.
                  Data: < % D D > C0 25 C9 01 44 00 00 00 44 00 00 00 01 00 00 00
                  {225} normal block at 0x00286598, 103 bytes long.
                  Data: < % V V > C0 25 C9 01 56 00 00 00 56 00 00 00 01 00 00 00
                  Object dump complete.
                  The program '[3536] Test.exe: Native' has exited with code 0 (0x0).

                  E 1 Reply Last reply
                  0
                  • L Le rner

                    yes i add this in all *.cpp

                    'Test.exe': Loaded 'C:\Windows\System32\ntdll.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\kernel32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\user32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\gdi32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\advapi32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\rpcrt4.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\msimg32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\comdlg32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\msvcrt.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\shlwapi.dll'
                    'Test.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18005_none_5cb72f96088b0de0\comctl32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\shell32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\winspool.drv'
                    'Test.exe': Loaded 'C:\Windows\System32\oledlg.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\ole32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\oleaut32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\winmm.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\oleacc.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\imm32.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\msctf.dll'
                    'Test.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.6002.18005_none_9e50b396ca17ae07\GdiPlus.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\lpk.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\usp10.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\uxtheme.dll'
                    'Test.exe': Loaded 'C:\Windows\System32\dwmapi.dll'
                    'Test.exe': Unloaded 'C:\Windows\System32\dwmapi.dll'
                    Detected memory leaks!
                    Dumping objects ->
                    {235} normal block at 0x00286728, 145 bytes long.
                    Data: < % d > C0 25 C9 01 64 00 00 00 80 00 00 00 01 00 00 00
                    {227} normal block at 0x002866D8, 20 bytes long.
                    Data: < % > C0 25 C9 01 03 00 00 00 03 00 00 00 01 00 00 00
                    {226} normal block at 0x00286640, 85 bytes long.
                    Data: < % D D > C0 25 C9 01 44 00 00 00 44 00 00 00 01 00 00 00
                    {225} normal block at 0x00286598, 103 bytes long.
                    Data: < % V V > C0 25 C9 01 56 00 00 00 56 00 00 00 01 00 00 00
                    Object dump complete.
                    The program '[3536] Test.exe: Native' has exited with code 0 (0x0).

                    E Offline
                    E Offline
                    Eugen Podsypalnikov
                    wrote on last edited by
                    #21
                    1. Try to create, select and delete your background pen outside the drawing loop. 2) Could you post your *.cpp here ? :)

                    Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition

                    L 1 Reply Last reply
                    0
                    • E Eugen Podsypalnikov
                      1. Try to create, select and delete your background pen outside the drawing loop. 2) Could you post your *.cpp here ? :)

                      Check your definition of Irrationality[^] :) 1 - Avicenna 5 - Hubbard 3 - Own definition

                      L Offline
                      L Offline
                      Le rner
                      wrote on last edited by
                      #22

                      Eugen Podsypalnikov wrote:

                      Try to create, select and delete your background pen outside the drawing loop.

                      thanks its works

                      1 Reply Last reply
                      0
                      • L Le rner

                        i use this for color

                        CBrush m_brush;
                        m_brush.CreateSolidBrush(RGB(241,244,250));//in OnInitDialog

                        HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
                        {
                        HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

                        switch (nCtlColor)
                        {
                        	case CTLCOLOR\_EDIT:
                        		pDC->SetTextColor(RGB(0,0,0));
                        		pDC->SetBkColor(RGB(255,255,255));
                        		return hbr;
                        
                        	case CTLCOLOR\_STATIC:			
                        		LOGBRUSH logbrush;
                        		m\_brush.GetLogBrush( &logbrush );
                        		pDC->SetTextColor(RGB(0,0,0));
                        		pDC->SetBkColor(logbrush.lbColor);
                        		return m\_brush;
                        		
                        
                        	case CTLCOLOR\_BTN:
                        	case CTLCOLOR\_MSGBOX:
                        	case CTLCOLOR\_DLG:
                        		return m\_brush;
                        	
                        	default:
                        		return m\_brush;
                        }
                        

                        }

                        BOOL CTest::OnEraseBkgnd(CDC *pDC)
                        {
                        CPen myPen,hpenOld;
                        CRect rect;
                        GetClientRect(&rect);
                        for(int i=0;i<rect.bottom;)
                        { myPen.CreatePen(PS_SOLID,1,RGB(241,244,250));
                        pDC->SelectObject(&myPen);
                        pDC->MoveTo(0,i);
                        pDC->LineTo(rect.right,i);
                        i++;
                        myPen.DeleteObject();
                        }
                        return 1
                        }

                        M Offline
                        M Offline
                        Mohan Ramachandra
                        wrote on last edited by
                        #23

                        Le@rner wrote:

                        BOOL CTest::OnEraseBkgnd(CDC *pDC) { CPen myPen,hpenOld; CRect rect; GetClientRect(&rect); for(int i=0;iSelectObject(&myPen); pDC->MoveTo(0,i); pDC->LineTo(rect.right,i); i++; myPen.DeleteObject(); } return 1 }

                        Actually you are filling dialog with RGB(241,244,250) color. Change the OnEraseBkgnd

                        BOOL CTest::OnEraseBkgnd(CDC *pDC)
                        {
                        CRect rect;
                        GetClientRect(&rect);
                        pDC->FillSolidRect(rect,RGB(241,244,250));
                        return TRUE;
                        }

                        to avoid for loop, unnecessary creation and destroying of pen,and filling dialog background color using LineTo and MoveTo functions. This one can make you drawing bit faster.

                        modified on Tuesday, March 9, 2010 8:00 AM

                        L 1 Reply Last reply
                        0
                        • M Mohan Ramachandra

                          Le@rner wrote:

                          BOOL CTest::OnEraseBkgnd(CDC *pDC) { CPen myPen,hpenOld; CRect rect; GetClientRect(&rect); for(int i=0;iSelectObject(&myPen); pDC->MoveTo(0,i); pDC->LineTo(rect.right,i); i++; myPen.DeleteObject(); } return 1 }

                          Actually you are filling dialog with RGB(241,244,250) color. Change the OnEraseBkgnd

                          BOOL CTest::OnEraseBkgnd(CDC *pDC)
                          {
                          CRect rect;
                          GetClientRect(&rect);
                          pDC->FillSolidRect(rect,RGB(241,244,250));
                          return TRUE;
                          }

                          to avoid for loop, unnecessary creation and destroying of pen,and filling dialog background color using LineTo and MoveTo functions. This one can make you drawing bit faster.

                          modified on Tuesday, March 9, 2010 8:00 AM

                          L Offline
                          L Offline
                          Le rner
                          wrote on last edited by
                          #24

                          thanks it works

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups