serialserver/c32serialserver/Test/te_C32Performance/USB PC Side Code/SerialPortDlg.cpp
branchRCL_3
changeset 70 b564fb5fd78b
parent 0 dfb7c4ff071f
equal deleted inserted replaced
69:9d7ce34704c8 70:b564fb5fd78b
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // SerialPortDlg.cpp :- This class implements the CDialog class
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent.
       
    21 */
       
    22 
       
    23 #include "stdafx.h"
       
    24 #include "SerialPort.h"
       
    25 #include "SerialPortDlg.h"
       
    26 #include "SerialConnection.h"
       
    27 
       
    28 #ifdef _DEBUG
       
    29 #define new DEBUG_NEW
       
    30 #undef THIS_FILE
       
    31 static char THIS_FILE[] = __FILE__;
       
    32 #endif
       
    33 
       
    34 //
       
    35 // CAboutDlg dialog used for App About
       
    36 
       
    37 class CAboutDlg : public CDialog
       
    38 {
       
    39 public:
       
    40 	CAboutDlg();
       
    41 
       
    42 // Dialog Data
       
    43 	//{{AFX_DATA(CAboutDlg)
       
    44 	enum { IDD = IDD_ABOUTBOX };
       
    45 	//}}AFX_DATA
       
    46 
       
    47 	// ClassWizard generated virtual function overrides
       
    48 	//{{AFX_VIRTUAL(CAboutDlg)
       
    49 	protected:
       
    50 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
       
    51 	//}}AFX_VIRTUAL
       
    52 
       
    53 // Implementation
       
    54 protected:
       
    55 	//{{AFX_MSG(CAboutDlg)
       
    56 	//}}AFX_MSG
       
    57 	DECLARE_MESSAGE_MAP()
       
    58 };
       
    59 
       
    60 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
       
    61 {
       
    62 	//{{AFX_DATA_INIT(CAboutDlg)
       
    63 	//}}AFX_DATA_INIT
       
    64 }
       
    65 
       
    66 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
       
    67 {
       
    68 	CDialog::DoDataExchange(pDX);
       
    69 	//{{AFX_DATA_MAP(CAboutDlg)
       
    70 	//}}AFX_DATA_MAP
       
    71 }
       
    72 
       
    73 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
       
    74 	//{{AFX_MSG_MAP(CAboutDlg)
       
    75 		// No message handlers
       
    76 	//}}AFX_MSG_MAP
       
    77 END_MESSAGE_MAP()
       
    78 
       
    79 //
       
    80 // CSerialPortDlg dialog
       
    81 
       
    82 CSerialPortDlg::CSerialPortDlg(CWnd* pParent /*=NULL*/)
       
    83 	: CDialog(CSerialPortDlg::IDD, pParent)
       
    84 {
       
    85 	//{{AFX_DATA_INIT(CSerialPortDlg)
       
    86 	m_StrComPortNo = _T("");
       
    87 	//}}AFX_DATA_INIT
       
    88 	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
       
    89 	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
       
    90 }
       
    91 
       
    92 void CSerialPortDlg::DoDataExchange(CDataExchange* pDX)
       
    93 {
       
    94 	CDialog::DoDataExchange(pDX);
       
    95 	//{{AFX_DATA_MAP(CSerialPortDlg)
       
    96 	DDX_Control(pDX, IDC_Text, m_LabelText);
       
    97 	DDX_Text(pDX, IDC_EDIT1, m_StrComPortNo);
       
    98 	//}}AFX_DATA_MAP
       
    99 }
       
   100 
       
   101 BEGIN_MESSAGE_MAP(CSerialPortDlg, CDialog)
       
   102 	//{{AFX_MSG_MAP(CSerialPortDlg)
       
   103 	ON_WM_SYSCOMMAND()
       
   104 	ON_WM_PAINT()
       
   105 	ON_WM_QUERYDRAGICON()
       
   106 	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
       
   107 	//}}AFX_MSG_MAP
       
   108 END_MESSAGE_MAP()
       
   109 
       
   110 //
       
   111 // CSerialPortDlg message handlers
       
   112 
       
   113 BOOL CSerialPortDlg::OnInitDialog()
       
   114 {
       
   115 	CDialog::OnInitDialog();
       
   116 
       
   117 	// Add "About..." menu item to system menu.
       
   118 
       
   119 	// IDM_ABOUTBOX must be in the system command range.
       
   120 	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
       
   121 	ASSERT(IDM_ABOUTBOX < 0xF000);
       
   122 
       
   123 	CMenu* pSysMenu = GetSystemMenu(FALSE);
       
   124 	if (pSysMenu != NULL)
       
   125 	{
       
   126 		CString strAboutMenu;
       
   127 		strAboutMenu.LoadString(IDS_ABOUTBOX);
       
   128 		if (!strAboutMenu.IsEmpty())
       
   129 		{
       
   130 			pSysMenu->AppendMenu(MF_SEPARATOR);
       
   131 			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
       
   132 		}
       
   133 	}
       
   134 
       
   135 	// Set the icon for this dialog.  The framework does this automatically
       
   136 	//  when the application's main window is not a dialog
       
   137 	SetIcon(m_hIcon, TRUE);			// Set big icon
       
   138 	SetIcon(m_hIcon, FALSE);		// Set small icon
       
   139 	
       
   140 	// TODO: Add extra initialization here
       
   141 	
       
   142 	return TRUE;  // return TRUE  unless you set the focus to a control
       
   143 }
       
   144 
       
   145 void CSerialPortDlg::OnSysCommand(UINT nID, LPARAM lParam)
       
   146 {
       
   147 	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
       
   148 	{
       
   149 		CAboutDlg dlgAbout;
       
   150 		dlgAbout.DoModal();
       
   151 	}
       
   152 	else
       
   153 	{
       
   154 		CDialog::OnSysCommand(nID, lParam);
       
   155 	}
       
   156 }
       
   157 
       
   158 // If you add a minimize button to your dialog, you will need the code below
       
   159 //  to draw the icon.  For MFC applications using the document/view model,
       
   160 //  this is automatically done for you by the framework.
       
   161 
       
   162 void CSerialPortDlg::OnPaint() 
       
   163 {
       
   164 	if (IsIconic())
       
   165 	{
       
   166 		CPaintDC dc(this); // device context for painting
       
   167 
       
   168 		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
       
   169 
       
   170 		// Center icon in client rectangle
       
   171 		int cxIcon = GetSystemMetrics(SM_CXICON);
       
   172 		int cyIcon = GetSystemMetrics(SM_CYICON);
       
   173 		CRect rect;
       
   174 		GetClientRect(&rect);
       
   175 		int x = (rect.Width() - cxIcon + 1) / 2;
       
   176 		int y = (rect.Height() - cyIcon + 1) / 2;
       
   177 
       
   178 		// Draw the icon
       
   179 		dc.DrawIcon(x, y, m_hIcon);
       
   180 	}
       
   181 	else
       
   182 	{
       
   183 		CDialog::OnPaint();
       
   184 	}
       
   185 }
       
   186 
       
   187 // The system calls this to obtain the cursor to display while the user drags
       
   188 //  the minimized window.
       
   189 HCURSOR CSerialPortDlg::OnQueryDragIcon()
       
   190 {
       
   191 	return (HCURSOR) m_hIcon;
       
   192 }
       
   193 
       
   194 void CSerialPortDlg::OnOK() 
       
   195 {
       
   196 	CString strPortNo;
       
   197 
       
   198 	UpdateData (TRUE);
       
   199 
       
   200 /*
       
   201   set the virtual com port no.This can be any value greater than available 
       
   202   physical port no.eg \\\\.\\com14
       
   203 */
       
   204 	if( m_StrComPortNo != "" )
       
   205 	{
       
   206 		strPortNo = "\\\\\\\\.\\\\" + m_StrComPortNo;
       
   207 		serialconnect.PortInitialize ( strPortNo );
       
   208 	}
       
   209 	else
       
   210 	{
       
   211 		AfxMessageBox(" Please enter the Com Port No ");
       
   212 	}
       
   213 	
       
   214 }
       
   215 
       
   216 void CSerialPortDlg::OnCancel() 
       
   217 {
       
   218 	CDialog::OnCancel();
       
   219 }
       
   220 
       
   221 void CSerialPortDlg::OnButton1() 
       
   222 {
       
   223 }
       
   224