控制台程序调用基于对话框的MFC程序

鶄鈊 2015-11-06 10:58:59
有一个基于对话框的MFC程序,其中有一个按钮,点击按钮会弹出一个消息框显示消息。 要怎么做才能在运行控制台程序时,不生成MFC的窗口,实现点击按钮的结果,并将按钮要弹出的消息框中的消息显示到dos窗口中?
...全文
198 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
paschen 版主 2015-11-06
  • 打赏
  • 举报
回复
引用 4 楼 jianghuchuanzhize 的回复:
[quote=引用 3 楼 paschen 的回复:] 先获取你控制台程序的Hwnd,然后调用MessageBox(包含Windows.h头文件) MessageBox(Hwnd, "提示内容!", "标题", MB_OK);
额,我是要写一个控制台程序,然后控制台程序里调MFC程序啊[/quote]

			SHELLEXECUTEINFO shell = {0};
			shell.cbSize = sizeof(shell);
			shell.fMask = SEE_MASK_NOCLOSEPROCESS;
			shell.lpVerb = _T("open");
			shell.lpFile = 程序路径
			shell.nShow = SW_NORMAL;
			shell.lpParameters = 命令行参数;
			ShellExecuteEx(&shell);
鶄鈊_MapleA 2015-11-06
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
难道要 CreateDesktop ?
用ShellExcute函数成功调用到了MFC对话框,最后一个参数虽然设置成了SW_HIDE,但是还是会弹出对话框,而且按钮也需要自己点。 怎么才能不点按钮,直接实现这个按钮的功能呢?
赵4老师 2015-11-06
  • 打赏
  • 举报
回复
难道要 CreateDesktop ?
鶄鈊_MapleA 2015-11-06
  • 打赏
  • 举报
回复
引用 3 楼 paschen 的回复:
先获取你控制台程序的Hwnd,然后调用MessageBox(包含Windows.h头文件) MessageBox(Hwnd, "提示内容!", "标题", MB_OK);
额,我是要写一个控制台程序,然后控制台程序里调MFC程序啊
鶄鈊_MapleA 2015-11-06
  • 打赏
  • 举报
回复
引用 1 楼 jiht594 的回复:
命令行运行: mfc.exe /hiede mfc.exe中读这个参数, 隐藏窗体, printf
控制台程序是我现在要写的,我用ShellExcute调用了MFC程序,但是最后一个参数设置成SW_HIDE后还是会显示MFC程序窗口
paschen 版主 2015-11-06
  • 打赏
  • 举报
回复
先获取你控制台程序的Hwnd,然后调用MessageBox(包含Windows.h头文件) MessageBox(Hwnd, "提示内容!", "标题", MB_OK);
jiht594 2015-11-06
  • 打赏
  • 举报
回复
命令行运行: mfc.exe /hiede mfc.exe中读这个参数, 隐藏窗体, printf
赵4老师 2015-11-06
  • 打赏
  • 举报
回复
引用 6 楼 jianghuchuanzhize 的回复:
[quote=引用 5 楼 zhao4zhong1 的回复:] 难道要 CreateDesktop ?
用ShellExcute函数成功调用到了MFC对话框,最后一个参数虽然设置成了SW_HIDE,但是还是会弹出对话框,而且按钮也需要自己点。 怎么才能不点按钮,直接实现这个按钮的功能呢?[/quote] SendInput Function -------------------------------------------------------------------------------- The SendInput function synthesizes keystrokes, mouse motions, and button clicks. Syntax UINT SendInput( UINT nInputs, LPINPUT pInputs, int cbSize ); Parameters nInputs [in] Number of structures in the pInputs array. pInputs [in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream. cbSize [in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails. Return Value The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread. To get extended error information, call GetLastError. Microsoft Windows Vista. This function fails when it is blocked by User Interface Privilege Isolation (UIPI). Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking. Remarks Microsoft Windows Vista. This function is subject to UIPI. Applications are permitted to inject input only into applications that are at an equal or lesser integrity level. The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events are not interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput. This function does not reset the keyboard's current state. Any keys that are already pressed when the function is called might interfere with the events that this function generates. To avoid this problem, check the keyboard's state with the GetAsyncKeyState function and correct as necessary. Function Information Minimum DLL Version user32.dll Header Declared in Winuser.h, include Windows.h Import library User32.lib Minimum operating systems Windows XP, Windows NT 4.0 Service Pack 3 See Also Keyboard Input, INPUT, GetAsyncKeyState, keybd_event, mouse_event --------------------------------------------------------------------------------

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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