Solved

ScrollBar controls outside MainWndProc

Posted on 1997-08-26
10
239 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
Comment Utility
how do you put your scroll bat into the main window?
0
 
LVL 4

Expert Comment

by:davmarc
Comment Utility
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
Comment Utility
Thank you davmarc. A hook is probably what I am looking for, but how do I create a hook?
0
 
LVL 2

Author Comment

by:obg
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Author Comment

by:obg
Comment Utility
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
Comment Utility
I finally discovered that SetWindowLong contains a much easier way of intercepting messages...
0
 
LVL 4

Expert Comment

by:davmarc
Comment Utility
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
Comment Utility
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
Comment Utility
What you've done is actually "subclassing" a window :-)

Davide Marcato.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now