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. The Lounge
  3. Question about GetDlgItem()

Question about GetDlgItem()

Scheduled Pinned Locked Moved The Lounge
questionc++learning
4 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.
  • J Offline
    J Offline
    jamal
    wrote on last edited by
    #1

    Hi, I am reading jeff Prosise Book, "Programming Windows With MFC", I have a question regarding GetDlgItem() Function To obtain control pointer. In page 403, Jeff states that it is poor programming practice and dangerous at the same time to use statement like this: CListBox* pList= (CListBox*) GetDlgItem(IDC_LIST); I have seen many examples code that they are using this statement to obtain the pointer. Unfortunately, Jeff didn't explain why it is dangerous to use it. Anybody can explain to me why?

    M C 2 Replies Last reply
    0
    • J jamal

      Hi, I am reading jeff Prosise Book, "Programming Windows With MFC", I have a question regarding GetDlgItem() Function To obtain control pointer. In page 403, Jeff states that it is poor programming practice and dangerous at the same time to use statement like this: CListBox* pList= (CListBox*) GetDlgItem(IDC_LIST); I have seen many examples code that they are using this statement to obtain the pointer. Unfortunately, Jeff didn't explain why it is dangerous to use it. Anybody can explain to me why?

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

      Well, it's dangerous because it's up to you to make sure IDC_LIST really is a listbox. The compiler can't check that the cast is valid. The safer method is to make a CListBox member variable in the dialog class, and manipulate the listbox through that member. --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

      1 Reply Last reply
      0
      • J jamal

        Hi, I am reading jeff Prosise Book, "Programming Windows With MFC", I have a question regarding GetDlgItem() Function To obtain control pointer. In page 403, Jeff states that it is poor programming practice and dangerous at the same time to use statement like this: CListBox* pList= (CListBox*) GetDlgItem(IDC_LIST); I have seen many examples code that they are using this statement to obtain the pointer. Unfortunately, Jeff didn't explain why it is dangerous to use it. Anybody can explain to me why?

        C Offline
        C Offline
        Chris Maunder
        wrote on last edited by
        #3

        See Paul DiLascia's Sep '97 MSJ article. cheers, Chris Maunder

        J 1 Reply Last reply
        0
        • C Chris Maunder

          See Paul DiLascia's Sep '97 MSJ article. cheers, Chris Maunder

          J Offline
          J Offline
          jamal
          wrote on last edited by
          #4

          Thanks Chris for the link. It is very helpful. Codeproject is a great site and keep up the good work.

          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