R
raylopez99
Hi all,
I'm just a hobbiest but I have a question on Microsoft Visual Studio
C++.NET 2002 version 1.0; I think there's a bug in 'manually' entering
a member function.
First of all, unlike the previous verison of Visual Studio C++ 6 from a
few years ago, I cannot find (or don't have) the button to use the
"Class Wizard" to add a member function from the MFC. (Instead, I get a
Wizard for Generic C++ class, for ATL, and for a MFC class in four
flavors: Class, ActiveX, TypeLib and ODBC Consumer))
Therefore I must add a MFC class (from the library, such as
"OnRButtonDown"), "manually", by adding a definition/declaration in the
header and source files.
This is a problem because now, though the program compiles, it seems
like the 'manually added' function is not recognized. But from the
"Properties" window it appears that it is recognized as a MFC
CMainFrame VCCodeClass function (in the example below,
"CMainFrame::OnRButtonDown" was added 'manually' but not (seemingly)
recognized.
Anybody else have this problem?
Might be specific to 2002 Visual Studio, not 2003.
RL
PS--in the below code snippet, I can get a MessageBox to pop up by left
clicking the mouse but never by right clicking the mouse. Since the
program does not appear to have any bugs, and is otherwise symmetrical,
I assume it's a problem with MFC "recognizing" that what I call
"OnRButtonDown" is from the library <afxwin.h> and not my own version.
////////////////////////
// MainFrame.h
#include <afxwin.h>
class CMainFrame : public CFrameWnd
{
private:
CString mStr;
CPoint mPt;
public:
CMainFrame(); // Constructor
// window msg handling function
afx_msg void OnPaint();
afx_msg void OnChar (UINT nChar, UINT nRep, UINT nFlags);
afx_msg void OnLButtonDown (UINT nFlags, CPoint pt); // THIS WORKS
(runtime)
afx_msg void OnRButtonDown(UINT nFlags, CPoint pt); // THIS DOES NOT
EVER GET CALLED (runtime)
DECLARE_MESSAGE_MAP();
};
///////////////////////////////////////////////////////////////////////
// MainFrame.cpp
#include "MainFrame.h"
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
// message calls this function
ON_WM_PAINT() // void OnPaint()
ON_WM_CHAR() // void OnChar (UINT nChar, UINT nRep, UINT
nFlags)
ON_WM_LBUTTONDOWN() // void OnLButtonDown (UINT nFlags, CPoint pt)
END_MESSAGE_MAP()
CMainFrame::CMainFrame() // Constructor
{
Create(NULL,"Ex04b Left Click then Type Characters",
WS_OVERLAPPEDWINDOW, CRect(20,30,350,140));
mStr = "Hi!";
mPt = CPoint(5, 10);
};
void CMainFrame::OnPaint()
{
CPaintDC dc(this);
dc.TextOut (mPt.x, mPt.y, mStr);
}
void CMainFrame::OnChar (UINT nChar, UINT nRep, UINT nFlags)
{
CString str;
str.Format(" %c Ascii code: %d ", nChar, nChar);
SetWindowText(str);
mStr = mStr + (char)nChar; // append char to mStr
Invalidate (TRUE); // Display method 2
}
////////// THIS WORKS - OnLButtonDown //////////
void CMainFrame::OnLButtonDown (UINT nFlags, CPoint pt)
{
mStr = ""; // Begin with new string
mPt = pt; // at this new coordinate position
MessageBox("Hows it going LEFT BUTTON", "AGreeting", MB_ICONQUESTION);
}
////////// THIS DOES NOT WORK (compiled but never gets called despite
clicking on right mouse button) - OnRButtonDown //////////
void CMainFrame::OnRButtonDown(UINT nChar, CPoint pt)
{
mStr = ""; // Begin with new string
mPt = pt; // at this new coordinate position
MessageBox("Hows it going Right button click??!!!", "AGreeting",
MB_ICONQUESTION);
}
/////////////////////////
I'm just a hobbiest but I have a question on Microsoft Visual Studio
C++.NET 2002 version 1.0; I think there's a bug in 'manually' entering
a member function.
First of all, unlike the previous verison of Visual Studio C++ 6 from a
few years ago, I cannot find (or don't have) the button to use the
"Class Wizard" to add a member function from the MFC. (Instead, I get a
Wizard for Generic C++ class, for ATL, and for a MFC class in four
flavors: Class, ActiveX, TypeLib and ODBC Consumer))
Therefore I must add a MFC class (from the library, such as
"OnRButtonDown"), "manually", by adding a definition/declaration in the
header and source files.
This is a problem because now, though the program compiles, it seems
like the 'manually added' function is not recognized. But from the
"Properties" window it appears that it is recognized as a MFC
CMainFrame VCCodeClass function (in the example below,
"CMainFrame::OnRButtonDown" was added 'manually' but not (seemingly)
recognized.
Anybody else have this problem?
Might be specific to 2002 Visual Studio, not 2003.
RL
PS--in the below code snippet, I can get a MessageBox to pop up by left
clicking the mouse but never by right clicking the mouse. Since the
program does not appear to have any bugs, and is otherwise symmetrical,
I assume it's a problem with MFC "recognizing" that what I call
"OnRButtonDown" is from the library <afxwin.h> and not my own version.
////////////////////////
// MainFrame.h
#include <afxwin.h>
class CMainFrame : public CFrameWnd
{
private:
CString mStr;
CPoint mPt;
public:
CMainFrame(); // Constructor
// window msg handling function
afx_msg void OnPaint();
afx_msg void OnChar (UINT nChar, UINT nRep, UINT nFlags);
afx_msg void OnLButtonDown (UINT nFlags, CPoint pt); // THIS WORKS
(runtime)
afx_msg void OnRButtonDown(UINT nFlags, CPoint pt); // THIS DOES NOT
EVER GET CALLED (runtime)
DECLARE_MESSAGE_MAP();
};
///////////////////////////////////////////////////////////////////////
// MainFrame.cpp
#include "MainFrame.h"
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
// message calls this function
ON_WM_PAINT() // void OnPaint()
ON_WM_CHAR() // void OnChar (UINT nChar, UINT nRep, UINT
nFlags)
ON_WM_LBUTTONDOWN() // void OnLButtonDown (UINT nFlags, CPoint pt)
END_MESSAGE_MAP()
CMainFrame::CMainFrame() // Constructor
{
Create(NULL,"Ex04b Left Click then Type Characters",
WS_OVERLAPPEDWINDOW, CRect(20,30,350,140));
mStr = "Hi!";
mPt = CPoint(5, 10);
};
void CMainFrame::OnPaint()
{
CPaintDC dc(this);
dc.TextOut (mPt.x, mPt.y, mStr);
}
void CMainFrame::OnChar (UINT nChar, UINT nRep, UINT nFlags)
{
CString str;
str.Format(" %c Ascii code: %d ", nChar, nChar);
SetWindowText(str);
mStr = mStr + (char)nChar; // append char to mStr
Invalidate (TRUE); // Display method 2
}
////////// THIS WORKS - OnLButtonDown //////////
void CMainFrame::OnLButtonDown (UINT nFlags, CPoint pt)
{
mStr = ""; // Begin with new string
mPt = pt; // at this new coordinate position
MessageBox("Hows it going LEFT BUTTON", "AGreeting", MB_ICONQUESTION);
}
////////// THIS DOES NOT WORK (compiled but never gets called despite
clicking on right mouse button) - OnRButtonDown //////////
void CMainFrame::OnRButtonDown(UINT nChar, CPoint pt)
{
mStr = ""; // Begin with new string
mPt = pt; // at this new coordinate position
MessageBox("Hows it going Right button click??!!!", "AGreeting",
MB_ICONQUESTION);
}
/////////////////////////