帮忙隐藏窗口

2season 2009-06-27 04:03:56
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 construction

CCWApp::CCWApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CCWApp object

CCWApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CCWApp initialization

BOOL 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();
}
}


...全文
37 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
2season 2009-06-27
  • 打赏
  • 举报
回复
已经成功,谢谢各位!
Fireway2008 2009-06-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 2season 的回复:]
这个应该加到什么地方呀,是在函数OnInitDialog中还是onpaint?
[/Quote]

你的这个程序是基于对话框的吧

看你是选择用什么方式退出对话框的。
如果是你打算点击某个按钮就退出程序,
就在任意按钮的响应消息函数里边加。


如果你打算现在去掉这个窗口,让这段程序直接发送000001010000,使甲灯亮,程序隐藏运行后退出。

那就在执行发送字符的代码后边追加即可。


但是,一定不要在OnInitDialog或是onpaint内添加。
2season 2009-06-27
  • 打赏
  • 举报
回复
这个应该加到什么地方呀,是在函数OnInitDialog中还是onpaint?
Fireway2008 2009-06-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 2season 的回复:]
多谢,已经成了,但是还有如何结束程序呢!?
[/Quote]

追加语句
this->OnCancel();
2season 2009-06-27
  • 打赏
  • 举报
回复
多谢,已经成了,但是还有如何结束程序呢!?
2season 2009-06-27
  • 打赏
  • 举报
回复
我放了,没有改善,还是弹出对话框
猞猁狲 2009-06-27
  • 打赏
  • 举报
回复
在你的对话框的初始化函数OnInitDialog里加入 this->ShowWindow(SW_HIDE); 是这个意思吗?

或者放到一个按钮点击事件里

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧