John your insight has led to a proper solution to the problem. I disabled the WM_ACTIVE message block and and then duplicated the WM_INITDIALOG code as I think I mentioned above.
Then by trail and error I just turned on and off a variety of functions in that code until I could get it to the minimum needed to run correctly. I added a return statement to the WM_INITDIALOG block too so this code only runs once. I think before it just dropped through the switch statement on init and into the WM_ACTIVE block because I removed the return.
Anyways....to cut a long story short it ran properly when the function setResolution was run twice. I'll post the original below:
Code:
void setResolution(HWND hDlg)
{
D3DObj.mComboResData.clear();
D3DClass::resData _resData;
int j = 0;
for (int i = 0; i < D3DObj.mResolutionPair.size(); i += 4)
{
_resData.w = D3DObj.mResolutionPair[i];
_resData.h = D3DObj.mResolutionPair[i + 1];
_resData.Hz = (double)(D3DObj.mResolutionPair[i + 2]) / D3DObj.mResolutionPair[i + 3];
std::wstring _resolution = std::to_wstring(_resData.w) +
L" x " + std::to_wstring(_resData.h);
const WCHAR* resolution = _resolution.c_str();
D3DObj.mComboResData.push_back(_resData);
WPARAM nI = (WPARAM)SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING, (WPARAM)0, (LPARAM)resolution);
SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETITEMDATA, (WPARAM)nI, (LPARAM) & (D3DObj.mComboResData[j])); // change nI variable to 0 and it works (for first entry)
j++;
#ifdef SKIP // change to _DEBUG to display
std::wstring _string = std::to_wstring(_resData.w) + L" "
+ std::to_wstring(_resData.h) + L"\n"
+ std::to_wstring(_resData.Hz) + L"\n"
+ std::to_wstring(nI) + L"\n\n"; // may as well print nI, too
OutputDebugString(_string.c_str());
#endif
}
return;
}
I wrote a duplicate of it called pingCombo which I used to replace the first call to setRefresh. Then I cannibalised everything in it down to the bare minimum to get it to work. I even noticed if I messed with the iterator size in the for loop it would affect whether or not it worked. Confusing but I knew I was still getting close.
Well....turns out I needed to completely fill out the mComboResData vector before running the for loop which uses the indexing for the combo box data stuff. Here's the new version of setResolution:
(note the new for loop at the top)
Code:
void setResolution(HWND hDlg)
{
D3DObj.mComboResData.clear();
D3DClass::resData _resData;
int j = 0;
for (int i = 0; i < D3DObj.mResolutionPair.size(); i += 4)
{
D3DObj.mComboResData.push_back(_resData);
}
for (int i = 0; i < D3DObj.mResolutionPair.size(); i += 4)
{
_resData.w = D3DObj.mResolutionPair[i];
_resData.h = D3DObj.mResolutionPair[i + 1];
_resData.Hz = (double)(D3DObj.mResolutionPair[i + 2]) / D3DObj.mResolutionPair[i + 3];
std::wstring _resolution = std::to_wstring(_resData.w) +
L" x " + std::to_wstring(_resData.h);
const WCHAR* resolution = _resolution.c_str();
D3DObj.mComboResData[j] = _resData;
WPARAM nI = (WPARAM)SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING, (WPARAM)0, (LPARAM)resolution);
SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETITEMDATA, (WPARAM)nI, (LPARAM) & (D3DObj.mComboResData[j])); // change nI variable to 0 and it works (for first entry)
j++;
#ifdef SKIP // change to _DEBUG to display
std::wstring _string = std::to_wstring(_resData.w) + L" "
+ std::to_wstring(_resData.h) + L"\n"
+ std::to_wstring(_resData.Hz) + L"\n"
+ std::to_wstring(nI) + L"\n\n"; // may as well print nI, too
OutputDebugString(_string.c_str());
#endif
}
return;
}
And that finally...is it. The struct resData is defined in the separate class with initialized variables, so this way of filling up the vector doesn't throw any errors. Then it's just a case of using the typical array indexing on the vector rather than push_back function and that's the end of the matter.
I still don't know exactly why this works but it's obviously the cause and now there are no longer any issues with the indexing, and the code doesn't have to run twice to work.
If anyone can mop up that last little mystery of why this works that would be most helpful.
Thanks