IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

rendre un control invisible quand il est visible


Sujet :

MFC

  1. #1
    Membre confirmé
    Inscrit en
    Décembre 2010
    Messages
    98
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 98
    Par défaut rendre un control invisible quand il est visible
    Salut,
    Je travaille avec les MFC en VC++. En fait j'ai deux boutons radio
    quand je clique sur le premier un edit box apparait et quand je clique sur le deuxième un combobox apparait .
    J'ai changé la propriété visible en false et j'ai utilisé la fonction showWindow mais le probleme c'est que, pendant l'exécution si je clique sur le premier bouton (mon edit box apparait) puis sur le deuxième le combobox apparait mais je veux aussi que l'edit box redevient invisible et inversement pour le premier bouton.
    Merci de m'aider

  2. #2
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 464
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 464
    Par défaut
    Algorithmie de base.
    Un jeu de radio boutons est associé à UNE valeur.
    En cas de changement de la valeur, affichez et cachez TOUS les composants correspondant à la nouvelle valeur.
    Il faut juste faire attention que la valeur associée au radio bouton à la création de la fenêtre et le caractère visible des contrôles (radio boutons compris) soit cohérent.

  3. #3
    Membre confirmé
    Inscrit en
    Décembre 2010
    Messages
    98
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 98
    Par défaut controle visible/invisible
    pouvez vous me clarifier votre réponse s'il vous plait? j'ai mis les radio boutons toujours visible.Ce sont les combobox et les edit control qui sont visibles/invisibles.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    void CClient1Dlg::OnBnClickedRadio1()
    {
    	UpdateData(true);
    	communicationTCP=true;	
    	CWnd *ptr3 = (CWnd*)GetDlgItem(IDC_GB);
    	ptr3->SetWindowTextW(_T("Paramètres de connexion TCP"));
    	m_Port_TCP="Port";
    	m_adress="Adresse IP";
    	 ptr =  GetDlgItem(IDC_IPADDRESS1);
    	 ptr->ShowWindow(1);
    	edit_Port.ShowWindow(1);
    	UpdateData(false);
    }
     
    void CClient1Dlg::OnBnClickedRadio2()
    {
    	UpdateData(true);
    	communicationTCP=false;
    	CWnd* objet =  GetDlgItem(IDC_COMBO1);
    	CWnd* objet1 =  GetDlgItem(IDC_COMBO2);
        CComboBox* Combo;
    	CComboBox* Combo1;
        Combo = (CComboBox*) objet;
    	Combo1 = (CComboBox*) objet1;
    	CWnd *ptr_GB = (CWnd*)GetDlgItem(IDC_GB);
    	ptr_GB->SetWindowTextW(_T("Paramètres de connexion série"));
    	Combo->ShowWindow(1);//port com
    	Combo1->ShowWindow(1);
    	m_adress="Com";
    	m_Port_TCP="Bauderate";
    	UpdateData(false);
    }

  4. #4
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 464
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 464
    Par défaut
    testMFCAppDiagDlg.h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    // testMFCAppDiagDlg.h : header file
    //
    
    #pragma once
    #include "afxwin.h"
    
    
    // CtestMFCAppDiagDlg dialog
    class CtestMFCAppDiagDlg : public CDialogEx
    {
    // Construction
    public:
    	CtestMFCAppDiagDlg(CWnd* pParent = NULL);	// standard constructor
    
    // Dialog Data
    	enum { IDD = IDD_TESTMFCAPPDIAG_DIALOG };
    
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
    
    
    // Implementation
    protected:
    	HICON m_hIcon;
    
    	// Generated message map functions
    	virtual BOOL OnInitDialog();
    	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    	afx_msg void OnPaint();
    	afx_msg HCURSOR OnQueryDragIcon();
    	DECLARE_MESSAGE_MAP()
    public:
    	int m_selection;
    	afx_msg void OnBnClickedRadio1();
    	afx_msg void OnBnClickedRadio2();
    private:
    	void UpdateUI();
    public:
    	CEdit m_editbox;
    	CComboBox m_comboBox;};
    testMFCAppDiagDlg.cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    // testMFCAppDiagDlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "testMFCAppDiag.h"
    #include "testMFCAppDiagDlg.h"
    #include "afxdialogex.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    
    // CAboutDlg dialog used for App About
    
    class CAboutDlg : public CDialogEx
    {
    public:
    	CAboutDlg();
    
    // Dialog Data
    	enum { IDD = IDD_ABOUTBOX };
    
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    
    // Implementation
    protected:
    	DECLARE_MESSAGE_MAP()
    };
    
    CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
    {
    }
    
    void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialogEx::DoDataExchange(pDX);
    }
    
    BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
    END_MESSAGE_MAP()
    
    
    // CtestMFCAppDiagDlg dialog
    
    
    
    
    CtestMFCAppDiagDlg::CtestMFCAppDiagDlg(CWnd* pParent /*=NULL*/)
    	: CDialogEx(CtestMFCAppDiagDlg::IDD, pParent)
    	, m_selection(0)
    {
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    
    void CtestMFCAppDiagDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialogEx::DoDataExchange(pDX);
    	DDX_Control(pDX, IDC_EDIT1, m_editbox);
    	DDX_Control(pDX, IDC_COMBO1, m_comboBox);}
    
    BEGIN_MESSAGE_MAP(CtestMFCAppDiagDlg, CDialogEx)
    	ON_WM_SYSCOMMAND()
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	ON_BN_CLICKED(IDC_RADIO1, &CtestMFCAppDiagDlg::OnBnClickedRadio1)
    	ON_BN_CLICKED(IDC_RADIO2, &CtestMFCAppDiagDlg::OnBnClickedRadio2)END_MESSAGE_MAP()
    
    
    // CtestMFCAppDiagDlg message handlers
    
    BOOL CtestMFCAppDiagDlg::OnInitDialog()
    {
    	CDialogEx::OnInitDialog();
    
    	// Add "About..." menu item to system menu.
    
    	// IDM_ABOUTBOX must be in the system command range.
    	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    	ASSERT(IDM_ABOUTBOX < 0xF000);
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		BOOL bNameValid;
    		CString strAboutMenu;
    		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
    		ASSERT(bNameValid);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// Set the icon for this dialog.  The framework does this automatically
    	//  when the application's main window is not a dialog
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    
    	// TODO: Add extra initialization here
    
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    
    void CtestMFCAppDiagDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    	{
    		CAboutDlg dlgAbout;
    		dlgAbout.DoModal();
    	}
    	else
    	{
    		CDialogEx::OnSysCommand(nID, lParam);
    	}
    }
    
    // If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.
    
    void CtestMFCAppDiagDlg::OnPaint()
    {
    	if (IsIconic())
    	{
    		CPaintDC dc(this); // device context for painting
    
    		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
    
    		// Center icon in client rectangle
    		int cxIcon = GetSystemMetrics(SM_CXICON);
    		int cyIcon = GetSystemMetrics(SM_CYICON);
    		CRect rect;
    		GetClientRect(&rect);
    		int x = (rect.Width() - cxIcon + 1) / 2;
    		int y = (rect.Height() - cyIcon + 1) / 2;
    
    		// Draw the icon
    		dc.DrawIcon(x, y, m_hIcon);
    	}
    	else
    	{
    		CDialogEx::OnPaint();
    	}
    }
    
    // The system calls this function to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CtestMFCAppDiagDlg::OnQueryDragIcon()
    {
    	return static_cast<HCURSOR>(m_hIcon);
    }
    
    
    
    void CtestMFCAppDiagDlg::OnBnClickedRadio1()
    {
    	m_selection = 1;
    	UpdateUI();
    }
    
    
    void CtestMFCAppDiagDlg::OnBnClickedRadio2()
    {
    	m_selection = 2;
    	UpdateUI();
    }
    
    void CtestMFCAppDiagDlg::UpdateUI()
    {
    	m_editbox.ShowWindow(m_selection!=1 ? SW_HIDE : SW_NORMAL);
    	m_comboBox.ShowWindow(m_selection!=2 ? SW_HIDE : SW_NORMAL);
    }
    Extrait des ressources :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    IDD_TESTMFCAPPDIAG_DIALOG DIALOGEX 0, 0, 320, 200
    STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
    EXSTYLE WS_EX_APPWINDOW
    CAPTION "testMFCAppDiag"
    FONT 8, "MS Shell Dlg", 0, 0, 0x1
    BEGIN
        DEFPUSHBUTTON   "OK",IDOK,209,179,50,14
        PUSHBUTTON      "Cancel",IDCANCEL,263,179,50,14
        CTEXT           "TODO: Place dialog controls here.",IDC_STATIC,10,96,300,8
        GROUPBOX        "Static",IDC_STATIC,7,7,68,40
        CONTROL         "Radio1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | WS_GROUP,14,17,38,10
        CONTROL         "Radio2",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,14,28,38,10
        EDITTEXT        IDC_EDIT1,210,19,40,14,ES_AUTOHSCROLL | NOT WS_VISIBLE    COMBOBOX        IDC_COMBO1,206,38,48,30,CBS_DROPDOWN | CBS_SORT | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP
    END
    Enfin, pas de quoi casser 3 pattes à un canard.

Discussions similaires

  1. Bind seulement si le controle est visible
    Par dudule dans le forum Windows Presentation Foundation
    Réponses: 3
    Dernier message: 05/12/2013, 16h44
  2. Réponses: 1
    Dernier message: 02/09/2011, 14h13
  3. Réponses: 12
    Dernier message: 20/10/2009, 16h09
  4. Réponses: 2
    Dernier message: 29/11/2007, 20h02
  5. Souris désactivée quand elle est invisible
    Par tarzanjane dans le forum Flash
    Réponses: 2
    Dernier message: 05/06/2007, 11h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo