Solved

ScrollBar controls outside MainWndProc

Posted on 1997-08-26
10
244 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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