Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CreateWindow

Posted on 1997-08-03
10
Medium Priority
?
2,877 Views
Last Modified: 2013-12-03
When using CreateWindow , the first classname could be like "button" or "static". When using the "listbox" it should be able to make a drop down listbox..
How do i fill this listbox with variables ?
How do i get the ID of what i clicked on ?
I want a small example to try on and i want some small comments.
It should be written in c .. Perhaps a little switch statement ?

Thanks in advance Abbe
0
Comment
Question by:superabbe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1402782
Normally, you can send messages to manipulate the listbox, for example, SendMessage(handle,LB_ADDSTRING,0,"some string")

To get the selection, just send LB_GETCURSEL to the listbox with wparam and lparam of 0, the return value is the index of the selected item

0
 

Author Comment

by:superabbe
ID: 1402783
Where is the example ?
I Asked for a small example ...

Not a complete program but enough to show how it could be used in a real program
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1402784
you are talking about a drop down "listbox".
are you meaning a drop down "combobox" ?
it is a static area above a popup list using an arrow
button ?

In that case, you can take a look at the WIN32\FONTVIEW
VC++ sample and the TOOLS.C file


If you are looking for real plain listboxes, here are some
good VC++ samples :
   WIN32\PRINTER   enumport.c, getcaps.c
   WIN32\TTFONTS   dialog.c
   WIN32\REGISTRY  monkey.c

0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 4

Expert Comment

by:AVaulin
ID: 1402785
If you are use MSVC see SAMPLES\SDK\WIN32\FONTVIEW example. If no give me your e-mail and I'll send it to you.
Good luck.
0
 

Author Comment

by:superabbe
ID: 1402786
...Using bc5
faster was on the right way..
What i'm calling a listbox is a dropdown combobox

now is 300 points for a nice example..
0
 
LVL 4

Accepted Solution

by:
davmarc earned 990 total points
ID: 1402787
The following is some sample code that should help you. I am writing it by hand without a compiler so I couldn't test it, but I hope you'll be able to make a sense of it. It has comments and some error handling.

/* Declare a static handle for the combo window in the beginning of the source file */
static HWND hMyComboCtrl = NULL;

/* Create the dropdown combobox */
BOOL CreateMyComboCtrl()
{
    if (hMyComboCtrl)
        return TRUE; /* Already created - resource leak proof */

   /* Replace the params between -- */
   hMyComboCtrl = CreateWindow("COMBOBOX", --WindowNameStr--, --styleFlags--, --xPos--, --yPos--, --width--, --height--, --hParentWnd--, NULL, --hInstance--, --lpParam--);

    if (hMyComboCtrl)
        return TRUE;
    else
        return FALSE;
}

/* To add items */
BOOL InitializeMyComboCtrl()
{
    assert(hMyComboCtrl);  /* Check if the handle is valid */

    LRESULT result = 0;
    result |= SendMessage(hMyComboCtrl, LB_ADDSTRING, 0, "item1text");
    result |= SendMessage(hMyComboCtrl, LB_ADDSTRING, 0, "item2text");
    result |= SendMessage(hMyComboCtrl, LB_ADDSTRING, 0, "item3text");

    if (result == LB_ERR || result == LB_ERRSPACE)
        return FALSE; /* If any error occurred, return FALSE */
    else
        return TRUE;
}

int GetMyComboCtrlCurSel()
{
    assert(hMyComboCtrl);  /* Check if the handle is valid */

    return SendMessage(hMyComboCtrl, LB_GETCURSEL, 0, 0);
}

By the way, where are the 300 points? I still see only 200 :)

Davide Marcato.
0
 

Author Comment

by:superabbe
ID: 1402788
Hmmm good answer but i need a little bit more ...
The listbox style params which should i use ?
and the final argumet in createwindow lparam havent figure out
how to get it to work...
The |= operator , how does that one work ?

I get the listbox visible but i just cant get the """items""" into it...

Oh by the way is the points 320 and now it must be right or the pointsystem is out of order :)
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1402789
Let's begin from the last question: no the points are not even 320 - they are 330 if my human viewsystem is still working well :-)

Combobox style: since you want a dropdown combo with a static control showing the currently selected item, I suggest to use CBS_DROPDOWNLIST. I cannot say anything about other combobox-specific and general window styles because I don't have enough info about what you want, anyway the documentation explains them pretty well. In any case, you'll probably want to apply also the window styles WS_VISIBLE and WS_CHILD.

lparam: it is used to pass a pointer to a structure (CREATESTRUCT) that contains creation parameters to the windowproc of the created window. The handling code for WM_CREATE receives a pointer to this structure and can do some initialization if desired.
You don't need to set this parameter in your case - just pass NULL.

operator |= : sintactically the following statements are equivalent:
a = a | b;
a |= b;
Since "|" is the bit-wise OR operator and since the no-error condition in SendMessage() is represented by 0 return value, ORing the return values of 3 subsequent function calls is a compact and readable way to know if *any* of the calls returned an error with only one test in the end!

Hope this answer is exaustive enough...

Davide Marcato.
0
 

Author Comment

by:superabbe
ID: 1402790
Now it seems to work ...
It was nice to see someone that read the whole question before answering.
Abbe
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1402791
:-)
Glad it works now!

Davide Marcato.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question