Solved

Change ICON of Picture Control

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 98
FizzBuzz challenge 9 81
MaxSpan challenge 9 97
Capture logon name 13 74
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

832 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