Solved

ScrollBar controls outside MainWndProc

Posted on 1997-08-26
10
248 Views
Last Modified: 2013-12-03
I have created scrollbar controls inside a window that actually does not belong to me (from a DLL). The problem is that I can't catch the messages (WM_HSCROLL and WM_VSCROLL). As far as I know, they end up in the main window process, which is out of my control. It responds with something like "Unknown exception..."

Is there any way to create a separate window process for the scrollbars, though they are children to the other window? I guess they have to be children, or...? How else should I solve this? - Please, help!!!

I don't know how much this could be worth... It ought to be fairly easy, but regarding windows programming - what is? I'll give you 100 points for it, anyway. Thanks in advance.
0
Comment
Question by:obg
  • 5
  • 4
10 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1404869
how do you put your scroll bat into the main window?
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1404870
The problem is that you must get your handling code into main window's process context - a hook is probably what you are looking for.

Davide Marcato.
0
 
LVL 2

Author Comment

by:obg
ID: 1404871
Thank you davmarc. A hook is probably what I am looking for, but how do I create a hook?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 2

Author Comment

by:obg
ID: 1404872
I use the following to create the horizontal scrollbar:
hHScroll = CreateWindow("SCROLLBAR", NULL, WS_CHILD | WS_VISIBLE
                        | SBS_HORZ | SBS_BOTTOMALIGN, r.left,
                        r.top, r.right - r.left - iHThumb,
                        r.bottom - r.top, hWnd, (HMENU)10,
                        hInst, NULL);
SetScrollRange(hHScroll, SB_CTL, 0, 100, FALSE);
... as proposed in MSDN.
0
 
LVL 4

Accepted Solution

by:
davmarc earned 50 total points
ID: 1404873
The API to use to create hooks is:

HHOOK SetWindowsHookEx(
int idHook, // type of hook to install
HOOKPROC lpfn, // address of hook procedure
HINSTANCE hMod, // handle of application instance
DWORD dwThreadId // identity of thread to install hook for
);

Check it out in the documentation for more info...in any case you must put your code in a DLL to let it be mapped into the other process context. Use UnhookWindowsHookEx() to remove the hook.

A great source of info about how&why using hooks and subclassing to interfer with other apps (in Win32) is the book "Advanced Windows" by Jeff Richter. It even has a whole chapter on that topic.
An SDK sample on how to install system hooks is HOOKS

Davide Marcato.
0
 
LVL 2

Author Comment

by:obg
ID: 1404874
Thanks for your answer. I haven't fully tried it yet, but I think I can get it to work.
0
 
LVL 2

Author Comment

by:obg
ID: 1404875
I finally discovered that SetWindowLong contains a much easier way of intercepting messages...
0
 
LVL 4

Expert Comment

by:davmarc
ID: 1404876
You used SetWindowLong() to subclass the control?
You must have another window procedure to handle the messages anyway, so I don't think it's that much easier.

Davide Marcato.
0
 
LVL 2

Author Comment

by:obg
ID: 1404877
Well, I don't know about "subclassing". All I did was:

OldWndProc = SetWindowLong(hWnd, GWL_WNDPROC, NewWndProc);

and then I ended the NewWndProc by calling OldWndProc, if the message wasn't WM_HSCROLL or WM_VSCROLL. Could it be simpler? I found it much simpler than my hooking (?) efforts. :-)

0
 
LVL 4

Expert Comment

by:davmarc
ID: 1404878
What you've done is actually "subclassing" a window :-)

Davide Marcato.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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