Solved

I have used AddString to add elements to a combobox in a dialog box, but he list isn't displayed

Posted on 1998-10-11
4
717 Views
Last Modified: 2012-08-13
Hi again...

I'm programming an application based on a dialog box. That dialog box is a resource. I have on the dialog a Combobox which I fill with strings using AddString method. It seems that it works, because when I run the application.. the elements are on the list (pressing up or down arrow keys, the elements are displayed one by one), but when I press on the combobox arrow, the list isn't dropped down.

The million question... How can I do it? I'm programming in BC++ 5.0.
Thanks in advance

Jaime

Here's my application:

#include <owl\pch.h>
#include <owl\applicat.h>
#include <owl\combobox.h>
#include <owl\dialog.h>
#include <owl\framewin.h>
#include "Clusters.h"

class TClusterDlg : public TDialog
{
  public:
    TClusterDlg( TWindow* parent, const char far* name );

    void UpdateDialog( );

  protected:
    TComboBox* DiskList;

    void SetupWindow( );

  DECLARE_RESPONSE_TABLE( TClusterDlg );
};

DEFINE_RESPONSE_TABLE1( TClusterDlg, TDialog )
  EV_COMMAND( IDOK, CmOk ),
END_RESPONSE_TABLE;

TClusterDlg::TClusterDlg( TWindow* parent, const char far* name ) :
                          TDialog( parent, name ), TWindow( parent )
{
  DiskList = new TComboBox( this, IDC_DRIVES );
}

void TClusterDlg::SetupWindow( )
{
  char Discos[80];
  UINT StringPos = 0, TipoDisco;

  TDialog::SetupWindow( );
  /* Borra los datos a desplegar en el cuadro de diálogo */
  SetDlgItemText( IDC_NUMBYTES, "" );
  SetDlgItemText( IDC_NUMFILES, "" );
  SetDlgItemText( IDC_BYTES, "" );
  SetDlgItemText( IDC_PORCENTAJE, "" );
  SetDlgItemText( IDC_CLUSTERSIZE, "" );
  /* Obtiene las unidades de disco disponibles */
  GetLogicalDriveStrings( 78, Discos );
  while( Discos[StringPos] ) {
    /* Obtiene que tipo de disco es */
    TipoDisco = GetDriveType( &Discos[StringPos] );
    if( TipoDisco == DRIVE_FIXED || TipoDisco == DRIVE_REMOVABLE ) {
      /* Llena el combobox de discos si es disco duro o diskette */
      DiskList->AddString( &Discos[StringPos] );
    }
    StringPos += 4;
  }
}

void TClusterDlg::UpdateDialog( )
{

}

class TClusterApplication : public TApplication
{
  public:
    TClusterApplication( ) : TApplication( "Desperdicio de clusters App" ) {}

    void InitMainWindow( )
    {
      EnableCtl3d( );
      Dialog = new TClusterDlg( 0, "ClusterDlg" );
      MainWindow = new TFrameWindow( 0, "Desperdicio de Clusters", Dialog, TRUE );
      MainWindow->SetIcon( this, "ClusterDlg" );
      MainWindow->Attr.Style &= ~(WS_MAXIMIZEBOX|WS_THICKFRAME);
    }

  private:
    TClusterDlg* Dialog;
};

int OwlMain( int /*argc*/, char * /*argv*/ [] )
{
  return TClusterApplication( ).Run( );
}
0
Comment
Question by:demarcy
  • 2
4 Comments
 

Accepted Solution

by:
clance earned 50 total points
ID: 1174862
The problem is that your combo box has the same height opened as it does closed.  You change its height in the resource file (MyApp.rc).  Examine the following example:

BEGIN
    COMBOBOX        IDC_MY_CBO,360,161,157,118,CBS_DROPDOWNLIST |
                    WS_VSCROLL | WS_TABSTOP
END

The numbers represent in order upper-left corner X, upper-left corner Y, width, and height.  Increase the height and you increase the size of the drop down portion.

If you need to do this programmatically, I believe you'd have to make your combo box an owner draw and handle messages yourself.  However, I can't imagine why anyone would want or need to do that.

Hope that answers your question.

-- Craig

0
 

Expert Comment

by:KCN
ID: 1174863
In dialog editor,you can click the drop down box on the right of the combo box.The rectangle of control will extension to the area after droping down.Then you can adjust it.
0
 

Author Comment

by:demarcy
ID: 1174864
Thanks.. that worked.... now... how can I notify the application that the combobox has changed its value? that is, how can I define an event for the combobox.

Thanks again in advance
Jaime
0
 

Expert Comment

by:clance
ID: 1174865
Well, here's the rub.  You're using Borland's OWL.  I use Microsoft's MFC ClassWizard.  So, I cannot tell you the easy OWL way of doing this.  However, I can tell you how to find it.

Given my example of having a combo box identifier IDC_MY_CBO, I can tell MFC's ClassWizard to map the CBN_SELCHANGE windows message to my IDC_MY_CBO combo box.  ClassWizard makes an empty function named OnSelchangeMyCBO().  I'm sure Borland has something similar to ClassWizard.

But, the key here is to look up the CBN_SELCHANGE windows message.  Regardless of what brand compiler, what application framework you are using, and whether you use C or C++, when the current selection has changed a CBN_SELCHANGE message will be sent to the dialog box that has the combo box as a control (unless you make your combo box an owner-draw control, but that's another story).
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question