I need to open an image with Microsoft Paint - winapi

As the title says. I'm looking for an easy way to open an image (.jpg if it matters) with Microsoft Paint by using Windows API and the image's file path. Any ideas?

You can use CreateProcess as #Jonathan Potter mentioned in the comments or you can use ShellExecute.
ShellExecute(nullptr, "open", "mspaint.exe", "YourImage.jpg", nullptr, SW_SHOWMAXIMIZED);
If as #Remy Lebeau mentions, you want the user registered default application to open the image rather than force mspaint.exe you can just pass the image name to ShellExecute
ShellExecute(nullptr, "open", "YoutImage.jpg", nullptr, nullptr, SW_SHOWMAXIMIZED);

Related

How to change desktop background image on windows with c++?

How to change the desktop background image on Windows?
Right now, I found this solution:
SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (PVOID*)desktop_image_file, SPIF_SENDCHANGE);
It works fine, but after a restart, the image is gone. How to save it permanently?
You need to include the SPIF_UPDATEINIFILE flag:
SPIF_UPDATEINIFILE
Writes the new system-wide parameter setting to the user profile.
SystemParametersInfoA(..., SPIF_SENDCHANGE | SPIF_UPDATEINIFILE);

How to handle drag-and-drop to a Win32 application icon?

I have to update a Win32 application in order to handle the drag-and-drop of files over the icon of the executable.
I am not sure about how to proceed. A few researches led me to considering the "WM_DROPFILES" message, but MSDN syas it is "Sent when the user drops a file on the window", while I don't want to open a window.
Think of a command line tool "MyProgram.exe" : if I drag "MyFile.file" on the windows icon "MyProgram" in the desktop, I would like it to execute the same way as it would do when typing ">MyProgram MyFile.file" in the command prompt.
Any idea how to achieve this result ?
While it is true that apps get this for free by parsing the command line, there is a shell interface called IDropTarget you can implement if you need more control. See MSDN and this blog entry for more details.
Windows does this for you automatically. Any program foo.exe accepts drags of any file.
Martyn

How can I override or customize the delete confirmation dialog in Windows?

When we press Shift+Delete key, a delete confirmation dialog is generated. I want to handle this dialog according my need or change its message. Can anyone tell me what thing is responsible for that dialog?
I either need to know the code which handles the delete confirmation dialog generated by the Shift+Delete key sequence in Windows XP, or the code by which we can control this operation.
I don't think what you want to do is going to be fun.
Im guessing you have to intercept the SHFileOperation function (and the IFileOperation interface for Vista onward)
Here what my google-fu got me on winapi interception:
http://www.codeproject.com/kb/system/hooksys.aspx
You might want to look at this : http://easyhook.codeplex.com/
This project supports extending
(hooking) unmanaged code (APIs) with
pure managed ones, from within a fully
managed environment like C# using
Windows 2000 SP4 and later...
Good Luck! =)
If you only want to mess with the dialog (change the displayed text, image, etc.) you can try to modify the resources with a free tool such as Resource Hacker.
The "delete" dialog resources are in shell32.dll in Windows XP (you mentioned only that version of Windows); fire up the Resource Hacker and open shell32.dll, then search for the warning text "Are you sure you want to delete" and you'll find:
CONTROL "Are you sure you want to delete '%1'?", 12295, STATIC, SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 41, 10, 220, 28
Now that's only the static text, but the whole dialog definition (buttons etc.) should be here. I think this way you can make it a simple warning dialog--e.g. "You're forbidden to delete anything!" and only a "Cancel" button.
One way to address file deletion restrictions could be by employing NTFS security descriptors.
Security Descriptors
Security Descriptor Operations
That way, you change it in one place and not have to worry about covering all cases to prevent deleting a file.

Save a portion of my program’s own window to a bitmap file using mfc/win32

Within my mfc program, I need to programmatically capture a portion of that program’s own window, then save it out as a file (bmp or jpg etc). How to do this without using 3rd party library?
Here is a comprehensive sample project that provides an example of saving an image of a window to a bitmap: http://www.codeguru.com/cpp/g-m/gdi/capturingimages/article.php/c11231/.

How does one detect when the wallpaper has changed (Windows XP or greater)?

I have figured out how to change the desktop wallpaper (there are dozens of examples on the Internet.)
One thing that still eludes me: how do I detect when the wallpaper has changed? (Say via the Display control panel or another program changing it.)
Add a message handler for WM_SETTINGCHANGE, SystemEvents.UserPreferenceChanged in .NET. Check if the wallpaper is still the same.
Here is an example in C# to retrieve the wallpaper. All you would need to add is some additional code to store the last wallpaper and check to see if it is different.
RegistryKey wallpaper = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop",false);
string wallpapername = wallpaper.GetValue("wallpaper").ToString();
wallpaper.Close();
If you were writing something in a non .net language you could use the Win32 API RegNotifyChangeKeyValue function to check to see if this value has changed:
HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper

Resources