Solved

Change ICON of Picture Control

Posted on 2009-07-03
5
2,704 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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. …
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, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

624 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