| |

VerySource

 Forgot password?
 Register
Search
View: 1698|Reply: 14

Ask the heroes for help: Why can't the simplest LButton messages respond?

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

Post time: 2020-2-16 20:00:01
| Show all posts |Read mode
Hum, I started to suffer from learning vc. I wrote a win32 Application under VC. After running, it can't respond to the left and right mouse buttons. The code is as follows:

#include <afxwin.h>
class CMyApp: public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMainWnd: public CFrameWnd
{
protected:
afx_msg void OnLButtonDown (UINT nFlags, CPoint point);
afx_msg void OnRButtonDown (UINT nFlags, CPoint point);
public:
DECLARE_MESSAGE_MAP ()
};
///////////////////////////////////////////////////////// ///////

BEGIN_MESSAGE_MAP (CMainWnd, CFrameWnd)
ON_WM_RBUTTONDOWN ()
ON_WM_LBUTTONDOWN ()
END_MESSAGE_MAP ()
void CMainWnd :: OnLButtonDown (UINT nFlags, CPoint point)
{
// MessageBox ("left-click");
CDC * pDC = GetDC ();
pDC-> TextOut (point.x, point.y, "hello", 5);
CFrameWnd :: OnLButtonDown (nFlags, point);
}
void CMainWnd :: OnRButtonDown (UINT nFlags, CPoint point)
{
MessageBox ("right-click");
CFrameWnd :: OnRButtonDown (nFlags, point);
}
BOOL CMyApp :: InitInstance ()
{
CFrameWnd * p = new CFrameWnd;
p-> Create (0, "yang");
p-> ShowWindow (SW_SHOWDEFAULT);
p-> UpdateWindow ();
// AfxGetApp ()-> m_pMainWnd = p;
this-> m_pMainWnd = p;
return TRUE;
}
CMyApp myapp;
Reply

Use magic Report

0

Threads

70

Posts

42.00

Credits

Newbie

Rank: 1

Credits
42.00

 China

Post time: 2020-4-18 21:45:01
| Show all posts
You move the mouse to the edge of the entire form and click the mouse to see
Reply

Use magic Report

2

Threads

19

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-4-19 09:30:01
| Show all posts
Your WM_RBUTTONDOWN WM_LBUTTONDOWN message functions are defined in the main frame class, only click on the main frame idea frame form (in MDI, the sub frame form is above the main frame form, the window body is in the sub frame form (On), it will respond, you should have a visual class, click on the visual will not respond, only the message function try to put in the visual class
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-19 10:45:01
| Show all posts
It should be upstairs, you should respond to the message of the framework, not the client area
Reply

Use magic Report

0

Threads

59

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-4-20 08:45:01
| Show all posts
First convert the screen coordinates to the client area coordinates
ScreenToClient (&point);

If you want to convert to window coordinates, write a function
void CMainFrame :: ScreenToWindow (LPPOINT lpPoint)
{
   CRect rc;
   GetWindowRect (&rc);
   lpPoint-> x-= rc.left;
   lpPoint-> y-= rc.top;
}
Reply

Use magic Report

0

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-20 21:30:01
| Show all posts
personal opinion:
Respond to mouse clicks in MainFrame ??

I think it should be responded to in the View!
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

 Author| Post time: 2020-4-30 23:15:01
| Show all posts
Thank you guys first, let me give it a try!
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

 Author| Post time: 2020-5-2 14:00:01
| Show all posts
Thank you heroes, see hope!
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

 Author| Post time: 2020-5-7 21:00:01
| Show all posts
But this is a project I built with win32 application, not mfc. It is said that I did not consider generating CView objects. If it is sdi or mdi generated by mfc, the first one to capture the mouse is the view, but I am at all Without view, is it difficult to have a view class as long as you use a framework class? Even if it is generated with win32 application is no exception.

Please also master to help. Please!
Reply

Use magic Report

0

Threads

59

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-5-15 16:45:02
| Show all posts
First understand the document view structure
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list