BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

No TForm::OnMove()-Event?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
MR
Guest





PostPosted: Sat Feb 11, 2006 9:03 am    Post subject: No TForm::OnMove()-Event? Reply with quote



Is there really no event to be called, if a form is moved like
TForm::OnMove()?

Thanks,

Michael
Back to top
HF
Guest





PostPosted: Sat Feb 11, 2006 9:03 am    Post subject: Re: No TForm::OnMove()-Event? Reply with quote



In TForm1 add this section
//***********************************
protected:
void __fastcall MyWMMove(TMessage &Message);

BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_MOVE, TMessage, MyWMMove)
END_MESSAGE_MAP(TControl)
//***********************************

in your cpp file add the implementation of MyWMMove
Memo1->Lines->Add(IntToStr(Message.LParamLo)+" ,
"+IntToStr(Message.LParamHi));

// from Win Api documentation
WM_MOVE
xPos = (int) LOWORD(lParam); // horizontal position
yPos = (int) HIWORD(lParam); // vertical position


? <MR> ?????? ??? ?????? news:rl7ru11rhcihthn1800r9bdqrhe32oik1q (AT) 4ax (DOT) com...
Quote:
Is there really no event to be called, if a form is moved like
TForm::OnMove()?

Thanks,

Michael
Back to top
HF
Guest





PostPosted: Sat Feb 11, 2006 10:03 am    Post subject: Re: No TForm::OnMove()-Event? Reply with quote



sorry once more, I forgot the implementation

//---------------------------------------------------------------------------
void __fastcall TForm1::MyWMMove(TMessage &Message)
{
Memo1->Lines->Add(IntToStr(Message.LParamLo)+" ,
"+IntToStr(Message.LParamHi));
}
//---------------------------------------------------------------------------
? <MR> ?????? ??? ?????? news:rl7ru11rhcihthn1800r9bdqrhe32oik1q (AT) 4ax (DOT) com...
Quote:
Is there really no event to be called, if a form is moved like
TForm::OnMove()?

Thanks,

Michael
Back to top
HF
Guest





PostPosted: Sat Feb 11, 2006 10:03 am    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

sorry,
Suppose that you put a memo control in your form
Also instead of END_MESSAGE_MAP(TControl) you can use
END_MESSAGE_MAP(TForm)


? <MR> ?????? ??? ?????? news:rl7ru11rhcihthn1800r9bdqrhe32oik1q (AT) 4ax (DOT) com...
Quote:
Is there really no event to be called, if a form is moved like
TForm::OnMove()?

Thanks,

Michael
Back to top
JD
Guest





PostPosted: Sat Feb 11, 2006 3:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

MR <> wrote:
Quote:

Is there really no event to be called, if a form is moved
like TForm::OnMove()?

No such event exists but it's a simple proposition to add code
that intercepts window messages that you can act on. The best
message to act on would depend on exactly what you are trying
to accomplish. For example, you could be notified before the
move, during the move and after the move has finished.

By now, you should know that there are 2 basic ways to
intercept Window messages and that one is a message map and
that the other is to override the form's WndProc method:


private:
MESSAGE void __fastcall WM( TMessage &Message );
public:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER( WM_WINDOWPOSCHANGING, TMessage, WMWindowPosChanging );
END_MESSAGE_MAP( TForm )

//-------------------------------------------------------------
MESSAGE void __fastcall TForm1::WMWindowPosChanging(TMessage &Message)
{
// your code here
TForm::Dispatch(&Message);
}
//-------------------------------------------------------------

or:

protected: // User declarations
virtual void __fastcall WndProc( TMessage &Message );

//-------------------------------------------------------------
void __fastcall TForm1::WndProc( TMessage &Message )
{
if( Message.Msg == WM_WINDOWPOSCHANGING )
{
// call your event
}
TForm::WndProc( Message );
}
//-------------------------------------------------------------

~ JD
Back to top
JD
Guest





PostPosted: Sat Feb 11, 2006 3:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

"HF" <min_charLOOK (AT) ATyahoo (DOT) gr> wrote:
Quote:

Also instead of END_MESSAGE_MAP(TControl) you can use
END_MESSAGE_MAP(TForm)

Since it's within a TForm class, it MUST be TForm.

~ JD
Back to top
JD
Guest





PostPosted: Sat Feb 11, 2006 3:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

"HF" <min_charLOOK (AT) ATyahoo (DOT) gr> wrote:
Quote:

sorry once more, I forgot the implementation

You also forgot to use Dispatch. See my other reply to MR.

~ JD
Back to top
JD
Guest





PostPosted: Sat Feb 11, 2006 3:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

"HF" <min_charLOOK (AT) ATyahoo (DOT) gr> wrote:
Quote:
In TForm1 add this section
//***********************************
protected:
void __fastcall MyWMMove(TMessage &Message);

BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_MOVE, TMessage, MyWMMove)
END_MESSAGE_MAP(TControl)

That is not the correct way to declare a message map. See my
reply to MR.

~ JD
Back to top
HF
Guest





PostPosted: Sat Feb 11, 2006 4:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

Thanks JD,
if I am not wrong that's the "job" of macro
END_MESSAGE_MAP(TForm)
In sysmac.h found the macro definition
of END_MESSAGE_MAP

- minas

Ο "JD" <nospam (AT) nospam (DOT) com> έγραψε στο μήνυμα
news:43edf2e6$1 (AT) newsgroups (DOT) borland.com...
Quote:

"HF" <min_charLOOK (AT) ATyahoo (DOT) gr> wrote:

sorry once more, I forgot the implementation

You also forgot to use Dispatch. See my other reply to MR.

~ JD
Back to top
MR
Guest





PostPosted: Sat Feb 11, 2006 6:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

Thanks JD, for the extensive answer...

Playing around with
Quote:
private:
MESSAGE void __fastcall WM( TMessage &Message );
MESSAGE void __fastcall WMWindowPosChanging (TMessage

&Message );
Quote:
public:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER( WM_WINDOWPOSCHANGING, TMessage, WMWindowPosChanging );
END_MESSAGE_MAP( TForm )
//-------------------------------------------------------------
MESSAGE void __fastcall TForm1::WMWindowPosChanging(TMessage &Message)
{
// your code here
TForm::Dispatch(&Message);
}
//-------------------------------------------------------------

I run into the same problem as the OnCreate()-issue:
WMWindowPosChanging has been called before Form1 has been created
completely, i.e. it's constructor-function has been executed
completely.

Because WMWindoPosChanging() is a methode of Form1, wouldn't that make
the same problem as the OnCreate?

I tried the second methode too and there it is exactly the same...

To avoid being 'used' before the construction/initialization is done I
defined
bool ConstructionDone;
as private inside the TForm1-Class and initializated it at the end of
TForm1's constructor
ConstructionDone=true;
(I think ConstructionDone is always 0 (false) at first!?)

Than I checked this (e.g. with the second methode):

void __fastcall TForm1::WndProc( TMessage &Message )
{
if(ConstructionDone) {
if( Message.Msg == WM_WINDOWPOSCHANGING )
{
// call your event
}
}
TForm::WndProc( Message );
}

It did what I wanted, but I suppose this
using-before-construction-is-done-issue is not solved with that, is
it?


Thanks a lot,

Michael
Back to top
JD
Guest





PostPosted: Sat Feb 11, 2006 7:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

"HF" <min_charLOOK (AT) ATyahoo (DOT) gr (HellenicFire)> wrote:
Quote:

if I am not wrong that's the "job" of macro END_MESSAGE_MAP(TForm)

Sorry, but you're wrong. If you don't Dispatch the message,
you would be effectively swallowing the message and would then
have to assume complete responsibility for fullfilling the
purpose of that particular message.

~ JD
Back to top
HF
Guest





PostPosted: Sat Feb 11, 2006 8:03 pm    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

JD, take a look in sysmac.h to see what I am saying

//BEGIN_MESSAGE_MAP expands to:
virtual void __fastcall Dispatch(void* Message)
{
switch(((TMessage*)Message)->Msg)
{
//VCL_MESSAGE_HANDLER(msg,type,meth) expands to:
case msg : meth(*((type*)Message));
break;
//END_MESSAGE_MAP(base) expands to:
default: base::Dispatch(Message);
break;
}
}

-minas

Ο "JD" <nospam (AT) nospam (DOT) com> έγραψε στο μήνυμα
news:43ee30d0$1 (AT) newsgroups (DOT) borland.com...
Quote:

"HF" <min_charLOOK (AT) ATyahoo (DOT) gr (HellenicFire)> wrote:

if I am not wrong that's the "job" of macro END_MESSAGE_MAP(TForm)

Sorry, but you're wrong. If you don't Dispatch the message,
you would be effectively swallowing the message and would then
have to assume complete responsibility for fullfilling the
purpose of that particular message.

~ JD
Back to top
JD
Guest





PostPosted: Sun Feb 12, 2006 5:10 am    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

"HF" <min_charLOOK@ATyahooADD_DOTgr (HellenicFire)> wrote:
Quote:

JD, take a look in sysmac.h to see what I am saying

You have misunderstood the code. The 'default' statement (the
Dispatch statement) only executes if the message map *doesn't*
include the current message. Ergo ... one must Dispatch once
the message is intercepted *unless* the intercepter wants to
assume complete responsibility for processing the message.

~ JD
Back to top
JD
Guest





PostPosted: Sun Feb 12, 2006 5:10 am    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

MR <> wrote:
Quote:

MESSAGE void __fastcall WM( TMessage &Message );

The above line was a cut-n-paste error (as if you haven't
figured that out by now).

Quote:
[...] I run into the same problem as the OnCreate()-issue:
WMWindowPosChanging has been called before Form1 has been
created [...] I defined bool ConstructionDone; as private
[...] It did what I wanted, but I suppose this using-before-
construction-is-done-issue is not solved with that, is it?

Sure it is. That was the entire point that I was trying to
make when I accused you of missing it. Same thing, different
approach.

~ JD
Back to top
HF
Guest





PostPosted: Sun Feb 12, 2006 9:03 am    Post subject: Re: No TForm::OnMove()-Event? Reply with quote

Yes JD, you are right.After relook the code of switch .My coffee was very
light Smile
Thanks.


Ο "JD" <nospam (AT) nospam (DOT) com> έγραψε στο μήνυμα
news:43eeb5be$1 (AT) newsgroups (DOT) borland.com...
Quote:

"HF" <min_charLOOK@ATyahooADD_DOTgr (HellenicFire)> wrote:

JD, take a look in sysmac.h to see what I am saying

You have misunderstood the code. The 'default' statement (the
Dispatch statement) only executes if the message map *doesn't*
include the current message. Ergo ... one must Dispatch once
the message is intercepted *unless* the intercepter wants to
assume complete responsibility for processing the message.

~ JD
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.