问题描述
大家好,
我的问题是我想通过编程在另一个应用程序中打开MSPaint,然后在MSPaint的无标题文档上绘制了一些形状,图形和文字的图形之后,我想将其保存为bmp或jpeg文件.所有这些都需要通过编程来完成.截至目前,我只做了这么多. ShellExecute函数可打开绘制应用程序,然后为绘制创建图形对象并执行一些绘图操作,然后生成保存菜单项click事件以保存无标题的文档.一旦出现另存为"对话框,它需要用户响应来保存文件,但我希望通过编程自动调用保存"按钮事件,甚至还要获取用于绘画的图形对象,我无法在未命名的文档上看到任何图形油漆.伙计们,请为我的问题提供一些解决方案,因为我被罢工已经有好几天了.
注意:该应用程序是使用MFC标头的基于Windows控制台的应用程序
调用MSPaint的代码如下:
Hi folks,
My problem is I wanna open MSPaint within another application through programming then after doing some drawing like shapes, figures and text over the untitled document of MSPaint I wanna save the same as bmp or jpeg file. all this needs to be done through programming. As of now I have done this much only. ShellExecute function to open the paint application then creating a graphics object for paint and performing some drawing operations and then generating the save menu item click event for saving the untitled document. once the Save As dialog box comes up it needs user response to save the file but i want the save button event should automatically be called through programming and also even obtaining the graphics object for paint i am not able to see any drawing on the untitled document of paint. guys please provide some solutions for my problem as I am struck there for quite few days now.
Note: Application is a windows console based application using MFC headers
Code for the invoking MSPaint is given below:
HWND hWndPaint = NULL;
HINSTANCE hinst = ShellExecute(hWndPaint, NULL, "C:\\WINDOWS\\system32\\mspaint.exe", NULL, NULL, SW_HIDE);
DWORD dwErr = GetLastError();
hWndPaint = FindWindow("MSPaintApp", NULL);
int err = (int)hinst;
dwErr = GetLastError();
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Graphics g(hWndPaint, true);
Pen pen(Color::Black, 3.0f);
g.DrawLine(&pen, 0, 10, 200, 10);
SolidBrush brush(Color::Red);
未涂漆的无标题文档上没有任何内容
g.FillEllipse(&brush, 0, 30, 200, 100);
g.FillRectangle(&brush, 0, 155, 500, 30);
HMENU hMenu;
hMenu = GetMenu(hWndPaint);
dwErr = GetLastError();
HMENU hMenu1;
hMenu1 = GetSubMenu(hMenu, 0);
dwErr = GetLastError();
UINT unMenu;
unMenu = GetMenuItemID(hMenu1, 3);
dwErr = GetLastError();
LRESULT res = SendMessage(hWndPaint, WM_COMMAND, MAKEWPARAM(unMenu, 1), NULL);
我很惊讶,因为它需要用户响应才能进一步进行,请建议使用任何Win API来自动执行另存为"过程
I''m struck at this point as it needs user response to proceed further please suggest any Win API for automating the Save As process
res = SendMessage(hWndPaint, WM_CLOSE, 0, 0);
GdiplusShutdown(gdiplusToken);
推荐答案
这篇关于查询在另一个应用程序中使用MSPaint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!