I'm c++ programmer. I can make message box with my icon with .ico file extension. I can make with MSGBOXPARAMS. My question is, if got answers, to make MessageBox with my icon with .bmp file extension. Too make in MSGBOXPARAMS?
Try with resource, create macro andnBITMAPvalue is of bitmap for MessageBoxIcon.
Sample:
head1.h
#define RCICON 23
res1.rc
#define RCICON 23
RCION BITMAP "example.bmp"
And try, MSGBOXPARAMS member for icon is example macro RCICON.
Related
I'm using Visual Studio Community 2019 Version 16.10.4. I've created a Win32 C++ app that displays a bmp picture. I've been trying to embed the picture into the complied .exe but not having success. My goal is to create the .exe without the need for any additional files or folders.
I did the following:
Right click on the App name in the Solution Explorer
Select Add from the dropdown and New Item from the popup box
Select Resource in the left column and Resource File(.rc) in the right column, then the Add button at the bottom
A pop up occurred: warning RC4005: '_APS_NEXT_RESOURCE_VALUE':redefinition, select OK
In the Resource View, right click on Resource.rc and select Add Resource… at the bottom
Select Bitmap and select New
There were a few more steps, but I lost track after trying to resolve the issue.
In the Solution Explorer under Resource Files I have Resource.rc and art1.bmp. For art1.bmp I have it so it is not excluded from the build. A resource.h file was also created.
resource.h has the following:
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Resource.rc
//
#define IDB_BITMAP1 103
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
In the .rc file, it has the following (and more)
IDB_BITMAP1 BITMAP "art1.bmp"
I have art1.bmp in the project root, Release folder and Debug folder.
After I compile the code into Release x86, the picture shows up without any issues (same in Debug) when I run the .exe. If I delete the picture from the Release folder, the picture no longer shows up.
Any suggestions on what step or steps I missed or what I need to change so the picture will be part of the .exe and not a seperate file?
A big thank you to Igor, With his help, this issue is finally resolved.
My original code (which was not posted at the time) was:
bitmap = (HBITMAP)LoadImageA(NULL, "art1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
Igor correctly asked "do you use IDB_BITMAP1 anywhere in your code?" which it was not.
I manage to get farther, but it still failed:
bitmap = (HBITMAP)LoadImageA(NULL, MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
I had tried replacing LR_LOADFROMFILE with NULL without success. The final key Igor provided was GetModuleHandle(nullptr) and NULL for UINT.
bitmap = (HBITMAP)LoadImageA(GetModuleHandleA(nullptr), MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, NULL);
I have a weird problem with an icon in a dialog under Windows.
I define a dialog and icon in the RC-file. Below are the relevant lines:
define IDI_LOGO 102
ICON IDI_LOGO, IDC_ICON_LOGO, 440, 322, 21, 20
IDI_LOGO ICON "icon.ico"
Later I display the dialog and get a system icon displayed in the dialog instead of my own. However, if I run the following code, I get my icon displayed in the dialog:
HMODULE module = GetModuleHandle(NULL);
HICON icon = LoadIcon(module, MAKEINTRESOURCE(IDI_LOGO));
SendMessage(GetDlgItem(dlg, IDC_ICON_LOGO), STM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
I use MSVC2010 Express (please do not ask why).
What is going wrong? Why the icon is not displayed as expected? Please advise. Thanks!
I have solved this. The thing was that I did not provide the module handle when displaying the dialog itself. When I do as follows I get the icon and bitmaps displayed properly without doing anything in run-time.
INT_PTR displayMainDialog() {
HMODULE module = GetModuleHandle(NULL);
return DialogBox(module, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)dlgProc);
}
The first argument of DialogBox was NULL, but it must be a handle to the module. I think this way Windows knows where to fetch the icons and bitmaps for static controls in the dialog from.
Anyway, many thanks to all responded!
I'm working on a Windows app that needs to run on XP, Vista, 7, and 8. I'm trying to set the application icon, and it works, using DI_ICON1 as the tag in my RC file:
DI_ICON1 ICON DISCARDABLE "myapp.ico"
Using IDI_ICON1 didn't seem to do the right thing here.
However, I also create a second window (also at the root level, ie not a child of my app's main window) and the ALT-TAB icon for that second window wasn't showing up correctly; it was just the default, generic app icon. Adding a second line to the RC now made the ALT-TAB icon work:
IDI_ICON1 ICON DISCARDABLE "myapp.ico"
so with both lines everything works. But I don't know why or how or wtf these identifiers even mean. So what are they, where are they defined, and by what magic do they work?
IDI_ICON1 is just a unique name identifying the resource. You can give it any name as long as it is unique. The development environment should generate a Resource.h file that uses a #define preprocessor directive to assign it a 16-bit unsigned integer unique identifier.
See:
https://learn.microsoft.com/en-us/windows/win32/menurc/icon-resource
https://learn.microsoft.com/en-us/cpp/windows/resource-files-visual-studio?view=msvc-170
IDI_ICON1 is probably just a convention that someone came up with, where IDI means "ID Icon", and 1 is because it is the first icon being defined. So, if you were defining another icon you'd identify it with IDI_ICON2. If you were defining a bitmap resource, you would identify it with IDB_BITMAP1.
DISCARDEABLE is only relevant for 16-bit Windows. See: https://learn.microsoft.com/en-us/windows/win32/menurc/common-resource-attributes
I wanted to ask about winApi 32 custom icons creation. When I define icon in recource.h:
#define IDI_MYICON 1
What does that number, in this case 1 mean?
And what about IDI is it just a standard or it actually means something?
1 is the value, IDI_MYICON is just a placeholder for the 1
IDI is an prefix and stands for An Icon or bitmap resource
see this list
Normaly ResourceID's get assigned automaticly by Visual Studio (or other IDE).
So you could use IDI_MYICON instead of using the 1 in your code.
Icons are stored in the resource section of the PE file when it is built. The "1" is the resource identifier for that icon. It doesn't have to be "1" but each icon must have a unique identifier. It's just easier to start at 1 and go up.
IDI is a Microsoft convention to identify an Icon resource. You could actually name it anything you want but sticking with convention will lead to less confusion.
I've got a dialog box where I need to display the standard Information icon. Here's my RC code:
ICON "",IDC_ICON_INFORMATION,18,70,21,20
I process the WM_INITDIALOG message as follows:
HICON aIcn = LoadIcon(NULL, IDI_INFORMATION);
SendDlgItemMessage(m_hWnd, IDC_ICON_INFORMATION, STM_SETICON, (WPARAM) aIcn, 0);
Everything works great under 96 DPI: the static control displays a 32x32-pixel icon.
However, when I switch to higher DPI's (through right-clicking on the Desktop, choosing Screen resolution, and clicking Make or other items larger or smaller) the icon does not scale! Since everything else scales nicely, the icon looks visually much smaller than the neighboring text. I would expect that on 144 DPI (150%) the icon dimensions will be 48x48 pixels. I did declare my application as DPI-aware through an XML manifest.
The damnedest thing is that when I use my own custom-made icon (also coming from the RC file), everything scales perfectly. Furthermore, the MessageBox function called with the MB_ICONINFORMATION flag does display a scaled version of the icon, as well.
Given these thoughts, I assume of the following:
The static control with the SS_ICON style can display scaled versions of icons.
The icon resource that contains the standard Information icon has a scaled version of the icon (48x48).
What am I doing wrong then?
Use LoadImage() instead of LoadIcon(), and specify the cxDesired and cyDesired params with the values you get from GetSystemMetrics(SM_CYICON) and GetSystemMetrics(SM_CXICON).
Or maybe just declaring your app as DPI aware could be enough? You can try that easily by simple creating a text file making it a manifest file.
See the example in the remarks section for the SetProcessDPIAware API