Jump to content
  • Advertisement
Sign in to follow this  
Zeke

Win32, Combobox and GetItemData/SetItemData

This topic is 4777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

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);
}


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?

Share this post


Link to post
Share on other sites
Advertisement
try something like storing your modes somewhere (a std:vector, maybe) and store the mode's index in the combo box item.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!