afeng
asked on
How can i get a mouseevent message? help me!
I make a programme with Borland c++ Builder 4.0.
I want get a mouseevent message when mouse lbutton down,and i make a message handle,but it can't work,please help me.
There is the code:
#define MI_ICONEVENT (WM_APP + 1);
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPopupMenu *PopupMenu1;
TMenuItem *status;
TMenuItem *n1;
TMenuItem *close1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
protected:
void __fastcall IconOnClick(TMessage &message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MI_ICONEVE NT, TMessage, IconOnClick)
END_MESSAGE_MAP(TForm)
private: // User declarations
bool statu;
void installicon();
void changeicon(bool statu);
void uninstall();
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
void __fastcall TForm1::IconOnClick(TMessa ge &message)
{ POINT p;
if (message.LParam=WM_LBUTTON DOWN)
ShowWindow( Application->Handle, SW_SHOW );
if (message.LParam = WM_RBUTTONDOWN)
{GetCursorPos(&p);
Form1->PopupMenu1->Popup(p .x,p.y );
}}
When i compile it,BDE give me a error message said "case statement expected;",
but i search it in help,there is no case statement.why??
thank you for answer.
I want get a mouseevent message when mouse lbutton down,and i make a message handle,but it can't work,please help me.
There is the code:
#define MI_ICONEVENT (WM_APP + 1);
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPopupMenu *PopupMenu1;
TMenuItem *status;
TMenuItem *n1;
TMenuItem *close1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
protected:
void __fastcall IconOnClick(TMessage &message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MI_ICONEVE
END_MESSAGE_MAP(TForm)
private: // User declarations
bool statu;
void installicon();
void changeicon(bool statu);
void uninstall();
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
void __fastcall TForm1::IconOnClick(TMessa
{ POINT p;
if (message.LParam=WM_LBUTTON
ShowWindow( Application->Handle, SW_SHOW );
if (message.LParam = WM_RBUTTONDOWN)
{GetCursorPos(&p);
Form1->PopupMenu1->Popup(p
}}
When i compile it,BDE give me a error message said "case statement expected;",
but i search it in help,there is no case statement.why??
thank you for answer.
Dear Afeng,
Just check out with the if condition statements.
They are as below :
if (message.LParam=WM_LBUTTON DOWN)
They should be
if (message.LParam == WM_LBUTTONDOWN)
The comparision is done using == and not =.
= means assignment and is not a case statement.
A case statement is one which compares.
The two statements you need to change are
if (message.LParam=WM_LBUTTON DOWN) and
if (message.LParam=WM_RBUTTON DOWN)
TO
if (message.LParam == WM_LBUTTONDOWN)
if (message.LParam == WM_LBUTTONDOWN)
Good Luck.
Just check out with the if condition statements.
They are as below :
if (message.LParam=WM_LBUTTON
They should be
if (message.LParam == WM_LBUTTONDOWN)
The comparision is done using == and not =.
= means assignment and is not a case statement.
A case statement is one which compares.
The two statements you need to change are
if (message.LParam=WM_LBUTTON
if (message.LParam=WM_RBUTTON
TO
if (message.LParam == WM_LBUTTONDOWN)
if (message.LParam == WM_LBUTTONDOWN)
Good Luck.
The error message occurs because BEGIN_MESSAGE_MAP, MESSAGE_HANDLER and END_MESSAGE_MAP are macros which implement a switch/case block to map the messages to the functions.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes you are right, Zoppo.
ASKER
Hi:
thank you all!
The trouble is gone.After I correct the the error in "if message.LParam=WM_LBUTTOND OWN)
if (message.LParam=WM_RBUTTON DOWN) " ,
the error message also in. I hardly find the true mistake.Then, I seached the topic in help,found the example about it.I found "#define MI_ICONEVENT (WM_APP + 1); " in the example have no the char ";",so ,I delete the char,
and the trouble has gone.
thanks you a lot!,Zoppo
thank you al!
thank you all!
The trouble is gone.After I correct the the error in "if message.LParam=WM_LBUTTOND
if (message.LParam=WM_RBUTTON
the error message also in. I hardly find the true mistake.Then, I seached the topic in help,found the example about it.I found "#define MI_ICONEVENT (WM_APP + 1); " in the example have no the char ";",so ,I delete the char,
and the trouble has gone.
thanks you a lot!,Zoppo
thank you al!
Just for interest:
Do you sill have the BEGIN_MESSAGEMAP/END_MESSA GEMAP within the declaration of the class?
ZOPPO
Do you sill have the BEGIN_MESSAGEMAP/END_MESSA
ZOPPO
ASKER
thank you all!
the error has gone.
the trouble is come from the line"#define .........;",
after i delete the char ";",trouble gone.
the error has gone.
the trouble is come from the line"#define .........;",
after i delete the char ";",trouble gone.
I'm not sure because I have no expierence with Borland, but with VC++ the BEGIN_MESSAGE_MAP/END_MESS
hope that helps,
ZOPPO