Click here to Skip to main content
15,902,032 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MsFlexGrid editable Pin
tidhar9-Oct-03 4:44
tidhar9-Oct-03 4:44 
GeneralNeed help in simple game Pin
Snyp8-Oct-03 14:55
Snyp8-Oct-03 14:55 
GeneralRe: Need help in simple game Pin
parths8-Oct-03 16:09
parths8-Oct-03 16:09 
GeneralRe: Need help in simple game Pin
Terry O'Nolley8-Oct-03 19:23
Terry O'Nolley8-Oct-03 19:23 
GeneralRe: Need help in simple game Pin
YaronNir9-Oct-03 0:05
YaronNir9-Oct-03 0:05 
GeneralRe: Need help in simple game Pin
Member 139425924-Dec-04 20:05
Member 139425924-Dec-04 20:05 
Generalbuttons and word doc's Pin
N.Byarley8-Oct-03 14:37
N.Byarley8-Oct-03 14:37 
GeneralRe: buttons and word doc's Pin
Terry O'Nolley8-Oct-03 18:45
Terry O'Nolley8-Oct-03 18:45 
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.









GeneralRe: buttons and word doc's Pin
N.Byarley8-Oct-03 20:33
N.Byarley8-Oct-03 20:33 
GeneralRe: buttons and word doc's Pin
Terry O'Nolley8-Oct-03 23:32
Terry O'Nolley8-Oct-03 23:32 
QuestionHow can I make the property sheet buttons in the XP style? Pin
bin89228-Oct-03 13:19
bin89228-Oct-03 13:19 
Generalwarning C4273 - inconsistent dll linkage. dllexport assumed. Pin
YaronNir8-Oct-03 12:54
YaronNir8-Oct-03 12:54 
QuestionHow to change the color of the dialog box Pin
Deepak Samuel8-Oct-03 12:15
Deepak Samuel8-Oct-03 12:15 
AnswerRe: How to change the color of the dialog box Pin
YaronNir8-Oct-03 13:16
YaronNir8-Oct-03 13:16 
QuestionEM_STREAMOUT and EditStreamCallback() function? Pin
Kayembi8-Oct-03 12:07
Kayembi8-Oct-03 12:07 
QuestionHow to make a dialog box pop up on receiving an event Pin
Deepak Samuel8-Oct-03 11:18
Deepak Samuel8-Oct-03 11:18 
GeneralWindows Xp Style Buttons Pin
Marissa1828-Oct-03 11:14
Marissa1828-Oct-03 11:14 
GeneralRe: Windows Xp Style Buttons Pin
Ravi Bhavnani8-Oct-03 11:51
professionalRavi Bhavnani8-Oct-03 11:51 
General"This" adress changing in the same object Pin
Chris Gilbert8-Oct-03 10:27
Chris Gilbert8-Oct-03 10:27 
GeneralRe: "This" adress changing in the same object Pin
Tim Smith8-Oct-03 11:19
Tim Smith8-Oct-03 11:19 
GeneralRe: "This" adress changing in the same object Pin
Chris Gilbert9-Oct-03 11:02
Chris Gilbert9-Oct-03 11:02 
GeneralRe: "This" adress changing in the same object Pin
ZoogieZork8-Oct-03 16:35
ZoogieZork8-Oct-03 16:35 
GeneralDisplaying images on CWnd dervied windows Pin
Ph@ntom8-Oct-03 9:49
Ph@ntom8-Oct-03 9:49 
General1 day only! I will answer your beginner home-work assignments! Pin
Terry O'Nolley8-Oct-03 9:24
Terry O'Nolley8-Oct-03 9:24 
GeneralRe: 1 day only! I will answer your beginner home-work assignments! Pin
Ryan_Roberts8-Oct-03 9:58
Ryan_Roberts8-Oct-03 9:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.