1.此窗口的功能是用于给串口发送16进制字符
  例如发送000001010000 甲灯亮;发送000001020000,乙灯亮
2.现在想去掉这个窗口,让这段程序直接发送000001010000,使甲灯亮,程序隐藏运行后退出。CommWizard.cpp:BEGIN_MESSAGE_MAP(CCWApp, CWinApp)
//{{AFX_MSG_MAP(CCWApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
//    DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CCWApp constructionCCWApp::CCWApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CCWApp objectCCWApp theApp;/////////////////////////////////////////////////////////////////////////////
// CCWApp initializationBOOL CCWApp::InitInstance()
{
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CCWDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
} // Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}
CommWizardDlg.cpp:
BOOL CCWDlg::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
m_ctrlDataType.AddString(_T("按ASCII码"));
m_ctrlDataType.AddString(_T("按2进制"));
m_ctrlDataType.AddString(_T("按16进制"));
m_ctrlDataType.SetCurSel(m_nInputMode); return TRUE;  // return TRUE  unless you set the focus to a control
}void CCWDlg::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 CCWDlg::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();
}
}

解决方案 »

  1.   

    在你的对话框的初始化函数OnInitDialog里加入 this->ShowWindow(SW_HIDE); 是这个意思吗?或者放到一个按钮点击事件里
      

  2.   


    追加语句
    this->OnCancel();
      

  3.   

    这个应该加到什么地方呀,是在函数OnInitDialog中还是onpaint?
      

  4.   


    你的这个程序是基于对话框的吧看你是选择用什么方式退出对话框的。
    如果是你打算点击某个按钮就退出程序,
    就在任意按钮的响应消息函数里边加。
    如果你打算现在去掉这个窗口,让这段程序直接发送000001010000,使甲灯亮,程序隐藏运行后退出。 那就在执行发送字符的代码后边追加即可。但是,一定不要在OnInitDialog或是onpaint内添加。