读书人

vector,该怎么解决

发布时间: 2013-01-01 14:04:19 作者: rapoo

vector
HubertButton是我自定的按
HB, HBT, HBTT三有
但HBs致程式停止作
有甚解法和甚?


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_HREDRAW|CS_VREDRAW|CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL,
MAKEINTRESOURCE(IDR_MAINMENU), PARENT_CLASS_NAME , NULL };
WNDCLASSEX wcc = { sizeof(WNDCLASSEX), CS_HREDRAW|CS_VREDRAW|CS_OWNDC, ChildMsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL,
NULL, CHILD_CLASS_NAME , NULL };
RegisterClassEx(&wc);
RegisterClassEx(&wcc);

HWND g_hWnd = CreateWindow(PARENT_CLASS_NAME, L"Title", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600,
GetDesktopWindow(), NULL, wc.hInstance, NULL);
HWND hWnd = CreateWindow(CHILD_CLASS_NAME, L"----", WS_CHILDWINDOW|WS_THICKFRAME|WS_CAPTION|WS_VSCROLL,
486, 0, 300, 400, g_hWnd, NULL, wcc.hInstance, NULL);

ShowWindow(g_hWnd, SW_SHOWDEFAULT);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(g_hWnd);
UpdateWindow(hWnd);
HubertButton HB, HBT, HBTT;
HB.Create(L"HB", g_hWnd, 0, 0, 64, 16);
HBT.Create(L"HBT", g_hWnd, 0, 36, 64, 16);
HBTT.Create(L"HBT", g_hWnd, 64, 36, 64, 16);
LPWSTR btnName[3] = { L"one", L"two", L"three" };
int btnWidth[] = { 32 };
vector<HubertButton> HBs;
HubertButton bufButton;
for (int i=0; i<3;i++)
{
HBs.push_back(bufButton);
HBs[i].Create(btnName[i], hWnd, i*btnWidth[0], 0, btnWidth[0], 16);
}
MSG msg;
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
UnregisterClass(PARENT_CLASS_NAME, wc.hInstance);
UnregisterClass(CHILD_CLASS_NAME, wc.hInstance);
return 0;
}

[解决办法]
我记得Vector不支持下标直接访问的。
1.用迭代器iterator
2.用list好了,这个能
[解决办法]
vector请用iterator
[解决办法]
vector<HubertButton*> HBs;
HubertButton pbufButton;
for (int i=0; i<3;i++)
{
pbufButton = new HubertButton;
HBs.push_back(bufButton);
HBs[i]->Create(btnName[i], hWnd, i*btnWidth[0], 0, btnWidth[0], 16);
}
试试.

读书人网 >VC/MFC

热点推荐