Skip to main content
gamedev.net
🔒 Locked

c++ builder 4

Started by MadProgrammer 5 replies 250+ views
Original Post
MadProgrammer
MadProgrammer
i am using borland c++ builder 4. how can i get into the event loop? i want to be able to use the GUI from builder, but also want to write event-triggered winsock code. bottom line, i need to be notified of custom events. how do i get that to happen?
Hway
Hway

You want to use GUI? As in VCL?

VCL does a pretty good job hiding the event loop from you, but there is a way to do this: threads.

Basically, you create a thread (see CreateThread in win32 api, it''s really not as difficult as it sounds), where all you do is process those events.
~~~ "'impossible' is a word in the dictonary of fools" --Napoleon
MButchers
MButchers
Hi there,

look at

Application->OnIdle and Application->OnMessage

Hope it helps

Mark.
Arild Fines
Arild Fines
Hmm...I think both the above posts failed to hit the mark. I guess what you want to do is provide event handlers for custom window messages? If so, this is the way to do it:
You define a method in your component class to handle the message WM_DIDDELIDOO, lets call it MyMessageHandler. Have it take a single parameter, a reference to a TMessage object:
  
void TMyComponent::MyMessageHandler( TMessage& msg )
{
//do lots of fun stuff in here

}

Of course you have to declare that method in the class declaration. You also need a way to map the message to the appropriate method; this is done with the following macro:

  
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER( WM_DIDDELIDOO, TMessage, MyMessageHandler )
END_MESSAGE_MAP( TComponent )


This is the jist of it, anyway. There is more info on this in the BCB help file, under Creating Custom Components->Handling Messages.

"A society without religion is like a crazed psychopath without a loaded .45"
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
MadProgrammer
MadProgrammer
This is what the Help tells me to do:
1 Declare the method in a protected part of the component’s class declaration.
2 Be sure that the method returns void.
3 Name the method after the message it handles, but without any underline characters.
4 Pass a pointer called Message of the type of the message structure.
5 Map the method to the message using macros.
6 Within the message method implementation, write code for any handling specific to the component.
7 Call the inherited message handler.

i can''t seem to understand 5 and 7.
Arild, you were pretty close to doing what i want to do, but the second thingy of code gives me errors. i''m probably putting it in the wrong spot.
MButchers
MButchers
Hello again,

5. The BEGIN_MESSAGE_MAP as above in
Arild Fines post.

7. You shouldn''t have to do this for
custom events however you just call
the inherited function ( sorry i use
delphi and have forgotten c builders
equivalent) in order to pass the message
to the default handlers.

Hope it helps.

Mark
MadProgrammer
MadProgrammer
where do i put the BEGIN_MESSAGE_MAP thingy?
where would i find the name of the default handler?

Topic Locked

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

Sign in to reply to this topic.