Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Property sheet-based app has icon problems

Property sheet-based app has icon problems

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rfparker
    wrote on last edited by
    #1

    I am developing a property sheet-based application on XP using VC++ 6. When it starts it talks briefly to an instrument over a serial port in app::InitInstance(), creates the property sheet, adds a few pages, and does an appSheet.DoModal() to make it appear. In order to get an icon to appear in the taskbar and Alt-Tab, I use this code in appSheet::OnInitDialog():

    // Set the icons for the app
    AfxGetMainWnd()->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
    AfxGetMainWnd()->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), FALSE);

    The app works just fine, and until I added a slight twist mentioned next the icons appeared as expected. For the several seconds during which the app is initially talking to the instrument the user sees nothing happening. So at the beginning of app::InitInstance() I create a modeless dialog that asks the user to be patient while the app starts up, and then hide the dialog at the end of the startup property page's OnInitDialog(). This works fine and looks great. Except that now SetIcon(), above, returns 0 and I get the generic white window icon for Alt-Tab and nothing in the taskbar. The icon in the title bar is still correct. If I use the following code in place of the previous code, I can get the icon to display when I do an Alt-Tab, but nothing shows up in the taskbar.

    HICON hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    CWnd* pFrame=AfxGetMainWnd();
    ::SetClassLong(pFrame->GetSafeHwnd(), GCL_HICON, (long)hIcon);

    Interestingly, until I do this the generic MFC icon shows up in the taskbar. Any ideas why this is happening and how to get my icon and app name to appear in the taskbar? Thanks

    P M 2 Replies Last reply
    0
    • R rfparker

      I am developing a property sheet-based application on XP using VC++ 6. When it starts it talks briefly to an instrument over a serial port in app::InitInstance(), creates the property sheet, adds a few pages, and does an appSheet.DoModal() to make it appear. In order to get an icon to appear in the taskbar and Alt-Tab, I use this code in appSheet::OnInitDialog():

      // Set the icons for the app
      AfxGetMainWnd()->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
      AfxGetMainWnd()->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), FALSE);

      The app works just fine, and until I added a slight twist mentioned next the icons appeared as expected. For the several seconds during which the app is initially talking to the instrument the user sees nothing happening. So at the beginning of app::InitInstance() I create a modeless dialog that asks the user to be patient while the app starts up, and then hide the dialog at the end of the startup property page's OnInitDialog(). This works fine and looks great. Except that now SetIcon(), above, returns 0 and I get the generic white window icon for Alt-Tab and nothing in the taskbar. The icon in the title bar is still correct. If I use the following code in place of the previous code, I can get the icon to display when I do an Alt-Tab, but nothing shows up in the taskbar.

      HICON hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
      CWnd* pFrame=AfxGetMainWnd();
      ::SetClassLong(pFrame->GetSafeHwnd(), GCL_HICON, (long)hIcon);

      Interestingly, until I do this the generic MFC icon shows up in the taskbar. Any ideas why this is happening and how to get my icon and app name to appear in the taskbar? Thanks

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      What are the values returned by the SetIcon() method? It could be that your modeless dialog has the icons locked while it is displayed?


      You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

      R 1 Reply Last reply
      0
      • P PJ Arends

        What are the values returned by the SetIcon() method? It could be that your modeless dialog has the icons locked while it is displayed?


        You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

        R Offline
        R Offline
        rfparker
        wrote on last edited by
        #3

        SetIcon() returns 0 (zero) rather than a handle to an icon. I'm not sure what you mean about the application's icons being locked by the modeless dialog; how would I investigate this possibility? And if this is the case, can I make the dialog unlock them? The dialog lives as long as the app and is hidden or displayed, with different messages, as I change modes while communicating with the instrument.

        P 1 Reply Last reply
        0
        • R rfparker

          SetIcon() returns 0 (zero) rather than a handle to an icon. I'm not sure what you mean about the application's icons being locked by the modeless dialog; how would I investigate this possibility? And if this is the case, can I make the dialog unlock them? The dialog lives as long as the app and is hidden or displayed, with different messages, as I change modes while communicating with the instrument.

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          rfparker wrote:

          SetIcon() returns 0 (zero) rather than a handle to an icon.

          So SetIcon is failing. I would suggest that you take the communication and startup dialog code out of your InitInstance() function and put them in a separate function so that your app can be properly initialized before you do anything else. One way is to post a custom message to your main window at the end of InitInstance() and do the communication from the message handler.


          You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

          R 1 Reply Last reply
          0
          • P PJ Arends

            rfparker wrote:

            SetIcon() returns 0 (zero) rather than a handle to an icon.

            So SetIcon is failing. I would suggest that you take the communication and startup dialog code out of your InitInstance() function and put them in a separate function so that your app can be properly initialized before you do anything else. One way is to post a custom message to your main window at the end of InitInstance() and do the communication from the message handler.


            You may be right I may be crazy -- Billy Joel -- Within you lies the power for good - Use it!

            R Offline
            R Offline
            rfparker
            wrote on last edited by
            #5

            Yes, that might be a better way to do it (though AppWizard puts the call to DoModal() in a dialog-based app's InitInstance()) and I've made that change. It makes no difference to the functionality that I see. Since I can get the correct title bar and Alt-Tab icons to appear by setting them in the property sheet's OnInitDialog(), the real issue is the button on the taskbar. I guess the modeless dialog is considered the main window for the task (it has to be created first), since when it is displayed the button appears and as soon as it is hidden (SW_HIDE) the button disappears. So I can't hide the modeless dialog without also disappearing the taskbar button. So for now I'm not hiding the modeless dialog, which is undesirable. There is also the issue of the initial icon on the taskbar button. I've added SetWindowText() to the modeless dialog's OnInitDialog() to set the proper caption, since there's no title bar, and added WS_SYSMENU to the .rc to force the icon to appear, but, until the property sheet loads the icon I want, I see the MFC cube icon in the taskbar button. After the property sheet loads the icon, that one is always displayed on the taskbar, even when I've temporarily destroyed the property sheet and the modeless dialog has reappeared. What I'd like is to be able to hide the modeless dialog when I display the property sheet and not have the taskbar button disappear, and to set the taskbar button's icon so the MFC cube doesn't appear.

            1 Reply Last reply
            0
            • R rfparker

              I am developing a property sheet-based application on XP using VC++ 6. When it starts it talks briefly to an instrument over a serial port in app::InitInstance(), creates the property sheet, adds a few pages, and does an appSheet.DoModal() to make it appear. In order to get an icon to appear in the taskbar and Alt-Tab, I use this code in appSheet::OnInitDialog():

              // Set the icons for the app
              AfxGetMainWnd()->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
              AfxGetMainWnd()->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), FALSE);

              The app works just fine, and until I added a slight twist mentioned next the icons appeared as expected. For the several seconds during which the app is initially talking to the instrument the user sees nothing happening. So at the beginning of app::InitInstance() I create a modeless dialog that asks the user to be patient while the app starts up, and then hide the dialog at the end of the startup property page's OnInitDialog(). This works fine and looks great. Except that now SetIcon(), above, returns 0 and I get the generic white window icon for Alt-Tab and nothing in the taskbar. The icon in the title bar is still correct. If I use the following code in place of the previous code, I can get the icon to display when I do an Alt-Tab, but nothing shows up in the taskbar.

              HICON hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
              CWnd* pFrame=AfxGetMainWnd();
              ::SetClassLong(pFrame->GetSafeHwnd(), GCL_HICON, (long)hIcon);

              Interestingly, until I do this the generic MFC icon shows up in the taskbar. Any ideas why this is happening and how to get my icon and app name to appear in the taskbar? Thanks

              M Offline
              M Offline
              Mahesh Kulkarni
              wrote on last edited by
              #6

              i just tried following code it works

              m_prop.m_hIcon = AfxGetApp()->LoadIcon(IDI_MYICON);
              m_prop.m_psh.dwFlags |= PSP_USEHICON;
              m_prop.m_psh.hIcon = m_prop.m_hIcon;
              SetIcon(m_hIcon, TRUE);

              try this may help you...

              The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups