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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI+ cause the application freeze

GDI+ cause the application freeze

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformshelp
8 Posts 2 Posters 0 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.
  • T Offline
    T Offline
    Tal Rashas Guardianship
    wrote on last edited by
    #1

    I have got a trouble of GDI+, my code is like this: CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&rect); CDC dcMem; dcMem.CreateCompatibleDC(&dc); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()); dcMem.SelectObject(&bitmap); Graphics graphics(dcMem.m_hDC); SolidBrush brushBKGnd(Color(0,0,0)); //freeze at here graphics.FillRectangle(&brushBKGnd, Rect(rect.left, rect.top, rect.Width(), rect.Height())); The code will freeze at the last line, I don't know why, please help me.

    S 1 Reply Last reply
    0
    • T Tal Rashas Guardianship

      I have got a trouble of GDI+, my code is like this: CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&rect); CDC dcMem; dcMem.CreateCompatibleDC(&dc); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()); dcMem.SelectObject(&bitmap); Graphics graphics(dcMem.m_hDC); SolidBrush brushBKGnd(Color(0,0,0)); //freeze at here graphics.FillRectangle(&brushBKGnd, Rect(rect.left, rect.top, rect.Width(), rect.Height())); The code will freeze at the last line, I don't know why, please help me.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Well - your code is OK - I've just tried it and it works even if you don't startup GDI+ properly. You do have to remember to blit the bitmap to the window DC to see anything, mind. So - your code's (superficially) OK - maybe there's something about your setup that's not quite right? What are the co-ordinates of your rectangle? What happens if you paint to dc rather than dcMem?

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      T 1 Reply Last reply
      0
      • S Stuart Dootson

        Well - your code is OK - I've just tried it and it works even if you don't startup GDI+ properly. You do have to remember to blit the bitmap to the window DC to see anything, mind. So - your code's (superficially) OK - maybe there's something about your setup that's not quite right? What are the co-ordinates of your rectangle? What happens if you paint to dc rather than dcMem?

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        T Offline
        T Offline
        Tal Rashas Guardianship
        wrote on last edited by
        #3

        I have tried to test the parameters which were sent to FillRectangle function, I found that when they are big numbers(i.e, 200,000), the calling to FillRectangle will freeze. But from my code, the value of CRect is got from API GetClientRect, does this function have some possibility to fail?

        S 1 Reply Last reply
        0
        • T Tal Rashas Guardianship

          I have tried to test the parameters which were sent to FillRectangle function, I found that when they are big numbers(i.e, 200,000), the calling to FillRectangle will freeze. But from my code, the value of CRect is got from API GetClientRect, does this function have some possibility to fail?

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Can I suggest you set a breakpoint on FillRectangle and see what the client rect value is?

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          T 1 Reply Last reply
          0
          • S Stuart Dootson

            Can I suggest you set a breakpoint on FillRectangle and see what the client rect value is?

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            T Offline
            T Offline
            Tal Rashas Guardianship
            wrote on last edited by
            #5

            No,I didn't set breakpoint, I just create a CRect object with large paramaters: CRect rect(0, 0, 200000, 200000); //Disable this line //GetClientRect(&rect);

            S 1 Reply Last reply
            0
            • T Tal Rashas Guardianship

              No,I didn't set breakpoint, I just create a CRect object with large paramaters: CRect rect(0, 0, 200000, 200000); //Disable this line //GetClientRect(&rect);

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              No - get rid of those test parameters and try to find what the rectangle co-ordinates are when the call freezes when the rectangle is derived from the client rect.

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              T 2 Replies Last reply
              0
              • S Stuart Dootson

                No - get rid of those test parameters and try to find what the rectangle co-ordinates are when the call freezes when the rectangle is derived from the client rect.

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                T Offline
                T Offline
                Tal Rashas Guardianship
                wrote on last edited by
                #7

                I see, thanks for your mention

                1 Reply Last reply
                0
                • S Stuart Dootson

                  No - get rid of those test parameters and try to find what the rectangle co-ordinates are when the call freezes when the rectangle is derived from the client rect.

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  T Offline
                  T Offline
                  Tal Rashas Guardianship
                  wrote on last edited by
                  #8

                  Hi there. The reason is clear. It's because that I called the GDI+ APIs in another thread, and GDI+ doesn't support multi-thread calling

                  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