Thread View: borland.public.cppbuilder.nativeapi
13 messages
13 total messages
Started by nick
Mon, 11 Feb 2008 10:17
How to use traditional Windows message and API function ?
Author: nick
Date: Mon, 11 Feb 2008 10:17
Date: Mon, 11 Feb 2008 10:17
6 lines
873 bytes
873 bytes
Hi, Can anyone give an example of how to use traditional Windows message and API function in C++ builder ? much thanks nick
Re: How to use traditional Windows message and API function ?
Author: Asger Joergensen
Date: Mon, 11 Feb 2008 11:39
Date: Mon, 11 Feb 2008 11:39
18 lines
1379 bytes
1379 bytes
Hi nick nick says: > > Hi, > > Can anyone give an example of how to use traditional Windows message and API function in C++ builder ? much thanks Could You be a little bit more specific, do You want send messages, do You want to recieve messages in Your own component or in the application etc. explaine what You want to achieve. P.s. please break Your text line. Kind regards Asger
Re: How to use traditional Windows message and API function ?
Author: nick
Date: Mon, 11 Feb 2008 22:00
Date: Mon, 11 Feb 2008 22:00
25 lines
1657 bytes
1657 bytes
Asger Joergensen <junk@Asger-P.dk> wrote: > >Hi nick > > nick says: >> >> Hi, >> >> Can anyone give an example of how to use traditional Windows message and API function in C++ builder ? much thanks > >Could You be a little bit more specific, do You want send messages, >do You want to recieve messages in Your own component or in the >application etc. >explaine what You want to achieve. > >P.s. please break Your text line. > >Kind regards >Asger (1) Receiving a message in application. (2) I want application receiving a message and then display some kind of infomation. I can do that in traditional Windows API program but don't know how to do it in C++ builder. Thanks.
Re: How to use traditional Windows message and API function ?
Author: Dennis Jones
Date: Mon, 11 Feb 2008 23:10
Date: Mon, 11 Feb 2008 23:10
36 lines
2062 bytes
2062 bytes
"nick" <nileiqi@hotmail.com> wrote in message
news:47b0d385$1@newsgroups.borland.com...
> (1) Receiving a message in application.
> (2) I want application receiving a message and then display some kind of
> infomation. I can do that in traditional Windows API program but don't
> know how to do it in C++ builder. Thanks.
Easy. Let's say you want to know when the PC clock time has changed (I do
this in one of my apps):
// in your header file
class TMyForm : public TForm
{
private:
// declare a handler function for your message
MESSAGE void __fastcall WM_TimeChange(TMessage &Message);
BEGIN_MESSAGE_MAP
// associate your handler function with some message
VCL_MESSAGE_HANDLER(WM_TIMECHANGE, TMessage,
WM_TimeChange);
END_MESSAGE_MAP(TForm);
};
// in your source file
// define the handler function
MESSAGE void __fastcall TMyForm::WM_TimeChange(TMessage &Message)
{
// do something when the WM_TIMECHANGE message is received
}
This works for both Windows messages and application-defined messages.
- Dennis
Re: How to use traditional Windows message and API function ?
Author: Remy Lebeau (TeamB)
Date: Mon, 11 Feb 2008 23:40
Date: Mon, 11 Feb 2008 23:40
19 lines
1632 bytes
1632 bytes
"nick" <nileiqi@hotmail.com> wrote in message news:47b0d385$1@newsgroups.borland.com... > Receiving a message in application. But at what level, though? To accomplish what exactly? Window messages are handled at different levels in different ways depending on what you are trying to do with them. > I can do that in traditional Windows API program but don't know how > to do it in C++ builder. Everything you do in traditional API programming can be done with the VCL as well. It is just a matter of identifying what kind of message handling you are tyring to do first. Gambit
Re: How to use traditional Windows message and API function ?
Author: Asger Joergensen
Date: Tue, 12 Feb 2008 07:51
Date: Tue, 12 Feb 2008 07:51
34 lines
2037 bytes
2037 bytes
Hi nick
nick says:
>
> (1) Receiving a message in application.
> (2) I want application receiving a message and then display
> some kind of infomation. I can do that in traditional Windows
> API program but don't know how to do it in C++ builder. Thanks.
In adition to what Dennis wrote.
You can find the definations of the VCL messages in Messages.hpp,
using the right message structure usually gives nicer code when
using the message.
e.g.
void __fastcall TMyPanel::WMMouseMove(Messages::TWMMouse &Msg)
{
TPanel::Dispatch((void*)&Msg);
//do things with Msg.XPos or Msg.YPos
}
Dispatch is used to make sure that the message is passed on to
the ancestor. I most cases You must use Dispatch otherwise things
don't work correctly.
P.s. Please manually breake Your text lines, due to code lines
most of us have turned of auto linebreak, which makes it hard
to read when people don't break lines.
Kind regards
Asger
Re: How to use traditional Windows message and API function ?
Author: nick
Date: Tue, 12 Feb 2008 11:22
Date: Tue, 12 Feb 2008 11:22
40 lines
2039 bytes
2039 bytes
Asger Joergensen <junk@Asger-P.dk> wrote:
>
>Hi nick
>
> nick says:
>>
>> (1) Receiving a message in application.
>> (2) I want application receiving a message and then display
>> some kind of infomation. I can do that in traditional Windows
>> API program but don't know how to do it in C++ builder. Thanks.
>
>In adition to what Dennis wrote.
>You can find the definations of the VCL messages in Messages.hpp,
>using the right message structure usually gives nicer code when
>using the message.
>
>e.g.
>void __fastcall TMyPanel::WMMouseMove(Messages::TWMMouse &Msg)
>{
> TPanel::Dispatch((void*)&Msg);
> //do things with Msg.XPos or Msg.YPos
>}
>
>Dispatch is used to make sure that the message is passed on to
>the ancestor. I most cases You must use Dispatch otherwise things
>don't work correctly.
>
>
>
>P.s. Please manually breake Your text lines, due to code lines
>most of us have turned of auto linebreak, which makes it hard
>to read when people don't break lines.
>
>Kind regards
>Asger
Thanks, very much for the help.
Nick
Re: How to use traditional Windows message and API function ?
Author: Luka Gabri�
Date: Fri, 22 Feb 2008 02:14
Date: Fri, 22 Feb 2008 02:14
30 lines
1960 bytes
1960 bytes
Can you modify the code so I could use it in my Application!?
I have a DLL that should send a variable(parameter) to my APP. This may be
the solution!
Can I use this with PostMessage in my DLL or something.
Please help,
thanks!
> // in your header file
> class TMyForm : public TForm
> {
> private:
> // declare a handler function for your message
> MESSAGE void __fastcall WM_TimeChange(TMessage &Message);
>
> BEGIN_MESSAGE_MAP
> // associate your handler function with some message
> VCL_MESSAGE_HANDLER(WM_TIMECHANGE, TMessage,
> WM_TimeChange);
> END_MESSAGE_MAP(TForm);
> };
>
> // in your source file
> // define the handler function
> MESSAGE void __fastcall TMyForm::WM_TimeChange(TMessage &Message)
> {
> // do something when the WM_TIMECHANGE message is received
> }
>
Re: How to use traditional Windows message and API function ?
Author: Dennis Jones
Date: Fri, 22 Feb 2008 04:43
Date: Fri, 22 Feb 2008 04:43
13 lines
1563 bytes
1563 bytes
"Luka Gabri�" <luka.gabric@gmail.com> wrote in message news:47be2fa2$1@newsgroups.borland.com... > Can you modify the code so I could use it in my Application!? > > I have a DLL that should send a variable(parameter) to my APP. This may be > the solution! > Can I use this with PostMessage in my DLL or something. Modify what code? You'll have to be more specific about what you want to do. - Dennis
Re: How to use traditional Windows message and API function ?
Author: Luka Gabri�
Date: Fri, 22 Feb 2008 19:59
Date: Fri, 22 Feb 2008 19:59
44 lines
2606 bytes
2606 bytes
> Modify what code? You'll have to be more specific about what you want to
> do.
>
> - Dennis
>
I would like my DLL to comunicate with my application in any way. Windows
message api function seems like a good idea. This is the code for receiving
a message on date time change. When the message on date time change is
received, an event (or function) is triggered. I would like to "trigger" a
handler function in my application from my DLL, and pass some parameters if
possible.
Something like this should be in my application (this works for date/time
change i would like a handler for messages from another application, not
date/time)!
class TMyForm : public TForm
{
private:
// declare a handler function for your message
MESSAGE void __fastcall WM_TimeChange(TMessage &Message);
BEGIN_MESSAGE_MAP
// associate your handler function with some message
VCL_MESSAGE_HANDLER(WM_TIMECHANGE, TMessage,
WM_TimeChange);
END_MESSAGE_MAP(TForm);
};
// in your source file
// define the handler function
MESSAGE void __fastcall TMyForm::WM_TimeChange(TMessage &Message)
{
ShowMessage("Date or time has been changed!");
}
Now I need the code to send a meessage from DLL (or another application) to
my application. (I think it's the PostMessage method, but I'm not sure)!
I hope this clears what I want the code for.
Thanks,
Luka.
Re: How to use traditional Windows message and API function ?
Author: Luka Gabri�
Date: Sat, 23 Feb 2008 00:06
Date: Sat, 23 Feb 2008 00:06
71 lines
3324 bytes
3324 bytes
This code seems to be working, but I still need to do some testing!
Message receiving code:
// application header
MESSAGE void __fastcall func_name(TMessage &Message);
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(xxxx,TMessage,func_name); //xxxx - message identifier,
> 1024
END_MESSAGE_MAP(TForm);
// application cpp file
MESSAGE void __fastcall TFormX::func_name(TMessage &Message)
{
ShowMessage("Message received, parameter1 = " + IntToStr(Message.LParam) +
", parameter2 = " + IntToStr(Message.WParam));
}
Code to send a message
SendMessageA(hinst,xxxx,5,7);
//hinst - app form handle, xxxx - message identifier (same as in main
application), parameter1=5, parameter2=7.
> I would like my DLL to comunicate with my application in any way. Windows
> message api function seems like a good idea. This is the code for
> receiving
> a message on date time change. When the message on date time change is
> received, an event (or function) is triggered. I would like to "trigger" a
> handler function in my application from my DLL, and pass some parameters
> if
> possible.
>
> Something like this should be in my application (this works for date/time
> change i would like a handler for messages from another application, not
> date/time)!
>
> class TMyForm : public TForm
> {
> private:
> // declare a handler function for your message
> MESSAGE void __fastcall WM_TimeChange(TMessage &Message);
>
> BEGIN_MESSAGE_MAP
> // associate your handler function with some message
> VCL_MESSAGE_HANDLER(WM_TIMECHANGE, TMessage,
> WM_TimeChange);
> END_MESSAGE_MAP(TForm);
> };
>
> // in your source file
> // define the handler function
> MESSAGE void __fastcall TMyForm::WM_TimeChange(TMessage &Message)
> {
> ShowMessage("Date or time has been changed!");
> }
>
> Now I need the code to send a meessage from DLL (or another application)
> to
> my application. (I think it's the PostMessage method, but I'm not sure)!
>
> I hope this clears what I want the code for.
>
> Thanks,
> Luka.
>
>
Re: How to use traditional Windows message and API function ?
Author: Luka Gabri�
Date: Sat, 23 Feb 2008 01:54
Date: Sat, 23 Feb 2008 01:54
34 lines
2410 bytes
2410 bytes
SendMessage works from my application using it's handle, but HWND_BROADCAST
for handle doesn't work in application nor from other applications. When I
try to Send something from DLL it works only when application is in focus,
if not in focus send message is not working. When I use a timer in app to
send a message to itself it works even if focus is not set on a form. I
think everything would work fine if this SendMessage would work with
HWND_BROADCAST! What is the problem with code below?
> Message receiving code:
>
> // application header
>
> MESSAGE void __fastcall func_name(TMessage &Message);
> BEGIN_MESSAGE_MAP
> VCL_MESSAGE_HANDLER(xxxx,TMessage,func_name); //xxxx - message
> identifier,
> > 1024
> END_MESSAGE_MAP(TForm);
>
> // application cpp file
>
> MESSAGE void __fastcall TFormX::func_name(TMessage &Message)
> {
> ShowMessage("Message received, parameter1 = " + IntToStr(Message.LParam) +
> ", parameter2 = " + IntToStr(Message.WParam));
> }
>
> Code to send a message
>
> SendMessageA(hinst,xxxx,5,7);
>
> //hinst - app form handle, xxxx - message identifier (same as in main
> application), parameter1=5, parameter2=7.
Re: How to use traditional Windows message and API function ?
Author: Asger Joergensen
Date: Sat, 23 Feb 2008 11:35
Date: Sat, 23 Feb 2008 11:35
31 lines
2373 bytes
2373 bytes
Hi Luka Luka Gabri says: > SendMessage works from my application using it's handle, but HWND_BROADCAST > for handle doesn't work in application nor from other applications. When I > try to Send something from DLL it works only when application is in focus, > if not in focus send message is not working. When I use a timer in app to > send a message to itself it works even if focus is not set on a form. I > think everything would work fine if this SendMessage would work with > HWND_BROADCAST! What is the problem with code below? > I dont think You can use SendMesssage width HWND_BROADCAST, SendMesssage does not return untill the message is handled it is kind of like calling a function. You have to use PostMessage instead that one returns right avay and let the applications deal with the message in their own time. You shoould have a look at this thread: http://tinyurl.com/23wrpe By the way You dont need the MESSAGE keyword it is defined as nothing, so whether You use it or not doesn't matter. P.s. please trim Your qoutes. Kind regards Asger
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads