[問題] MFC GetDlgItem的用法
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++ 2010
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
MFC
問題(Question):
在使用MFC時,常可看到下述的指令
CButton *a;
a=(CButton*)GetDlgItem(IDC_BUTTON);
a->SetWindowText(_T("Default State"));
因為msdn裡說:
1. CWnd::GetDlgItem
CWnd* GetDlgItem(
int nID
) const;
2. class CButton : public CWnd
3. CWnd::SetWindowText
void SetWindowText(
LPCTSTR lpszString
);
我只看得出來GetDlgItem為CWnd的函數成員,且GetDlgItem回傳值為指標型式
另外,CButton繼承自CWnd,
藉由SetWindowText來設定IDC_BUTTON上的字樣為Default State,
但一直搞不清楚(CButton*)GetDlgItem(IDC_BUTTON)裡的(CButton*)是什麼意思(汗)
我試著改寫成我所能理解的"指向物件的指標"形式:
CButton *a,*b;
b=a->GetDlgItem(IDC_BUTTON);
b->SetWindowText(_T("Default State"));
結果當然是不行XD 在第二行定義b的地方出現錯誤:
IntelliSense: 型別 "CWnd *" 的值無法指派至型別 "CButton *" 的實體
但卻看不懂這個問題.....
想請問各位熱心的板友, 小弟的邏輯出了什麼問題>_<
謝謝!!
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.72.212.97
→
10/08 21:56, , 1F
10/08 21:56, 1F
→
10/08 23:00, , 2F
10/08 23:00, 2F
→
10/08 23:16, , 3F
10/08 23:16, 3F
→
10/08 23:16, , 4F
10/08 23:16, 4F
→
10/08 23:17, , 5F
10/08 23:17, 5F
→
10/08 23:37, , 6F
10/08 23:37, 6F
→
10/08 23:52, , 7F
10/08 23:52, 7F
→
10/08 23:53, , 8F
10/08 23:53, 8F
→
10/08 23:56, , 9F
10/08 23:56, 9F
→
10/08 23:58, , 10F
10/08 23:58, 10F
→
10/09 00:56, , 11F
10/09 00:56, 11F
→
10/09 07:42, , 12F
10/09 07:42, 12F
推
10/09 14:45, , 13F
10/09 14:45, 13F
推
10/09 15:34, , 14F
10/09 15:34, 14F
推
10/13 00:58, , 15F
10/13 00:58, 15F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):