Re: Dynamic icon on dialog

Tech-Archive recommends: Fix windows errors by optimizing your registry



OK, you can do a SetWindowPos, but you can do it once in the OnInitDialog

m_iconTitle.SetWindowPos(NULL, 0, 0, 16, 16, SWP_NOMOVE | SWP_NOZORDER);

and you never need to do it again.

In fact, here's code that works from one of my apps:

c_Icon.SetWindowPos(NULL, 0, 0, 16, 16, SWP_NOMOVE | SWP_NOZORDER);
HICON icon = (HICON)::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(icon_id_here),
IMAGE_ICON, 16, 16,
LR_SHARED);
c_Icon.SetIcon(icon);

joe
On Fri, 30 Mar 2007 16:57:35 +0100, "GT" <ContactGT_remove_@xxxxxxxxxxx> wrote:

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:meaq0313b4cg290slrjm6s6eo4cib38g0g@xxxxxxxxxx
See below...
On Fri, 30 Mar 2007 13:08:58 +0100, "GT" <ContactGT_remove_@xxxxxxxxxxx>
wrote:

I have a floating, modeless dialog window with an icon in the corner to
indicate which area of the system is currently being displayed. I change
this icon in code by using lines like:

m_iconTitle.SetIcon(AfxGetApp()->LoadIcon(IDI_IterationPlannedEmpty));
m_iconTitle.SetWindowPos( NULL, 0, 0, 16, 16, SWP_NOMOVE );
****
SWP_NOMOVE | SWP_NOZORDER. But why SetWIndowPos at all? Just put the
icon at the top
left corner, and it will stay there.

I'm trying to set its size to 16x16 as the resource editor won't let me make
the control that small. I dont want to move it, hence the 0,0 for the x,y
parameters and the SWP_NOMOVE at the end. I couldn't find another way of
resizing the CStatic control! I have changed my code to only do this once in
the InitDialog now! I had it all over the place because it keeps resizing
the control whenever I load an icon, but once that is fixed, this constant
resizing shouldn't be necessary.


I want the icon to be 16x16, but everytime I call LoadIcon it resizes to a
bigger icon. After loading 2 icons, the second line above stops working
and
I only see the top left quarter of the icon in a 16x16 size. Is there a
way
to force LoadIcon to load the icon at 16x16 pixels, or to force the
CStatic
on the dialog to remain at 16x16, so I don't have to keep resizing it.
Visual Studio won't let me set it to be 16x16 by dragging the handles in
the
resource/dialog editor - it won't let me make the icon smaller than about
24x24 (or maybe 32x32, I can't tell)!
*****
Note that CWnd::SetIcon has a second parameter, indicating the icon type.
Also, you could
use ::LoadImage to load the 16x16 icon.
*****

Yes, CWnd::SetIcon has a second parameter, but I don't have an instance of
that base class, I have an instance of the derived class CStatic. The
CStatic::SetIcon doesn't have that second parameter, so I can't use it to
choose the icon size:

"error C2660: 'CStatic::SetIcon' : function does not take 2 arguments"
and
MSDN: http://msdn2.microsoft.com/en-us/library/5w91yh47(VS.71).aspx

I tried deriving my own class from CStatic and overriding the SetIcon method
to call the CWnd method directly, but using this method results in no icon
being shown on the screen at all!

Thanks you for your tips - the LoadImage might be the way to go - I will
investigate this option on Monday.

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Make an automatic task?
    ... I thought that after clicking on the icon, ... There is no paste command. ... you are copying from and the one you are copying to. ... If the second parameter ...
    (microsoft.public.windowsxp.customize)
  • Re: Dynamic icon on dialog
    ... this icon in code by using lines like: ... I had it all over the place because it keeps resizing ... the control whenever I load an icon, but once that is fixed, this constant ... Note that CWnd::SetIcon has a second parameter, ...
    (microsoft.public.vc.mfc)
  • Re: Dynamic icon on dialog
    ... why can't you make a 16x16 icon and assign that to the ... The static control automatically will resize itself to the ... of resizing the CStatic control! ... Note that CWnd::SetIcon has a second parameter, ...
    (microsoft.public.vc.mfc)
  • Re: Dynamic icon on dialog
    ... Just put the icon at the top ... I don't see why you are doing SetWindowPos at all ... to force LoadIcon to load the icon at 16x16 pixels, ...
    (microsoft.public.vc.mfc)
  • Re: How to get rid of the icon that appears forms titlebar
    ... which is Windows 2000/XP default icon. ... >get rid of this icon without sacrificing the resizing and control menu ... Simplest way is to replace it with your own icon or use a blank (all ...
    (microsoft.public.vb.winapi)