• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

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.
0
afeng
Asked:
afeng
  • 4
  • 2
  • 2
1 Solution
 
ZoppoCommented:
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
0
 
gaurangbhattCommented:
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.
0
 
ZoppoCommented:
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.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ZoppoCommented:
gaurangbhatt : something like 'if ( a = b )' does not produce a compiler error, because it's legal expression. It's also not a case statement! You're right mentioning these errors (which I did not see in cause of hurry), but they're not the cause for the compiler error.
0
 
gaurangbhattCommented:
Yes you are right, Zoppo.
0
 
afengAuthor Commented:
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!


 
0
 
ZoppoCommented:
Just for interest:

Do you sill have the BEGIN_MESSAGEMAP/END_MESSAGEMAP within the declaration of the class?

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

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now