005
22.02.2005, 14:30 Uhr
mstank
|
Nun Post 2: Hier ist die Dlg:
C++: |
// StarDustUDPDlg.cpp : implementation file //
#include "stdafx.h" #include "MySocket.h" #include "StarDustUDP.h" #include "StarDustUDPDlg.h"
#include "ClearScreenDlg.h"
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About
class CAboutDlg : public CDialog { public: CAboutDlg();
// Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA
// ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL
// Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() };
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT }
void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP }
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CStarDustUDPDlg dialog
CStarDustUDPDlg::CStarDustUDPDlg(CWnd* pParent /*=NULL*/) : CDialog(CStarDustUDPDlg::IDD, pParent) { //{{AFX_DATA_INIT(CStarDustUDPDlg) m_port = 4000; m_strReceive = _T(""); m_strRemote = _T(""); m_remoteport = 4000; //remote port doesn't have to be same to local port for UDP //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_pUDPSocket = NULL; m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
void CStarDustUDPDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CStarDustUDPDlg) DDX_Control(pDX, IDC_CLEARSCREEN, m_ClearScreen); DDX_Control(pDX, IDC_ACTION, m_Action); DDX_Control(pDX, IDC_COUNT, m_Count); DDX_Control(pDX, IDC_RESULTS, m_ctrlResults); DDX_Text(pDX, IDC_PORT, m_port); DDV_MinMaxUInt(pDX, m_port, 1024, 50000); DDX_Text(pDX, IDC_RECEIVE, m_strReceive); DDX_Text(pDX, IDC_REMOTE, m_strRemote); DDX_Text(pDX, IDC_REMOTEPORT, m_remoteport); DDV_MinMaxUInt(pDX, m_remoteport, 1024, 50000); //}}AFX_DATA_MAP }
BEGIN_MESSAGE_MAP(CStarDustUDPDlg, CDialog) //{{AFX_MSG_MAP(CStarDustUDPDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_CREATESK, OnCreatesk) ON_WM_DESTROY() ON_BN_CLICKED(IDC_CLOSESOCK, OnClosesock) ON_BN_CLICKED(IDC_INFO, OnInfo) ON_BN_CLICKED(IDC_SAVE, OnSave) ON_BN_CLICKED(IDC_CLEARSCREEN, OnClearscreen) //}}AFX_MSG_MAP END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // CStarDustUDPDlg message handlers
BOOL CStarDustUDPDlg::OnInitDialog() { CDialog::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) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); 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 CStarDustUDPDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::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 CStarDustUDPDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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 { CDialog::OnPaint(); } }
// The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CStarDustUDPDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }
void CStarDustUDPDlg::OnCreatesk() { UpdateData(TRUE);
//Update Number Of Datasets m_txt.Format("%d", m_txt_Array.GetSize()); m_Count.SetWindowText(m_txt);
if (m_pUDPSocket) AfxMessageBox("Socket existiert bereits!"); else { if (m_port == 0) { AfxMessageBox ("Bitte geben Sie eine lokale Portnummer ein!"); return; } if ((m_pUDPSocket = new CMySocket(this)) == NULL) { AfxMessageBox ("Es konnte kein Socket zugewiesen werden! Star.Dust UDP schließen und neu starten!"); return; } m_pUDPSocket->m_nBytesBufferSize = 0;
if (!m_pUDPSocket->Create(m_port, SOCK_DGRAM)) { wsprintf(m_szError, "Failed to create UDP socket: %d! Close and restart app.", m_pUDPSocket->GetLastError()); delete m_pUDPSocket; m_pUDPSocket = NULL; AfxMessageBox (m_szError); return; } }
m_Action.SetWindowText("Socket wurde erfolgreich erzeugt!"); GetDlgItem(IDC_CLOSESOCK)->EnableWindow( TRUE ); GetDlgItem(IDC_CREATESK)->EnableWindow( FALSE ); GetDlgItem(IDC_SAVE)->EnableWindow( FALSE );
}
void CStarDustUDPDlg::OnDestroy() { CDialog::OnDestroy();
if (m_pUDPSocket) { m_pUDPSocket->Close(); delete m_pUDPSocket; } }
void CStarDustUDPDlg::OnClosesock() { if (m_pUDPSocket) { UpdateData(FALSE); m_pUDPSocket->Close(); delete m_pUDPSocket; m_pUDPSocket = NULL; }
//Output, how much Datasets are receive m_txt.Format("%d", m_txt_Array.GetSize()); m_Count.SetWindowText(m_txt); m_Action.SetWindowText("Socket wurde gelöscht!");
GetDlgItem(IDC_CLOSESOCK)->EnableWindow( FALSE ); GetDlgItem(IDC_SAVE)->EnableWindow( TRUE ); GetDlgItem(IDC_CREATESK)->EnableWindow( TRUE ); }
void CStarDustUDPDlg::OnInfo() { // TODO: Code für die Behandlungsroutine der Steuerelement-Benachrichtigung hier einfügen
m_Action.SetWindowText("Aufruf der Infobox!");
//create object of class CAboutDlg, named Info CAboutDlg Info;
Info.DoModal();
m_Action.SetWindowText("Infobox wurde geschlossen!");
}
void CStarDustUDPDlg::OnSave() {
CString strResults; CFileDialog m_ldFile(FALSE); //false for save and true for read
m_Action.SetWindowText("Daten werden gespeichert!");
//open Dialogbox and catch event if (m_ldFile.DoModal() == IDOK) { strResults = m_ldFile.GetFileName();
//get selected Filename m_ctrlResults.SetWindowText(m_ldFile.GetFileName());
//Update Dialogbox UpdateData(TRUE); }
//now save file like Star.DustRS232
//open or create file and write string per string include <cr> and <lf> CStdioFile MyFile(strResults, CFile::modeCreate | CFile::modeWrite);
for (int i=0; i<m_txt_Array.GetSize(); i++) { MyFile.WriteString(m_txt_Array[i]); }
MyFile.Close();
if (MyFile.Open(strResults, 1)) { m_Action.SetWindowText("Speichern war erfolgreich!"); } else { m_Action.SetWindowText("Die Daten konnten nicht gespeichert werden!"); }
GetDlgItem(IDC_SAVE)->EnableWindow(FALSE); }
void CStarDustUDPDlg::OnClearscreen() { // TODO: Code für die Behandlungsroutine der Steuerelement-Benachrichtigung hier einfügen CClearScreenDlg Clear;
if (Clear.DoModal() == IDOK) { //Are Datasets receive? if (m_txt_Array.GetSize() == 0) { m_Action.SetWindowText("Keine Datensätze vorhanden!"); } else { //clear the Array with the NMEA0183-Data... m_txt_Array.RemoveAll();
//...and update Number Of Datasets m_txt.Format("%d", m_txt_Array.GetSize()); m_Count.SetWindowText(m_txt);
//clear the Display and update the view m_strReceive = _T(""); UpdateData(FALSE);
m_Action.SetWindowText("Bisherige Datensätze wurde gelöscht!"); } } else { m_Action.SetWindowText("Das Löschen wurde abgebrochen!"); } }
|
Kannst du was damit anfangen?
Danke im Voraus Markus -- Hier spricht die dunkle Seite der Macht! |