Link to home
Start Free TrialLog in
Avatar of Aggarwal
Aggarwal

asked on

syncronize scroll bars

hello ,

suppose i'm having any windows app. running say Word running . then my application starts .now the requirement is ..when ever document in first app. ( word in our case ) is scrolled ..my app. also srcolls by same area .

please help !!!!

Thanks in advance ..

regards ,
aggarwal

ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One more thing.  Personal experience shows that system-level hooks are almost non-debuggable.  Prepare for lots of aggravation...
Avatar of Aggarwal
Aggarwal

ASKER

thanks for the info .

current status :

i installed WH_SYSMSGFILTER ..

i tried using WH_GETMESSAGE ..but its not catching any SCROLL msg. its recieving WM_PAINT msg ..but not scroll ..

using WH_SYSMSGFILTER ...i'm getting there is something happening with the Scroll bar as nCode = MSGH_SCROLLBAR .. now the problem is getting the scroll info ..like nPos , nTrackPos , nMin , nMax ..

i tried using lParam of the msg to get lpsi( LPSCROLLINFO) ..its not working ..

can u please help me !!!

regards ,
aggarwal

lparam is a pointer to an MSG structure.  Try the something like following (not tested):

MSG* pMsg = (MSG*)lparam;
if ((pMsg->hwnd == /* handle to the desired scrollbar */) &&
    (pMsg->message == SBM_SETSCROLLINFO))
{
    SCROLLINFO* pInfo =  (SCROLLINFO*)pMsg->lParam;
    // Do the rest...
}

If you cannot make it work, try the WH_CALLWNDPROC or WH_CALLWNDPROCRET filters.  However they will waste more CPU so I'll suggest you do your best to stick with WH_SYSMSGFILTER.

One more suggestion, try writing a *local* WH_MSGFILTER hook with a test application.  It is easier to debug and you can "graduate" to a sustemwide WH_SYSMSGFILTER when things work OK.

WH_GETMESSAGE is for *posted* messages.  Scrollbar messages are *sent*.

i have tested this ..

MSG* pMsg = (MSG*)lparam;
if ((pMsg->hwnd == /* handle to the desired scrollbar */) && 
    (pMsg->message == SBM_SETSCROLLINFO))
{
    SCROLLINFO* pInfo =  (SCROLLINFO*)pMsg->lParam;
    // Do the rest...
}

same code i have already tried ..no use ..it doesn't recieve this "SBM_SETSCROLLINFO" msg.

anyways ..i'll try other suggestions and post here .

thanks a lot

regards ,
aggarwal

WH_CALLWNDPROC or WH_CALLWNDPROCRET will catch this message (guaranteed!).  More overhead though so the hook proc needs to be as efficient as possible.
yeah WH_CALLWNDPROC  is catching this message , now i got nPos , nMin , nMax basically LPSCROLLINFO , now i need to apply that information to my app. scroll bar ..

any suggestions .

thanks
aggarwal
You need to transfer the info to your application.  Easiest way is to keep the handle to your app's window in the DLL (in a shared section!) and send (or post) it a message from inside the hook.  Just remember that sent messages may be also caught by your hook so take care to avoid an infinite loop.

When your app receives the message, it can adjust your scrollbars according to the received info.

One thing to remember is not to pass pointers between different address spaces.  It *may* work but it can also crash the target app (or just pass wrong data).  You can use WM_COPYDATA for safe copying.
hello ,

now in my application i got all the information regarding scrollbar of the other app.

basically in my app. i got lpsi , and scrollbar handle ..

now i need to apply in my application ..now i need ur help ..

my app. is MFC application ..derived from CScrollView ..nothing added to the app. ritenow ..how to apply this information ..as i dun know size of the doc.

please help me ..

regards ,
aggarwal
>> my app. is MFC application
Sorry Aggarwal, I can't help you with MFC.

>> as i dun know size of the doc.
Well, you can query the "original" scrollbar.
SBM_GETSCROLLINFO sounds right but you can also try SBM_GETRANGE.
Or, if you prefer the functions: GetScrollInfo() and GetScrollRange().
thanks !!!