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.
  • 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
                        • V VCProgrammer

                          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 Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #21

                          I just tested this on my system and it works fine, using the BM_SETIMAGE message. I am not sure how you would do that in MFC but I guess in much the same way.

                          V 1 Reply Last reply
                          0
                          • L Lost User

                            I just tested this on my system and it works fine, using the BM_SETIMAGE message. I am not sure how you would do that in MFC but I guess in much the same way.

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

                            sir you tested this on XP?

                            L 1 Reply Last reply
                            0
                            • V VCProgrammer

                              sir you tested this on XP?

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

                              No, Windows 7.

                              V 1 Reply Last reply
                              0
                              • L Lost User

                                No, Windows 7.

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

                                sir i already told so many times os version upper than XP, my code also working fine, the problem is just about XP and lower version...

                                L 2 Replies Last reply
                                0
                                • V VCProgrammer

                                  sir i already told so many times os version upper than XP, my code also working fine, the problem is just about XP and lower version...

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

                                  Do you have Visual Styles enabled[^]?

                                  1 Reply Last reply
                                  0
                                  • V VCProgrammer

                                    sir i already told so many times os version upper than XP, my code also working fine, the problem is just about XP and lower version...

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

                                    I have managed to get my XP VM set up and have run a number of tests but cannot make this work. Having a look around with Google it seems that this feature does not work on XP, despite the fact that the MSDN documentation states that this should work on versions from Windows 2000 and above. It looks like you are stuck, and the only solution is to decide whether to use text or icon in your product.

                                    V 1 Reply Last reply
                                    0
                                    • L Lost User

                                      I have managed to get my XP VM set up and have run a number of tests but cannot make this work. Having a look around with Google it seems that this feature does not work on XP, despite the fact that the MSDN documentation states that this should work on versions from Windows 2000 and above. It looks like you are stuck, and the only solution is to decide whether to use text or icon in your product.

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

                                      yes sir thanks... i am using now NM_CUSTOMDRAW and its solve my problem...

                                      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