locked
Changing the childframe´s icon dinamically RRS feed

  • Question

  • Hi all!

    I am building a multidoc MFC App. Accordingly to certain data given at startup the App is supposed to create docs that have certain iconsthat should be displayed by my child frame, everytime a doc is created. Namely, as the App starts a new doc is created and the child frame displayed should hold a particular icon.

    I have tried GetParentFrame()->SetIcon(ico1, FALSE) in CmyView class. It is ok, but in order to display the correct icon, I need to resize the child frame: to minimize it and then maximize it again, for instance.

    In a website it is suggested to override the CView::OnCreate() function. But as I implement it, I get a runtime error (no idea why!):

    int CmyView::OnCreate(LPCREATESTRUCT lpcs)

    {

    CWnd::OnCreate(lpcs);

    HICON ico1 = AfxGetApp()->LoadIconA(IDI_ICON1);

    GetParentFrame()->SetIcon(ico1, FALSE);

    return 0;

    }

    Can anyone help? Thanks


    Jorge Teixeira

    Wednesday, July 11, 2012 1:11 AM

Answers

  • Hi,

    Welcome back.

    Based on your description, you want the ChildFrame changes automatically, when the inputting occurs. Maybe your application can not retrieve the changes dynamically. Here, I suggest you create a button to handle the displayed action, so that you can get the result you want.

    Have a good weekend.

    Regards,

    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Friday, July 13, 2012 8:14 AM
    Moderator
  • Thank you both. The suggestion milonass gave didn´t work.

    Meanwhile I found myself a solution: dinamically resizing the child frame. After that, the window does assume the desired icon.

    Jorge


    Jorge Teixeira

    Friday, July 20, 2012 3:05 AM

All replies

  • Can you please look the following msdn forum

    http://social.msdn.microsoft.com/Forums/is/vcgeneral/thread/06ade4fe-00c6-4d55-a366-cb47e8716efc


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/

    Wednesday, July 11, 2012 4:26 AM
  • Thank you Selvan.

    I have already found that forum, but the proposed slutions do not work ...


    Jorge Teixeira

    Wednesday, July 11, 2012 7:44 AM
  • Hi Jorge Teixeira 1957,

    Welcome here.

    Based on my understanding, may I ask you a question: have you put the GetParentFrame()->SetIcon( , ) inside the function void OnInitialUpdate() of the CView file(quoting from the last reply of Selvams link )?

    Have a nice day.

    Regards,

    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 12, 2012 8:35 AM
    Moderator
  • Hi Xie!

    Indeed I have already tried that apporach, but got nothing.

    Jorge


    Jorge Teixeira

    Friday, July 13, 2012 2:09 AM
  • Hi,

    Welcome back.

    Would you mind show your error?

    If you want to dynamically change the icon, maybe you can try to verify your own icon to your frame, using

    m_hIcon = (HICON) LoadImage (NULL, L"C:\\...\\222.ico",
                  IMAGE_ICON, 0, 0, LR_LOADFROMFILE); //load icon from your path

    See more:  http://social.msdn.microsoft.com/Forums/en-US/vcmfcatl/thread/05a846ed-8f05-45f0-a197-7904aa7f0b99 (Load icon dynamically)

    I hope my suggestions will help.

    Regrads,

    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Friday, July 13, 2012 4:41 AM
    Moderator
  • Hi again!

    The problem is not loading the icon: the problem is loading it at startup. I shall be more specific.

    My App is supposed to produce a certain kind of docs. In CmyDoc there is a variable, let us call it x. The values of x will be generated by a function of CmyDoc, thar depends of user input values a and b. Depending on the values of x, the CmyDoc::OnNewDocument() should produce a view with an accordingly ChildFrame´s icon. For instance: if a=1 and b=2, then x=10 and a childframe with ico1 should be displayed; should a and b have other values, so other icons should be displayed.

    With the above mentioned apporach, I´ll have them displayed only if I manually resize the childframe ... not when the view opens.

    I hope I made myself clear. Thanks for help.

    Jorge


    Jorge Teixeira

    Friday, July 13, 2012 7:48 AM
  • Hi,

    Welcome back.

    Based on your description, you want the ChildFrame changes automatically, when the inputting occurs. Maybe your application can not retrieve the changes dynamically. Here, I suggest you create a button to handle the displayed action, so that you can get the result you want.

    Have a good weekend.

    Regards,

    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Friday, July 13, 2012 8:14 AM
    Moderator
  • Did you try a

    RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);

    ?

    Sunday, July 15, 2012 7:34 PM
  • Thank you both. The suggestion milonass gave didn´t work.

    Meanwhile I found myself a solution: dinamically resizing the child frame. After that, the window does assume the desired icon.

    Jorge


    Jorge Teixeira

    Friday, July 20, 2012 3:05 AM
  • Hi,

    Welcome back.
    Thanks for your sharing answer here, it’s very great and helpful for other community members who stunk in the similar issue.
    Regards,
    Elegentin


    Elegentin Xie [MSFT]
    MSDN Community Support | Feedback to us

    Friday, July 20, 2012 3:35 AM
    Moderator