|
Hi,
Look at this (maybe it will be useful for you)
void CImageListFromBitmap::ReplaceBackgroundColor (CBitmap& ioBM)
{
// figure out how many pixels there are in the bitmap
BITMAP bmInfo;
VERIFY (ioBM.GetBitmap (&bmInfo));
// add support for additional bit depths here if you choose
VERIFY (bmInfo.bmBitsPixel == 24);
VERIFY (bmInfo.bmWidthBytes == (bmInfo.bmWidth * 3));
const UINT numPixels (bmInfo.bmHeight * bmInfo.bmWidth);
// get a pointer to the pixels
DIBSECTION ds;
VERIFY (ioBM.GetObject (sizeof (DIBSECTION), &ds) == sizeof (DIBSECTION));
RGBTRIPLE* pixels = reinterpret_cast<rgbtriple*>(ds.dsBm.bmBits);
VERIFY (pixels != NULL);
// get the user's preferred button color from the system
RGBTRIPLE userBackgroundColor = {
GetBValue (m_screenBackColor), GetGValue (m_screenBackColor), GetRValue (m_screenBackColor)};
BYTE imageBlue=GetBValue(m_imageBackColor);
BYTE imageGreen=GetGValue(m_imageBackColor);
BYTE imageRed=GetRValue(m_imageBackColor);
// search through the pixels, substituting the user's button
// color for any pixel that has the magic background color
for (UINT i = 0; i < numPixels; ++i)
{
if (pixels [i].rgbtBlue == imageBlue &&
pixels [i].rgbtGreen == imageGreen &&
pixels [i].rgbtRed == imageRed)
{
pixels [i] = userBackgroundColor;
}
}
}
Sincerely Yours,
RadioShark
|
|
|
|
|
I am a bit confused! If you are programing for windows all that is required is that you load an image into a device context then call GetPixel() to read the RGB value or call SetPixel() to set the RGB value.
Now if you want to access the values directly (which is faster) I recommend 2 aticles: DIBSection By Chris Maunder and CDibData By me. There are probably other aticles at codeproject that will answer your question.
Steps:
1. Load bitmap.
2. Create a memory DC (or CDC in MFC).
3. Select bitmap into DC.
4. Read or Write pixel
(SDK: SetPixel(hdc,x,y,color), MFC: pdc->SetPixel(x,y,color))
5. Select origanal bitmap into DC.
6. Release DC.
Now, If you need to save the image after you have modified it read the articles mentioned above and if you need to support multiple bitmap formats then I recommend looking at CxImage.
INTP
|
|
|
|
|
How can I know the actual size of a menu? I need to display a menu from a CToolBarCtrl toolbar. When the menu is from top to bottom, the menu should be popped up from the bottom of the bar, on the other hand, when the bar is near the bottom of the screen and the menu needs to be displayed from bottom to top, the menu should be popped up from the top of the bar. IE paints menu this way so that the bar won't be blocked by the menu.
But I don't know how to get the acutal size (in pixles) of the menu. Or if I can how which way it pops up the menu, that would be better.
Thanks a lot in advance.
|
|
|
|
|
I beleive that BCMenu By Brent Corkum (@ codeproject) will probably answer your question. The following is from some code I wrote a while ago, it was derivived from Bent Corkum's code (since his was less complicated than my first idea):
BOOL CDialogMenu::TrackWindow()
{
if( m_rcExclude.left == __BADPOSITION )
return FALSE;
CRect rectWindow;
WINDOWPLACEMENT wndpl;
wndpl.length = sizeof(WINDOWPLACEMENT);
if( !GetWindowPlacement( &wndpl ) )
return FALSE;
rectWindow = wndpl.rcNormalPosition;
int cx = ::GetSystemMetrics(SM_CXSCREEN);
int cy = ::GetSystemMetrics(SM_CYSCREEN);
rectWindow.SetRect(
m_rcExclude.left,m_rcExclude.bottom,
m_rcExclude.left+rectWindow.Width(),
m_rcExclude.bottom+rectWindow.Height());
if( m_bCenter )
rectWindow.OffsetRect(-((rectWindow.Width() + m_rcExclude.Width())>>1),0);
if (rectWindow.right > cx)
rectWindow.OffsetRect(-(rectWindow.right - cx), 0);
if (rectWindow.left < 0)
rectWindow.OffsetRect( -rectWindow.left, 0);
if (rectWindow.bottom > cy)
rectWindow.OffsetRect(0,-(m_rcExclude.Height() + rectWindow.Height()));
wndpl.rcNormalPosition = rectWindow;
SetWindowPlacement( &wndpl );
return FALSE;
}
I hope this helps!
Good luck!
INTP
|
|
|
|
|
Here's what I use in the CP SearchBar:
void CalcMenuLocation ( HMENU menu, const RECT& rcBtn,
POINT& ptMenuLocation, UINT& uFlags )
{
POINT pt = { rcBtn.left, rcBtn.bottom };
UINT uMenuFlags = 0;
UINT uItemCnt = GetMenuItemCount ( menu );
int nMenuHeight = uItemCnt * GetSystemMetrics ( SM_CYMENUSIZE );
int nScreenHeight = GetSystemMetrics ( SM_CYSCREEN );
if ( nMenuHeight + pt.y > nScreenHeight )
{
uMenuFlags |= TPM_BOTTOMALIGN;
pt.y = rcBtn.top;
}
ptMenuLocation = pt;
uFlags |= uMenuFlags;
} Call it like this:
LRESULT CSearchBar::OnToolbarDropdown ( NMHDR* phdr )
{
NMTOOLBAR* pnmtb = (NMTOOLBAR*) phdr;
HMENU hmenu, hPopup;
RECT rcItem = pnmtb->rcButton;
hmenu = AtlLoadMenu ( IDR_YOUR_MENU_HERE );
if ( NULL == hmenu )
return TBDDRET_DEFAULT;
hPopup = GetSubMenu ( hmenu, 0 );
ATLASSERT ( NULL != hPopup );
POINT ptMenuLocation;
UINT uFlags = TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD;
int nMenuItem;
ClientToScreen ( &rcItem );
CalcMenuLocation ( hPopup, rcItem, ptMenuLocation, uFlags );
nMenuItem = (int) TrackPopupMenu ( hPopup, uFlags,
ptMenuLocation.x, ptMenuLocation.y,
0, m_hWnd, NULL );
} Note that this is not multi-monitor aware. I don't have 2 monitors at home so I haven't fixed the code to work on secondary monitors.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
Mike, I am in the process of writing an article about menus. Would I be able to make use of this code as part of it?
It would be a good complement to some of the stuff I already have complete.
Roger Allen - Sonork 100.10016
Strong Sad:
Clever I am? Next to no one.
Undiscovered and soggy.
Look up. Look down. They're around.
Probably laughing. Still, bright, watery.
Listed among the top. Ten.
Nine. Late night. Early morn.
Early mourn. Now I sleep.
|
|
|
|
|
Roger Allen wrote:
Mike, I am in the process of writing an article about menus. Would I be able to make use of this code as part of it?
Sure, go right ahead
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
visual C++ 6
is there an open type variable that can access the string type of data or double ..
( To be used in an edit box, read from and write in )
|
|
|
|
|
I am not sure what you mean by open type! If you mean a variable type the can hold either a double or a string then you are talking about a VARIANT which is communaly used in visual basic (probably where it came from) and when creating OLE controls. If you need and edit box control that is either designed for a perticular data type or can be generalized using masks then goto the the edit controls section of codeproject (where there are many aticles on this subject).
INTP
|
|
|
|
|
I have the following message map:
ON_MESSAGE (WM_ACTION, OnAction)
(where WM_ACTION is defined as WM_USER+0x100 )
and I get the following error:
error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMainFrame::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'<br />
None of the functions with this name in scope match the target type
Can anybody help?
Thanks
|
|
|
|
|
Naturaly I would look for any where that you use static_cast. In C you probubly would not see the error, but C++ is less forgiving (a good thing).
This is realy not quite enough infomation to solve the problem, although the deference between CMainFrame* and CWnd* does suggest a scopping problem, accept for the fact that static_cast is being used.
If you know the line on which the error occurs (I assume you do), then you have half the problem solved. Now look at all the related functions that take arguments (WPARAM,LPARAM) and work from there.
This is one of the reasons that C++ can be very irritating, because in C what you see is what you get. But in C++, not only does it hide information but, it often hides the reason for the error.
Well! Good luck in solving your problem, it does not look too difficult.
Sorry if this did not help, since it looks like you are already applying the method I would use.
INTP
|
|
|
|
|
Can you show how you have defined the OnAction method, i guess thats where the problem lies.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
OK, i have 2 dialogs. I want to show one as a child of another. Can someone take me through how to do this, i have no idea how. Im using VC++6, and im reletivly new to c++ so please be explain how it works if u would, thank you
i really appreciate it.
---------------------
And Like The Wind Our Hero Vanishes Off Into The Distance...
|
|
|
|
|
|
Thank you, but not exactly what im trying to do. I want to be able to move the child around inside of the parrent, i guess turning my parrent into a sort of MDI Dialog box. But yeah, i want to be able to move the dialog box around, close it...ect
thank you
---------------------
And Like The Wind Our Hero Vanishes Off Into The Distance...
|
|
|
|
|
There's a fair bit of work ahead of you then, unless you just use the existing MFC or WTL MDI classes (i would strongly suggest doing this). Regardless, that's the place to look for information - both MFC and WTL come with full source code, and the MDI stuff is reasonably clear.
How do you move in a world of fog, That's always changing things?
Makes me wish that i could be a dog, When i see the price that you pay.
|
|
|
|
|
Would anybody like to help me to produce a random number for my C++ guessing game?
|
|
|
|
|
Sure. Here's one: 6410086356. Or you could use rand() and srand() .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
If you are content with pseudo-random numbers, use rand() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
srand((unsigned) time(NULL));
this is what I use to "seed" the random number generator. Otherwise the numbers won't be so random.
number=(rand()%6)+1;
this picks a random number 1-6. (0-5 until you get to the +1).
|
|
|
|
|
Would anybody like to help me to produce a random number for my C++ guessing game?
|
|
|
|
|
I wrote a DLL in C++ that I am testing by calling it from VB. the dll works and does what it's supposed to do, but when I end the running vb demo, I get a heap memory error. any idea what's up?
thank you.
If it's broken, I probably did it
bdiamond
|
|
|
|
|
The DLL is not cleaning up after its' self. Or the demo program is not calling the functions in the DLL that are reasponsible for cleaning up.
INTP
|
|
|
|
|
there is only one function in the dll, so it must be me not cleaning up after myself. Can you give me any hints on how to go about doing this?
If it's broken, I probably did it
bdiamond
|
|
|
|