|
Sorry, actually the code above is working, but if i use std::hash_set instead of std::set , it does not work. I am writing code below:
using namespace std;
int main(int argc, char* argv[])
{
string name = "india";
hash_set<string> val;
val.insert(name);
return 0;
}
The error i am getting is:
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xhash(38): error C2440: 'type cast' : cannot convert from 'const std::string' to 'size_t'
Yes i am including all the required headers.
|
|
|
|
|
how to add entry to personnel address book programatically
|
|
|
|
|
Hello,
I'm using following function :
-----------------------------------------------------------------------
void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, int xStart,
int yStart, COLORREF cTransparentColor)
{
BITMAP bm;
COLORREF cColor;
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;
POINT ptSize;
hdcTemp = CreateCompatibleDC(hdc);
SelectObject(hdcTemp, hBitmap); // Select the bitmap
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth; // Get width of bitmap
ptSize.y = bm.bmHeight; // Get height of bitmap
DPtoLP(hdcTemp, &ptSize, 1); // Convert from device
// to logical points
// Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc);
hdcObject = CreateCompatibleDC(hdc);
hdcMem = CreateCompatibleDC(hdc);
hdcSave = CreateCompatibleDC(hdc);
// Create a bitmap for each DC. DCs are required for a number of
// GDI functions.
// Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
// Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);
bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);
// Each DC must select a bitmap object to store pixel data.
bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);
bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);
bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);
bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);
// Set proper mapping mode.
SetMapMode(hdcTemp, GetMapMode(hdc));
// Save the bitmap sent here, because it will be overwritten.
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);
// Set the background color of the source DC to the color.
// contained in the parts of the bitmap that should be transparent
cColor = SetBkColor(hdcTemp, cTransparentColor);
// Create the object mask for the bitmap by performing a BitBlt
// from the source bitmap to a monochrome bitmap.
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,
SRCCOPY);
// Set the background color of the source DC back to the original
// color.
SetBkColor(hdcTemp, cColor);
// Create the inverse of the object mask.
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,
NOTSRCCOPY);
// Copy the background of the main DC to the destination.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart,
SRCCOPY);
// Mask out the places where the bitmap will be placed.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);
// Mask out the transparent colored pixels on the bitmap.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);
// XOR the bitmap with the background on the destination DC.
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);
// Copy the destination to the screen.
BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0,
SRCCOPY);
// Place the original bitmap back into the bitmap sent here.
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);
// Delete the memory bitmaps.
DeleteObject(SelectObject(hdcBack, bmBackOld));
DeleteObject(SelectObject(hdcObject, bmObjectOld));
DeleteObject(SelectObject(hdcMem, bmMemOld));
DeleteObject(SelectObject(hdcSave, bmSaveOld));
// Delete the memory DCs.
DeleteDC(hdcMem);
DeleteDC(hdcBack);
DeleteDC(hdcObject);
DeleteDC(hdcSave);
DeleteDC(hdcTemp);
}
-----------------------------------------------------------------------
I use function a lot and it works perfect. Recently , by chance i finded out
there's a problem in win98 ( second edition ) when using 16 BIT COLOR.
Here's example of how i use this function :
DrawTransparentBitmap(
m_hMemDC ,
HBITMAP(pictBubble),
nBubblePosX,
nBubblePosY,
CLR_TRANSPARENT);
Here's my define of transparent color ( "clean" CYAN )
#define CLR_TRANSPARENT RGB(0,255,255)
As i said , it works everywhere except win98 ( second edition ) when using 16 BIT COLOR.
As far as i know , each loaded image produces it's own palette. In some cases , it can
cause color to be changed to nearest color and obviously , transparency won't work in this
case since above function needs transparent color to be exact down to pixel.
So , i tried to use following to work it out :
cTransparentColor = GetNearestColor( hdc , CLR_TRANSPARENT );
But , it didn't work.
Need your help ( it's pretty urgent ) , thanks !
P.S. I just prefer solution that won't force me to change everything , but a small patch
|
|
|
|
|
|
All right I'll give you this one function, since it is in my list for posseble aticles to this site. (it is only a part of of the file - the MSDN has an aticle on this suject some where, not to mention the wwww)
////////////////////////////////
// John R. Shaw (2001/03/23)
// Transparent Blit for Windows 3.x and above
//////////////////////////////////////////////////////////
BOOL TransBitBlt(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int hHeightDest, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
UINT crTransparent // color to make transparent
)
{
// Win 98 and above
if( g_TransBlt.DrawTransparent(
hdcDest, nXOriginDest, nYOriginDest, nWidthDest, hHeightDest,
hdcSrc , nXOriginSrc , nYOriginSrc , nWidthSrc , nHeightSrc, crTransparent) )
{
return TRUE;
}
// Win 3.x and above
// Note: This technique may not necessarily work on printer devices.
// Create temporary DCs
HDC hdcTemp = CreateCompatibleDC(hdcDest);
if( hdcTemp == NULL )
return FALSE;
HDC hdcMask = CreateCompatibleDC(hdcDest);
if( hdcTemp == NULL )
{
DeleteDC(hdcTemp);
return FALSE;
}
// Create temporary Bitmaps
HBITMAP hBmpMask = CreateBitmap(nWidthSrc,nHeightSrc,1,1,NULL);
if( hBmpMask == NULL )
{
DeleteDC(hdcMask);
DeleteDC(hdcTemp);
return FALSE;
}
HBITMAP hBmpTemp = CreateCompatibleBitmap(hdcDest,nWidthSrc,nHeightSrc);
if( hBmpTemp == NULL )
{
DeleteObject(hBmpTemp);
DeleteDC(hdcMask);
DeleteDC(hdcTemp);
return FALSE;
}
HGDIOBJ hOldBmpMask = SelectObject(hdcMask,HGDIOBJ(hBmpMask));
// Use temporary DC to reduce flicker
HGDIOBJ hOldBmpTemp = SelectObject(hdcTemp,HGDIOBJ(hBmpTemp));
if( BitBlt(hdcTemp,0, 0, nWidthSrc,nHeightSrc, hdcDest, nXOriginDest, nYOriginDest, SRCCOPY) )
{
// If we made it here there should be no more possible problems
// Create mask using crTransparent
COLORREF OldBkColor = SetBkColor(hdcSrc,crTransparent);
BitBlt(hdcMask,0, 0, nWidthSrc,nHeightSrc,hdcSrc, nXOriginSrc,nYOriginSrc, SRCCOPY);
SetBkColor(hdcTemp,OldBkColor);
// Draw bitmap using mask
BitBlt(hdcTemp,0, 0, nWidthSrc,nHeightSrc,hdcSrc, nXOriginSrc,nYOriginSrc, SRCINVERT);
BitBlt(hdcTemp,0, 0, nWidthSrc,nHeightSrc,hdcMask, 0, 0, SRCAND);
BitBlt(hdcTemp,0, 0, nWidthSrc,nHeightSrc,hdcSrc, nXOriginSrc,nYOriginSrc, SRCINVERT);
// Copy Temporary DC to Destination DC
BitBlt(hdcDest,nXOriginDest, nYOriginDest, nWidthDest,hHeightDest,hdcTemp, 0, 0, SRCCOPY);
}
// Clean up
SelectObject(hdcMask,hOldBmpMask);
SelectObject(hdcTemp,hOldBmpTemp);
DeleteDC(hdcMask);
DeleteDC(hdcTemp);
DeleteObject(hBmpMask);
DeleteObject(hBmpTemp);
return TRUE;
}
Trust in the code Luke. Yea right!
|
|
|
|
|
John,
Thanks , but your answer isn't answering my question. I do know how works
TransparentBlt function , i asked what's wrong in my function for drawing transparent BITMAPS.
|
|
|
|
|
|
IncrediBuild[^] is a development tool that substantially boosts C/C++ compilation speed, reducing a project's build time by up to 90%.
|
|
|
|
|
Hi Friends
I need to shutdown a PC By Code ?
I know ExitWindowsEx but can't understand all the Parameters
The Code Should be able to turn off the PC On All Windows OS.
|
|
|
|
|
BOOL ExitWindowsEx(<br />
UINT uFlags,
DWORD dwReserved
);
set uFlags to EWX_POWEROFF to turn off !!
|
|
|
|
|
I have to get the Bitmap of a HTML page,without displaying it .
The class used to load HTML is CDhtmlDialog .This is the sample code
CDhtmlDialog key;
Key.Navigate(fileName,0,NULL,NULL,NULL,0);
Key.SetWindowPos(this,rect1.left,rect1.top,rect1.Width(),rect1.Height(),SWP_SHOWWINDOW);//OK working
CDC * pDc=Key.GetDC();
HDC htmlDC=pDc->GetSafeHdc();
//create a sample image
CImage dest;
if(dest.CreateEx(118,88,24,BI_RGB,NULL,0)==FALSE)
{
AfxMessageBox("Error in extracting the Keyframe");
return FALSE;
}
HDC destDC=dest.GetDC();
SetStretchBltMode(destDC,HALFTONE);
//copy the
if(StretchBlt(destDC,0,0,118,88,htmlDC,0,0,rect1.Width(),rect1.Height(),SRCCOPY)==FALSE)
{
AfxMessageBox("Unable to Extract Key Frame");
return FALSE;
}
Now the problem with this is that the BItMap is not of the HTML page but of the application Mainframe window !!!!!!
|
|
|
|
|
Hey Friends Can someone suggest a way to get the active
FrameWindow From the Document Class in case of an MDI .
|
|
|
|
|
http://www.codeguru.com/FAQS/FAQ-A01.html
|
|
|
|
|
I want to generate an alarm on the pressing of a certain button in my MFC application. I am totally blank in it. Plz suggest me relevent apis/codes e.t.c to do the particular task.
Reply me soon
|
|
|
|
|
Hi, I tried to change the default document icon in my application but it doesn't reflect in the saved file. Does anybody help me how to do it?
|
|
|
|
|
Did you change both the 16x16 and 32x32 versions of the document icon? Depending on how you have windows explorer setup, only one of these is actually displayed.
Dave
|
|
|
|
|
I have downloaded smtp wrapper classes(infact an MGF project). The code compiles but when I send the mail an error message box appears. I am providing the right SMTP server address(IP) but connection to the server fails.
Thats where the error lies.
if( !m_wsSMTPServer.Connect( GetServerHostName(), GetPort() ) )
{
m_sError = _T( "Unable to connect to the server" );
m_wsSMTPServer.Close();
return FALSE;
}
Please suggest me what to do as I am a beginner and can't figure the errors out easily. So kindly guide me step by step or if you have any codes in working order Plz send me as I am running out of time.
__________________
Reply me soon
|
|
|
|
|
HI,
I'm sure this problem has been reach at least by one developper : in a property sheet, property pages are not initialized (the window handle is invalid) while the user don't activate it.
What is the right manner to initialize all property pages ? Cause I must read the content of all of them in order to produce a XML output and I don't want to produce an update of the modified data.
Thanks !!
|
|
|
|
|
During the OnInitDialog (or equivalent) of the propertysheet, you need to iterate through all the pages and make each one active in turn, I think SetActivePage() is what you want. You may have to add in a small message pumped delay between each SetActivePage() call so that he page can create itself properly.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
Thanks Roger,
The same idea comes to me but I wasn't sure that it was such a good idea because I think this method will produce flickering during initialization, isn't it ?
For my current project, it'es not a problem because I use multiple SDI views and the view containing property sheet isn't showed by default
Thank you agin !
|
|
|
|
|
During the constructor, modify the m_psp struct of the newly added property page in this way:
this->m_YourPropertyPageDlg.m_psp.dwFlags |= PSP_PREMATURE;
hope this helps.
|
|
|
|
|
Yeah too cool !! Exactly what I was looking for !! Thank you very much Joan !
Sincerly.
|
|
|
|
|
Could someone do me a favor and run depends.exe on windows 95 and let me know if the User32.dll has SendMessageW in it.
I have been able to check windows 98 and it has it, but I dont have a build of windows 95 installed.
I would really appreciate it.
Thank you
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
User32.dll has SendMessageW in it.
FYI: I have access to Win31/95/98/NT 4.0/2000/XP. I not sure about the millinium edition, but I have the installation CD for it.
Trust in the code Luke. Yea right!
|
|
|
|
|
;PHi to all,
MFC TREE CONTROL QUERY
I am working on CTreeCtrl with checkboxes. I donot want checkbox for parent item and at same time require check boxes for child items. Please suggest any way
My tree hierarcy is as
Parent1
Child1.1
Child1.2
Child1.3
Child1.4
Parent2
Child2.1
Child2.2
Child2.3
Child2.4
|
|
|
|
|