Sign in to follow this  
shadowisadog

WinAPI need to thread standard scrollbar control

Recommended Posts

Hello everyone :). I am developing a scrollbar plugin for a software program, and I need to be able to run the WinProc for the scrollbar control window (standard Windows API) on a seperate thread, however I am unsure how to go about doing this. Becuase I don't have access to the program's source code, I can't multithread the program logic itself. Currently if I try to use my scrollbar, then my application pauses. Anyone know how to go about doing this? Thanks :).

Share this post


Link to post
Share on other sites
Every thread needs its own message pump. A HWND expects its message to be sent in the thread it was created in. So it's not enough to simply move your WindowProc in another thread.

You have to

A) also create the window in that thread and
B) pump messages in that thread as well

Share this post


Link to post
Share on other sites
Thanks for the help, so if I say make a thread, and in the init function create my window, then the winproc will be threaded? Is there anything special that I need to do in order to my winproc?

Thanks again.

Share this post


Link to post
Share on other sites
Splitting window messages for controls on a single window across multiple threads is bad practice. Doing any threading whatsoever on a program whose source you cannot access and check for safety is extremely bad practice, due to the extremely high likelihood of introducing deadlocks, race conditions, and other very bad side-effects of ad hoc multithreaded code. Threading is a very dangerous and sensitive beast, and you absolutely have to plan carefully for it from square one, or it will bite you.

Why exactly do you need this in a separate thread? There's probably a much cleaner way to accomplish what you need...

Share this post


Link to post
Share on other sites
Ok. I am making a scrollbar control for an authorware program. Currently when I use the scrollbar, everything else on the window pauses while the scrollbar is in use. I need to make it so that the Scrollbar can run at the same time as the other code. I thought threads were the only way to do this, but I could be wrong. If you have any other suggestions please share them :).

Thanks!

Share this post


Link to post
Share on other sites
What else is on the window? What is it doing that "pauses" when your scrollbar is being used? How are you adding the scrollbar to the window in the first place? (I don't know what "authorware" is, unless you're referring to the Macromedia product, so that might be a good thing to describe as well.)

Most pertinently: does this other program continue working as expected after your scrollbar is no longer used?

Share this post


Link to post
Share on other sites
Ok, this program is a game creation program from www.clickteam.com. This program allows you to make games and such using a "visual" style interface.

Now, this software program has an SDK and I use CreateWindowEx. Basically the main program uses a loop that causes the instructions to be executed, however this is paused when the scrollbar is used. However the application works fine when the scrollbar is no longer being scrolled.

Currently the problem is that without the "events" being executed at the same time as the scrollbar, the scrollbar control is useless. It only updates the window and such after the scrollbar has scrolled, and it stops all movement, ect on the window.

I have searched for ways around this, and so far I have been a bit empty handed. Any ideas?

Thanks :).

Share this post


Link to post
Share on other sites
Sorry, but you're going to have to start from the very beginning. At this point I have no idea what you're doing.

What context are you writing code in? Is your code running in the same process and thread space as the "game?" Are you trying to inject controls onto the game's window, or the game-creator itself? What's the purpose of this entire project?

Also, as I asked before, what exactly is "getting paused" that you want to be running while the scroll bar is "in use?" And what does "in use" mean, anyways?


You really need to provide some actual details and information, or there's not much anyone can do to help you.

Share this post


Link to post
Share on other sites
Would I be correct in assuming that, when you hold the left mouse button down on the scroll bar, no window messages are getting processed by your main loop until the mouse button is released?

Share this post


Link to post
Share on other sites
Hey, sorry if I am a bit vague. I will try to explain from the start.

There is a program called Multimedia Fusion that can make games, and applications.It runs using something called "Events" which are put together using an event editor (It is a drag and drop style of programming). While this language isn't very powerful, it is quick to develop with. The events are processed one after another, in one thread, however events can be triggered by extensions or the program and these are called "Triggered Conditions".


This program has a software development kit, that gives you access to the main window, and allows you to do surface operations, ect. You can retrieve the window handle of the main window with this SDK, and make your own actions, conditions, and expressions (that return a value).

Currently the program has no Scrollbar control, and so I set off to create one. Now, the problem is that it appears that when the scrollbar is being scrolled, the events don't seem to be executed. The reason for this is unclear, although I think the problem is that the events are paused while the message is being processed.

My code is ran on the same process as the events, and this is what must be causing the problem.

Thanks for the help, I hope it is possible to work around this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nitage
Would I be correct in assuming that, when you hold the left mouse button down on the scroll bar, no window messages are getting processed by your main loop until the mouse button is released?


It appears that way.

Share this post


Link to post
Share on other sites
How do you do the scrolling while the user is using the scrollbar?

this might be completely wrong.. but it could be something like this.. =)

My guess is that the user clicks the scrollbar, then a message is sent to the WndProc, now your scrollbar starts handling the scrolling.
This is done constantly until the user releases the mouse button, and the WndProc doesn't return until this happens. Therefore every other messages is queued and not handled until the scrolling is completed.
If you want to allow the program to handle other messages during this scrolling you need to return from the WndProc right away after the user clicks it, then you need to handle new messages you get when the mouse moves, and do one scroll-step and then return again, and when the users releases the mouse button then you stop scrolling on mouse moved messages.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this