combobox reacts strangely to a mouse

This is a discussion on combobox reacts strangely to a mouse within the Windows Programming forums, part of the Platform Specific Boards category; I have made a combobox in a simple dialog like this Code: CONTROL "", IDCOMBO, "ComboBox", WS_BORDER|CBS_DROPDOWNLIST|CBS_HASSTRINGS|WS_VSCROLL|CBS_SORT , 28, 28, ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    76

    Unhappy combobox reacts strangely to a mouse

    I have made a combobox in a simple dialog like this

    Code:
    CONTROL "", IDCOMBO, "ComboBox", WS_BORDER|CBS_DROPDOWNLIST|CBS_HASSTRINGS|WS_VSCROLL|CBS_SORT , 28, 28, 84,300
    I have added a couple of options to it, and i can select them with the keyboard.
    However, when i click with a mouse on the combobox i get an empty dropdownbox which does not react to mouseclicks. I have to use the keyboard to make the options visible and to select one.

    this is the command handling procedure (or whatever it is called):
    Code:
    BOOL CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	HWND hParent = GetParent(hwnd);	
    	HWND hBut;
    	RECT rectParent;
    	RECT rectBut;
    	HWND hStatus = GetDlgItem(hwnd, ID_TEX_STATUS); 
    	int i;
    	GetClientRect(hParent,&rectParent);
        switch(msg)
        {
    		case WM_INITDIALOG:
    			 
    			SendMessage(GetDlgItem(hwnd,IDCOMBO),  CB_RESETCONTENT ,0,0);
    			EnableWindow(GetDlgItem(hwnd, IDCOMBO), false);
    			EnableWindow(GetDlgItem(hwnd, IDCOMBO), true); 
    			SendMessage(GetDlgItem(hwnd,IDCOMBO),  CB_ADDSTRING ,0,(LPARAM)"option1");
    			SendMessage(GetDlgItem(hwnd,IDCOMBO),  CB_ADDSTRING ,0,(LPARAM)"option2");
    			SendMessage(GetDlgItem(hwnd,IDCOMBO),  CB_ADDSTRING ,0,(LPARAM)"option3");
    			SendMessage(GetDlgItem(hwnd, IDCOMBO),CB_SELECTSTRING,(WPARAM)-1,(LPARAM)"option3");
                return true;
    		break;
    		case WM_MOVE:
                return true;
    		break;
            case WM_CLOSE:
                PostQuitMessage(WM_QUIT);
                return true;
            break;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
    				case ID_BUT_GO:
    
    					SendMessage(GetDlgItem(hwnd, IDCOMBO),CB_SELECTSTRING,(WPARAM)-1,(LPARAM)"option1"); 
    					SendMessage(hStatus,WM_SETTEXT,(WPARAM)NULL,(LPARAM) "blablabla");		 
    					return true;
    				break;
    				case ID_BUT_EXIT:
    					
    					PostQuitMessage(WM_QUIT);
    					return true;
    				break;	
    				case IDCOMBO:
    					//MessageBox(hwnd, "combo is used", "WARNING",MB_OK | MB_ICONEXCLAMATION);
    					return true;
    				break;
                    default:
                    return false;
                }
            break;
            default:
            return false;
        }
        return false;
    }

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You should probably check for a CBN_SELCHANGE notification.

    Try something like:
    Code:
    case WM_COMMAND:
      {
      HWND hCntrl;
      WORD wID,wNotify;
    
      hCntrl=(HWND)lParam;
      wID=LOWORD(wParam);
      wNotify=HIWORD(wParam):
      
      if (hCntrl)
        {
        /*message is for/from control*/
        if (CBN_SELCHANGE==wNotify)
          {
          /*combobox selection has changed*/
          }
        }
      }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    76
    I found a solution to my problem but i havent got a clue why this works.

    Instead of using CreateDialog i used DialogBox and now it works.
    If somebody knows why a combobox does NOT work with CreateDialog but does work with DialogBox i would really like to hear it.

    @ken, i dont exactly understand what u mean, but do u think that could cause the difference in usage of CreateDialog / DialogBox?
    I mean there is no way i can get a working combobox on a dialog which is created with CreateDialog.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need Help in Mouse Pointer
    By obaid in forum C++ Programming
    Replies: 3
    Last Post: 12-07-2006, 02:33 AM
  2. Problem in mouse position
    By Arangol in forum Game Programming
    Replies: 6
    Last Post: 08-08-2006, 07:07 AM
  3. Making a mouse hover button, API style
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 05-27-2004, 06:17 AM
  4. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM
  5. Mouse in 800x600 24Bit Mode?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-11-2001, 12:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21