void COptionsDlg::InitAdapterModeCombo()
{
HWND hWndModeList=GetDlgItem(m_hDlg,IDC_ADAPTERMODES);
int iModes=m_d3d->GetDevice()->GetAdapterModeCount(D3DADAPTER_DEFAULT);
if(iModes)
{
int x;
for(x=0;x<iModes;x++)
{
D3DDISPLAYMODE mode=new D3DDISPLAYMODE;
m_d3d->GetDevice()->EnumAdapterModes(D3DADAPTER_DEFAULT,x,mode);
char modebuf[128]={0};
_snprintf(modebuf,sizeof modebuf,"%ldx%ld",m_AdapterModes[x].Width,m_AdapterModes[x].Height);
SendMessage(hWndModeList,CB_ADDSTRING,0,(LPARAM)modebuf);
SendMessage(hWndModeList,CB_SETITEMDATA,x,(LPARAM)mode);
//the following line gives me the correct D3DDISPLAYMODE
D3DDISPLAYMODE* mode2=(D3DDISPLAYMODE*)SendMessage(hWndModeList,CB_GETITEMDATA,x,0);
}
SendMessage(hWndModeList,CB_SETCURSEL,0,0);
}
//the following gives me a NULL pointer
D3DDISPLAYMODE* mode2=(D3DDISPLAYMODE*)SendMessage(hWndModeList,CB_GETITEMDATA,0,0);
}
Win32, Combobox and GetItemData/SetItemData
Hi there,
I am trying to store a ptr to a D3DDISPLAYMODE in the data portion of a combo box item. The following code snippet will best describe my problem.
I dont understand why as soon as I set the data I can retrieve it but once I am out of that loop it returns me a NULL pointer.
Does anyone have any idea's?
try something like storing your modes somewhere (a std:vector, maybe) and store the mode's index in the combo box item.
The buffer, modebuf goes out of scope and gets returned to the stack to be used by the next proc that comes along. You can solve it by declaring data on the heap ( remembering to clean it up afterwards) or have some form of global string manager.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement