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
711 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now