Solved

Change ICON of Picture Control

Posted on 2009-07-03
5
2,549 Views
Last Modified: 2013-11-20
I create a ATL dialog and put a pitcure control, IDC_TESTICON.

I try to put system icon in this pitcure control but nothing changed.

Do I miss something?

LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)

{

   CAxDialogImpl<CppInvalidRecipientsDlg>::OnInitDialog(uMsg, wParam, lParam, bHandled);
 

    // Centres the window relative to the parent window.

    CenterWindow();
 

    BringWindowToTop();
 

    if (::GetParent(m_hWnd) == NULL)

    {

      ::ShowWindow(m_hWnd, SW_MINIMIZE);

      ::ShowWindow(m_hWnd, SW_RESTORE);

    }
 

    // nothing change in TESTICON

    GetDlgItem(TESTICON).SetIcon(::LoadIcon(NULL, IDI_INFORMATION));
 

    return 1;  // Let the system set the focus

}

Open in new window

0
Comment
Question by:blancx
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
Comment Utility
Just in case - add UpdateWindow or Invalidate.
You actually redraw the window here (or deactivate and then activate):
    if (::GetParent(m_hWnd) == NULL)
    {
      ::ShowWindow(m_hWnd, SW_MINIMIZE);
      ::ShowWindow(m_hWnd, SW_RESTORE);
    }
 and then load the icon. why?
0
 

Author Comment

by:blancx
Comment Utility
Regarding the code you mention, It is just the testing code that I forgot to remove.

I have tried to put UpdateWindow or Invalidate function at the end of OnInitDialog(). Nothing changed.

0
 
LVL 33

Expert Comment

by:pgnatyuk
Comment Utility
So check that LoadIcon brings the icon for you.  You can just draw the icon in the client area from OnPaint.
Check that your dialog has the style to redraw the child windows. Check the control
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 250 total points
Comment Utility
I had to do a short test - just an MFC app with aboutbox - there is the icon in the style you need. I just removed the icon resource name on the about box dialog resource and loaded the icon manually as you did. Of course I didn't see the icon - just reproduced your question.
So I just added (CStatic*) before GetDlgItem:
((CStatic*)GetDlgItem(TESTICON))->SetIcon(hIcon);
the hIcon I loaded before as AfxGetApp()->LoadIcon(IDR_MAINFRAME);
Now I see the icon on the dialog.
0
 

Author Comment

by:blancx
Comment Utility
I think it is a solution but I can't use CStatic in my ATL dialog.
There are link errors when I try to include "Afxwin.h".

In order to minimize the side effect, I send STM_SETICON via SendMessage(). It also change the icon.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now