Announcement

Collapse
No announcement yet.

ComboBox odd behavior

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ComboBox odd behavior

    I have a dialog that creates a Combobox as part of its controls.

    I want to process the result of the user choosing a diffrent item. When I use the ID in CBCTL the processing is done MULTIPLE times???

    Also the this ID in CBCTL is called after I open a dialog box and the user selects a file. Why?

    Here is the bare bones in an example:
    (the show btn shows the number of times the ID is called.

    #COMPILE EXE "Combo.exe" ' Combo problem example
    #INCLUDE "WIN32API.INC" ' Win API definitions

    GLOBAL Called AS LONG
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
    CALLBACK FUNCTION MainCB() AS LONG

    SELECT CASE CBMSG
    CASE %WM_INITDIALOG
    COMBOBOX ADD CBHNDL, 99, " CME 08:30 to 15:15"
    COMBOBOX ADD CBHNDL, 99, " CBOT 08:30 to 15:15"
    COMBOBOX ADD CBHNDL, 99, " NASDAQ 09:30 to 16:00"
    COMBOBOX ADD CBHNDL, 99, " NYSE 09:30 to 16:00"
    COMBOBOX ADD CBHNDL, 99, " AMEX 09:30 to 16:00"
    COMBOBOX SELECT CBHNDL, 99, 1
    END SELECT

    SELECT CASE CBCTL
    CASE 99
    INCR called
    'I want to CALL a function to process the ComboBox choice ONCE here
    CASE 103
    CONTROL SET TEXT CBHNDL, 114, " "+STR$(Called)
    Called = 0
    CASE 104 ' Quit
    DIALOG END CBHNDL
    END SELECT
    END FUNCTION

    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
    FUNCTION PBMAIN
    LOCAL hDlg AS LONG
    DIALOG NEW 0, " example", 230, 60, 110, 159, 0 TO hDlg
    CONTROL ADD COMBOBOX,hDlg, 99, , 4, 1, 102, 150, %CBS_DROPDOWNLIST
    CONTROL ADD FRAME, hDlg, 100, "", 4, 13, 102, 93
    CONTROL ADD FRAME, hDlg, 105, "", 4, 116, 102, 24
    CONTROL ADD BUTTON, hDlg, 103, "Show", 35, 123, 40, 14, 0
    CONTROL ADD BUTTON, hDlg, 104, "Quit", 5, 145, 100, 12, 1
    CONTROL ADD LABEL, hDlg, 114, " ", 2, 108, 109, 12, 0
    DIALOG SHOW MODAL hDlg CALL MainCB
    END FUNCTION



    ------------------
    Kind Regards
    Mike

  • #2
    Mike,

    I think your SELECT CASE CBCTL structure should be
    encapsulated inside a %WM_COMMAND case for the CBMSG structure.



    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

    Comment


    • #3
      Not just that, but Mike should check the type of notification message for the control you are responding to... ie, test the value of CBCTLMSG. For example, you will likely be getting "UPDATE" and "CHANGE" messages, and responding to each one without regard to the context of the event.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        so what am I looking for? What does the combobox send when the user makes a selection?
        I only want it to call my function once, and I cont want it to call my function at any other time which it seems to be doing now.


        Is this what i need:

        SELECT CASE %WM_COMMAND
        SELECT CASE CBCTL
        CASE 99
        IF LOWRD(CBCTLMSG) = %CBN_SELENDOK THEN
        INCR called
        'CALL a function to process the ComboBox choice ONCE here
        end if

        it seems to work but is it right?


        ------------------
        Kind Regards
        Mike

        Comment


        • #5
          Out of interest, can you tell us the purpose of the "SHOW" button?

          If that is the "action" key (for the user to actually do something after making a selection in the combo), you would get the selection(s) from the combobox and process them when the SHOW button is clicked. However, your questions suggest you are doing something when a selection is made in addition to when the SHOW button is clicked.

          Basically, when a selection is make (and especially if the combo has an edit control), you'll receive a series of messages from the combobox control. These notification messages are documented in MSDN and most good API programming books.

          Therefore I have to ask... have you read the section on ComboBoxes in WIN32.HLP? It also outlines the notification messages a combobox generates and sends to the parent window/dialog callback function (WNDPROC) depending on the kind of user interraction event that occurred.


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment

          Working...
          X