Solved

ScrollBar controls outside MainWndProc

Posted on 1997-08-26
10
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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 …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 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