Question about GetDlgItem()
-
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?
-
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?
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
-
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?
See Paul DiLascia's Sep '97 MSJ article. cheers, Chris Maunder
-
See Paul DiLascia's Sep '97 MSJ article. cheers, Chris Maunder