Board index » cppbuilder » Want to Make a form unmovable

Want to Make a form unmovable


2003-12-19 01:36:52 AM
cppbuilder51
Hi,
I have a need to make a form that cannot have its position changed.
I have tried using a MessageMap for the WM_WINDOWPOSChanging message and was
successful using SWP_NOMOVE flag.
The problem I am experiencing is that I have MinWidth and MinHeight
constraints set for the form.
The constraints are honored if I don't process the WINDOWPOSChanging
message, but are not if I do handle it.
I have had limited success in constraining the size with the SWM_NOSIZE flag
in the same message map procedure, but the operation is not as smooth as I
would like. I have tried using OnCanResize event but this doesn't get fired
off when using the message map.
I also tried to include a WM_SIZE message map procedure, but then any other
resizing controls don't receive their message.
Any suggestions.
Thanks,
Mike
 
 

Re:Want to Make a form unmovable

"Michael Brazee" < XXXX@XXXXX.COM >wrote in message
Quote
The problem I am experiencing is that I have MinWidth and
MinHeight constraints set for the form. The constraints are
honored if I don't process the WINDOWPOSChanging
message, but are not if I do handle it.
What does your exact code look like? Did you pass the message to the
default handler after you modified it?
Gambit
 

Re:Want to Make a form unmovable

Remy,
here are code snippets.
void __fastcall
TformSummaryEditor::WMWindowPosChanging(TWMWindowPosChanging& Message)
{
tagWINDOWPOS *WindowPos = Message.WindowPos;
/*
if ((WindowPos->cx>0 && WindowPos->cx < 640) || (WindowPos->cy>0 &&
WindowPos->cy < 480))
{
if (Width < 640)
{
WindowPos->cx = 640;
WindowPos->flags = WindowPos->flags | SWP_NOSIZE;
}
if (Height < 480)
{
WindowPos->cy = 480;
WindowPos->flags = WindowPos->flags | SWP_NOSIZE;
}
//WindowPos->flags = WindowPos->flags | SWP_NOSIZE;
}
*/
if (!AllowWindowMove)
{
WindowPos->flags = WindowPos->flags | SWP_NOMOVE;
}
DefWindowProc(Handle, Message.Msg, NULL, (long)WindowPos);
}
//--------------------------------------------------------------------------
-
(from .h file)
void __fastcall WMEndSession(TWMEndSession& Message);
void __fastcall WMWindowPosChanging(TWMWindowPosChanging& Message);
void __fastcall WMSize(TWMSize& Message);
BEGIN_MESSAGE_MAP
//VCL_MESSAGE_HANDLER(WM_ENDSESSION, TWMEndSession, WMEndSession)
VCL_MESSAGE_HANDLER(WM_WINDOWPOSChanging, TWMWindowPosChanging,
WMWindowPosChanging);
//VCL_MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize);
END_MESSAGE_MAP(TForm)
The commented out code was just various attempts at getting positive
results. I was actually using Constraints->MinWidth and MinHeight.
These values were actually being changed during runtime (but not by my
code).
Mike
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

<snip>
What does your exact code look like? Did you pass the message to the
default handler after you modified it?


Gambit


 

{smallsort}

Re:Want to Make a form unmovable

"Michael Brazee" < XXXX@XXXXX.COM >wrote in message
Quote
DefWindowProc(Handle, Message.Msg, NULL, (long)WindowPos);
Change that line to this instead:
TForm::Dispatch(&Message);
Gambit
 

Re:Want to Make a form unmovable

Remy,
As always you're brilliant.
Thanks for the help and enjoy the Holiday season.
Mike
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Michael Brazee" < XXXX@XXXXX.COM >wrote in message
news:3fe20299$ XXXX@XXXXX.COM ...

>DefWindowProc(Handle, Message.Msg, NULL, (long)WindowPos);

Change that line to this instead:

TForm::Dispatch(&Message);


Gambit


 

Re:Want to Make a form unmovable

Hi Mike
This should also prevent the user from moving the Form
...
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DeleteMenu(GetSystemMenu(Handle, false), SC_MOVE, MF_BYCOMMAND);
}
//--------------------------------------------------------------------------
-
...