Skip to main content
GameDev.net gamedev.net
🔒 Locked

Please Help Me La!

Started by wah_on_2 Dec 3, 2001 at 4:57 AM 13 replies 500+ views
Original Post
wah_on_2
wah_on_2
How to use multithread in C++? Can write a very very simple program?
invective
invective
C++ does not have multithreading support built into the language like java does, so multithreading is a platform specific issue. If you are using windows, use CreateThread().

see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/prothred_3mgj.asp?frame=true
http://www.flipcode.com/tutorials/tut_mthreading.shtml
wah_on_2
wah_on_2
oic. Thank You!

On the other hand, i designed an own button, i want it can handle its event.

If i new the button object in program, it can get the user input and then process it automatically. Is it use multithreading to do? I mean that the button will create a thread and capture the user input continously.

Or use another method?
NuffSaid
NuffSaid
To the anon, it isn''t very nice to make fun of somebody else''s command of English. And besides, it should be "My English not very good lar. You all speaking English so good wan. Use Delphi lah". You need to decorate your sentences with lar/lah(s) and wan(s). Man, get your Manglish/Chinglish right.

Okay, now the serious bit.

If you want to handle button clicks, you''ll need to handle the WM_COMMAND message (or use the ON_COMMAND macro if you''re using MFC). As for the rest of your question, I think you''re wanting to create a thread when the button is clicked? Or something else entirely?
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
wah_on_2
wah_on_2
Thx for your reply sin. ^^

My question is that: I want to create a own button class. When WinMain create the button object, a new thread was start. The thread will capture windows message until match a specific input. I don''t want to use MFC.

Can i write that?

//in WinMain
MyOwnButton button(); //button thread is start now
for(;
GetMessage(&msg, NULL ,0 ,0);
.....handle message..

//in the second thread (Button thread)
for(;
GetMessage(&msg, NULL ,0 ,0);
.....handle message...
ShawnO
ShawnO
Generally, in a Windows program, there will be one thread to process all of the events in the GUI. If an event triggers a time consuming job, a worker thread can be spawned to work in the background while the user interface thread goes back to handling user interface events.
Are you planning to have both threads try to get messages from the same message queue. I don''t think that would be a good idea.
I can''t tell what you are trying to do, but are you sure you need a separate thread just for the button?

Shawn
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.
ShawnO
ShawnO
I still can''t tell what you are trying to do, but I still don''t think a separate thread is the answer.
User interaction with your custom control should happen in the main UI thread.
If you are creating an animated control you could create a separate thread to handle the animation, but you could probably animate a control just as easily from the main UI thread.

Shawn
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.
Arild Fines
Arild Fines
Who is La?

Psalm 137:9: "Happy shall he be, that taketh and dasheth thy little ones against the stones."
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
wah_on_2
wah_on_2
To: ShawnO
I hear you said that main UI thread.

Is it mean create a new thread for handle all the events of different windows control(button, textbox....)?
wah_on_2
wah_on_2
To Arild Fines: "La" is not a person, it is just a word to enhance the tone.
ShawnO
ShawnO
quote:
Original post by wah_on_2
To: ShawnO
I hear you said that main UI thread.

Is it mean create a new thread for handle all the events of different windows control(button, textbox....)?


No.
In a typical Windows program WinMain() is the entry point of your program. Your program will register a window class, create the window, create controls, make the window visible, and then enter a loop calling GetMessage() or PeekMessage(). The loop will then dispatch the message to the WindowProc() of the appropriate window. Usually, all events are handled this way. If a user clicks on a button control on a window, the main message loop will get the event and dispatch it to the WindowProc() for the appropriate window.
The thread that executed WinMain() is typically used as the UI thread, handling all events for the UI. If you need to perform some time consuming work in response to a UI event, you can create a thread to do that work in the background, and allow your main thread to return to processing UI events.
What kind of custom control are you trying to create? Are you subclassing an existing control?

Shawn
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.