Plex 2E

Expand all | Collapse all

How to change icon in MDI Parent

Jump to Best Answer
  • 1.  How to change icon in MDI Parent

    Posted 09-24-2014 04:16 AM

    I found a cpp source code to change the icon of the MDI parent. I use it related to change company (library list) by user selection. And it works when I had full path to icon object.  But I need to reset to orginal icon f.i. when company record has an empty value in path for icon.

     

    CWnd *pWnd = ObPanelAPI::GetPanelCWndByName("*Current");
    if (pWnd){
           // loads from file
           HICON hIcon = (HICON)LoadImage(0, &(1:), IMAGE_ICON, 0 , 0 ,LR_DEFAULTSIZE|LR_LOADFROMFILE);
           // TODO: Set orginal icon if LoadImage returns NULL
           if(hIcon) {
                 // send the message to frame to update icon
                 HICON hPrevIcon = (HICON) pWnd->SetIcon(hIcon,FALSE);
                 if(hPrevIcon) {
                        // Free the previous icon resource
                        DestroyIcon(hPrevIcon);
                 }
           }
    }
    

     

    But I cant find out how to get the orginal icon from the EXE object  f.i. OBicon.ico.

    Last try was like this:

    CWnd *pWnd = ObPanelAPI::GetPanelCWndByName("*Current");
    if (pWnd){
           // loads from file
           HICON hIcon = (HICON)LoadImage(0, &(1:), IMAGE_ICON, 0 , 0 ,LR_DEFAULTSIZE|LR_LOADFROMFILE);
           if (!hIcon) {
                  HICON hIcon = AfxGetApp()->LoadIcon(128);
                 // eða ef IDE_MAINFRAME finnst ekki HICON hIcon = AfxGetApp()->LoadIcon(128);
                 if (!hIcon) 
                        MessageBox(NULL,"from Exe in error","msg1", MB_OK); 
           }
           if(hIcon) {
                 // send the message to frame to update icon
                 HICON hPrevIcon = (HICON) pWnd->SetIcon(hIcon,FALSE);
                 if(hPrevIcon) {
                        // Free the previous icon resource
                        DestroyIcon(hPrevIcon);
                 }
           }
    }
    


  • 2.  Re: How to change icon in MDI Parent

    Posted 09-30-2014 12:28 PM

    Any suggestions?

     

    GUNNAR GUNNARSSON wrote:

     

    I found a cpp source code to change the icon of the MDI parent. I use it related to change company (library list) by user selection. And it works when I had full path to icon object.  But I need to reset to orginal icon f.i. when company record has an empty value in path for icon.

     

    1. CWnd *pWnd = ObPanelAPI::GetPanelCWndByName("*Current"); 
    2. if (pWnd){ 
    3.        // loads from file 
    4.        HICON hIcon = (HICON)LoadImage(0, &(1:), IMAGE_ICON, 0 , 0 ,LR_DEFAULTSIZE|LR_LOADFROMFILE); 
    5.        // TODO: Set orginal icon if LoadImage returns NULL 
    6.        if(hIcon) { 
    7.              // send the message to frame to update icon 
    8.              HICON hPrevIcon = (HICON) pWnd->SetIcon(hIcon,FALSE); 
    9.              if(hPrevIcon) { 
    10.                     // Free the previous icon resource 
    11.                     DestroyIcon(hPrevIcon); 
    12.              } 
    13.        } 

     

    But I cant find out how to get the orginal icon from the EXE object  f.i. OBicon.ico.

    Last try was like this:

    1. CWnd *pWnd = ObPanelAPI::GetPanelCWndByName("*Current"); 
    2. if (pWnd){ 
    3.        // loads from file 
    4.        HICON hIcon = (HICON)LoadImage(0, &(1:), IMAGE_ICON, 0 , 0 ,LR_DEFAULTSIZE|LR_LOADFROMFILE); 
    5.        if (!hIcon) { 
    6.               HICON hIcon = AfxGetApp()->LoadIcon(128); 
    7.              // eða ef IDE_MAINFRAME finnst ekki HICON hIcon = AfxGetApp()->LoadIcon(128); 
    8.              if (!hIcon)  
    9.                     MessageBox(NULL,"from Exe in error","msg1", MB_OK);  
    10.        } 
    11.        if(hIcon) { 
    12.              // send the message to frame to update icon 
    13.              HICON hPrevIcon = (HICON) pWnd->SetIcon(hIcon,FALSE); 
    14.              if(hPrevIcon) { 
    15.                     // Free the previous icon resource 
    16.                     DestroyIcon(hPrevIcon); 
    17.              } 
    18.        } 


  • 3.  Re: How to change icon in MDI Parent
    Best Answer

    Posted 10-01-2014 02:44 AM

    To restore the original icon you have to load the icon included in the resource, IDI_EXE_ICON.

    Here you have the the source code to restore both, small and big icon:

     

    #include "obrc.h"
    
    
    {
         CWnd *pWnd = ObPanelAPI::GetPanelCWndByName("*Current");
         ASSERT(pWnd);
         if(pWnd) {
              HICON hIcon = NULL;
    
              hIcon = (HICON) LoadImage(GetModuleHandle(NULL), 
                                       MAKEINTRESOURCE(IDI_EXE_ICON),
                                       IMAGE_ICON,
                                       GetSystemMetrics(SM_CXICON) ,
                                       GetSystemMetrics(SM_CYICON) ,
                                       0);
         if(hIcon) {
              // send the message to frame to update the large icon
              HICON hPrevIcon = (HICON) pWnd->SetIcon(hIcon,TRUE);
              if(hPrevIcon) {
                   // Free the previous icon resource
                   DestroyIcon(hPrevIcon);
              }
         }
    
    
         hIcon = (HICON) LoadImage(GetModuleHandle(NULL), 
                                   MAKEINTRESOURCE(IDI_EXE_ICON),
                                   IMAGE_ICON,
                                   GetSystemMetrics(SM_CXSMICON) ,
                                   GetSystemMetrics(SM_CYSMICON) ,
                                   0);
         if(hIcon) {
              // send the message to frame to update the small icon
              HICON hPrevIcon = (HICON) pWnd->SetIcon(hIcon,FALSE);
              if(hPrevIcon) {
                   // Free the previous icon resource
                   DestroyIcon(hPrevIcon);
              }
         }
    }
    
    

     

    Elvis Stokovac



  • 4.  Re: How to change icon in MDI Parent

    Posted 10-01-2014 05:33 AM

    Thank you Elvis,

    This works as planed now. 

     

    I remembered where I "stole" the change icon source code : Changing a panel's icon at runtime - The CA Plex Wiki



  • 5.  Re: How to change icon in MDI Parent

    Posted 10-01-2014 05:44 AM

    I'm glad that helped you,

    Thanks for the feedback.

     

    Elvis Stokovac