Click here to Skip to main content
16,004,833 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: MFC app with iPhone Pin
Albert Holguin24-Mar-12 8:04
professionalAlbert Holguin24-Mar-12 8:04 
QuestionHow to hanle header click & prevent of a list control Pin
Amrit Agr23-Mar-12 1:52
Amrit Agr23-Mar-12 1:52 
QuestionRe: How to hanle header click & prevent of a list control Pin
David Crow23-Mar-12 2:11
David Crow23-Mar-12 2:11 
AnswerRe: How to hanle header click & prevent of a list control Pin
Amrit Agr23-Mar-12 19:20
Amrit Agr23-Mar-12 19:20 
SuggestionRe: How to hanle header click & prevent of a list control Pin
David Crow24-Mar-12 12:29
David Crow24-Mar-12 12:29 
QuestionHow to set focus on an activeX? Pin
Member 875345022-Mar-12 18:48
Member 875345022-Mar-12 18:48 
AnswerRe: How to set focus on an activeX? Pin
Randor 23-Mar-12 7:27
professional Randor 23-Mar-12 7:27 
QuestionSubclassed CListCtrl Pin
David Crow22-Mar-12 11:18
David Crow22-Mar-12 11:18 
With each passing day, I keep feeling like I'm taking 2 steps forward and 1.9 steps backward. I'm not sure what that 0.1 step is telling me, however.

On a dialog, when I right-click a control, I'm wanting to display a list control with images (not bring up a second modal dialog with those images). When an image is selected, or if the list control loses focus, I want it to close. My first go at this was to derive a class from CListCtrl, and display it dynamically. Other variations of this exist on the web, and as a matter of fact I am using some of them elsewhere in my project. The only difference being none of them are derived from CListCtrl. With that in place, the list control displays and I can interact with it. When an item is selected, I get an NM_CLICK notification and can close the list control. The problem is closing the list control when it loses focus, either because I tabbed or mouse-clicked elsewhere. No other messages (e.g., WM_KILLFOCUS, WM_ACTIVATE, WM_LBUTTONUP) are sent during these events, nor is PreTranslateMessage() called.

My second approach was to instead derive a class from CWnd, with a CListCtrl member variable. The window and the list control displays and I can interact with it (I say "it" because the list control completely covers the window). In addition, message handlers such as OnActivate(), OnKillFocus(), and OnLButtonUp now get called as well as PreTranslateMessage(). When and how these get called depend on how SetCapture() is called.

If I call it in the context of the CWnd object, the message handlers get called. When an item in the list control is selected, OnLButtonUp() is called and I can close the list control. The problem is that it is also called when I click the scroll bar. If I call it in the context of the CListCtrl object, some of the message handlers and PreTranslateMessage() get called. Now when an item in the list control is selected, PreTranslateMessage() is called with WM_LBUTTONDOWN and I can close the list control. The problem is that it is also called when I click the scroll bar. Both of these approaches require a little bit of client-to-screen and point-in-rect fiddling, but I *think* it's possible.

At this point, I'm confused as to exactly what I have. Neither approach gets me exactly what I'm after, and I feel like I'm having to put too much code in it to do what is otherwise easy when dealing with a CListCtrl object on a dialog template. I'd much prefer the first approach as it seems a bit cleaner, but I'm not against the second approach if I didn't feel like the "hidden" window was getting in the way.

Having said all of that, am I completely doing something wrong, or just mising some little piece that would sew it all up nicely?

Thanks.

- DC

[edit]
I made a bit of progress today by subclassng both CWnd and CListCtrl (before I was just using a native CListCtrl object). Now I'm able to intercept various messages in the list control class. The list control is opening and closing as expected. So far so good...
[/edit]

"One man's wage rise is another man's price increase." - Harold Wilson

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous



modified 23-Mar-12 12:03pm.

AnswerRe: Subclassed CListCtrl Pin
Jochen Arndt22-Mar-12 22:36
professionalJochen Arndt22-Mar-12 22:36 
GeneralRe: Subclassed CListCtrl Pin
David Crow23-Mar-12 2:09
David Crow23-Mar-12 2:09 
GeneralRe: Subclassed CListCtrl Pin
Jochen Arndt23-Mar-12 2:26
professionalJochen Arndt23-Mar-12 2:26 
QuestionSerial Port / Windows Sockets clash Pin
ad_robot22-Mar-12 2:07
ad_robot22-Mar-12 2:07 
AnswerRe: Serial Port / Windows Sockets clash Pin
Jochen Arndt22-Mar-12 2:55
professionalJochen Arndt22-Mar-12 2:55 
QuestionRe: Serial Port / Windows Sockets clash Pin
ad_robot22-Mar-12 7:39
ad_robot22-Mar-12 7:39 
AnswerRe: Serial Port / Windows Sockets clash Pin
Jochen Arndt22-Mar-12 8:07
professionalJochen Arndt22-Mar-12 8:07 
GeneralRe: Serial Port / Windows Sockets clash Pin
ad_robot22-Mar-12 10:03
ad_robot22-Mar-12 10:03 
GeneralRe: Serial Port / Windows Sockets clash Pin
Jochen Arndt22-Mar-12 21:41
professionalJochen Arndt22-Mar-12 21:41 
GeneralRe: Serial Port / Windows Sockets clash Pin
ad_robot23-Mar-12 2:21
ad_robot23-Mar-12 2:21 
GeneralRe: Serial Port / Windows Sockets clash Pin
Jochen Arndt23-Mar-12 2:43
professionalJochen Arndt23-Mar-12 2:43 
Questiondebug dll not working Pin
appollosputnik21-Mar-12 6:05
appollosputnik21-Mar-12 6:05 
AnswerRe: debug dll not working Pin
Chris Losinger21-Mar-12 6:16
professionalChris Losinger21-Mar-12 6:16 
AnswerRe: debug dll not working Pin
Rajesh R Subramanian21-Mar-12 6:26
professionalRajesh R Subramanian21-Mar-12 6:26 
AnswerRe: debug dll not working Pin
Albert Holguin21-Mar-12 7:43
professionalAlbert Holguin21-Mar-12 7:43 
AnswerRe: debug dll not working Pin
Malli_S21-Mar-12 20:09
Malli_S21-Mar-12 20:09 
AnswerRe: debug dll not working Pin
Stephen Hewitt22-Mar-12 3:41
Stephen Hewitt22-Mar-12 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.