Bonjour,
J'explique mon problème.
J'ai une fenêtre principale dans laquelle il y a une Combobox CComboMain
Dans une boite de dialogue modale CNewModalInfo, il y a un bouton "Ajouter".
Je veux que quand j'appuie sur le bouton "Ajouter" de cette boite modale,
une chaîne "Essai" soit insérée dans ma Combobox CComboMain.
J'ai pour cela suivi les conseil de Farscape dans la FAQ: Comment charger les contrôles d’une CDialog avant DoModal() ?
http://c.developpez.com/faq/vc/?page...ControlForward
J'ai essayé et la fonction DoModal me met une erreur.
Classe CComboMain:
ComboMain.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 class CComboMain : public CComboBox { // Construction public: CComboMain(); enum { IDC = IDC_COMBO1 }; // Attributes public: int AddString( LPCTSTR lpszItem ); // Operations public: CStringArray m_strArray; // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CComboMain) public: protected: virtual void PreSubclassWindow(); //}}AFX_VIRTUAL // Implementation public: virtual ~CComboMain(); // Generated message map functions protected: //{{AFX_MSG(CComboMain) // NOTE - the ClassWizard will add and remove member functions here. //}}AFX_MSG DECLARE_MESSAGE_MAP() };
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 // ComboMain.cpp : implementation file // #include "stdafx.h" #include "BW1.h" #include "ComboMain.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CComboMain CComboMain::CComboMain() { } CComboMain::~CComboMain() { } int CComboMain::AddString(LPCTSTR lpszItem) { // si la listbox est valide appel de la fonction d'origine. if(m_hWnd!=NULL) return CComboBox::AddString(lpszItem); m_strArray.Add(lpszItem); return LB_ERR; } void CComboMain::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class CComboBox::PreSubclassWindow(); for(int i=0;i<m_strArray.GetSize();i++) AddString(m_strArray[i]); } BEGIN_MESSAGE_MAP(CComboMain, CComboBox) //{{AFX_MSG_MAP(CComboMain) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CComboMain message handlers
Fonction "OnAjouter" de ma boite modale:
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 void CNewModalInfo::OnAjouter() { // TODO: Add your control notification handler code here // Récupération des différents champs CEdit CFiche newfiche; CEdit * pm_edit_ref1,* pclient,* plieu,* ptype,* pdate,* pm_edit_mod1; pm_edit_ref1 = (CEdit*) GetDlgItem(IDC_EDIT_REF1); pm_edit_ref1->GetWindowText(newfiche.m_edit_ref1); pclient = (CEdit*) GetDlgItem(IDC_EDIT_CLI); pclient->GetWindowText(newfiche.client); plieu = (CEdit*) GetDlgItem(IDC_EDIT_LIEU); plieu->GetWindowText(newfiche.lieu); ptype = (CEdit*) GetDlgItem(IDC_EDIT_TYPE); ptype->GetWindowText(newfiche.type); pm_edit_mod1 = (CEdit*) GetDlgItem(IDC_EDIT_MOD1); pm_edit_mod1->GetWindowText(newfiche.m_edit_mod1); pdate = (CEdit*) GetDlgItem(IDC_EDIT_DATE); pdate->GetWindowText(newfiche.date); // LE PROBLEME EST ICI //Ajout de la référence dans la ComboBox de la fenêtre principale CComboMain choix; choix.AddString("Essai1"); choix.AddString("Essai2"); //choix.DoModal(); //choix.InsertString(-1,"test"); //Ecriture des caractéristiques dans un nouveau fichier CString pFileName = newfiche.m_edit_ref1; //Affectation de la référence au nom du fichier CStdioFile testx (pFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText | CFile::modeNoTruncate ); testx.WriteString("REFERENCE: "); testx.WriteString(newfiche.m_edit_ref1); testx.WriteString("\nClient: "); testx.WriteString(newfiche.client); testx.WriteString("\nLieu: "); testx.WriteString(newfiche.lieu); testx.WriteString("\nType: "); testx.WriteString(newfiche.type); testx.WriteString("\nModèle: "); testx.WriteString(newfiche.m_edit_mod1); testx.WriteString("\nDate de mise en service: "); testx.WriteString(newfiche.date); testx.WriteString("\nAdresse IP: "); //testx.WriteString(newfiche.); testx.Close(); //DestroyWindow(); }
J'ai aussi essayé
qui ne marche pas non plus.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 choix.InsertString(-1,"test");
J'ai aussi un plantage à l'exécution avec le DestroyWindow();
Merci pour vos réponses.
Partager