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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. icon on button not displayed in XP.

icon on button not displayed in XP.

Scheduled Pinned Locked Moved C / C++ / MFC
help
27 Posts 3 Posters 5 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.
  • V Offline
    V Offline
    VCProgrammer
    wrote on last edited by
    #1

    Hi all, i am set icon on button and display the caption in front of icon. but in XP the icon not displayed if icon and text both are using,if only icon i want to display its working fine. i dont wahts going wrong here please help me.

    L D 2 Replies Last reply
    0
    • V VCProgrammer

      Hi all, i am set icon on button and display the caption in front of icon. but in XP the icon not displayed if icon and text both are using,if only icon i want to display its working fine. i dont wahts going wrong here please help me.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      VCProgrammer wrote:

      i dont wahts going wrong here

      Neither do we. Please give some proper detail, including a copy of the code that is not working.

      1 Reply Last reply
      0
      • V VCProgrammer

        Hi all, i am set icon on button and display the caption in front of icon. but in XP the icon not displayed if icon and text both are using,if only icon i want to display its working fine. i dont wahts going wrong here please help me.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Is the problem XP-specific or does it act the same on other OSs?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

        V 1 Reply Last reply
        0
        • D David Crow

          Is the problem XP-specific or does it act the same on other OSs?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

          V Offline
          V Offline
          VCProgrammer
          wrote on last edited by
          #4

          i am using this to set icon on button only on xp i found this problem.

          HICON hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
          m_btn2.SetIcon(hIcon);

          HICON icon =NULL;

          HINSTANCE	hInstResource	= NULL;	
          
          hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI\_ICON2), RT\_GROUP\_ICON);
          
          icon = (HICON) LoadImage(hInstResource,
          						MAKEINTRESOURCE(IDI\_ICON2),
          						IMAGE\_ICON,
          						16,
          						16,
          						LR\_DEFAULTCOLOR); 
          
          m\_btn3.SetIcon(icon);
          

          on other os like Vista and Windows 7 the icon on button with button caption display properly, but in case of XP the icon not display only the button caption is visible.

          D 1 Reply Last reply
          0
          • V VCProgrammer

            i am using this to set icon on button only on xp i found this problem.

            HICON hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
            m_btn2.SetIcon(hIcon);

            HICON icon =NULL;

            HINSTANCE	hInstResource	= NULL;	
            
            hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI\_ICON2), RT\_GROUP\_ICON);
            
            icon = (HICON) LoadImage(hInstResource,
            						MAKEINTRESOURCE(IDI\_ICON2),
            						IMAGE\_ICON,
            						16,
            						16,
            						LR\_DEFAULTCOLOR); 
            
            m\_btn3.SetIcon(icon);
            

            on other os like Vista and Windows 7 the icon on button with button caption display properly, but in case of XP the icon not display only the button caption is visible.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            From where is this code being used? Do the icon handles have function-level scope? You are not checking the return value from any of the function calls. If one of them is failing, how would you know? Check out GetLastError().

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

            V 1 Reply Last reply
            0
            • D David Crow

              From where is this code being used? Do the icon handles have function-level scope? You are not checking the return value from any of the function calls. If one of them is failing, how would you know? Check out GetLastError().

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

              V Offline
              V Offline
              VCProgrammer
              wrote on last edited by
              #6

              i am checking GetLastError for LoadIcon and LoadImage, both are return 6 (The Handle is invalid). i dont understand why this fails only on xp otherwise its working fine. even if i set Button style BS_ICON ,than its also working on XP,but my requirement to display both icon and text on button. please help me how can i resolve this. thanks.

              L 1 Reply Last reply
              0
              • V VCProgrammer

                i am checking GetLastError for LoadIcon and LoadImage, both are return 6 (The Handle is invalid). i dont understand why this fails only on xp otherwise its working fine. even if i set Button style BS_ICON ,than its also working on XP,but my requirement to display both icon and text on button. please help me how can i resolve this. thanks.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                VCProgrammer wrote:

                both are return 6 (The Handle is invalid).

                That suggests the your resource ids are also invalid. Check that all the values match up with their target resources and are correctly loaded into your final application.

                V 1 Reply Last reply
                0
                • L Lost User

                  VCProgrammer wrote:

                  both are return 6 (The Handle is invalid).

                  That suggests the your resource ids are also invalid. Check that all the values match up with their target resources and are correctly loaded into your final application.

                  V Offline
                  V Offline
                  VCProgrammer
                  wrote on last edited by
                  #8

                  but when i set Button style BS_ICON ,than its also working on XP.it means ids are not invalid,i think so... i really cant get it whats going wrong here, is there any other method to display icon on button with text.

                  L 1 Reply Last reply
                  0
                  • V VCProgrammer

                    but when i set Button style BS_ICON ,than its also working on XP.it means ids are not invalid,i think so... i really cant get it whats going wrong here, is there any other method to display icon on button with text.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    VCProgrammer wrote:

                    i really cant get it whats going wrong here,

                    Without a lot more information I don't think we can either.

                    V 1 Reply Last reply
                    0
                    • L Lost User

                      VCProgrammer wrote:

                      i really cant get it whats going wrong here,

                      Without a lot more information I don't think we can either.

                      V Offline
                      V Offline
                      VCProgrammer
                      wrote on last edited by
                      #10

                      please sir tell me what other information you required to help me.

                      L 1 Reply Last reply
                      0
                      • V VCProgrammer

                        please sir tell me what other information you required to help me.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        You need to show some more of the failing code and the error messages or codes that you receive. Remember, we cannot see your system and are not familiar with your program.

                        D V 2 Replies Last reply
                        0
                        • L Lost User

                          You need to show some more of the failing code and the error messages or codes that you receive. Remember, we cannot see your system and are not familiar with your program.

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #12

                          Richard MacCutchan wrote:

                          Remember, we cannot see your system...

                          Atlantic ocean in your way, Richard?

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                          L 1 Reply Last reply
                          0
                          • D David Crow

                            Richard MacCutchan wrote:

                            Remember, we cannot see your system...

                            Atlantic ocean in your way, Richard?

                            "One man's wage rise is another man's price increase." - Harold Wilson

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            Yes, and the fact that you people will insist on hiding below the horizon.

                            1 Reply Last reply
                            0
                            • L Lost User

                              You need to show some more of the failing code and the error messages or codes that you receive. Remember, we cannot see your system and are not familiar with your program.

                              V Offline
                              V Offline
                              VCProgrammer
                              wrote on last edited by
                              #14

                              in my test application for button icon: i have 2 Icon,load them in resource with id IDI_ICON1,and IDI_ICON2 2 buttons :CButton m_btn; CButton m_btn2; on which i wan to set the icon if i set the icon style true for buth buttons its working fine and display the icon on button in XP. but when i FALSE the ICON style for button and run this application,only text of button is display not the icon on button. now please help,if want something more please tel me what information i provide you to better assist me...

                              BOOL CBtnIconDlg::OnInitDialog()
                              {

                                  HICON hIcon = AfxGetApp()->LoadIcon(IDI\_ICON1);
                              
                              AfxMessageBox(ErrorMsg());//here i get GetLastError =0 (The operation completed successfully.)
                              if(hIcon)
                              {
                              	//ok valid icon found
                              }
                              else
                              {
                              	AfxMessageBox(\_T("NULL hIcon"));//this not popup
                              }
                              	
                              m\_btn.SetIcon(hIcon);	
                              AfxMessageBox(ErrorMsg());//here i get GetLastError =87 (The parameter is incorrect.)
                              
                              HICON icon =NULL;
                              HINSTANCE	hInstResource	= NULL;	
                              hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI\_ICON2), RT\_GROUP\_ICON);
                              
                              AfxMessageBox(ErrorMsg());//here i get GetLastError =0 (The operation completed successfully.)
                              
                              if(hInstResource)
                              {
                              	//ok valid hInstResource found
                              }
                              else
                              {
                              	AfxMessageBox(\_T("hInstResource null"));//this not popup
                              }
                              
                              icon = (HICON) LoadImage(hInstResource,
                              						MAKEINTRESOURCE(IDI\_ICON2),
                              						IMAGE\_ICON,
                              						16,
                              						16,
                              						LR\_DEFAULTCOLOR); 
                              
                              
                              AfxMessageBox(ErrorMsg());//here i get GetLastError =0 (The operation completed successfully.)
                              if(icon )
                              {
                              	//valid icon 
                              }
                              else
                              {
                              	AfxMessageBox(\_T("NULL icon "));//this not popup
                              }
                              	
                              m\_btn2.SetIcon(icon);
                              
                              AfxMessageBox(ErrorMsg());//here i get GetLastError =87 (The parameter is incorrect.)
                              
                                  return TRUE;
                              

                              }

                              CString CBtnIconDlg::ErrorMsg()
                              {
                              CString ret_msg=_T("");

                              LPVOID lpMsgBuf;
                              HRESULT hr;
                              
                              hr = GetLastError();
                              
                              ret\_msg.Format(\_T("%d :: "),GetLastError());
                              
                              FormatMessage( 
                              	FORMAT\_MESSAGE\_ALLOCATE\_BUFFER | 
                              	FORMAT\_MESSAGE\_FROM\_SYSTEM | 
                              	FORMAT\_MESSAGE\_IGNORE\_INSERTS,
                              	NULL,
                              	hr,
                              	0, // Default language
                              	(LPTSTR) &lpMsgBuf,
                              	0,
                              	NULL 
                              );
                              
                              ret\_msg+=(LPCTSTR)lpMsgBuf;	
                              LocalFree( lpMsgBuf);
                              
                              return ret\_msg;
                              

                              }

                              L 1 Reply Last reply
                              0
                              • V VCProgrammer

                                in my test application for button icon: i have 2 Icon,load them in resource with id IDI_ICON1,and IDI_ICON2 2 buttons :CButton m_btn; CButton m_btn2; on which i wan to set the icon if i set the icon style true for buth buttons its working fine and display the icon on button in XP. but when i FALSE the ICON style for button and run this application,only text of button is display not the icon on button. now please help,if want something more please tel me what information i provide you to better assist me...

                                BOOL CBtnIconDlg::OnInitDialog()
                                {

                                    HICON hIcon = AfxGetApp()->LoadIcon(IDI\_ICON1);
                                
                                AfxMessageBox(ErrorMsg());//here i get GetLastError =0 (The operation completed successfully.)
                                if(hIcon)
                                {
                                	//ok valid icon found
                                }
                                else
                                {
                                	AfxMessageBox(\_T("NULL hIcon"));//this not popup
                                }
                                	
                                m\_btn.SetIcon(hIcon);	
                                AfxMessageBox(ErrorMsg());//here i get GetLastError =87 (The parameter is incorrect.)
                                
                                HICON icon =NULL;
                                HINSTANCE	hInstResource	= NULL;	
                                hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI\_ICON2), RT\_GROUP\_ICON);
                                
                                AfxMessageBox(ErrorMsg());//here i get GetLastError =0 (The operation completed successfully.)
                                
                                if(hInstResource)
                                {
                                	//ok valid hInstResource found
                                }
                                else
                                {
                                	AfxMessageBox(\_T("hInstResource null"));//this not popup
                                }
                                
                                icon = (HICON) LoadImage(hInstResource,
                                						MAKEINTRESOURCE(IDI\_ICON2),
                                						IMAGE\_ICON,
                                						16,
                                						16,
                                						LR\_DEFAULTCOLOR); 
                                
                                
                                AfxMessageBox(ErrorMsg());//here i get GetLastError =0 (The operation completed successfully.)
                                if(icon )
                                {
                                	//valid icon 
                                }
                                else
                                {
                                	AfxMessageBox(\_T("NULL icon "));//this not popup
                                }
                                	
                                m\_btn2.SetIcon(icon);
                                
                                AfxMessageBox(ErrorMsg());//here i get GetLastError =87 (The parameter is incorrect.)
                                
                                    return TRUE;
                                

                                }

                                CString CBtnIconDlg::ErrorMsg()
                                {
                                CString ret_msg=_T("");

                                LPVOID lpMsgBuf;
                                HRESULT hr;
                                
                                hr = GetLastError();
                                
                                ret\_msg.Format(\_T("%d :: "),GetLastError());
                                
                                FormatMessage( 
                                	FORMAT\_MESSAGE\_ALLOCATE\_BUFFER | 
                                	FORMAT\_MESSAGE\_FROM\_SYSTEM | 
                                	FORMAT\_MESSAGE\_IGNORE\_INSERTS,
                                	NULL,
                                	hr,
                                	0, // Default language
                                	(LPTSTR) &lpMsgBuf,
                                	0,
                                	NULL 
                                );
                                
                                ret\_msg+=(LPCTSTR)lpMsgBuf;	
                                LocalFree( lpMsgBuf);
                                
                                return ret\_msg;
                                

                                }

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #15

                                I suspect the error 87 should be ignored as you have not checked if the previous function was successful or not. You can validate that by calling SetLastError(0) before the SetIcon() call. You also say that when you set icon style to FALSE it does not display the icon; isn't that what it should do?

                                V 1 Reply Last reply
                                0
                                • L Lost User

                                  I suspect the error 87 should be ignored as you have not checked if the previous function was successful or not. You can validate that by calling SetLastError(0) before the SetIcon() call. You also say that when you set icon style to FALSE it does not display the icon; isn't that what it should do?

                                  V Offline
                                  V Offline
                                  VCProgrammer
                                  wrote on last edited by
                                  #16

                                  i set icon style to FALSE,coz i dont want only icon on button is display i want icon and text both are display on button....

                                  L 1 Reply Last reply
                                  0
                                  • V VCProgrammer

                                    i set icon style to FALSE,coz i dont want only icon on button is display i want icon and text both are display on button....

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    See the remarks section[^].

                                    V 1 Reply Last reply
                                    0
                                    • L Lost User

                                      See the remarks section[^].

                                      V Offline
                                      V Offline
                                      VCProgrammer
                                      wrote on last edited by
                                      #18

                                      thanks for your guidance and support ,but please help me what function use to display text and icon on button....

                                      L 1 Reply Last reply
                                      0
                                      • V VCProgrammer

                                        thanks for your guidance and support ,but please help me what function use to display text and icon on button....

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #19

                                        Use the methods and properties as described in the documentation[^].

                                        V 1 Reply Last reply
                                        0
                                        • L Lost User

                                          Use the methods and properties as described in the documentation[^].

                                          V Offline
                                          V Offline
                                          VCProgrammer
                                          wrote on last edited by
                                          #20

                                          according to the documentationt set icon on button use CButton:SetIcon method,that have i already used...as you know also is not working fine...

                                          L 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