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);
Nothing is getting drawn on the paint untitled document
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);
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);