Click here to Skip to main content
15,846,826 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WebSockets in native C++ (not managed) Pin
enhzflep17-Feb-12 0:57
enhzflep17-Feb-12 0:57 
GeneralRe: WebSockets in native C++ (not managed) Pin
Fred Ackers19-Feb-12 7:57
Fred Ackers19-Feb-12 7:57 
GeneralRe: WebSockets in native C++ (not managed) Pin
enhzflep19-Feb-12 13:19
enhzflep19-Feb-12 13:19 
QuestionSending message between objects Pin
aangerma16-Feb-12 10:16
aangerma16-Feb-12 10:16 
QuestionRe: Sending message between objects Pin
David Crow16-Feb-12 11:54
David Crow16-Feb-12 11:54 
AnswerRe: Sending message between objects Pin
aangerma16-Feb-12 20:42
aangerma16-Feb-12 20:42 
AnswerRe: Sending message between objects Pin
Albert Holguin16-Feb-12 19:15
professionalAlbert Holguin16-Feb-12 19:15 
AnswerRe: Sending message between objects Pin
enhzflep16-Feb-12 19:19
enhzflep16-Feb-12 19:19 
Its a simple process with a number of small steps.

1. Wire-up the message handling of the radio buttons so that you get a WM_NOTIFY (or whatever the pertinent message is) whenever the active radio-button in the group changes.

2. Call method of object 2 with the selected option passed in as a variable somehow - either as text, or (preferably) as an INT that represents the choice number.

Here's a dialog-based app that demonstrates the principle. Whether you call the method of the second object when the selection changes or when an 'action' button is pressed, is up to you.

(And yes, I do realize that as they're radio-buttons, one of the options should be checked by default - just can't remember how just this minute - it was easier and quicker to add a test case to check if an option had been selected yet or not Blush | :O )

resource.rc
XML
// Generated by ResEdit 1.5.8
// Copyright (C) 2006-2011
// http://www.resedit.net

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"




//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOGEX 6, 5, 194, 106
STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_CAPTION | WS_VISIBLE | WS_GROUP | WS_THICKFRAME | WS_SYSMENU
CAPTION "Code::Blocks Template Dialog App"
FONT 8, "Tahoma", 0, 0, 1
{
    PUSHBUTTON      "&Test", IDC_BTN_TEST, 138, 5, 46, 15
    PUSHBUTTON      "&Quit", IDC_BTN_QUIT, 138, 29, 46, 15
    GROUPBOX        "Static", IDC_STATIC, 13, 16, 114, 68
    AUTORADIOBUTTON "Radio Button 1", IDC_RADIO1, 38, 32, 63, 8
    AUTORADIOBUTTON "Radio Button 2", IDC_RADIO2, 38, 45, 63, 8
    AUTORADIOBUTTON "Radio Button 3", IDC_RADIO3, 38, 59, 63, 8
}


resource.h
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define DLG_MAIN                                101
#define IDC_BTN_TEST                            1000
#define IDC_BTN_QUIT                            1001
#define IDC_RADIO1                              1002
#define IDC_RADIO2                              1003
#define IDC_RADIO3                              1004


main.cpp
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <stdio.h>

#include "resource.h"

HINSTANCE hInst;
int curRadioOption = -1;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    char msgBuffer[1024];
    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_CLOSE:
            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                /*
                 * TODO: Add more control ID's, when needed.
                 */
                case IDC_BTN_QUIT:
                    EndDialog(hwndDlg, 0);
                    return TRUE;

                case IDC_BTN_TEST:
                    if (curRadioOption != -1)
                        sprintf(msgBuffer, "You clicked the \"test\" button\nCurrent radio selection: #%d", curRadioOption);
                    else
                        sprintf(msgBuffer, "No radio-button option selected...\nPlease select an option then try again");

                    MessageBox(hwndDlg, msgBuffer, "Information", MB_ICONINFORMATION);
                    return TRUE;

                case IDC_RADIO1:
                    curRadioOption = 1;
                    return true;

                case IDC_RADIO2:
                    curRadioOption = 2;
                    return true;

                case IDC_RADIO3:
                    curRadioOption = 3;
                    return true;
            }
    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}

GeneralRe: Sending message between objects Pin
aangerma16-Feb-12 20:57
aangerma16-Feb-12 20:57 
GeneralRe: Sending message between objects Pin
enhzflep16-Feb-12 23:35
enhzflep16-Feb-12 23:35 
AnswerRe: Sending message between objects Pin
JackDingler17-Feb-12 11:35
JackDingler17-Feb-12 11:35 
QuestionControl Multiple Dialog boxes in SDI application Pin
johnjitu16-Feb-12 5:35
johnjitu16-Feb-12 5:35 
GeneralRe: Control Multiple Dialog boxes in SDI application Pin
David Crow16-Feb-12 5:39
David Crow16-Feb-12 5:39 
GeneralRe: Control Multiple Dialog boxes in SDI application Pin
johnjitu16-Feb-12 6:03
johnjitu16-Feb-12 6:03 
SuggestionRe: Control Multiple Dialog boxes in SDI application Pin
David Crow16-Feb-12 6:06
David Crow16-Feb-12 6:06 
Questionhow to add image in SDI Pin
sarfaraznawaz16-Feb-12 3:52
sarfaraznawaz16-Feb-12 3:52 
AnswerRe: how to add image in SDI Pin
Richard MacCutchan16-Feb-12 5:19
mveRichard MacCutchan16-Feb-12 5:19 
QuestionHow to create OLE object for MS Office Pin
LionAM16-Feb-12 0:31
LionAM16-Feb-12 0:31 
AnswerRe: How to create OLE object for MS Office Pin
CPallini16-Feb-12 1:36
mveCPallini16-Feb-12 1:36 
GeneralRe: How to create OLE object for MS Office Pin
LionAM16-Feb-12 5:51
LionAM16-Feb-12 5:51 
GeneralRe: How to create OLE object for MS Office Pin
LionAM16-Feb-12 6:59
LionAM16-Feb-12 6:59 
GeneralRe: How to create OLE object for MS Office Pin
CPallini16-Feb-12 10:23
mveCPallini16-Feb-12 10:23 
GeneralRe: How to create OLE object for MS Office Pin
LionAM16-Feb-12 22:04
LionAM16-Feb-12 22:04 
QuestionMFC Multiple Splitter for MDI Application Pin
SHWRRMSH16-Feb-12 0:29
SHWRRMSH16-Feb-12 0:29 
GeneralRe: MFC Multiple Splitter for MDI Application Pin
Jochen Arndt16-Feb-12 1:11
professionalJochen Arndt16-Feb-12 1:11 

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.