Link to home
Start Free TrialLog in
Avatar of afeng
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_ICONEVENT, 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(TMessage &message)
{ POINT p;
if (message.LParam=WM_LBUTTONDOWN)
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.
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi afeng,

I'm not sure because I have no expierence with Borland, but with VC++ the BEGIN_MESSAGE_MAP/END_MESSAGE_MAP must appear outside of the class decleration.

hope that helps,

ZOPPO
Avatar of gaurangbhatt
gaurangbhatt

Dear Afeng,

Just check out with the if condition statements.

They are as below :
if (message.LParam=WM_LBUTTONDOWN)

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_LBUTTONDOWN)  and
if (message.LParam=WM_RBUTTONDOWN)
           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
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes you are right, Zoppo.
Avatar of afeng

ASKER

Hi:
 thank you all!
 The trouble is gone.After I correct the the error in "if message.LParam=WM_LBUTTONDOWN)  
if (message.LParam=WM_RBUTTONDOWN) " ,
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_MESSAGEMAP within the declaration of the class?

ZOPPO
Avatar of afeng

ASKER

thank you all!
the error has gone.
the trouble is come from the line"#define .........;",
after i delete the char ";",trouble gone.