Solved

ScrollBar controls outside MainWndProc

Posted on 1997-08-26
10
242 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
A short film showing how OnPage and Connectwise integration works.

943 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

3 Experts available now in Live!

Get 1:1 Help Now