Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change ICON of Picture Control

Posted on 2009-07-03
5
Medium Priority
?
2,787 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 750 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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