Ok I have a data structure as follows
I have a dialog box with a combo box which wants to use values in this structure. On the dialog init I load up this data structure from a data file as followsCode:typedef struct { char ConstructionName[20]; }Constructions;
I then loop through the elements and populate the comboBox as followsCode:char * pConstructionArchive; int j; Constructions* pConstructionData = new Constructions; //Load the data ifstream file("constructions.dat", ios::in|ios::binary); file.seekg (0, ios::end); int size = file.tellg(); file.seekg(0,ios::beg); pConstructionArchive = new char [size]; file.read (pConstructionArchive, size); file.close(); long * header = reinterpret_cast<long *>(&pConstructionArchive[0]); long ConstructionSig = header[0]; long NumConstructions = header[2]; long ConDataStart = header[3]; char * pConDataArchive = &pConstructionArchive[ConDataStart];
Finally I have an on selection change as followsCode:if(NumConstructions>0) { for (j=0;j<NumConstructions;j++) { char * pHeaderLocation; pHeaderLocation = &pConDataArchive[(j*20)]; memcpy(pConstructionData->ConstructionName, pHeaderLocation,20); intIndex = m_addFabricConstruction.AddString(pConstructionData->ConstructionName); m_addFabricConstruction.SetItemData(intIndex,(DWORD)pConstructionData); } } //set the appropriate one as current selection m_addFabricConstruction.SetCurSel(0);
Now the problem is that no matter what I change the value in the comboBox to I get the same value for result. Stepping through the debugger it seems that intIndex gets stuck at 2 and never increments anymore.. I am wondering if its that or something else I am doing wrong..Code:void CAddFabric::OnCbnSelchangeFabricConstruction() { //Get the current value se we can write new data to file int nCurSel = m_addFabricConstruction.GetCurSel(); CString result = (LPCSTR)m_addFabricConstruction.GetItemData(nCurSel); }
Thanks for any advice...Andrew




Reply With Quote