Author Topic: Fun with combo boxes  (Read 1740 times)

0 Members and 1 Guest are viewing this topic.

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Fun with combo boxes
I'm trying to implement texture replacement in FRED, but I've run into a snag.  I can't populate a combo box with a list of texture names; apparently there's no room (as in memory), even though I'm only adding 5 entries. :doubt: I've committed what I did to the fred2_open branch; what's there works fine and doesn't affect anything else, except for the one bug that's preventing me from proceeding further.

Here's what I'm working on...
Code: [Select]
BOOL CShipTexturesDlg::OnInitDialog()
{
CDialog::OnInitDialog();

int i;
char *p = NULL;
char texture_file[MAX_FILENAME_LEN];

// get our model
polymodel *pm = model_get(Ships[self_ship].modelnum);

// empty old and new fields
for (i=0; i {
*old_texture_name[i] = 0;
*new_texture_name[i] = 0;
}

// set option button
((CButton *) GetDlgItem(IDC_REGULAR_REPLACE))->SetCheck(1);

// set up pointer to combo box
m_old_texture_box = (CComboBox *) GetDlgItem(IDC_OLD_TEXTURE);

// look for textures to populate the combo box
m_old_texture_box->ResetContent();

for (i=0; in_textures; i++)
{
// get texture file name
bm_get_filename(pm->original_textures[i], texture_file);

// skip blank textures
if (!strlen(texture_file))
continue;

// get rid of file extension
p = strchr( texture_file, '.' );
if ( p )
{
mprintf(( "ignoring extension on file '%s'\n", texture_file ));
*p = 0;
}

// now add it to the box
[b]m_old_texture_box->AddString(texture_file);[/b]

// and the field as well
strcpy(old_texture_name[i], texture_file);
}

return TRUE;  // return TRUE unless you set the focus to a control
             // EXCEPTION: OCX Property Pages should return FALSE
}


The problem area is bolded.  AddString simply isn't adding anything.  Can anyone figure out what I'm doing wrong?

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
:wtf: that should be working...
it's basicly thae same thing I do but with more code in between, are you sure the string has a null terminator... it should, but just a thought

this is what I tipicaly do
Code: [Select]
texture_select.ResetContent();
for(int i = 0; inum_textures; i++){
menu.Format("(%d) %s",i ,(CString)p_TXTR->tex_filename[i]);
texture_select.AddString(menu);
}
texture_select.SetCurSel(cur_tex);

texture_select being a combo box
menu being a CString

run it through the debugger and see if everything is what you think it should be, that useualy finds stuff for me
sorry I'm not more helpfull
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
I did some more testing.  It seems that the lines are in fact being added to the combo box, but for some reason they're not being displayed.  It looks like the combo box is only displaying the last item in the list.

The revised version...

Code: [Select]
BOOL CShipTexturesDlg::OnInitDialog()
{
int i, z;
char *p = NULL;
char texture_file[MAX_FILENAME_LEN];
CComboBox *box;

// get our model
polymodel *pm = model_get(Ships[self_ship].modelnum);

// empty old and new fields
for (i=0; i {
*old_texture_name[i] = 0;
*new_texture_name[i] = 0;
}

// set option button
((CButton *) GetDlgItem(IDC_REGULAR_REPLACE))->SetCheck(1);

// set up pointer to combo box
box = (CComboBox *) GetDlgItem(IDC_OLD_TEXTURE);
box->ResetContent();

// look for textures to populate the combo box
for (i=0; in_textures; i++)
{
// get texture file name
bm_get_filename(pm->original_textures[i], texture_file);

// skip blank textures
if (!strlen(texture_file))
continue;

// get rid of file extension
p = strchr( texture_file, '.' );
if ( p )
{
mprintf(( "ignoring extension on file '%s'\n", texture_file ));
*p = 0;
}

// now add it to the box
z = box->AddString(texture_file);

// and the field as well
strcpy(old_texture_name[i], texture_file);
}
box->SetCurSel(0);

CDialog::OnInitDialog();
UpdateData(FALSE);

return TRUE;  // return TRUE unless you set the focus to a control
             // EXCEPTION: OCX Property Pages should return FALSE
}

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Ugh.  Well, the problem now becomes easier but slightly different.  It seems that the box contained all the values after all, because you can arrow up or down and see your choices.  But, when you hit the down arrow, you can't see the rest of the list.  How do I fix that?

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Well, as is often the case, if it doesn't work, take it apart and do it again. :doubt: Now it works. :)