|
hi,
this is what you are looking for..
Since Microsoft got rid of ClassWizard in VC++ 7, quite a lot of jobs have become much more difficult. This article shows how to hook up the normal click events for toolbars in VC7, and how to disable buttons programmatically, depending on context.
First, let us assume we have an SDI application created using AppWizard.
The buttons are called ID_TBRED, ID_TBGREEN, and ID_TBBLUE respectively.
Creating Event Functions for the Buttons
If we built the program above just by adding in the toolbar buttons, they would by default be disabled, which is not very useful. Now we want to add an event function to each button so they do something when clicked.
First, let's create the functions for each of them. If you are following my SDI example, it is likely you will want to define the functions in your view. Open the header file for your view (double-click the class name in Class View), this is CDisableToolbarView in the example.
Okay; we need to write the declarations for our three functions; these would be as so:
afx_msg void OnToolbarRedClick();
afx_msg void OnToolbarGreenClick();
afx_msg void OnToolbarBlueClick();
That's all we need in our header, so we can close that and open our cpp file.
For each of the three functions declared above, we need to create a function defintition like the one below.
void CDisableToolbarView::OnToolbarRedClick()
{
MessageBox("Red clicked");
}
We've now finished creating the event functions. As they stand, VC++ doesn't know what events to hook our functions up to, so we need to specify this.
Toward the top of the cpp file you will see a block of code starting with BEGIN_MESSAGE_MAP. Within these lines we can hook the click events up to our functions. Between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP lines, add the following three lines:
ON_BN_CLICKED(ID_TBRED,OnToolbarRedClick)
ON_BN_CLICKED(ID_TBGREEN,OnToolbarGreenClick)
ON_BN_CLICKED(ID_TBBLUE,OnToolbarBlueClick)
By building the application, you should now see the three buttons enabled, and clicking them should show the respective message box. That's all there is to it!
cheers
Himanshu
|
|
|
|
|
Himanshu, do you know you can do it with the Class Wizard ? So you need not to add all the MFC stuff "by hand"...
~RaGE();
|
|
|
|
|
what if there is no classwizard...boom...
have you seen it is vc++7 not 6..and it doesn't support class wizard..so you have to do it manually..
cheers
Himanshu
|
|
|
|
|
Great
thanx a lot
this was the what I was looking for
I have another question related to this:
how to add functions such as in VC++6 OnDraw() for SDI and MDI, InitInstance(),..
thanx.
|
|
|
|
|
I guess thats something like this..
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
public:
virtual BOOL InitInstance();
i guess that should work fine with your code..
cheers
Himanshu
|
|
|
|
|
I am designing a scripting engine for use in a student project, that has similar syntax to C++ but not quite all the power. I have recently come to one small problem. When you have an operation, like a+b, there needs to be a return type from that operation. (though this does have a lot to do with my engine, it also is a question as to how C++ works, since I havn't really enountered any material on this subject - maybe I'm just not looking hard enough).
Say we have:
float f = 1+1.0;
f gets the value 2.0 since we know we are storing to a float.
But, if I am not going to store to float, but rather do something like
cout << 1+1.1 << endl; (not in my code, but in C++)
That gets the value of 2.1 (tested in C++), but how does the compiler know to promote to a float? Seems simple enough, but the engine is designed so that types can be added, so I want to know whats the best way to know how to promote a variable to another type during an operator (specifically, a binary operator)? I guess a better way of putting it would be "How can you determine what the resulting type will be from an operator that is done on two different types"? Will the first operand have precidence, or the second?
|
|
|
|
|
|
Exactly what I was looking for, thanks!
|
|
|
|
|
Neither the first nor the second, but the you may make the precidence according to the type : in fact, memory sapce allocated for float is bigger than memory for int. According to this criteria, make a previdence list (like : double,float,long int,int,char) and promote all your operand to the best ranked in this list.
~RaGE();
|
|
|
|
|
Hi
I am creating a CObject-derived class by first creating a class with CDocument as base class, and then replacing all 'CDocument' with 'CObject' and then removing the below message maps functions from the source and header
files.
BEGIN_MESSAGE_MAP(CMyClass, CObject)
//{{AFX_MSG_MAP(CMyClass)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
and
// Generated message map functions
protected:
//{{AFX_MSG(CMyClass)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
I have no problem compiling the program but when i try to use the class wizard, an error dialog box appeared with:
"Cannot find the insert section "AFX_MSG" in file.Class wizard cannot import or edit this class."
Anyone with suggestions as to what i should do?
|
|
|
|
|
why did you remove those blocks of code?
they are (obviously) what the CW is looking for.
-c
Zzzzz...
|
|
|
|
|
because what i actually want is a CObject-derived class, not CDocument-derived. And CObject-derived classes has no no message mapping.(This method of deriving from CObject class is taught by someone)
Actually, why does it want to find the insert section for "AFX_MSG"?
thks thks
|
|
|
|
|
raner wrote:
Actually, why does it want to find the insert section for "AFX_MSG"?
MFC needs it for message mapping. Maybe you did not remove everything needed.
Actually, to derive a class from a CObject, you only need to add the class with the wizard, and say you want it to be derived from CObject.
~RaGE();
|
|
|
|
|
raner wrote:
Actually, why does it want to find the insert section for "AFX_MSG"?
Its a guess but:
Possibly becuase the CDocument object used the DECLARE_SERIAL() / IMPLEMENT_SERIAL() macros and you need to switch to DECLARE_DYNAMIC() / IMPLEMENT_DYNAMIC() ?
Roger Allen
Sonork 100.10016
This is a multiple choice question, choose wisely
Why did the hedgehog cross the road?
A: To show he had guts?
B: To see his flat mate?
|
|
|
|
|
i did not see the DECLARE_SERIAL() / IMPLEMENT_SERIAL() macros but i saw the DECLARE/IMPLEMENT_DYNCREATE macros pair...does it matter?
thks
|
|
|
|
|
a better question is: if you don't need message mapping, what do you need the CW for?
-c
Zzzzz...
|
|
|
|
|
actually i don't really need the class wizard for that class...but the error message appearing every time i activate the CW seem to mean that something is terribly wrong? So i thought if i don't fix it now, it's bound to give me problems someday?
was i wrong?
|
|
|
|
|
in that case, i think you were right to delete those sections. and, i think you should get rid of any //{{AFX_* comments in there (leave any delcarations, etc. - just get rid of the comment lines). those are all the places CW is scanning. also, you should delete the *.CLW file for your project, then re-run CW. hopefully, it won't try to re-parse your class.
-c
|
|
|
|
|
I'm using WM_MOUSEWHEEL message to provide zoom control in a window that has no scroll bars. Certain mice have an "enhanced scroll" option. If this is turned on, my window doesn't receive the WM_MOUSEWHEEL message at all (Spy doesn't show any messages when the wheel is turned). Other applications, such as IE, do receive the message (according to Spy). Any ideas?
-- Rubio
|
|
|
|
|
Essentially what I want to do is the samething that happens when you select "Window->Document Name" from the menu. I have a CView pointer to the View I want to activate.
Any help would be appreciated.
Thanks.
Eldon Zacek
Czech-Mate Enterprises, LLC
|
|
|
|
|
get the CView's associated frame (making sure it has one first) and then call ActivateFrame on the frame
- Roman -
|
|
|
|
|
Hello All,
I have previously developed a device driver for Windows NT 4.0. That was in 1999. I've since moved on to other projects. 4 years on now, I want to port my original WinNT device driver to Windows XP.
I'm wondering if thw Windows NT device driver source codes (written in C) can still be used in WinXP (usning WinXP DDK) ?
Has anyone done such porting before ?
Thanks, All,
Bio.
|
|
|
|
|
i am writing a windows app, so i know windows will always be installed , but i wont be gauranteed that its system path is c:\windows\system\
i need to programmatically find out the windows\system folder and drive on the o/s the app is running on so that i can put files into it via my code... is there an api call or easy way to pull that info from the sys???
thanks
todo....
:: insert inpirational text here ::
|
|
|
|
|
hi,
u can use
GetWindowsDirectory(...) [returns root:\windows dir] or
GetSystemDirectory(..) [returns root:\windows dir\system]
enjoy!!!!
<marquee>rishabhs<marquee>
|
|
|
|
|
U can use this function "GetSystemDirectory", this will return u the system directory on windows.
|
|
|
|