Im working on program #2 for CS153 and am having some trouble.
We're writing our own class and using it in the program, simple enough. However, in one of my classes member functions, I am trying to use the MessageBox function, and am getting compiler errors. The error I'm getting is:
s:\cs153\project2\payroll.cpp(35): error C2660: 'MessageBoxA' : function does not take 3 parameters
For some reason, it thinks I'm calling the function MessageBoxA, which I'm not. No A in my code. I'm giving it 3 parameters (text, caption, MB_OK). I can copy and paste that line of code into one of the pre-written files, like in a button event handler, and the code works great. I'm including stdafx.h in my cpp file. Anyone know whats wrong? Thanks.
Are you trying to MessageBox from your own class (ala Bag or some such) or from the dialog class?
MessageBox is a macro. The preprocessor replaces it with "the real thing" depending on certain conditions. The function that you want it to replace it with is CWnd::MessageBox(LPCTSTR, LPCTSTR, UINT). However, if you are not in a CWnd class (all of the dialogs you write in 153 are classes that derive from CWnd), the preprocessor won't expand MessageBox to the one you want.
Option 1:
You might be able to use AfxMessageBox(LPCTSTR message, UINT type, UINT Help). You can't set the title of the message box like you can with the CWnd version, though. UINT type is where you put the MB_OK, and you can omit the parameter for Help, as its default value is 0. Actually, you can omit the MB_OK for type as well, since that's the default value for that parameter.
This might get you into trouble with the graders, though.
Option 2:
I'm assuming that someone activates a control in your dialog, and that control's handler calls your "Bag" class function that you want to MessageBox from. You can try using the return value from your Bag function to pass information back to the control's handler [1], and then MessageBox() as appropriate from the dialog. This is what I would try first.
[1]For example, suppose you've "wired" a Delete button in your dialog to delete something from your Bag. You could have Bag::Delete(...) return an int to indicate which element was deleted, and have Delete return -1 or something when you try to delete a nonexistant element or if you try to delete when the Bag is empty. Then you could say something like
if(Bag.Delete(location) == -1)
MessageBox("You're a fucktard", "You're a fucktard", MB_OK);
Users browsing this forum: No registered users and 0 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum