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. Retrieving control's original class by its ID?

Retrieving control's original class by its ID?

Scheduled Pinned Locked Moved C / C++ / MFC
databasedata-structureshelpquestiondiscussion
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.
  • D Offline
    D Offline
    Daredevil
    wrote on last edited by
    #1

    Hello, In my program I dynamically create controls according to data read from a database. The control can be either CEdit or CComboBox. I also assign a unique control ID to each of the created controls (I know the ids). Once controls created when a button pressed it's supposed to save controls values in the database. Getting the text from the CEdit control isn't a problem as I just do GetDlgItemText(...). However, in case of the CComboBox I need to retrieve the ItemData using GetItemData. This is where I'm unsure of what to do. I don't save anywhere if control with specific ID is a CComboBox or CEdit. Is is possible to know only by ID what kind of a control it is and to retrieve its original class?. I was thinking just to make a struct: struct { CEdit *edit=NULL; CComboBox *combo=NULL; } myDynControls; and then make an array of this struct. Each coresponding to an ID. I won't have more than 10 controls at a time. What do you think? Is it a good idea? (i will delete everything after done working with ofcourse :))

    A D 2 Replies Last reply
    0
    • D Daredevil

      Hello, In my program I dynamically create controls according to data read from a database. The control can be either CEdit or CComboBox. I also assign a unique control ID to each of the created controls (I know the ids). Once controls created when a button pressed it's supposed to save controls values in the database. Getting the text from the CEdit control isn't a problem as I just do GetDlgItemText(...). However, in case of the CComboBox I need to retrieve the ItemData using GetItemData. This is where I'm unsure of what to do. I don't save anywhere if control with specific ID is a CComboBox or CEdit. Is is possible to know only by ID what kind of a control it is and to retrieve its original class?. I was thinking just to make a struct: struct { CEdit *edit=NULL; CComboBox *combo=NULL; } myDynControls; and then make an array of this struct. Each coresponding to an ID. I won't have more than 10 controls at a time. What do you think? Is it a good idea? (i will delete everything after done working with ofcourse :))

      A Offline
      A Offline
      Andrew Quinn AUS
      wrote on last edited by
      #2

      Hi Daredevil, All MFC classes that derive from CObject (of which CWnd does) have a CRuntimeClass object associated with it. So to see if your object is a CEdit control:

      CWnd* pWndControl = m_arrMyControls[i]; // or however you've implemented the collection of controls
      if (pWndControl && pWnd->GetSafeHwnd())
      {
      CRuntimeClass* pClass = pWnd->GetRuntimeClass();
      // MSDN says that pClass will never be NULL, but we should always check pointers before use
      if (pClass)
      {
      CString strName = pClass->m_lpszClassName;
      // Now you can do whatever you need to do based on what the runtime class is
      // ...
      // ...
      // ...
      }
      }

      Hope this helps, Andy

      1 Reply Last reply
      0
      • D Daredevil

        Hello, In my program I dynamically create controls according to data read from a database. The control can be either CEdit or CComboBox. I also assign a unique control ID to each of the created controls (I know the ids). Once controls created when a button pressed it's supposed to save controls values in the database. Getting the text from the CEdit control isn't a problem as I just do GetDlgItemText(...). However, in case of the CComboBox I need to retrieve the ItemData using GetItemData. This is where I'm unsure of what to do. I don't save anywhere if control with specific ID is a CComboBox or CEdit. Is is possible to know only by ID what kind of a control it is and to retrieve its original class?. I was thinking just to make a struct: struct { CEdit *edit=NULL; CComboBox *combo=NULL; } myDynControls; and then make an array of this struct. Each coresponding to an ID. I won't have more than 10 controls at a time. What do you think? Is it a good idea? (i will delete everything after done working with ofcourse :))

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        How about using IsKindOf()?


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        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