- Help with Creating a listbox
- Posted by JoeC on April 24th, 2007
I am trying to create a list box for a dialog box and I don;t have
good documentation or an example on how to do this.
I simply want to be able to choose from one to four players. How
would I write the script to create the box. Then I want the choice to
set an int to that number and create that number of players. A simple
example please this is what I have so far:
CTEXT "Number Of Players",IDC_STATIC,0,85,230,30
LISTBOX IDC_LIST,120,100,60,30, LBS_NOTIFY | WS_POPUP | WS_VSCROLL
| WS_GROUP | LBS_MULTIPLESEL
BEGIN
// what tags to use here for the items?
END
END
- Posted by homer on April 25th, 2007
JoeC wrote:
Everything is in MSDN with many complete samples.
- Posted by r_z_aret@pen_fact.com on April 25th, 2007
On 24 Apr 2007 16:41:50 -0700, JoeC <enki034@yahoo.com> wrote:
This is where a good, basic, book on Windows programming is useful.
The usual recommendation is Petzold (or Petzold and Boling). I prefer
Rector & Newcomer.
I leave these out. So does Petzold in my copy of his book. We both use
LB_ADDSTRING messages (actually, I use the wrapper defined in
windowsx.h).
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
- Posted by Vitor on April 25th, 2007
homer wrote:
OK, I did some searches and hadn't found that. Post a Link?
Using a different program because google crapped out on me.
- Posted by Vitor on April 25th, 2007
r_z_aret@pen_fact.com wrote:
I have Petzolds book but didn't have listboxes, I will look a gain on
how to create one. Don't see listbox in the index. I did find it in
the book but it is for the main window and dosn't expalin the script for
a dialog box. Usually they are not done the same but I will what I can
dig up.
Thanks, I only have petzol's book and I will see if I can find somthing
that helps.
- Posted by Larry Lindstrom on April 25th, 2007
JoeC wrote:
Hi JoeC:
First, I use the Resource Editor to lay out my dialogs, so I
don't have to mess with creating the control's window. I'm not
sure what I'm looking at, is that text from an RC file? I don't
usually manipulate my .rc file directly, so I'm unfamiliar with
their internals. I'm looking at my current project's .rc file
and I'm having trouble synching a dialog that has a listbox with
what I'm looking at in your post.
One thing that catches my eye is "WS_POPUP". Controls in my
dialogs aren't popups. But then the listbox, and other controls
in the dialog, in my .rc file, are defined inside the BEGIN END
pair.
If this is a .rc file, where did it come from? There are
brave souls who write their own .rc files, but you need to know
what you are doing. It's easy, fast, and reliable to let the
Resource Editor do this for you.
Robert E. Zaret is one of the few people I know of who write
their own .rc files.
In Petzold's "Programming Windows Fifth Edition", in chapter 9,
"Child Window Controls", on page 401, he has a section on the
listbox class. I haven't looked at it, but there might be
something interesting there.
If you are going to do Windows programming, I'd suggest
bookmarking the following:
http://msdn2.microsoft.com/en-gb/library/ms649776.aspx
This is a page that describes individual controls. Look at
the index in the left frame and select the control you are
interested in.
The List Box Controls selection will give you a wealth of
information on using them. I prefer the list box to the list
view.
Another hint. Create the list box, then use:
SendMessage(listbox_handle, LB_ADDSTRING...)
to add the strings, and perhaps parameters, that make up the
items in the list box, in the list box's setup function.
I hope this helps.
Larry
- Posted by r_z_aret@pen_fact.com on April 26th, 2007
On Wed, 25 Apr 2007 10:54:52 -0400, r_z_aret@pen_fact.com wrote:
Oops. Make that Petzold and Yao.
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
- Posted by r_z_aret@pen_fact.com on April 26th, 2007
On Wed, 25 Apr 2007 14:59:41 -0500, Vitor <vitor@comienet.ve.com>
wrote:
In my copy of "Programming Windows 95" by Charles Petzold (I haven't
bothered to get any newer version), the index lists "list box
controls" and that points to a section called "The Listbox Class" in
the chapter called "Child Windows Controls". That section shows some
snippets of resource scripts. A subsection called "Putting Strings in
the List Box" starts "After you've created the list box, the next step
is to put text strings in it. You do this by sending messages to the
list box window procedure .."
My copy of "Win32 Programming" by Rector and Newcomer has a more
detailed description of list boxes (such detail is why I prefer this
book). It also uses messages to add text.
Using messages to add text works for me, Petzold, Rector, and
Newcomer. Why are you so intent on adding them within the resource
script?
A related question. Are you sure you want to use list boxes, rather
than list views?
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
- Posted by JoeC on April 26th, 2007
Larry Lindstrom wrote:
Thanks, this is exactly what I am looking for. I found what I need.
This is often a great resource but at times, I have trouble finding
it. I do have a version of VC++ and I used it to get the correct
command for my dialog box. I need a combo box not a list box. Still
thanks for pointing me in right direction.
- Posted by Vitor on April 26th, 2007
r_z_aret@pen_fact.com wrote:
been looking in as many resources as I can and would like get some help
with where I am now.
extern int numPlayers;
BOOL CALLBACK newProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){
HWND hwndEdit;
char str[4];
str[0] = '1';
str[1] = '2';
str[2] = '3';
str[3] = '4';
switch(msg){
case WM_CREATE:
for(int lp = 0; lp != 4; lp++){
SendMessage(hwnd, LB_ADDSTRING, lp, (LPARAM) str[lp]);
}
break;
I just want to put the numbers 1-4 in the box later I will see if I can
get to recognize the selection then how to return the results to
numPlayers; That is later but for now I am trying to get the string or
chars in the box:
CTEXT "Number Of Players",IDC_STATIC,0,85,230,30
COMBOBOX IDC_LIST,110,95,35,30,CBS_DROPDOWN | CBS_SORT | WS_TABSTOP
END
Are there any other things I need to define in the resources like a case
for each slecetion such as #define ID_ONEPLR?
I am sorry the book is very confusing and what I am putting in is not
working.
- Posted by Scott McPhillips [MVP] on April 27th, 2007
Vitor wrote:
Those are characters, not strings. A string must end with a nul, which
is provided by the "x" syntax, not 'x' syntax.
Also, you appear to be sending a list box message (LB_ADDSTRING) to a
combo box.
Also, you are sending some number lp in wparam, but that message does
not use wparam.
Also, it appears that you are using the dialog's hwnd, not the control's
hwnd.
All in all, it looks like your knowledge is not yet up to doing this.
If you have the Petzold book work the examples to get a better
understanding of the basics.
--
Scott McPhillips [VC++ MVP]
- Posted by JoeC on April 27th, 2007
On Apr 26, 10:55 pm, "Scott McPhillips [MVP]" <org-dot-mvps-at-
scottmcp> wrote:
I am new at this although I have created other boxes with buttons
strings and radio buttons, this is a challenge. It turns out that I
need a combo box not a list box. I can't find any good examples, I
may have to settle for radio buttons because I can do them.
- Posted by homer on April 27th, 2007
JoeC wrote:
You even didn't search...
A kid could find tons of samples in a few seconds.
MSDN has plenty of samples
http://msdn.microsoft.com/library/de...comboboxes.asp
- Posted by Scott McPhillips [MVP] on April 27th, 2007
JoeC wrote:
Do you have Visual C++? (There is a free "express" edition available
for download.) It lets you create dialogs by dragging and dropping
controls from a toolbar instead of writing .rc script. If you really
want to write .rc script for some reason then you can do the drag/drop
in a test project and copy from the resulting .rc file.
--
Scott McPhillips [VC++ MVP]
- Posted by JoeC on April 27th, 2007
On Apr 27, 7:38 am, "Scott McPhillips [MVP]" <org-dot-mvps-at-
scottmcp> wrote:
I do that some times then I just copy the fine over to DEV C++. I
found my problem. I created the same thing with radio buttons but I
found out I have a very simple error that was messing up my program.
I had linked to the wrong proc file and nothing I was doing worked. I
might go back later and see if I can't do the combo box.