How do I add strings to the combo box

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1909 Views - Last Post: 16 January 2012 - 07:45 PM Rate Topic: -----

#1 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

How do I add strings to the combo box

Posted 16 January 2012 - 05:06 PM

Consider this code
#include <Windows.h>
#include "resource.h"
#include <string>

HWND dWnd;

BOOL CALLBACK
	WndProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	char txt[300];
	static HWND hEditBox = 0;
	static HWND comboBox = 0;
	static HWND button = 0;

	int index;

	switch(msg)
	{
	case WM_INITDIALOG:
		hEditBox = GetDlgItem(hDlg, IDC_EDIT1);
		comboBox = GetDlgItem(hDlg, IDC_COMBO1);
		button = GetDlgItem(hDlg, IDC_BUTTON1);

		SetWindowText(hEditBox, "testing");
		
		return true;
	case WM_COMMAND:
		switch(HIWORD(wParam))
		{
		case CBN_SELENDOK:
		/*	index = SendMessage(comboBox, CB_GETCURSEL, 0, 0);
			SendMessage(comboBox, CB_GETLBTEXT, (WPARAM)index, (LPARAM)txt);
			MessageBox(0, txt, "combo", MB_OK);*/
			return true;
		}
		switch(LOWORD(wParam))
		{
		case IDC_BUTTON1:
			GetWindowText(hEditBox, txt, 300);

			if(strlen(txt) > 0)
			{
				SendMessage(comboBox, CB_ADDSTRING, 0, (LPARAM)txt);
			}
			return true;
		}
		return true;
	case WM_CLOSE:
		DestroyWindow(hDlg);
		return true;
	case WM_DESTROY:
		PostQuitMessage(0);
		return true;
	}

	return false;
}
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd)
{
	dWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), 0, WndProc);

	if(dWnd == 0)
	{
		MessageBox(0, "Window Fail", "Error", MB_OK);
		return -1;
	}

	ShowWindow(dWnd, showCmd);

	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	while(GetMessage(&msg, 0,0,0))
	{
		if(dWnd == 0 || !IsDialogMessage(dWnd, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int)msg.wParam;
}



When I run it it seems that the Combo Box is not connected to anything. And when i hit the button the text in the Edit box is not transferred to the combo box.

What is wrong with my code (in relation to this problem)?

Thanks,
Dartos

Is This A Good Question/Topic? 0
  • +

Replies To: How do I add strings to the combo box

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:19 PM

Does GetWindowText get any text? What number does CB_ADDSTRING return?
Was This Post Helpful? 0
  • +
  • -

#3 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:25 PM

ADDSTRING returns 0 and the text is properly loaded. Its strange.
Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:35 PM

Did you size your combo dropdown correctly? send it a message - CB_SETITEMHEIGHT

No wait, that isn't the one... wait a min..

In your dialog editor, set the height of the combobox, otherwise you won't see the dropdown

This post has been edited by GunnerInc: 16 January 2012 - 05:33 PM

Was This Post Helpful? 0
  • +
  • -

#5 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:40 PM

Or what kind of combo box? If it is a SimpleCombo, it won't have a dropdown list, you have to press the up or down keys to scroll through the list.
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1325
  • View blog
  • Posts: 4,551
  • Joined: 19-February 09

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:42 PM

When creating a dialog do you not need a second callback procedure?

This post has been edited by #define: 16 January 2012 - 05:42 PM

Was This Post Helpful? 0
  • +
  • -

#7 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:46 PM

No, if you have 5 dialogs, you can create one callback proc and have all 5 dialogs use that one callback if you wanted to.
Was This Post Helpful? 1
  • +
  • -

#8 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:49 PM

You only need a second function if you have a normal window. My program is made of a dialog window. Also the box has height and im not sure if its simple or not. I am using ResEdit and it has only 1 combo box option
Was This Post Helpful? 2
  • +
  • -

#9 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:55 PM

The menu works if i use the arrow keys but it doesn't drop down. What option denotes whether it is simple or not.

I just looked and it says its type is dropdown

This post has been edited by dartoscoder: 16 January 2012 - 05:56 PM

Was This Post Helpful? 0
  • +
  • -

#10 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:56 PM

Really, one option?Attached Image
Was This Post Helpful? 0
  • +
  • -

#11 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:57 PM

by one option i meant in the list of all the boxes and buttons
Was This Post Helpful? 0
  • +
  • -

#12 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do I add strings to the combo box

Posted 16 January 2012 - 05:58 PM

You want a Drop LIst
Was This Post Helpful? 0
  • +
  • -

#13 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: How do I add strings to the combo box

Posted 16 January 2012 - 06:06 PM

I tried that too :( no dice
Was This Post Helpful? 0
  • +
  • -

#14 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: How do I add strings to the combo box

Posted 16 January 2012 - 06:18 PM

For shits and giggles in case IDC_BUTTON1: try this:

hEditBox = GetDlgItem(hDlg, IDC_EDIT1);
GetWindowText(hEditBox, txt, 300);

SendMessage(comboBox, CB_ADDSTRING, 0, (LPARAM)txt);
comboBox = GetDlgItem(hDlg, IDC_COMBO1);

You do know that GetWindowText returns the count of characters it copied into the buffer right? So you don't have to call strlen. Just check that the return from GetWindowText is not 0. That being said, what does GetWindowText return.
Was This Post Helpful? 0
  • +
  • -

#15 dartoscoder  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 313
  • Joined: 15-May 09

Re: How do I add strings to the combo box

Posted 16 January 2012 - 06:40 PM

Nope. Like i said, it works if i press button1 then the down arrow key but the dropdown menu just wont work
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2