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. Getting the handle of a PictureBox in MFC

Getting the handle of a PictureBox in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsgame-devhelp
2 Posts 2 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.
  • T Offline
    T Offline
    Tom Moore
    wrote on last edited by
    #1

    Hi, It's been a while since I've posted in here. A friend and I have a problem with MFC, We're trying to get the handle of a PictureBox in MFC, but the code we use keeps returning null. Here is a code snippet we're using

    CStatic* pCStatic = (CStatic*) GetDlgItem(IDC_STATIC1);
    HWND hWnd = pCStatic->m_hWnd;

    We're trying to get the handle of the PictureBox so we put a DirectX into the control. Many Thanks Tom

    L 1 Reply Last reply
    0
    • T Tom Moore

      Hi, It's been a while since I've posted in here. A friend and I have a problem with MFC, We're trying to get the handle of a PictureBox in MFC, but the code we use keeps returning null. Here is a code snippet we're using

      CStatic* pCStatic = (CStatic*) GetDlgItem(IDC_STATIC1);
      HWND hWnd = pCStatic->m_hWnd;

      We're trying to get the handle of the PictureBox so we put a DirectX into the control. Many Thanks Tom

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Tom, Make sure that you are calling GetDlgItem(int) from the parent window of the CStatic because the MFC wrapper auto-populates the first HWND parameter with this->m_hWnd. You could also use the global namespace function ::GetDlgItem(HWND,int) if you want to call this function from outside the window class. I would actually recommend that you avoid using GetDlgItem and instead use a control variable. In some cases the GetDlgItem function will return a pointer to a CTempWnd object. Another reason to void GetDlgItem is because of performance reasons... GetDlgItem causes the MFC framework to iterate through an internal handle map in an attempt at finding a permanent object. In some projects this map could contain several hundred or more handles. So if an engineer is using a function such as GetDlgItem from WM_PAINT handler or perhaps WM_TIMER they could potentially be iterating needlessly through this map dozens of times per second or more. Best Wishes, -David Delaune

      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