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. The Lounge
  3. What I really wanted in vc.net

What I really wanted in vc.net

Scheduled Pinned Locked Moved The Lounge
csharpc++graphicsjsonquestion
30 Posts 9 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.
  • B Bernhard

    Nish asked yesterday something like "why don't you like VC.Net".. frankly i'm not really informed what's hot and new in .net (excluded gc which i am not interested in)... and most of the things microsoft wrote where sthing like "use c# instead of the old c++. and if you are really that oldschool that you want to use c++, use managed c++ (the only thing which is new that it has got garbage collection)" yesterday and today i was messing around with drawing / printing.. so i was thinking what i wanted from the new MFC: * double buffering for all the drawing (who uses NOT double buffering?).. and if not EASIER double buffering (like CMemDC.. i want to thank Keith Rule...) * easier handling with resources.. wdf should be the use of this whole saveDC, restoreDC and all that stuff.. i want to construct it, i want to use it.. the rest should be the matter of the mfc * resizable dialogs without a big effort and from the C++ point of view: * STANDARDISE THIS BASTARD just my 2 cents bernhard


    Sometimes I think the surest sign for intelligent life elsewhere in the universe is that none of them ever tried to contact us.

    J Offline
    J Offline
    Joao Vaz
    wrote on last edited by
    #4

    I totally agree on your C++ point of view, particularly the lack of support for PTS(Partial Template Specialization) PTS PTS PTS PTS PTS PTS PTS PTS :omg: I'm investing my time on heavy template(and generic) programming, and i don't like very muck of the hacks to simulate this, like the templatized IF and SWITCH techiniques, neither the Struct hacks ... Bahhhhhhhhhh Waiting for the update... :mad: Cheers, Joao Vaz

    1 Reply Last reply
    0
    • N Nish Nishant

      Bernhard wrote: resizable dialogs without a big effort Yup, that'd be something. I am sure CG would agree :-) Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

      U Offline
      U Offline
      Uwe Keim
      wrote on last edited by
      #5

      Hey, what about some REAL photo in your profile? (I'm just curious :-D) -- See me: www.magerquark.de

      N 1 Reply Last reply
      0
      • B Bernhard

        Nish asked yesterday something like "why don't you like VC.Net".. frankly i'm not really informed what's hot and new in .net (excluded gc which i am not interested in)... and most of the things microsoft wrote where sthing like "use c# instead of the old c++. and if you are really that oldschool that you want to use c++, use managed c++ (the only thing which is new that it has got garbage collection)" yesterday and today i was messing around with drawing / printing.. so i was thinking what i wanted from the new MFC: * double buffering for all the drawing (who uses NOT double buffering?).. and if not EASIER double buffering (like CMemDC.. i want to thank Keith Rule...) * easier handling with resources.. wdf should be the use of this whole saveDC, restoreDC and all that stuff.. i want to construct it, i want to use it.. the rest should be the matter of the mfc * resizable dialogs without a big effort and from the C++ point of view: * STANDARDISE THIS BASTARD just my 2 cents bernhard


        Sometimes I think the surest sign for intelligent life elsewhere in the universe is that none of them ever tried to contact us.

        C Offline
        C Offline
        CodeGuy
        wrote on last edited by
        #6

        You might want to try porting WTL's CDialogResize over to MFC; it's not a large class, but it's extremely powerful and does what you're looking for. CodeGuy The WTL newsgroup: over 1100 members! Be a part of it. http://groups.yahoo.com/group/wtl

        B 1 Reply Last reply
        0
        • C CodeGuy

          You might want to try porting WTL's CDialogResize over to MFC; it's not a large class, but it's extremely powerful and does what you're looking for. CodeGuy The WTL newsgroup: over 1100 members! Be a part of it. http://groups.yahoo.com/group/wtl

          B Offline
          B Offline
          Bernhard
          wrote on last edited by
          #7

          there are tons of classes out there doing this (e.g. paul di lascia wrote on for msdn in the last 3 month) i just wish it would be easy as that: making a dialog resource, doing all the aligment graphically that's it.. i didn't want to say that all the things i've said are impossible (obviously) i just think they're too comberume and that the system should support them as it supports e.g. scrollviews.. bernhard


          Sometimes I think the surest sign for intelligent life elsewhere in the universe is that none of them ever tried to contact us.

          C 1 Reply Last reply
          0
          • B Bernhard

            there are tons of classes out there doing this (e.g. paul di lascia wrote on for msdn in the last 3 month) i just wish it would be easy as that: making a dialog resource, doing all the aligment graphically that's it.. i didn't want to say that all the things i've said are impossible (obviously) i just think they're too comberume and that the system should support them as it supports e.g. scrollviews.. bernhard


            Sometimes I think the surest sign for intelligent life elsewhere in the universe is that none of them ever tried to contact us.

            C Offline
            C Offline
            CodeGuy
            wrote on last edited by
            #8

            Well, I won't say anymore except that CDialogResize is about as easy as you can make resizing. For each control on a resource, you specify in a DLGRESIZE_MAP macro whether you want it moved or sized in the X direction, the Y direction or both. Aside from some minimal code to initialize the resizing, that's it. The class takes care of the rest. CDialogResize article by Michael Dunn CodeGuy The WTL newsgroup: over 1100 members! Be a part of it. http://groups.yahoo.com/group/wtl

            1 Reply Last reply
            0
            • U Uwe Keim

              Hey, what about some REAL photo in your profile? (I'm just curious :-D) -- See me: www.magerquark.de

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #9

              http://www.codeproject.com/script/profile/whos\_who.asp?id=20248 Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

              U 1 Reply Last reply
              0
              • B Bernhard

                Nish asked yesterday something like "why don't you like VC.Net".. frankly i'm not really informed what's hot and new in .net (excluded gc which i am not interested in)... and most of the things microsoft wrote where sthing like "use c# instead of the old c++. and if you are really that oldschool that you want to use c++, use managed c++ (the only thing which is new that it has got garbage collection)" yesterday and today i was messing around with drawing / printing.. so i was thinking what i wanted from the new MFC: * double buffering for all the drawing (who uses NOT double buffering?).. and if not EASIER double buffering (like CMemDC.. i want to thank Keith Rule...) * easier handling with resources.. wdf should be the use of this whole saveDC, restoreDC and all that stuff.. i want to construct it, i want to use it.. the rest should be the matter of the mfc * resizable dialogs without a big effort and from the C++ point of view: * STANDARDISE THIS BASTARD just my 2 cents bernhard


                Sometimes I think the surest sign for intelligent life elsewhere in the universe is that none of them ever tried to contact us.

                T Offline
                T Offline
                Tim Lesher
                wrote on last edited by
                #10

                * easier handling with resources.. wdf should be the use of this whole saveDC, restoreDC and all that stuff.. i want to construct it, i want to use it.. the rest should be the matter of the mfc Use private DCs. They're not a resource bottleneck anymore, and you don't have to bother with all the saving and restoring. Tim Lesher http://www.lesher.ws

                M B 2 Replies Last reply
                0
                • T Tim Lesher

                  * easier handling with resources.. wdf should be the use of this whole saveDC, restoreDC and all that stuff.. i want to construct it, i want to use it.. the rest should be the matter of the mfc Use private DCs. They're not a resource bottleneck anymore, and you don't have to bother with all the saving and restoring. Tim Lesher http://www.lesher.ws

                  M Offline
                  M Offline
                  Mark Lenz
                  wrote on last edited by
                  #11

                  "Use private DCs. They're not a resource bottleneck anymore, and you don't have to bother with all the saving and restoring." What do you mean when you say "private DCs"? Declared in the class as private or something WAY different? Mark Lenz

                  T T 2 Replies Last reply
                  0
                  • T Tim Lesher

                    * easier handling with resources.. wdf should be the use of this whole saveDC, restoreDC and all that stuff.. i want to construct it, i want to use it.. the rest should be the matter of the mfc Use private DCs. They're not a resource bottleneck anymore, and you don't have to bother with all the saving and restoring. Tim Lesher http://www.lesher.ws

                    B Offline
                    B Offline
                    Bernhard
                    wrote on last edited by
                    #12

                    could you explain this for us all? thanks in advance bernhard


                    Sometimes I think the surest sign for intelligent life elsewhere in the universe is that none of them ever tried to contact us.

                    1 Reply Last reply
                    0
                    • N Nish Nishant

                      http://www.codeproject.com/script/profile/whos\_who.asp?id=20248 Nish Sonork ID 100.9786 voidmain www.busterboy.org If you don't find me on CP, I'll be at Bob's HungOut

                      U Offline
                      U Offline
                      Uwe Keim
                      wrote on last edited by
                      #13

                      Aaaaaaaah. Much better :-D -- See me: www.magerquark.de

                      1 Reply Last reply
                      0
                      • M Mark Lenz

                        "Use private DCs. They're not a resource bottleneck anymore, and you don't have to bother with all the saving and restoring." What do you mean when you say "private DCs"? Declared in the class as private or something WAY different? Mark Lenz

                        T Offline
                        T Offline
                        Tim Lesher
                        wrote on last edited by
                        #14

                        Windows allocates a private DC for a window if the window class (not the C++ class, mind you, but the class of the window as defined using RegisterClass() in Win32 or AfxRegisterClass() or AfxRegisterWndClass() in MFC) specifies CS_OWNDC as one of the class styles. This means that you never have to call GetDC() and ReleaseDC() more than once--call it once in your WM_CREATE handler or OnCreate() function, store it, and don't release it until you're ready to destroy the window. It also means none of this hOldPen = SelectObject(); SelectObject(oldPen) restoration garbage. GetDC()/ReleaseDC() are expensive calls, so you can not only simplify your code, you can also speed it up if your code is graphics-intensive.

                        The drawbacks? On NT/2000/XP, there are none. DCs are allocated from the system heap. On Win95/98/ME, they're allocated from the 64k GDI heap, which means they're somewhat limited (but nowhere near as badly as on Win3.1, since a lot of other structures were moved out of the GDI heap).

                        So, if you're running on NT/2000/XP, use them as much as possible. If you're running on 95/98/ME, use them when your GetDC()/ReleaseDC() usage is getting to be a pain to manage or a performance bottleneck. Tim Lesher http://www.lesher.ws

                        M 1 Reply Last reply
                        0
                        • M Mark Lenz

                          "Use private DCs. They're not a resource bottleneck anymore, and you don't have to bother with all the saving and restoring." What do you mean when you say "private DCs"? Declared in the class as private or something WAY different? Mark Lenz

                          T Offline
                          T Offline
                          Todd Smith
                          wrote on last edited by
                          #15

                          Or use GDI+ which is an object oriented toolkit for GDI by MS.

                          Todd Smith

                          B 1 Reply Last reply
                          0
                          • T Tim Lesher

                            Windows allocates a private DC for a window if the window class (not the C++ class, mind you, but the class of the window as defined using RegisterClass() in Win32 or AfxRegisterClass() or AfxRegisterWndClass() in MFC) specifies CS_OWNDC as one of the class styles. This means that you never have to call GetDC() and ReleaseDC() more than once--call it once in your WM_CREATE handler or OnCreate() function, store it, and don't release it until you're ready to destroy the window. It also means none of this hOldPen = SelectObject(); SelectObject(oldPen) restoration garbage. GetDC()/ReleaseDC() are expensive calls, so you can not only simplify your code, you can also speed it up if your code is graphics-intensive.

                            The drawbacks? On NT/2000/XP, there are none. DCs are allocated from the system heap. On Win95/98/ME, they're allocated from the 64k GDI heap, which means they're somewhat limited (but nowhere near as badly as on Win3.1, since a lot of other structures were moved out of the GDI heap).

                            So, if you're running on NT/2000/XP, use them as much as possible. If you're running on 95/98/ME, use them when your GetDC()/ReleaseDC() usage is getting to be a pain to manage or a performance bottleneck. Tim Lesher http://www.lesher.ws

                            M Offline
                            M Offline
                            Mark Lenz
                            wrote on last edited by
                            #16

                            Thanks, I had never heard of them before. I'm having a problem where it looks like I'm running out of device contexts. I have a control which looks kinda like a fuel guage. The value that the needle represents is updated about every second, so the needle must be redrawn about every second. I have about 4 or 5 of these controls in my view. When I have been displaying the view for about 3 minutes, things start to get weird. All of my fonts revert to a standard font and it starts to draw white where there was supposed to another color. This starts to affect the title bar, making it white. Sometimes it even starts to affect other applications. Would using a private DC solve this, even running on Windows 98? Or is there something else I'm missing? Thanks. Mark Lenz

                            T 1 Reply Last reply
                            0
                            • M Mark Lenz

                              Thanks, I had never heard of them before. I'm having a problem where it looks like I'm running out of device contexts. I have a control which looks kinda like a fuel guage. The value that the needle represents is updated about every second, so the needle must be redrawn about every second. I have about 4 or 5 of these controls in my view. When I have been displaying the view for about 3 minutes, things start to get weird. All of my fonts revert to a standard font and it starts to draw white where there was supposed to another color. This starts to affect the title bar, making it white. Sometimes it even starts to affect other applications. Would using a private DC solve this, even running on Windows 98? Or is there something else I'm missing? Thanks. Mark Lenz

                              T Offline
                              T Offline
                              Tim Lesher
                              wrote on last edited by
                              #17

                              That definitely sounds like a resource leak. A private DC might appear to solve the problem, but it might just mask it. Look for calls to GetDC() that aren't balanced by calls to DeleteDC(). Also look for GDI objects that are created, selected into the DC, and then deleted before being selected back out--they won't actually be deleted, because they're still in use. Tim Lesher http://www.lesher.ws

                              M 2 Replies Last reply
                              0
                              • T Tim Lesher

                                That definitely sounds like a resource leak. A private DC might appear to solve the problem, but it might just mask it. Look for calls to GetDC() that aren't balanced by calls to DeleteDC(). Also look for GDI objects that are created, selected into the DC, and then deleted before being selected back out--they won't actually be deleted, because they're still in use. Tim Lesher http://www.lesher.ws

                                M Offline
                                M Offline
                                Mark Lenz
                                wrote on last edited by
                                #18

                                I have been using SaveDC() before I create any new GDI objects and then RestoreDC() when I'm done with them. Example: void DumbControl::OnPaint() { CPaintDC dc(this); int saveDC = dc.SaveDC(); CBrush brush; /*....using GDI object....*/ dc.RestoreDC(saveDC); } I make function calls within the OnPaint() method who take a pointer to the DC and then use GDI objects created within their scope, but those functions don't make a call to SaveDC(). Do I need to call SaveDC() in those functions as well, or am I missing something else? Thanks. Mark Lenz

                                T 1 Reply Last reply
                                0
                                • T Tim Lesher

                                  That definitely sounds like a resource leak. A private DC might appear to solve the problem, but it might just mask it. Look for calls to GetDC() that aren't balanced by calls to DeleteDC(). Also look for GDI objects that are created, selected into the DC, and then deleted before being selected back out--they won't actually be deleted, because they're still in use. Tim Lesher http://www.lesher.ws

                                  M Offline
                                  M Offline
                                  Mark Lenz
                                  wrote on last edited by
                                  #19

                                  Another thing I noticed. It happens in Windows 98, but not in Windows 2000. Mark Lenz

                                  D T 2 Replies Last reply
                                  0
                                  • M Mark Lenz

                                    Another thing I noticed. It happens in Windows 98, but not in Windows 2000. Mark Lenz

                                    D Offline
                                    D Offline
                                    Daniel Ferguson
                                    wrote on last edited by
                                    #20

                                    I had the same problem with a program I wrote. It's because Win2K manages it's GDI resources better. "The world has achieved brilliance without wisdom, power without conscience. Ours is a world of nuclear giants and ethical infants." - Omar Bradley

                                    1 Reply Last reply
                                    0
                                    • M Mark Lenz

                                      I have been using SaveDC() before I create any new GDI objects and then RestoreDC() when I'm done with them. Example: void DumbControl::OnPaint() { CPaintDC dc(this); int saveDC = dc.SaveDC(); CBrush brush; /*....using GDI object....*/ dc.RestoreDC(saveDC); } I make function calls within the OnPaint() method who take a pointer to the DC and then use GDI objects created within their scope, but those functions don't make a call to SaveDC(). Do I need to call SaveDC() in those functions as well, or am I missing something else? Thanks. Mark Lenz

                                      T Offline
                                      T Offline
                                      Tim Lesher
                                      wrote on last edited by
                                      #21

                                      I make function calls within the OnPaint() method who take a pointer to the DC and then use GDI objects created within their scope, but those functions don't make a call to SaveDC(). That's probably your problem. The path of execution looks like this: 1. Acquire DC 2. Save DC context 3. Call function 4. (in function) create resource 5. (in function) select resource into DC 6. (function returning) delete resource 7. Restore DC context Notice that you're still destroying the objects while they're still selected into the DC. The objects are probably what are leaking. Tim Lesher http://www.lesher.ws

                                      B M 3 Replies Last reply
                                      0
                                      • M Mark Lenz

                                        Another thing I noticed. It happens in Windows 98, but not in Windows 2000. Mark Lenz

                                        T Offline
                                        T Offline
                                        Tim Lesher
                                        wrote on last edited by
                                        #22

                                        Makes sense--under NT, device contexts aren't allocated in a small heap, as they are under Win 9x. Tim Lesher http://www.lesher.ws

                                        1 Reply Last reply
                                        0
                                        • T Tim Lesher

                                          I make function calls within the OnPaint() method who take a pointer to the DC and then use GDI objects created within their scope, but those functions don't make a call to SaveDC(). That's probably your problem. The path of execution looks like this: 1. Acquire DC 2. Save DC context 3. Call function 4. (in function) create resource 5. (in function) select resource into DC 6. (function returning) delete resource 7. Restore DC context Notice that you're still destroying the objects while they're still selected into the DC. The objects are probably what are leaking. Tim Lesher http://www.lesher.ws

                                          B Offline
                                          B Offline
                                          Bernhard
                                          wrote on last edited by
                                          #23

                                          hi... i've read your explanations, but there are still some things i don't get.. my normal drawing routine looks something like:

                                          void CView::OnDraw(CDC *pDC)
                                          {
                                          CObjectList::iterator i;

                                          for (i = m\_ObjList.begin(); i != m\_ObjList.end(); i++)
                                          	(\*i)->Draw(pDC);
                                          

                                          }

                                          //this is one of the objects i am drawing
                                          void CDrawObject::Draw(CDC *pDC)
                                          {
                                          int i_save = pDC->SaveDC()

                                          pDC->SelectObject (&cp\_dashdot);
                                          pDC->SelectObject (&cf\_arial20);
                                          
                                              pDC->Rectangle (0, 0, 100, 100);
                                          
                                          //Aufräumen
                                          pDC->RestoreDC (i\_save);
                                          

                                          }

                                          i really like to make the pens and fonts member of the base class of all draw objects.. cause they all use the same font - and pen - settings and then select em into the device contexts.. my problem now is WHEN should i do the things you've told me to. (cause i found out that i am leaking resources.. when drawing more than 1000 objects or so (when printing out.. more than 6 pages,i got the standard font on WIN NT) and if this is a good idea to make this in a base class.. and what would be other ways to share the same font / pen - settings for all objects.. thanks in advance bernhard


                                          Sometimes I think the surest sign for intelligent life elsewhere in the universe is that none of them ever tried to contact us.

                                          T 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