2016-02-11 58 views
-3

所以,我有一個列表框問題,我希望它顯示的條目沒有在Visual C++ 6中顯示。爲什麼列表框不顯示使用Visual C++ 6的元素?

代碼如下。

switch (m) { 
    case WM_INITDIALOG: //To initiate the dialog box 
    { 
     HICON hicon = (HICON__ *)LoadImageW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(IDI_ICONMAIN), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE); 
     SendMessageW(h, WM_SETICON, ICON_BIG, (long)hicon); 
     RECT Rect; 
     ::GetWindowRect(h, &Rect); 
     ::SetWindowPos(h, HWND_TOPMOST, (::GetSystemMetrics(SM_CXSCREEN)/2 - ((Rect.right - Rect.left)/2)), (::GetSystemMetrics(SM_CYSCREEN)/2 - ((Rect.bottom - Rect.top)/2)), (Rect.right - Rect.left), (Rect.bottom - Rect.top), SWP_SHOWWINDOW); 
     //Place items in listbox. 
     const std::string StringArray[] = {"10", "20", "30", "40", "50", "60", "70"}; 
     SendMessage(h, LB_ADDSTRING, DROPDOWN1, (LPARAM)StringArray); 
     return TRUE; 
    } 
+0

什麼是_C++ 6_實際上? –

+0

您正在將消息發送到錯誤的窗口。使用描述性變量名稱,「h」很糟糕。 –

+0

@πάνταῥεῖ一個快速的谷歌讓我覺得他的意思是Visual C++ 6,但我們不能確定。 –

回答

0

C++不是C#。原始數組不是類,也沒有方法。使用std::vector<std::string>

但在此之前,得到a good C++ book並學習C++。

ETA既然你拿出你的編輯,你試圖調用一個不存在的.LengthStringArray變量遍歷它在一個for循環...

MSDN文檔的LB_ADDSTRING什麼消息讓你認爲它會接受std::stringstd::string不是以NULL結尾的字符數組。你爲什麼認爲你可以將一列std::string投射到LPARAM

你想要的是更象:(我還沒有編譯的代碼)

typedef std::vector<std::string> string_vec; 
const string_vec StringArray{"10", "20", "30", "40", "50", "60", "70"}; 

for(const auto & s : StringArray) 
{ 
    SendMessage(h, LB_ADDSTRING, DROPDOWN1, (LPARAM)(s.c_str())); 
} 

Range-based for

注:這是現代C++,不是古老的,過時的VC++ 6.