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. what's an operator HBRUSH??

what's an operator HBRUSH??

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsquestion
3 Posts 3 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 Offline
    B Offline
    Bilal Naveed
    wrote on last edited by
    #1

    MFC Graphics classes like CBrush, CBitmap, etc. define a member "operator HBRUSH() const", or "operator HBITMAP() const". I thought that you couldn't define new operator types! Somebody explain what these are :confused: Bilal

    C M 2 Replies Last reply
    0
    • B Bilal Naveed

      MFC Graphics classes like CBrush, CBitmap, etc. define a member "operator HBRUSH() const", or "operator HBITMAP() const". I thought that you couldn't define new operator types! Somebody explain what these are :confused: Bilal

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      MFC GDI classes like CBrush, CDC and CBitmap are merely thin wrappers around Win32 functions. Everything that CDC, for example, does is really a wrapper around functions of the same name. So CDC::CreateCompatibleDC is a wrapper around a function called CreateCompatibleDC, which takes the same variables as CreateCompatibleDC ( a pointer to a DC or NULL), plus a HDC, which is a handle to a DC. A major benefit of this is that they are cleaned up by the destructor - not calling delete on a GDI resource in a Win32 program is a sure fire way to achieve memory leaks and disaster, MFC makes it a little harder to mess up. CDC as a class is then just a spot to hold a HDC and do HDC stuff to it. Any class can overload an operator in order to enable implicit casting to that type, for example a string class would overload char* so you could put an instance of the class where a char * is expected. The GDI classes have such an overload, so that anything that expects the handle can get it, although I usually point to the member variable ( such as m_hDC, m_hBitmap, etc. ) to be sure. Christian The content of this post is not necessarily the opinion of my yadda yadda yadda. To understand recursion, we must first understand recursion.

      1 Reply Last reply
      0
      • B Bilal Naveed

        MFC Graphics classes like CBrush, CBitmap, etc. define a member "operator HBRUSH() const", or "operator HBITMAP() const". I thought that you couldn't define new operator types! Somebody explain what these are :confused: Bilal

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        A class can define conversion functions, which is what those MFC functions are. For example, CBrush::operator HBRUSH() is called if you pass a CBrush to a function expecting an HBRUSH, or if you explicitly cast a CBrush to HBRUSH. You still use the keyword operator in the code. --Mike-- http://home.inreach.com/mdunn/ All your base are belong to ME~!

        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