Solved

Change ICON of Picture Control

Posted on 2009-07-03
5
2,690 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 24772690
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
ID: 24782272
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
ID: 24782406
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
ID: 24782604
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
ID: 24782964
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

729 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