I'm trying to make use of icon<owned> to get and hold an icon that I make use of in a status bar. I've used a non-Win32GUI C++ wrapper class for the purpose, and it works a treat. But I would like to be able to use the equivalent Win32GUI facility, just so that I know that I can :-)
Because I wanted a multi-pane status bar, I derived my own class from status_bar, so that I could keep all the details of my status bar contained in that class. For storing an icon that I want to display on it, I declare a class member:
icon <shared> m_icon;
In the class contructor, in the initialiser list, I say:
That seems to work, cos if i then check its ICONINFO, the value of the fIcon member is True.
In the on_full_create function, I then want to pass the icon as the second parameter of the pane_icon() function for the status_bar class. That function has the prototype of:
void pane_icon ( int pane_idx, HICON h)
I would think that I would use the raw_handle() function on my m_icon member variable, but it's not working:
self->pane_icon( 0, self->m_temp_icon.raw_handle());
// not working!
Any insight would be a treat! ;-)
did you check that raw_handle() doesn't return NULL?
Sorry, I should have added that to my question: yes I did; the return from raw_handle() is not NULL. I take it from your question that raw_handle() is _in theory_ the correct function to use for the purpose?
yes, the raw_handle()-functions return the plain old window handles (HBITMAP, HICON and so on)
hmm, i haven't used status bars with win32gui yet. maybe john will help you. or you can set a breakpoint and trace into the function. that's the way i first examine the exact location where a problem occurs.
you can also ensure that the icon is really ok - display it or load an icon with LoadImage() from your resources and pass this icon to pane_icon() so you can be sure that the problem is in pane_icon()
Grrrrr! I know what's going wrong! I aimed to display a 16 pixel by 16 pixel icon on the status bar, so the icon resource that I loaded by creating the icon<owned> object only contains a 16 by 16 icon. Creating a 32 pixel by 32 pixel icon in that set as well results in that new larger icon being displayed on the status bar.
Now, by using the Win32 API ::LoadImage() function, I can specify the height and width, to load a particular size of icon from an icon set. For my own information, does Win32GUI offer this facility for the icon class?
Thanks for pointing it out. I just included this constructors in the win32gui (for icon).
Will be available in next version.
you can pass the HICON to the c'tor -> thus you can pass the result of LoadImage() to it
Right - gotcha :-)
Will look into it.
As a side note, you can use:
// no need for the .raw_handle()
self->pane_icon( 0, self->m_temp_icon);
Okay, as suggested, I tried not using the raw_handle() but I got the following compiler error message:
c:\My C++ Lib\Builds\Win32GUI problems builds\win32gui_problems_statusbar5\my_status_bar.cpp(45) : error C2664: 'void win32::gui::status_bar::pane_icon(int,HICON)' : cannot convert parameter 2 from 'win32::gui::icon<r_type>' to 'HICON'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Sorry Steve, you're right. You can't convert directly to HICON.
Basically, HICON and icon<owned> can be converted to icon<shared>.
Log in to post a comment.