Link to home
Start Free TrialLog in
Avatar of markgilmore
markgilmore

asked on

Linking code to LISTBOX

Using straight calls to GetClassInfoEx (to get LISTBOX
class info, RegisterClassEx (to create class linking
to my WndProc_Main), and CreateWindow, I am unable to
load the list with any data using
SendMessage(..LB_ADDSTRING..) calls.
No errors are returned.
If I pass "LISTBOX" as the Class in the CreateWindow
call (for test purposes), everything works.
I have also tried DefDlgProc (instead of DefWindowProc)
in WndProc_Main() to no avail.
FYI:I am a very experienced pgmer, but new to Windows
(I may be missing something "obvious").
I have a very small "working" example for anyone
interested.
Avatar of Tommy Hui
Tommy Hui

Using RegisterClassEx is designed for new window classes you intend to use within the context of your program. It does not let you subclass or superclass any existing window classes. The major problem is the wndproc associated with the window class. Since the wndproc is nothing but a pointer, the pointer is invalid in your case because the wndproc points to a non-valid function. So if you want to use a listbox, you will need to create the wndow with the LISTBOX classname, otherwise it won't work.
Avatar of markgilmore

ASKER

I guess I understand that I must use the LISTBOX class for
it to work. What I am missing is how to link my code
(WndProc_Main or anything else) TO the LISTBOX so that
I can monitor its status (like user selections, etc).
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
After rereading your comment I'm beginning to wonder if I missundestood you.  Are you just trying to use an ordinary listbox and get you main window procedure you know what is happening in the list box?  That is, what is find out what is highlighted, etc.  If so, you don't need to sub-class or super-class the list box window.  Just use an ordinary list box.  The window that owns the list box (or other windows) can comunicate with the listbox using messsages.  

For example, you can send the LB_CURSEL to get the index of the currently highlighted item.  You can use LB_GETTEXT to get the text of a specified item, etc.  There are a bunch of "LB_" messages you can use, depending on what you need to do.

If you want to be notified when things happen in the list box, like when the highlight changes, your main window (the owner window of the list box, to be precise) will receive messages notifying it of changes.  The LBN_SELCHANGE is send to the owner when the selection (highlight) is changed.  The LBN_DBLCLCK is send when the user double clicks an item in the list box.  There are other notification messages sent as well, all begin with "LBN_".