|
It sounds like you are having difficulty mapping an event to a function.
(I make that assumption because event handling is the greatest common denominator of "click a button and pull up a web page" and "click a button and load a JPEG from disk")
An "event" is anything that a user can do with their input devices (typically mouse and keybopard) that results in your program being told something has happened (other events are generated by the system as well).
Windows informs your code that an event has happened by sending "Messages". Messages contain data that defines the name for the message and additional data that is pertinent to that specific message.
"Handle"ing that event is simply writing code that is executed in response to an event.
MFC passes information to your classes as events happen. For example - when a user double-clicks their mouse, Windows sends a message that tells your program that the mouse was double-clicked. For the double-click message, the additional data are the coordinates of where the mouse click was.
To get your program to respond to a button being clicked, you need to follow these steps:
1) Create an App in App-Wizard - make it Dialog based for learning. It is easier.
2) Go to the Resource view and look at your main dialog.
3) Add a button from the tool palette.
4) Edit that button's properties - name it IDC_DRAGON. For it's caption, enter whatever you want
5) Type Ctrl-W to open Class Wizard
6) Make sure the class selected is the Dialog box class for your main dialog
7) Highlight the button's ID (IDC_DRAGON) in the Object IDs listbox
8) You'll see 2 messages in the "Messages" listbox that Windows recognizes for that type of highlighted object
9) Double-click on the BN_CLICKED message
10) You will see a small dialog that opens and asks you for the name of the function that will Handle that Event (clicking the button). You can usually just use the default. Click OK.
11) What you have just done is add an empty Message Handler for code that will be executed when a user clicks that button.
12) Notice that the text in the Messages listbox is now bold for the message BN_CLICKED. This means that Class Wizard has created a Handler for that Message
13) Look at the Member Functions listbox - you should see that the function name you entered (or accepted as the default) for the handler for the BN_CLICKED Message for the IDC_DRAGON object is highlightd.
14) Double-click that highlighted function and you will be taken to your source code - right at the spot where you need to write the code to handle that event.
15) Just to verify that you are handling the event - write the following code where Class Wizard positions you:
MessageBox("Dragon Button", "BN_CLICK Handler");
16) If you do it correctly, you will see the message box when you click the Dragon button
If this explanation was too simplistic, I apologize. It sounded like you needed help in handling events.
If you complete steps 1-16 correctly, then you will be ready to write the actual code you need to respond to a button click.
|
|
|
|
|
no it was not to simplistic that was just what was looking for thank you
"Effort within the mind further limits the mind, because effort implies struggle towards a goal and when you have a goal, a purpose, an end in view, you have placed a limit on the mind"
|
|
|
|
|
Glad to help! Follow up if you have any problem......
|
|
|
|
|
How can I make the property sheet buttons in the XP style? I know there are classes that I can use to make the buttons in a dialog box looks like the XP style. I'd like to do how can I do the same thing to the Default buttons of the Property sheet?
Thanks a lot in advance
|
|
|
|
|
Hi all,
I've created a MFC extention dll project. in the stdafx.h file i've wrote:
#undef _GUI_LIB_EXPORT_
#ifdef _EXPORT_GUI_LIB_
#define _GUI_LIB_EXPORT_ __declspec(dllexport)
#else
#define _GUI_LIB_EXPORT_ __declspec(dllimport)
#endif
i have 2 exported classes, 1 is a dialog, the other one is a button:
1) class _GUI_LIB_EXPORT_ CMyDlg : public CDialog
2) class _GUI_LIB_EXPORT_ CMyBtn : public CButton
i use an MFC exe project to test my dll.
in the stdafx.h i also write :
#undef _GUI_LIB_EXPORT_
#ifdef _EXPORT_GUI_LIB_
#define _GUI_LIB_EXPORT_ __declspec(dllexport)
#else
#define _GUI_LIB_EXPORT_ __declspec(dllimport)
#endif
when i compile, it seams to recognize the dialog exported class (CMyDlg) but for the CMyBtn class i get
warning C4273 - inconsistent dll linkage. dllexport assumed.
can any1 help???
i am desparate here..
thanks in advanced,
Yaron
|
|
|
|
|
Hi,
Usually the color of the dialog box by default is grey, how do i change the color. How can i make the dialog box change its color as soon as i clickon a button.
Thanks and regards
Deepak Samuel
|
|
|
|
|
Hi,
there are several ways to change the dialog bk color:
1) use SetDialogBKColor() method in the InitInstance()
2) use OnColorCtl() Message handler
3) draw a rectangle that will cover the entire dialog
i prefer to use the second method
here is an example code on how to use it:
in the *.h file write down:
protected:<br />
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
in the *.cpp file write an entry in the message map:
BEGIN_MESSAGE_MAP(CYourDlg, CDialog)<br />
ON_WM_CTLCOLOR()<br />
END_MESSAGE_MAP()
implenent the OnColorCtl , write down:
HBRUSH CGUIBaseDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) <br />
{<br />
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);<br />
<br />
if (CTLCOLOR_DLG == nCtlColor)<br />
hbr = m_brushDlgBk;<br />
<br />
<br />
return hbr;<br />
}
notice the use of brushDlgBk.
in the *.h file define the brush:
CBrush m_brushDlgBk;
in the *.cpp file in the constructor of the dialog
create the brush:
m_brushDlgBk.CreateSolidBrush(RGB(200,200,200))// the color you chose place here
that should do the trick....
to switch the colors on a click just use 2 brushes and return the proper one in the OnCtlColor method according to a flag indicating the click
hope i helped ya
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Hi,
Could someone please give me some tips - or even better, link ot some examples - on how to create an EditStreamCallback function? I have searched the net and several coding forums, but can't find any solid information, even MSDN.
I have a Rich Edit text box, and whilst I can currently save to a .txt file using GetDlgItemText() and WriteFile(), this method is very limited and I really want to save as an RTF file. I have read the info on EM_STREAMOUT and EditStreamCallback, and it seems that these are the functions I need to use in order to save as an RTF file.
If anyone can tell me how to write a callback function that will write an .rtf file, link to some more comprehensive info, or just give me some general tips, I would be really grateful.
Incidentally, I am using the straight Win API SDK with _no_ MFC.
Many thanks!
KB
|
|
|
|
|
Hi,
I have a MFC applivcation which has around 5 dialog boxes. I also have another real time application . I want to make one of the dialog boxes to pop up as soon as receives a event from this real time process. How do I proceed ?
Thanks and regards,
Deepak Samuel
|
|
|
|
|
Hi i just tested my program on windows xp and its got the old style buttons how do i change them to xp style buttons? im using msvc 6.0
|
|
|
|
|
|
Hi!
In some class, the adress of "this" change from method to other method of the same class.
For example,
void X::doNothing()
{
doNothing2(); // adress of "this" = 0x053014e4
}
void X::doNothing2()
{
// adress of "this" = 0x053014f0
}
This happen only in some class of my project.
The "this" adress is essential for me because I use it to do object research by comparing adress.
Do someone have an idea why in some class this will happen and other not?
|
|
|
|
|
Multiple base clases with virtual methods?
Poor pointer casting? (don't use (X *), use static_cast <x *=""> ())
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi!
I don`t use poor pointer casting. In fact, I often use dynamic_cast on object having multiple base class (and the basic base class is inherited virtually).
Can it cause a problem?
I`m stocking "this" adress in a vector to do futur search base on adress difference.
Thanks
Chris
|
|
|
|
|
Perhaps an implicit copy is being made somewhere? You can try explicitly specifying the copy constructor and setting a breakpoint inside it.
- Mike
|
|
|
|
|
Hi all,
I am deriving a class from CWnd , I just want to display images from a CListImage . What I really need is to display images like Emoticon Window in messenger like applications.
I saw an article in C# which creates an emoticon window, I tried myself but were unable to do in VC++/MFC
Please anybody help me to create a window like the one I need.
Thanks.
The Phantom
|
|
|
|
|
PLEASE DISREGARD THIS POST - I WAS ONLY JOKING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Hmm
Whois Server Version 1.3
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http:
for detailed information.
No match for "PROGRAMMINGHOMEWORK.COM".
It might just work. A mate of mine from university set up www.cheathouse.com[^]. Makes a packet out of it too.
Ryan
"Everybody has a right to be stupid, but
some people abuse the privilege."
Uncle Joe Stalin
|
|
|
|
|
I was just kidding. Maybe someone would be willing to put something together to make some $$$.
|
|
|
|
|
Ok, I'll take you up on it. I've *very* new at this and assume the question is trivial, but can't seem to figure out how to get the documentation to tell me what I want to know.
I need to read a string and, if it's a number, convert it to double. How do I tell whether the string (input via the Console::ReadLine() method) contains only numeric characters (and can therefor be correctly converted to double via the Convert::ToDouble() method) or not?
If this turns out not to be trivial, just let me know and I'll think of something else. Maybe get a stream of chars or something (yuck!)
|
|
|
|
|
Your question sounds like a sincere request for advice - and I would gladly answer it if I could - but I am only familiar with MFC and C++ - I think your question is either .NET, JAVA or C# (I have no idea).
|
|
|
|
|
Terry O`Nolley wrote:
but I am only familiar with MFC and C++ - I think your question is either .NET, JAVA or C# (I have no idea).
No...it's C++ with managed extensions
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
Even though this isn't C/C++ like Terry said, you can still use this same method that I'd use.
Write a function that checks each character to see if it is a number or not. Return true if its a number and false if not. If it reaches the end of the string without returning false, then it converts it double, else it fails.
Two ways I can think of to do this. One is just check the char is equal to any number 0-9 (this probably isn't the most effective way) or convert to ascii and check if it is within the ascii range for a number.
Mike
|
|
|
|
|
You could look at the System::Text::RegularExpressions namespace and create a regular expression that would match the characters 0-9...then check to see if the thing is a match. You could also use the Microsoft::VisualBasic namespace and the IsNumeric() function.
Also, I think the Convert::ToDouble() throws an exception if the input string is not in a proper format. (Actually I know so, I just did this the other day in C#). You could wrap the call to ToDouble() in a try catch block and handle the error whichever way you want.
Hope that helps...
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
If you wish to buy some advertising then please contact marketing@codeproject.com. Advertising in this way is, unfortunately, unacceptable.
cheers,
Chris Maunder
|
|
|
|