Hey, I can't figure what is wrong with this part of my program. I know that it has something to do with that my variable i is exceeding the vector boundaries but I can't figure out how to stop it. I try to make the program exit before the vector goes beyond it's boundaries, but it's just not working for some reason. Here's the code:
int i = 0;
int numright = 0;
int rw = 0;
vector<string> wrong;
BOOL CALLBACK DlgProcqw2(HWND hwndqw2, UINT Messageqw2,WPARAM wParamqw2, LPARAM lParamqw2)
{
string word = rEngV[i];
HWND handle = GetDlgItem(hwndqw2, IDC_VIEW);
SetWindowText(handle, word.c_str());
switch(Messageqw2)
{
case WM_INITDIALOG:
{
g_hbmB = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_B));
g_hbmR = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_R));
g_hbmW = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_W));
if(g_hbmR == NULL || g_hbmW == NULL)
MessageBox(hwndqw2, "Could not load IDB_R or IDB_W!", "Error", MB_OK |MB_ICONEXCLAMATION);
}
case WM_PAINT:
{
BITMAP bm;
PAINTSTRUCT ps;
if(rw == 0)
{
HDC hdc = BeginPaint(hwndqw2, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject (hdcMem, g_hbmB);
GetObject(g_hbmB, sizeof(bm), &bm);
BitBlt(hdc, 34, 90, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwndqw2, &ps);
}
if(rw == 1)
{
HDC hdc = BeginPaint(hwndqw2, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject (hdcMem, g_hbmR);
GetObject(g_hbmR, sizeof(bm), &bm);
BitBlt(hdc, 34, 90, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwndqw2, &ps);
}
if(rw == 2)
{
HDC hdc = BeginPaint(hwndqw2, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject (hdcMem, g_hbmW);
GetObject(g_hbmW, sizeof(bm), &bm);
BitBlt(hdc, 34, 90, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwndqw2, &ps);
}
}
break;
case WM_COMMAND:
switch(LOWORD(wParamqw2))
{
case IDC_OKQW:
{
char text[255] = {0};
GetDlgItemText(hwndqw2, IDC_ANSQW, text, sizeof(text));
string span = text;
string span2 = rSpnV[i];
if(span == span2)
{
rw = 1;
++numright;
}
else
{
rw = 2;
wrong.push_back(word);
}
if (i == rEngV.size())
{
EndDialog(hwndqw2, 0);
hwndGotoqw2 = NULL;
}
else
++i;
InvalidateRect(hwndqw2, NULL, true);
}
break;
}
break;