|
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.
|
|
|
|
|
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
|
|
|
|
|
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.
modified 8-Feb-13 2:01am.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
VCProgrammer wrote: i really cant get it whats going wrong here, Without a lot more information I don't think we can either.
|
|
|
|
|
please sir tell me what other information you required to help me.
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
Yes, and the fact that you people will insist on hiding below the horizon.
|
|
|
|
|
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());
if(hIcon)
{
}
else
{
AfxMessageBox(_T("NULL hIcon"));
}
m_btn.SetIcon(hIcon);
AfxMessageBox(ErrorMsg());
HICON icon =NULL;
HINSTANCE hInstResource = NULL;
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_ICON2), RT_GROUP_ICON);
AfxMessageBox(ErrorMsg());
if(hInstResource)
{
}
else
{
AfxMessageBox(_T("hInstResource null"));
}
icon = (HICON) LoadImage(hInstResource,
MAKEINTRESOURCE(IDI_ICON2),
IMAGE_ICON,
16,
16,
LR_DEFAULTCOLOR);
AfxMessageBox(ErrorMsg());
if(icon )
{
}
else
{
AfxMessageBox(_T("NULL icon "));
}
m_btn2.SetIcon(icon);
AfxMessageBox(ErrorMsg());
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,
(LPTSTR) &lpMsgBuf,
0,
NULL
);
ret_msg+=(LPCTSTR)lpMsgBuf;
LocalFree( lpMsgBuf);
return ret_msg;
}
|
|
|
|
|
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?
|
|
|
|
|
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....
|
|
|
|
|
|
thanks for your guidance and support ,but please help me what function use to display text and icon on button....
|
|
|
|
|
|
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...
|
|
|
|
|
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.
|
|
|
|
|
sir you tested this on XP?
|
|
|
|
|
|
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...
|
|
|
|
|
|
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.
|
|
|
|
|
yes sir thanks...
i am using now NM_CUSTOMDRAW and its solve my problem...
|
|
|
|
|
Hello Everybody,
I hope i have choosen the right forum for my Question.
I have a little application which starts another programm with a specific path (a txt-file).
Yes, easy and simple, it works fine with ShellExecute, but i have a problem with some Executables(I have to test a few programs). One Executable opens correct but it don´t opens the given path. I don´t understake whats wrong, because if I drag and drop the txt-file manualy on the executable it works.
So my Question is, are ShellExecute and Drag&Drop two different things to open a programm? Does anybody know a way to fix my problem ?
Thanks in advance,
Michael
|
|
|
|