I have a .ico file that I've imported into my Visual Studio 2010 project. Within the .ico file, it looks like there are many different images of different sizes.
I am trying to set one of them as the icon for my button control:
HICON hIcon = LoadIcon(HINST_THISCOMPONENT, MAKEINTRESOURCE(IDI_ICON2));
SendMessage(GetDlgItem(hDlg, IDC_BUTTON1), BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
How do I choose which image/size within the .ico file will be displayed on the button?
You can use the LoadImage function to get a bit more control.
With LoadImage you can specify a desired width and height.
If you want even more control then you're down to parsing the icon resource, which I don't recommend.
Related
I'm using Qt 5.10.1. I created a window icon resource and applied to Qt application like following:
a.setWindowIcon(QIcon(":/icons/resources/logo_icon.png"));
The size of logo_icon.png is 256*256.
The result is this:
The icon is a little blurrly, which is not what I expected. For comparison, following is the window icon of GIMP in which I designed the icon:
I tried various sizes of the image from 16*16 to 256*256, there was no luck. Changing image format to ico from png also didn't work.
What should I do to render a clearer window icon?
Maybe in the ui file of your window there is a iconSize value that makes your icon scale not very well when rendered by the window manager. This blurry effect occurred to me sometimes because the size was 15 px instead of 16 (or another power of 2).
Try to open the .ui file of your main window in Design mode and look under the QMainWindow group in the widget properties panel to set the iconSize to something like 16.
You can also set the icon file from there, using the windowIcon property under the QWidget group.
My application use a .bmp file for ImageList.
To do this, I use ImageList_LoadImage macro (https://msdn.microsoft.com/fr-fr/library/windows/desktop/bb761557(v=vs.85).aspx)
I would like to scale this ImageList programmatically.
For example, my .bmp file dimension is 72x24 (3 items of 24x24 icons).
And I would like scale it to 144x46 (3 items of 48x48 icons).
I didn't find any ImageList function to scale my HIMAGELIST handle loaded from .bmp file.
I tried using LoadImage function (https://msdn.microsoft.com/en-us/library/ms648045(v=vs.85).aspx)
But it must be used with bmp file, and here I have HIMAGELIST handle.
I tried to create a new image, copying scaled icons:
ImageList_Create (with icons 48)
Enumerate icons from image list 24 with ImageList_ExtractIcon
Scale icon with DrawIconEx
Add to new image list with ImageList_AddIcon
But it fails when addin icon to new image list.
I am creating a MFC CDialog and adding a bitmap in a picture control and I have edit controls that need to be placed relative to positions on the image. However the size of the image in the picture control changes when I run my application.
This makes it difficult to align my edit boxes with the image.
Can anybody tell me why this happens?
There is no code to post as this is entirely done in the dialog editor of VS2013.
Windows adjusts the size of dialogs to match the system font, which can be changed by the user. For information about this look up dialog base units. If you need your dialog layout to match a bitmap then you need to override the Windows adjustment and explicitly set the size and location of the controls at run time. That would mean that in OnInitDialog you use MoveWindow on the dialog itself and on every control to set their size and location in pixel units that match the bitmap.
I have added a .rc file to my project with just the following:
IDI_MAIN_ICON ICON "..\\..\\icon_artwork\\windows_icons\\project.ico"
The .ico file contains icons at 16x16, 32x32, 48x48 and 256x256 resolutions.
I see the icon in the taskbar and explorer (so there is no doubt the .ico is successfully embedded in the .exe), but I see the default Windows 7 application icon in the application's own title bar, and in alt-tab.
Is there a way to get the OS to see the embedded icon by itself in all cases, or do I need to write some application code for this? I notice that there is an SDL2 function
void SDL_SetWindowIcon(SDL_Window* window, SDL_Surface* icon)
but that takes an SDL surface, not the embedded icon resource from the executable.
Any ideas gratefully received,
Tony
As it stands, no. SDL for some reason eats the icon for the actual application window. However you can use WINDOWS specific code to fix this. Keep in mind that this is not portable.
#if defined(_WIN32) && defined(GCL_HICON)
void setWindowsIcon(SDL_Window *sdlWindow) {
HINSTANCE handle = ::GetModuleHandle(nullptr);
HICON icon = ::LoadIcon(handle, "IDI_MAIN_ICON");
if(icon != nullptr){
SDL_SysWMinfo wminfo;
SDL_VERSION(&wminfo.version);
if(SDL_GetWindowWMInfo(sdlWindow,&wminfo) == 1){
HWND hwnd = wminfo.info.win.window;
::SetClassLong(hwnd, GCL_HICON, reinterpret_cast<LONG>(icon));
}
}
}
#endif
You should be able to get a SDL_Surface from a .png file using
SDL_Surface *IMG_Load(const char *file)
then pass it to your SDL_SetWindowIcon(SDL_Window* window, SDL_Surface* icon) method.
I don't think the IMG_Load(...) method takes .ico files though, but a 32x32 .png version of your icon would be a good compromise...
Not ideal but the best workaround I can think of ;)
I have a UI C++ Win32/WTL app. I have an application icon with many embedded sizes, including 16x16, 32x32, 48x48 and 64x64. I do a SetIcon() for both small and large icons and yet my Windows 7 task bar shows a blurry scaled up icon.
Are there any special APIs that need to be called or some special considerations?
The icon shown in the taskbar is not the one you set with SetIcon() but the one that explorer also shows for the exe file itself. That means it shows the very first icon in your exe resources.
Change the resource ID of your icon to e.g. 1 so it's the first icon, or add other sizes to the first icon your exe currently uses.
Icons are in the order? I have information, that Windows use icons in direct order. Try place icon 64x64 in the first place in array.
Unusual DPI / font size setting? I've seen XP ask for a 20x20 icon.