Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linking code to LISTBOX

Posted on 1997-11-28
4
Medium Priority
?
275 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:markgilmore
[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
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1408959
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.
0
 

Author Comment

by:markgilmore
ID: 1408960
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).
0
 
LVL 22

Accepted Solution

by:
nietod earned 150 total points
ID: 1408961
I hate to do dissagree with Thui, since I don't think he makes mistakes, but I think he (or maybe me) missunderstood something here.

Assume whatyou are trying to do mark is to start with the standard windows list window and to midify it slightly.  This is done by "super-classing".  You write a window procedure that handles a few messages differently and then passes anything it does not treat differently on to the original procedure.  

Your technique sounded right.  You get the window information with GetClassInfoEx() and you record the pointer to the window procedure specified there (Despite what Thui said (this makes me nervous), this is a valid pointer to a Windows DLL procedure.)
next you register a new listbox window class.  You specify the same information to RegisterClassEx as you obtained from the GetClassInfoEx.  Except you change the window procedure pointer to point to your "list window procedure".  (You can also make some little changes like increasing the window or class extra size, changing brushes, cursors etc, be careful though)

Now you "list window procedure" can look at any messages it want to, modify them if desired, handle them if desired and them pass any messages it wants (most messages) on to the original window procedure.  Note you don't call the DefaultWindowProc() or the default dialog procedure.  You call the procedure that was registered with the list window (it will (eventually) call the default window procedure for most messages).

Note that you will have at least two window procedures in your program.  The list window procedure will not be the same as you main window's window procedure.
Then you specify a pointer to youthe
0
 
LVL 22

Expert Comment

by:nietod
ID: 1408962
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_".
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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