Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
738 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 150 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

876 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