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. A couple of questions...

A couple of questions...

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphics
4 Posts 3 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.
  • 0 Offline
    0 Offline
    0v3rloader
    wrote on last edited by
    #1

    Hi there, I posted previously about GDI objects and how I should be dealing with them. Well someone said something (which I have implemented thereafter) about deselecting the objects used in a DC "session". In order to understand what I mean by DC session, we'll have to consider the following:

    void CClass::MyPaintProc(...)
    {
    CDC *pDC;

    pDC = new CDC;
    pDC -> Attach(GetDC() -> GetSafeHdc());
    
    **pOldPen** = pDC -> SelectObject(myPen);
    **pOldBrush** = pDC -> SelectObject(myBrush);
    .
    :
    .
    **pDC -> SelectObject(pOldPen);**	// does one need to do this?
    **pDC -> SelectObject(pOldBrush);**	// 
    ReleaseDC(pDC);
    delete pDC;
    

    }

    What is the purpose of de-selecting the GDI objects? I really would like to know the reason behind it... Now as for the second question. Is there any way of making the main thread (the app) receive and translate the keyboard accelerators which activate the menus regardless of the window that has the focus? I've tried using TranslateAccelerator but couldn't solve it. And the third and final question... hope you're not bored just as yet :). How can I get a CRegion (or something similar that Windows understands) of the visible area of the client area of a window? Imagine a dialog box hovering partially over a control. How can I know the visible area of the control? For just being brave enough to take the time to read through all this, I thank you. David

    R 1 Reply Last reply
    0
    • 0 0v3rloader

      Hi there, I posted previously about GDI objects and how I should be dealing with them. Well someone said something (which I have implemented thereafter) about deselecting the objects used in a DC "session". In order to understand what I mean by DC session, we'll have to consider the following:

      void CClass::MyPaintProc(...)
      {
      CDC *pDC;

      pDC = new CDC;
      pDC -> Attach(GetDC() -> GetSafeHdc());
      
      **pOldPen** = pDC -> SelectObject(myPen);
      **pOldBrush** = pDC -> SelectObject(myBrush);
      .
      :
      .
      **pDC -> SelectObject(pOldPen);**	// does one need to do this?
      **pDC -> SelectObject(pOldBrush);**	// 
      ReleaseDC(pDC);
      delete pDC;
      

      }

      What is the purpose of de-selecting the GDI objects? I really would like to know the reason behind it... Now as for the second question. Is there any way of making the main thread (the app) receive and translate the keyboard accelerators which activate the menus regardless of the window that has the focus? I've tried using TranslateAccelerator but couldn't solve it. And the third and final question... hope you're not bored just as yet :). How can I get a CRegion (or something similar that Windows understands) of the visible area of the client area of a window? Imagine a dialog box hovering partially over a control. How can I know the visible area of the control? For just being brave enough to take the time to read through all this, I thank you. David

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      dNimrod#X wrote: What is the purpose of de-selecting the GDI objects? The Windows docs state that you should release the DC in the same state as it was when you got it, ie. it should have all the same GDI objects selected, ideally the same mapping mode, background colour etc. Most of the time, Windows can handle any changes, but sometimes it falls over in a giant steaming heap :) dNimrod#X wrote: CDC *pDC; pDC = new CDC; pDC -> Attach(GetDC() -> GetSafeHdc()); What is the reason for doing this? Why not just do

      CDC *pDC = GetDC();

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      0 1 Reply Last reply
      0
      • R Ryan Binns

        dNimrod#X wrote: What is the purpose of de-selecting the GDI objects? The Windows docs state that you should release the DC in the same state as it was when you got it, ie. it should have all the same GDI objects selected, ideally the same mapping mode, background colour etc. Most of the time, Windows can handle any changes, but sometimes it falls over in a giant steaming heap :) dNimrod#X wrote: CDC *pDC; pDC = new CDC; pDC -> Attach(GetDC() -> GetSafeHdc()); What is the reason for doing this? Why not just do

        CDC *pDC = GetDC();

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        0 Offline
        0 Offline
        0v3rloader
        wrote on last edited by
        #3

        Ryan Binns wrote: CDC *pDC = GetDC(); So this should be enough, do you think? Hmmm... I've always liked to complicate what's simple by nature... Thanks for the tip! :-D What about the other questions? Can you think of anything?

        T 1 Reply Last reply
        0
        • 0 0v3rloader

          Ryan Binns wrote: CDC *pDC = GetDC(); So this should be enough, do you think? Hmmm... I've always liked to complicate what's simple by nature... Thanks for the tip! :-D What about the other questions? Can you think of anything?

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          Actually, you should use CClientDC instead of manual GetDC/ReleaseDC calls. It will call these functions for you in its constructor and destructor. Similarly, you can use CPaintDC in WM_PAINT-handling code. Tomasz Sowinski -- http://www.shooltz.com

          Alika masiaka!

          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