Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

CComboBox

shinsnakeshinsnake Member Posts: 93
CComboBox Combo1;
RECT monthsListRect;
monthsListRect.left = 50;
monthsListRect.top = 57.14;
monthsListRect.right = 175;
monthsListRect.bottom = 77.14;
unsigned int IDC_SSN = 1.0;
Combo1.Create(WS_VISIBLE | CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL |
WS_BORDER |WS_VSCROLL,monthsListRect,this,IDC_SSN);

Combo1.SetWindowText("November");
Combo1.AddString("January");
Combo1.AddString("February");
Combo1.AddString("March");
Combo1.AddString("April");
Combo1.AddString("May");
Combo1.AddString("June");
Combo1.AddString("July");
Combo1.AddString("August");
Combo1.AddString("September");
Combo1.AddString("October");
Combo1.AddString("November");
Combo1.AddString("December");


I'm using Visual C++ 6 and the MFC executable wizard, and when I put this code in OnDraw(), I get a flickerging rectangle with nothing inside. I know why I'm getting a flickering rectangle, I am always updating OnDraw(), but I can't get any dropdown box at all. Just a flickering rectangle. Can anyone help?

Comments

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : CComboBox Combo1;
    : RECT monthsListRect;
    : monthsListRect.left = 50;
    : monthsListRect.top = [red]57.14[/red];
    : monthsListRect.right = 175;
    : monthsListRect.bottom = [red]77.14[/red];
    : unsigned int IDC_SSN = 1.0;
    : Combo1.Create(WS_VISIBLE | CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL |
    : WS_BORDER |WS_VSCROLL,monthsListRect,this,IDC_SSN);
    :
    : Combo1.SetWindowText("November");
    : Combo1.AddString("January");
    : Combo1.AddString("February");
    : Combo1.AddString("March");
    : Combo1.AddString("April");
    : Combo1.AddString("May");
    : Combo1.AddString("June");
    : Combo1.AddString("July");
    : Combo1.AddString("August");
    : Combo1.AddString("September");
    : Combo1.AddString("October");
    : Combo1.AddString("November");
    : Combo1.AddString("December");
    :
    :
    : I'm using Visual C++ 6 and the MFC executable wizard, and when I put this code in OnDraw(), I get a flickerging rectangle with nothing inside. I know why I'm getting a flickering rectangle, I am always updating OnDraw(), but I can't get any dropdown box at all. Just a flickering rectangle. Can anyone help?
    :
    :
    [blue]Top and bottom of the rect different only by 20 units - you did not give some room for an opening down list - add 60 more units to the bottom side.[/blue]
  • shinsnakeshinsnake Member Posts: 93
    [blue]Top and bottom of the rect different only by 20 units - you did not give some room for an opening down list - add 60 more units to the bottom side.[/blue]


    ASM again to save the day. I tried to increase the size but it still just flickers. It doesn't show the drop down box arrow or even a box, just a white rectangle that flickers. Did I use the wrong flags? Should I call it somewhere else besides in OnDraw() because it keeps updating? I tried, but it just does nothing then.
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : [blue]Top and bottom of the rect different only by 20 units - you did not give some room for an opening down list - add 60 more units to the bottom side.[/blue]
    :
    :
    : ASM again to save the day. I tried to increase the size but it still just flickers. It doesn't show the drop down box arrow or even a box, just a white rectangle that flickers. Did I use the wrong flags? Should I call it somewhere else besides in OnDraw() because it keeps updating? I tried, but it just does nothing then.
    :
    [blue]
    Well, I missed something: try to add WS_CHILD style to the 'Create()' call.[/blue]

  • shinsnakeshinsnake Member Posts: 93
    I tried adding the WS_CHILD style flag in the create call. It was still just a flickering rectangle. I need to keep it in the OnDraw() function because it is only drawn a certain time.

    Say I do this. Say I define a new class strictly for the combo box. How would I call this function in OnDraw()? Say, I added MonthsList.cpp and MonthsList.h to my program through the class wizard. Could I do that and call it from OnDraw(), and how do I do that?

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : I tried adding the WS_CHILD style flag in the create call. It was still just a flickering rectangle. I need to keep it in the OnDraw() function because it is only drawn a certain time.
    :
    : Say I do this. Say I define a new class strictly for the combo box. How would I call this function in OnDraw()? Say, I added MonthsList.cpp and MonthsList.h to my program through the class wizard. Could I do that and call it from OnDraw(), and how do I do that?
    :
    :
    You want to say that you call Create() INSIDE OnDraw() somewhere????
    That is wrong. All child creation supposed to happen inside OnCreate() of the parent.

  • shinsnakeshinsnake Member Posts: 93
    Now if I only want to display this box whenever the user selects the option, then how do I hide it and draw it only when I need it?

  • risingforcerisingforce Member Posts: 1
    : Now if I only want to display this box whenever the user selects the option, then how do I hide it and draw it only when I need it?
    :
    :
    OK
    That is very easy.
    You must create global combo box in your class and every time you need to hide and
    Show your box you use this function.

    ShowWindow(int nCmdShow // show state);

    Whit this argument SW_SHOW or SW_HIDE

    For example:
    Define CComboBox Combo1; in your class;
    Then create your combobox in OnCreate() and
    On every section of your program you can use
    Combo1.ShowWindow(SW_SHOW); for Showing and
    Combo1.ShowWindow(SW_HIDE); for Hides the combo box

    Yours truly,


  • shinsnakeshinsnake Member Posts: 93
    Thanks guys. I haven't completely got it working, but that at least put me on the right track. Thanks.

  • rlcrlc Member Posts: 448
    Well if you haven't got your list to display try the following technique:

    [code]
    //create dropdown list box
    cboMonths.Create (WS_CHILD | WS_VISIBLE | LBS_NOTIFY
    | CBS_DROPDOWNLIST | CBS_SORT,
    CRect (CPoint(80,45),CSize(100,120)),
    this , IDC_CBO_MONTHS);

    //add items with the following code
    int idx;
    idx= cboMonths.AddString ("January");
    cboMonths.SetItemData(idx, 1000);
    idx= cboMonths.AddString ("Feb");
    cboMonths.SetItemData(idx, 1001);
    //etc...
    [/code]

    ~rlc
Sign In or Register to comment.