|
Thanks for helping me out with this. The situation is this:
I am in the middle of doing an owner-drawn button that I want to allow bitmaps or icons to be added, which I can do by adding either to a CImageList. The problem so far is the disabled image. I have two functions which are illustrated below. The first is for adding the bitmap, which works for standard and disabled images and the second which works for the standard image but requires the addition of the disabled image. I apologise if the code is a bit spaghetti, but I am working towards having the ability if having multiple images set, but I'm not there yet
BOOL SSLButtonEx::SetButtonBitmap(UINT nResourceID, COLORREF crMask) {
BOOL bReturn = m_bmpImage.LoadBitmap (nResourceID);
if (TRUE == bReturn) {
m_bmpImage.GetObject (sizeof m_bmp, &m_bmp);
m_nImageWidth = m_bmp.bmWidth;
m_nImageHeight = m_bmp.bmHeight;
bReturn = m_imageList.Create (nResourceID, m_bmp.bmWidth, 1, crMask);
if (TRUE == bReturn) {
if (m_imageList.Add (&m_bmpImage, crMask) > -1) {
m_bImageLoaded = TRUE;
}
else {
m_bImageLoaded = FALSE;
}
m_crMask = crMask;
HBITMAP bmpTemp;
COLORMAP mapColour;
mapColour.from = crMask;
mapColour.to = RGB(255,255,255);
bmpTemp = (HBITMAP)::CreateMappedBitmap (AfxGetApp()->m_hInstance,
nResourceID, IMAGE_BITMAP, &mapColour, 1);
m_hbmpDisabled = (HBITMAP)::CopyImage(bmpTemp, IMAGE_BITMAP,
m_nImageWidth, m_nImageHeight, LR_COPYDELETEORG);
}
else {
m_bImageLoaded = FALSE;
}
}
return bReturn;
}
BOOL SSLButtonEx::SetButtonIcon(UINT nResourceID, COLORREF crMask) {
BOOL bReturn = FALSE;
HINSTANCE hInstance = AfxFindResourceHandle (MAKEINTRESOURCE (nResourceID), RT_GROUP_ICON);
m_hIcon = (HICON)::LoadImage (hInstance, MAKEINTRESOURCE (nResourceID), IMAGE_ICON, 0, 0, 0);
if (NULL != m_hIcon) {
m_crMask = crMask;
ICONINFO iconInfo;
ZeroMemory (&iconInfo, sizeof (ICONINFO));
bReturn = ::GetIconInfo (m_hIcon, &iconInfo);
if (TRUE == bReturn) {
m_nImageWidth = iconInfo.xHotspot * 2;
m_nImageHeight = iconInfo.yHotspot * 2;
::DeleteObject(iconInfo.hbmMask);
::DeleteObject(iconInfo.hbmColor);
bReturn = m_imageList.Create (m_nImageWidth, m_nImageHeight, ILC_COLOR32 | ILC_MASK, 1, 1);
if (TRUE == bReturn) {
if (m_imageList.Add (m_hIcon) > -1) {
m_bImageLoaded = TRUE;
}
else {
m_bImageLoaded = FALSE;
}
}
}
}
return bReturn;
}
|
|
|
|
|
Two solutions are possible:
1) you can use ImageList_GetImageInfo or CImageList::GetImageInfo. This gives you underlying HBITMAP (all images in the list stored on single bitmap), which you can pass to DrawState. You should perform this on a copy of original imagelist, but that's an easy part - just use ImageList_Copy or its MFC counterpart.
2) you have icon/bitmap handle in SetButtonXXX methods. For each 'source' image create appropriate 'disabled' one, then add this to second imglist.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for sticking with me on this one
In SetButtonIcon I have the following to create a copy of the bitmap:
IMAGEINFO imgInfo;
m_imageList.GetImageInfo (0, &imgInfo);
m_hbmpDisabled = (HBITMAP)::CopyImage (imgInfo.hbmImage, IMAGE_BITMAP,
m_nImageWidth, m_nImageHeight, LR_COPYDELETEORG);
Then in DrawItem I use the following to draw it as a disabled image:
pDC->DrawState (CPoint (3, 3), CSize (m_nImageWidth, m_nImageHeight),
m_hbmpDisabled, DST_BITMAP | DSS_DISABLED);
Unfortunately this just draws a grey square, rather than the disabled image. The SetButtonBitmap function uses a similar process, but uses CreateMappedBitmap to map the mask colour to white. This bitmap is then copied into m_hbmpDisabled using ::CopyImage .
Presumably this is the step that is missing in SetButtonIcon , but how can I use CreateMappedBitmap without a bitmap resource id?
Derek Lakin.
Salamander Software Ltd.
|
|
|
|
|
So SetButtonBitmap works OK? If yes, you should try to pass DST_ICON flag to DrawState inside SetButtonIcon. No CopyImage call would be required in this case.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for your email yesterday.
Finally I've got it cracked
I add the bitmap ot icon into the image list in SetButtonBitmap or SetButtonIcon respectively, and then in DrawItem I use ExtractIcon and treat any image in the image list, regardless of source, as an icon. That way I don't need to worry about a copy of the bitmap or anything. This opens the door to multiple images
I feel like I've broken the back of this project. Hopefully before long I'll publish the article and code.
Thanks for your help.
Derek Lakin.
Salamander Software Ltd.
|
|
|
|
|
Hello,
Please can you help me to know what is the function to use to connect to a microsoft SQL server, and also how to put data into it.
It would be even better if you just point me a link where there is information about connecting to a MSSQL database gor beginners,
Thank you.
-Ali
|
|
|
|
|
You can find a sample apps in the SQL Server's sample directory. (/Microsoft SQL Server/80/Tools/DevTools/Samples/ado - for example). There is a lot more
|
|
|
|
|
I have to read the MAC addresses in our LAN, but I didn't know how. I know that there is something with NetBIOS, but nothing more. Please, somebody ... HELP !!!!!
|
|
|
|
|
http://www.codeproject.com/useritems/getmac.asp
|
|
|
|
|
|
Hello,
I will like to know, is there any custom attribute facility available for file in NTFS.
I want to assign my own data with he file. And want to store it as custom attribute.
If there is any such way then, please tell me whether there is any direct API to do so.
Thank you.
|
|
|
|
|
You could try the 'alternate data streams' feature. Check KB article Q105763 for details.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I want to write a Visual C program that can read resource in .exe file and modified its resource.
Any iead???
Regards
NBee
|
|
|
|
|
Try looking for:
BeginUpdateResource()
UpdateResource()
EndUpdateResource()
in MSDN.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Hello,
I'm working on a Dialogbased Windows CE application. The application communicates with a device. It's the intention that when I type in some digits in an EditBox and press Enter, the string of digits will be send to the device. When I use an OnChangeEDit Event, every time I type in a digit the data is send. How can I avoid this so it will only send the data when I press Enter?
Arjan.
|
|
|
|
|
i need to make a simple timer in an MFC dialog based app. Whats a simple way to do this?, because i'm new to timers completely.
Thankya
|
|
|
|
|
On the very first page of CodeProject there's a 'Latest tutorials' section. You can find the link to timers tutorial there.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I would like to know if in vc++ we could choose an option which make the debugger more accurate. I already know that there is a difference between Debug and Release.
thanks in advance
gerald
|
|
|
|
|
I would like to know if in vc++ we could choose an option which make the debugger more accurate.
What kind of accuracy do you need?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
There 're some link error in the following
"error LNK2001: unresolved external symbol imp__bind@12"
" error LNK2001: unresolved external symbol __imp__socket@12"
Please notify me how to solve this problem
Best regards,
THomm <tomm_mmx@yahoo.com>
|
|
|
|
|
You should be able to fix it by just adding 'Ws2_32.lib' to your project settings.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I'm writing a program using DirecX 8.0 in a Win32 environment. This program takes exclusive control over the screen and aquires the mouse using DirectInput. During the course of the program after a set amount of mouse clicks the pc speaker starts beeping for every movement or click (including the keyboard.) I must state that the program's performance isn't affected by what's going on in the background. I'm thinking that the OS's (Windows 9x) internal buffer is overflowing which is what's producing the beeping but I'm not sure. Is there a way to flush the OS's mouse buffer? Is this the solution to the problem?
Thank You,
Shimon
|
|
|
|
|
I have tryed the founction SetItem(icol,&item),but the function returned TRUE only when icol=0,that I cann't set the HeaderControl's image except item0.What's wrong? Thanks for your help.(sorry, my Englishi is so poor
|
|
|
|
|
What in the hell are you talking about ? A listbox ? A listctrl ? A FlexGrid ? Please ellucidate.
Christian
Secrets of a happy marriage #27:
Never go to bed if you are mad at each other. It's more fun to stay up and fight.
|
|
|
|
|
It's a HeaderCtrl in a ListView
|
|
|
|