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
720 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 123
Socket Programming (Unix) 8 160
Android development question 2 108
How to determine if the result of an equation is an integer in C++? 3 32
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…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 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