C'est ce que je me disais...
... Mais gt pas sur. Merci pour cette précieuse information.
Pitite question avant de réintègrer ma classe cl_bluetooth
Je désire obtenir le PORT et le Baud rate de mon port série, en validant les choix dans deux combobox.
param-serie est la classe de la boite de dialogue
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| //param_serie.h
protected:
virtual void DoDataExchange(CDataExchange* pDX); // Prise en charge de DDX/DDV
virtual BOOL OnInitDialog ();
DECLARE_MESSAGE_MAP()
public:
int vitesse;
public:
char port;
public:
CComboBox comboPORT;
public:
CComboBox comboRATE; |
Code:
1 2 3 4 5 6 7 8
|
void CGAB_PDAView::OnBnClickedOk()
{int x=obj.comboRATE.GetCurSel();
obj.comboRATE.GetLBText(x,???obj.vitesse);
obj.comboPORT.GetLBText(x,???obj.port);
obj.DestroyWindow();
} |
Comme vous le voyez le problème c'est que je désire convertir le paramètre en rouge pour passer d'un LPCSTR à un int pour la vitesse et en char* pour le port. Quels sont les fonctions qui permettent cela en précisant que mon évènement OnBnClickedOk() est dans le fichier View de mon appli
petit bilan et question importante
Bonjourje vous met le code source de mon appli. J'ai beaucoup de difficultés avec les MFC.
Code:
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
| // GAB_PDAView.h : interface de la classe CGAB_PDAView
//
#pragma once
#include "param_serie.h"
#include "cl_Bluetooth.h"
class CGAB_PDAView : public CFormView
{
protected: // création à partir de la sérialisation uniquement
CGAB_PDAView();
DECLARE_DYNCREATE(CGAB_PDAView)
public:
enum{ IDD = IDD_GAB_PDA_FORM };
// Attributs
public:
CGAB_PDADoc* GetDocument() const;
// Opérations
public:
// Substitutions
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // Prise en charge de DDX/DDV
virtual void OnInitialUpdate(); // premier appel après la construction
// Implémentation
public:
virtual ~CGAB_PDAView();
#ifdef _DEBUG
virtual void AssertValid() const;
#endif
protected:
// Fonctions générées de la table des messages
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnMenuParam32774();
public:
param_serie obj;
};
#ifndef _DEBUG // version de débogage dans GAB_PDAView.cpp
inline CGAB_PDADoc* CGAB_PDAView::GetDocument() const
{ return reinterpret_cast<CGAB_PDADoc*>(m_pDocument); }
#endif |
Code:
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
| // GAB_PDAView.cpp : implémentation de la classe CGAB_PDAView
//
#include "stdafx.h"
#include "GAB_PDA.h"
#include "GAB_PDADoc.h"
#include "GAB_PDAView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CGAB_PDAView
IMPLEMENT_DYNCREATE(CGAB_PDAView, CFormView)
BEGIN_MESSAGE_MAP(CGAB_PDAView, CFormView)
ON_COMMAND(ID_MENU_PARAM32774, &CGAB_PDAView::OnMenuParam32774)
END_MESSAGE_MAP()
// construction ou destruction de CGAB_PDAView
CGAB_PDAView::CGAB_PDAView()
: CFormView(CGAB_PDAView::IDD)
{
// TODO : ajoutez ici du code de construction
}
CGAB_PDAView::~CGAB_PDAView()
{
}
void CGAB_PDAView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
}
BOOL CGAB_PDAView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO : changez ici la classe ou les styles Window en modifiant
// CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CGAB_PDAView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
}
// diagnostics pour CGAB_PDAView
#ifdef _DEBUG
void CGAB_PDAView::AssertValid() const
{
CFormView::AssertValid();
}
CGAB_PDADoc* CGAB_PDAView::GetDocument() const // la version non déboguée est en ligne
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGAB_PDADoc)));
return (CGAB_PDADoc*)m_pDocument;
}
#endif //_DEBUG
// gestionnaires de messages pour CGAB_PDAView
void CGAB_PDAView::OnMenuParam32774()
/* Menu -> Paramètre */
{
obj.DoModal();
} |
Code:
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
| // GAB_PDA.h : fichier d'en-tête principal pour l'application GAB_PDA
//
#pragma once
#ifndef __AFXWIN_H__
#error "incluez 'stdafx.h' avant d'inclure ce fichier pour PCH"
#endif
#include "resourceppc.h"
#include "cl_Bluetooth.h"
// CGAB_PDAApp:
// Consultez GAB_PDA.cpp pour l'implémentation de cette classe
//
class CGAB_PDAApp : public CWinApp
{
public:
CGAB_PDAApp();
// Substitutions
public:
virtual BOOL InitInstance();
// Implémentation
public:
afx_msg void OnAppAbout();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnMenuParametre();
public:
cl_Bluetooth *serie;
};
extern CGAB_PDAApp theApp; |
Code:
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
|
// GAB_PDA.cpp : Définit les comportements de classe pour l'application.
//
#include "stdafx.h"
#include "GAB_PDA.h"
#include "MainFrm.h"
#include "GAB_PDADoc.h"
#include "GAB_PDAView.h"
#include "cl_Bluetooth.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CGAB_PDAApp
BEGIN_MESSAGE_MAP(CGAB_PDAApp, CWinApp)
ON_COMMAND(ID_APP_ABOUT, &CGAB_PDAApp::OnAppAbout)
ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
ON_COMMAND(ID_MENU_PARAMETRE, &CGAB_PDAApp::OnMenuParametre)
END_MESSAGE_MAP()
// construction CGAB_PDAApp
CGAB_PDAApp::CGAB_PDAApp()
: CWinApp()
{
// TODO : ajoutez ici du code de construction,
// Placez toutes les initialisations significatives dans InitInstance
}
// Seul et unique objet CGAB_PDAApp
CGAB_PDAApp theApp;
// initialisation de CGAB_PDAApp
BOOL CGAB_PDAApp::InitInstance()
{
// SHInitExtraControls doit être appelé une fois lors de l'initialisation de votre application afin d'initialiser
// l'un des contrôles spécifiques à Windows Mobile, tels que CAPEDIT et SIPPREF.
SHInitExtraControls();
// Initialisation standard
// Si vous n'utilisez pas ces fonctionnalités et que vous souhaitez réduire la taille
// de votre exécutable final, vous devez supprimer ci-dessous
// les routines d'initialisation spécifiques dont vous n'avez pas besoin.
// Changez la clé de Registre sous laquelle nos paramètres sont enregistrés
// TODO : modifiez cette chaîne avec des informations appropriées,
// telles que le nom de votre société ou organisation
SetRegistryKey(_T("Applications locales générées par AppWizard"));
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CGAB_PDADoc),
RUNTIME_CLASS(CMainFrame), // fenêtre frame SDI principale
RUNTIME_CLASS(CGAB_PDAView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
// Analyser la ligne de commande pour les commandes shell standard, DDE, ouverture de fichiers
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Commandes de dispatch spécifiées sur la ligne de commande. Retournent FALSE si
// l'application a été lancée avec /RegServer, /Register, /Unregserver ou /Unregister.
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// La seule fenêtre a été initialisée et peut donc être affichée et mise à jour
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
// boîte de dialogue CAboutDlg utilisée pour la boîte de dialogue 'À propos de' pour votre application
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Données de boîte de dialogue
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // Prise en charge de DDX/DDV
// Implémentation
protected:
#ifdef _DEVICE_RESOLUTION_AWARE
afx_msg void OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/);
#endif
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE; // retourne TRUE sauf si vous avez défini le focus sur un contrôle
// EXCEPTION : les pages de propriétés OCX devraient retourner FALSE
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
#ifdef _DEVICE_RESOLUTION_AWARE
ON_WM_SIZE()
#endif
END_MESSAGE_MAP()
#ifdef _DEVICE_RESOLUTION_AWARE
void CAboutDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX));
}
#endif
// Commande App pour exécuter la boîte de dialogue
void CGAB_PDAApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CGAB_PDAApp::OnMenuParametre()
{this->ExitInstance();
this->CloseAllDocuments(true);
} |
Code:
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
| // param_serie.cpp*: fichier d'implémentation
//
#include "stdafx.h"
#include "GAB_PDA.h"
#include "param_serie.h"
// Boîte de dialogue param_serie
IMPLEMENT_DYNAMIC(param_serie, CDialog)
param_serie::param_serie(CWnd* pParent /*=NULL*/)
: CDialog(param_serie::IDD, pParent)
, vitesse(0)
, port(0)
{
}
param_serie::~param_serie()
{
}
void param_serie::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, comboPORT);
DDX_Control(pDX, IDC_COMBO2, comboRATE);
}
BOOL param_serie::OnInitDialog()
{CString tmp;
CDialog::OnInitDialog();
comboRATE.AddString(_T("4800")); //remplissage du comboRATE
comboRATE.AddString(_T("9600"));
comboRATE.AddString(_T("19400"));
comboRATE.SetCurSel(1); //fin initialisation comboRATE
for (int i=0;i<8;i++)
{
tmp.Format(_T("COM%d"),i+1);
comboPORT.InsertString(i,tmp);
}
comboPORT.SetCurSel(0);
return true;
}
BEGIN_MESSAGE_MAP(param_serie, CDialog)
ON_BN_CLICKED(IDOK, ¶m_serie::OnBnClickedOk)
END_MESSAGE_MAP()
// Gestionnaires de messages de param_serie
void param_serie::OnBnClickedOk()
{int x,y;
CString tmp1,tmp2;
x=this->comboPORT.GetCurSel();
y=this->comboRATE.GetCurSel();
this->comboPORT.GetDlgItemText(x,tmp1);
this->comboRATE.GetDlgItemText(y,tmp2);
CGAB_PDAApp *pApp=static_cast<CGAB_PDAApp *>(AfxGetApp());
pApp->serie->modifPARAM(tmp1,tmp2);
OnOK();
} |
je dois convertir tmp1 en char* et tmp2 en int. je n'ai pas trouvé de fonction simple pour le faire même sur les forums.
Ensuite je dois afficher les trames reçues sur le port série dans un ListBox. Quelles fonctions utiliser pour créer et utiliser un timer et comment convertir un char* en CString