|
yes,it changes a lot,but what do you want to do?
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
Or you could just use:
#pragma comment(lib, "somelibfile.lib");
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
sorry,I don't get you,
you want to add or ignore any library?
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
It's how you can link a library from code...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi,
I need to make the background color of a bitmap in my dialog transparent, but I do not want to use MFC. I would like to make my dialog totally MFC (/ATL) independant. Does anyone have a clue on how to do this?
|
|
|
|
|
If you go to www.wdj.com and look at their online article fro Sept 2001, it is on how to do transparent blitting with a colour key. The code in the article is full of memory leaks ( they ran an earlier version to the one I finally submitted ), but the code in the online archive should be OK, unless they ran the correction in the code for the issue they ran it, which was Nov or Dec from memory.
If you don't need Windows 95 support, just use TransparentBlt. I believe you'll need the SDK to do that though.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian,
Thanks for your reply. I downloaded the source, and extracted the method I need. But it's not exactly clear to me how this mehod works. (I have never worked with GUI stuff before). Is this the correct code, without memory leaks? Your example copies a piece of the source bitmap and places it back on another location (?) How would I just make the source bitmap transparent?
The method:
bool TransparentBltU(
HDC dcDest, // handle to Dest 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 nHeightDest, // height of destination rectangle
HDC dcSrc, // 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
)
{
if (nWidthDest < 1) return false;
if (nWidthSrc < 1) return false;
if (nHeightDest < 1) return false;
if (nHeightSrc < 1) return false;
HDC dc = CreateCompatibleDC(NULL);
HBITMAP bitmap = CreateBitmap(nWidthSrc, nHeightSrc, 1, GetDeviceCaps(dc, BITSPIXEL), NULL);
if (bitmap == NULL)
return false;
HBITMAP oldBitmap = (HBITMAP)SelectObject(dc, bitmap);
if (!BitBlt(dc, 0, 0, nWidthSrc, nHeightSrc, dcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY))
return false;
HDC maskDC = CreateCompatibleDC(NULL);
HBITMAP maskBitmap = CreateBitmap(nWidthSrc, nHeightSrc, 1, 1, NULL);
if (maskBitmap == NULL)
return false;
HBITMAP oldMask = (HBITMAP)SelectObject(maskDC, maskBitmap);
SetBkColor(maskDC, RGB(0,0,0));
SetTextColor(maskDC, RGB(255,255,255));
if (!BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,NULL,0,0,BLACKNESS))
return false;
SetBkColor(dc, crTransparent);
BitBlt(maskDC, 0,0,nWidthSrc,nHeightSrc,dc,0,0,SRCINVERT);
SetBkColor(dc, RGB(0,0,0));
SetTextColor(dc, RGB(255,255,255));
BitBlt(dc, 0,0,nWidthSrc,nHeightSrc,maskDC,0,0,SRCAND);
HDC newMaskDC = CreateCompatibleDC(NULL);
HBITMAP newMask;
newMask = CreateBitmap(nWidthDest, nHeightDest, 1, GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);
if (newMask == NULL)
{
SelectObject(dc, oldBitmap);
DeleteDC(dc);
SelectObject(maskDC, oldMask);
DeleteDC(maskDC);
DeleteDC(newMaskDC);
return false;
}
SetStretchBltMode(newMaskDC, COLORONCOLOR);
HBITMAP oldNewMask = (HBITMAP) SelectObject(newMaskDC, newMask);
StretchBlt(newMaskDC, 0, 0, nWidthDest, nHeightDest, maskDC, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);
SelectObject(maskDC, oldMask);
DeleteDC(maskDC);
HDC newImageDC = CreateCompatibleDC(NULL);
HBITMAP newImage = CreateBitmap(nWidthDest, nHeightDest, 1, GetDeviceCaps(newMaskDC, BITSPIXEL), NULL);
if (newImage == NULL)
{
SelectObject(dc, oldBitmap);
DeleteDC(dc);
DeleteDC(newMaskDC);
return false;
}
HBITMAP oldNewImage = (HBITMAP)SelectObject(newImageDC, newImage);
StretchBlt(newImageDC, 0, 0, nWidthDest, nHeightDest, dc, 0, 0, nWidthSrc, nHeightSrc, SRCCOPY);
SelectObject(dc, oldBitmap);
DeleteDC(dc);
BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, newMaskDC,
0, 0, SRCAND);
BitBlt( dcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, newImageDC,
0, 0, SRCPAINT);
SelectObject(newImageDC, oldNewImage);
DeleteDC(newImageDC);
SelectObject(newMaskDC, oldNewMask);
DeleteDC(newMaskDC);
return true;
}
|
|
|
|
|
It works because it generates a mask and uses it to do a blt that removes the transparent colour. It does a portion to be flexible.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Ok, I still do not know how to do this. If I enter the dc of my dialog image as source and destination nothing happens. What am I doing wrong?
|
|
|
|
|
The source DC contains the image to draw, the destination is where it is drawn. Just like BitBlt.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I figured that out. But what I cannot figure out is how to actually modify the image in my dialog box. I tried to figure out the code but I just do not understand how this HDC stuff works (I don't have a good book and msdn isn't really helpfull). I tried something like this (transparent color = white):
HBITMAP hbmImg = (HBITMAP)LoadImage(g_hinst, MAKEINTRESOURCE(IDB_LOGO), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE );
if( hbmImg )
{
BITMAP bmInfo;
memset( &bmInfo, 0, sizeof BITMAP );
GetObject(hbmImg, sizeof BITMAP, &bmInfo);
HDC hdc = CreateCompatibleDC(NULL);
SelectObject(hdc, hbmImg);
TransparentBltU(hdc, 0,0, bmInfo.bmWidth,
bmInfo.bmHeight,hdc,0,0, bmInfo.bmWidth,
bmInfo.bmHeight, RGB(255,255,255));
}
|
|
|
|
|
I have a char vector allocated on the heap and want to test if one of the elements is equal with "\\" (simple \, but doen't I need to write \\ to tell the compiler that I mean a \, if you understand).
this is the if-statement...
if( localPath[i] == "\\" )
{
...
}
that gives me this error:
--------------------Configuration: Drag Hit - Win32 Release--------------------
Compiling...
source.cpp
C:\Program\Microsoft Visual Studio\MyProjects\Drag Hit\source.cpp(41) : error C2446: '==' : no conversion from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Program\Microsoft Visual Studio\MyProjects\Drag Hit\source.cpp(41) : error C2040: '==' : 'int' differs in levels of indirection from 'char [2]'
Error executing cl.exe.
Drag Hit.exe - 2 error(s), 0 warning(s)
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
When you use the double quotes, I believe a NULL terminator is added to your string. Use single quotes when checking an individual character.
if( localPath[i] == '\\' )
Have I been evicted from your sig already ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Then my app crashes...
Christian Graus wrote:
Have I been evicted from your sig already ?
Well, it didn't work with my HTML tags when I posted some messages... :/
weird... so I change it back.. but I realy want it to work!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Rickard Andersson wrote:
Then my app crashes...
Well, that's the right way to do it. Why does it crash ?
Rickard Andersson wrote:
but I realy want it to work!
Me too - I enjoy my fleeting moments of fame when they come...
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
here is the code (it's not complete):
int GetFileName(char cPath, char* pFileName)
{
if(cPath == NULL)
{
::MessageBox(NULL,"cPath = NULL","Error",MB_OK);
return -1; // return error }
int len = strlen((char*)cPath);
char* localPath = new char[len];
strcpy(localPath,(char*)cPath);
int chars = 0;
for(int i=len; i>len; i--);
{
chars++;
if(localPath[i] == '\\')
{
char* filename = new char[chars+1];
i++;
for(int j=0; j<chars+1; j++)
{
strncpy(filename+j,(char*)localPath[j],1);
}
::MessageBox(NULL, filename,"filename",MB_OK);
delete [] filename;
}
}
delete [] localPath;
return 0;
}
------------------------------------
<b><I><B>Rickard Andersson</I></B></b>, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
I mean that the function is not complete!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
It's a global function ? I don't know what you're trying to do, I presume you're trying to get the different parts of the filepath, i.e. seperate c:\my documents\my code\project1 into
c:\
my documents
my code
project1 ?
casting a char to a char * is not going to work, you need instead to do this
int len = strlen(&cPath);
This returns the address of the variable, (char*)cPath takes the value of cPath and assumes it is the address of a char array.
Overall, unless this is for an assignment, this is an ugly way of doing things. If you're not using MFC, your code would be a lot prettier if you use std::string. If you are using MFC, CString is another alternative.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I just realised something else that should have been screamingly obvious to me - cPath is a deep copy of one char, it no longer points to the char array that it did in the calling function. You need to pass it in as a char* if you want access to the entire string instead of a copy of the one character.
It's late - I'm going to bed
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
cPath needs to be a pointer
declare your function like this:
int GetFileName(const char* cPath, char* pFileName);
OR
int GetFileName(LPCSTR cPath, LPSTR pFileName)
By the way, pFileName was never used in your function
- Dirty hands lead to important discovery...
|
|
|
|
|
I tried it and it seems to work..
char* tst = "hkjsdh\\ks\\dj\\sdsdsd\\sfssf\\sfsfs";
for (int i=0; tst[i]; i++)
{
if (tst[i] == '\\')
printf("[backslash]");
else
printf("%c", tst[i]);
}
I suppose the bug is somewhere else in your program?
/moliate
|
|
|
|
|
Okay man, now I'm realy stucked...
Let's say that I have a path to a file: "C:\Program\MyApp\tehexe.exe"
My function's (GetFileName(...)) main thing is to return the file name (theexe.exe) from that path.
But can't get it to work!
You have the code for that function in some of my messages here... help me with it!!!!!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Try this code out :-
char *p=abc;
while(strchr(p,'\\'))
{
p=strchr(p,'\\');
p++;
}
MessageBox(p);
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Are you required to write this yourself? If not, then use PathFindFileName() in shlwapi.dll. Otherwise, use strrchr() to find the last backslash.
char* pLastBkslash = strrchr ( szPathName, '\\' );
char* pFilename;
if ( NULL != pLastBkslash )
pFilename = pLastBkslash + 1;
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
Michael Dunn wrote:
char* pLastBkslash = strrchr ( szPathName, '\\' );
That assumes that there is only one slash???
Or did it implicitly imply that the guy has to repeat that till he gets the last backslash?
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|