Click here to Skip to main content
15,880,503 members
Articles / Multimedia / GDI

boost 2: shared_ptr wraps resource handles

Rate me:
Please Sign up or sign in to vote.
4.96/5 (41 votes)
16 Nov 200415 min read 227.8K   1.3K   56  
Using boost, we can write "almost perfect" wrappers for GDI and other resource handles, in a few lines of code.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset="iso-8859-1" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta http-equiv="Content-Language" content="en" />
    <link rel="stylesheet" href="doxygen.css">
    <title>TreeView</title>
    <style type="text/css">
    <!--
    .directory { font-size: 10pt; font-weight: bold; }
    .directory h3 { margin: 0px; margin-top: 1em; font-size: 11pt; }
    .directory p { margin: 0px; white-space: nowrap; }
    .directory div { display: none; margin: 0px; }
    .directory img { vertical-align: middle; }
    -->
    </style>
    <script type="text/javascript">
    <!-- // Hide script from old browsers
    
    function findChildNode(node, name) 
    {
      var temp;
      if (node == null) 
      {
        return null;
      } 
      node = node.firstChild;
      while (node != null) 
      {
        if (node.nodeName == name) 
        {
          return node;
        }
        temp = findChildNode(node, name);
        if (temp != null) 
        {
          return temp;
        }
        node = node.nextSibling;
      }
      return null;
    }

    function toggleFolder(id, imageNode) 
    {
      var folder = document.getElementById(id);
      var l = 0;
      var vl = "ftv2vertline.png";
      if (imageNode != null && imageNode.nodeName != "IMG") 
      {
        imageNode = findChildNode(imageNode, "IMG");
        if (imageNode!=null) l = imageNode.src.length;
      }
      if (folder == null) 
      {
      } 
      else if (folder.style.display == "block") 
      {
        while (imageNode != null && 
               imageNode.src.substring(l-vl.length,l) == vl)
        {
          imageNode = imageNode.nextSibling;
          l = imageNode.src.length;
        }
        if (imageNode != null) 
        {
          l = imageNode.src.length;
          imageNode.nextSibling.src = "ftv2folderclosed.png";
          if (imageNode.src.substring(l-13,l) == "ftv2mnode.png")
          {
            imageNode.src = "ftv2pnode.png";
          }
          else if (imageNode.src.substring(l-17,l) == "ftv2mlastnode.png")
          {
            imageNode.src = "ftv2plastnode.png";
          }
        }
        folder.style.display = "none";
      } 
      else 
      {
        while (imageNode != null && 
               imageNode.src.substring(l-vl.length,l) == vl)
        {
          imageNode = imageNode.nextSibling;
          l = imageNode.src.length;
        }
        if (imageNode != null) 
        {
          l = imageNode.src.length;
          imageNode.nextSibling.src = "ftv2folderopen.png";
          if (imageNode.src.substring(l-13,l) == "ftv2pnode.png")
          {
            imageNode.src = "ftv2mnode.png";
          }
          else if (imageNode.src.substring(l-17,l) == "ftv2plastnode.png")
          {
            imageNode.src = "ftv2mlastnode.png";
          }
        }
        folder.style.display = "block";
      }
    }

    // End script hiding -->        
    </script>
  </head>

  <body>
    <div class="directory">
      <h3>HandleRef</h3>
      <div style="display: block;">
        <p><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="main.html" target="basefrm">Main Page</a></p>
        <p><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder1', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder1', this)"/><a class="el" href="files.html" target="basefrm">File List</a></p>
        <div id="folder1">
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="handleref_8h.html" target="basefrm">handleref.h</a></p>
        </div>
        <p><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder2', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder2', this)"/><a class="el" href="annotated.html" target="basefrm">Data Structures</a></p>
        <div id="folder2">
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="classCDCRef.html" target="basefrm">CDCRef</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterDeleteDC.html" target="basefrm">nsHandleRefDetail::CDeleterDeleteDC</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterGDI.html" target="basefrm">nsHandleRefDetail::CDeleterGDI</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterHANDLE.html" target="basefrm">nsHandleRefDetail::CDeleterHANDLE</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterHKEY.html" target="basefrm">nsHandleRefDetail::CDeleterHKEY</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterHMENU.html" target="basefrm">nsHandleRefDetail::CDeleterHMENU</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterImageList.html" target="basefrm">nsHandleRefDetail::CDeleterImageList</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterReleaseDC.html" target="basefrm">nsHandleRefDetail::CDeleterReleaseDC</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="structnsHandleRefDetail_1_1CDeleterVoid.html" target="basefrm">nsHandleRefDetail::CDeleterVoid</a></p>
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="classCHandleRefT.html" target="basefrm">CHandleRefT< HDL, DELETER ></a></p>
        </div>
        <p><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="functions.html" target="basefrm">Data Fields</a></p>
        <p><img src="ftv2pnode.png" alt="o" width=16 height=22 onclick="toggleFolder('folder3', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder3', this)"/><a class="el" href="namespaces.html" target="basefrm">Namespace List</a></p>
        <div id="folder3">
          <p><img src="ftv2vertline.png" alt="|" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="namespacensHandleRefDetail.html" target="basefrm">nsHandleRefDetail</a></p>
        </div>
        <p><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="globals.html" target="basefrm">Globals</a></p>
        <p><img src="ftv2plastnode.png" alt="\" width=16 height=22 onclick="toggleFolder('folder4', this)"/><img src="ftv2folderclosed.png" alt="+" width=24 height=22 onclick="toggleFolder('folder4', this)"/><a class="el" href="pages.html" target="basefrm">Related Pages</a></p>
        <div id="folder4">
          <p><img src="ftv2blank.png" alt="&nbsp;" width=16 height=22 /><img src="ftv2node.png" alt="o" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="pgUse.html" target="basefrm">Usage Recommendations</a></p>
          <p><img src="ftv2blank.png" alt="&nbsp;" width=16 height=22 /><img src="ftv2lastnode.png" alt="\" width=16 height=22 /><img src="ftv2doc.png" alt="*" width=24 height=22 /><a class="el" href="todo.html" target="basefrm">Todo List</a></p>
        </div>
      </div>
    </div>
  </body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Klippel
Germany Germany
Peter is tired of being called "Mr. Chen", even so certain individuals insist on it. No, he's not chinese.

Peter has seen lots of boxes you youngsters wouldn't even accept as calculators. He is proud of having visited the insides of a 16 Bit Machine.

In his spare time he ponders new ways of turning groceries into biohazards, or tries to coax South American officials to add some stamps to his passport.

Beyond these trivialities Peter works for Klippel[^], a small german company that wants to make mankind happier by selling them novel loudspeaker measurement equipment.


Where are you from?[^]



Please, if you are using one of my articles for anything, just leave me a comment. Seeing that this stuff is actually useful to someone is what keeps me posting and updating them.
Should you happen to not like it, tell me, too

Comments and Discussions