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. How do I change icon and small icon for a windows class

How do I change icon and small icon for a windows class

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
5 Posts 4 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.
  • S Offline
    S Offline
    scody
    wrote on last edited by
    #1

    Hi all, I was trying to change the application icon through the windows class by changing the icon macros loaded into windows class as shown below, but no matter what icon macro I choose the icon displayed is the application icon from IDI_APPLICATION macro. windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default Icon ... ... windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); Could please tell how to change the icons by icon macros. Any help would be greatly appriciated. Thanks Scody

    H W M 3 Replies Last reply
    0
    • S scody

      Hi all, I was trying to change the application icon through the windows class by changing the icon macros loaded into windows class as shown below, but no matter what icon macro I choose the icon displayed is the application icon from IDI_APPLICATION macro. windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default Icon ... ... windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); Could please tell how to change the icons by icon macros. Any help would be greatly appriciated. Thanks Scody

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      if you run this code wcex.hIconSm= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);what happens? From the MSDN HICON LoadIcon(HINSTANCE hInstance,LPCTSTR lpIconName); hInstance [in] Handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded


      WhiteSky


      S 1 Reply Last reply
      0
      • S scody

        Hi all, I was trying to change the application icon through the windows class by changing the icon macros loaded into windows class as shown below, but no matter what icon macro I choose the icon displayed is the application icon from IDI_APPLICATION macro. windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default Icon ... ... windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); Could please tell how to change the icons by icon macros. Any help would be greatly appriciated. Thanks Scody

        W Offline
        W Offline
        Waldermort
        wrote on last edited by
        #3

        open the resource header file, find the definition for the icons. Give the icon you want the smaller number. The default Icon for an exe is the first icon found (the one with the smallest number).

        1 Reply Last reply
        0
        • S scody

          Hi all, I was trying to change the application icon through the windows class by changing the icon macros loaded into windows class as shown below, but no matter what icon macro I choose the icon displayed is the application icon from IDI_APPLICATION macro. windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default Icon ... ... windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); Could please tell how to change the icons by icon macros. Any help would be greatly appriciated. Thanks Scody

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          You can override PreCreateWindow() to use your custom window class instead of the default... This example assumes szMyRegisteredWindowClass points to the class name associated with your "windowClass"

          BOOL MyWindowClass::PreCreateWindow(CREATESTRUCT& cs)
          {
          // Let base class fill in the default CREATESTRUCT

          if( !CBaseWndClass::PreCreateWindow(cs) )
          	return FALSE;
          
          // Now alter CREATESTRUCT with our custom settings
          
          cs.lpszClass = szMyRegisteredWindowClass;
          cs.style = ;
          cs.dwExStyle = ;
          
          return TRUE;
          

          }

          1 Reply Last reply
          0
          • H Hamid Taebi

            if you run this code wcex.hIconSm= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);what happens? From the MSDN HICON LoadIcon(HINSTANCE hInstance,LPCTSTR lpIconName); hInstance [in] Handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded


            WhiteSky


            S Offline
            S Offline
            scody
            wrote on last edited by
            #5

            Hi WhiteSky, I have just tried the code as you suggested windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(windowClass.hInstance, (LPCTSTR)IDI_WINLOGO); //default Icon windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); //default arrow cursor windowClass.hbrBackground = NULL; //don't need background windowClass.lpszMenuName = NULL; // no menu windowClass.lpszClassName = "AeroClass"; windowClass.hIconSm = LoadIcon(windowClass.hInstance, (LPCTSTR)IDI_WINLOGO); but still the default application icon is displayed. I would like to use standard icon Windows logo to be displayed on my application window, so I was using NULL in my code in the previous posting. All I want to do is change the icon on my application window to Windows logo using standard icon macro IDI_WINLOGO. Any help would be greatly appriciated. Thanks Scody

            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