Advertisement

TransparentBlt() Win32 Function Help

Started by December 12, 2005 10:32 PM
4 comments, last by furinto 18 years, 9 months ago
I'm trying to use the TransparentBlt() function to create a transparent color in a bitmap of my game, but i'm having some trouble. The book i'm reading says that I need to make sure my compiler is linked to a library file called msimg32.lib. The book offers instructions on how to do this linking with VCpp, but I use Dev-Cpp (why in a minute) and I can't quite seem to figure it out. This is the portion of the code giving me trouble:

    if (bTrans)
      TransparentBlt(hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0, GetWidth(), GetHeight(), crTransColor);
    else
      BitBlt(hDC, x, y, GetWidth(), GetHeight(), hMemDC, 0, 0, SRCCOPY);
And this is the error:
Bitmap.cpp:225: error: `TransparentBlt' undeclared (first use this function) Bitmap.cpp:225: error: (Each undeclared identifier is reported only once for each function it appears in.) make.exe: *** [Bitmap.o] Error 1 Execution terminated
Just in case, if anybody else has read the same book to offer better advice, the book is SAMS Teach Yourself Game Programming in 24 Hours. I don't really care what your opinion on the book is - but this code is from Hour 6, and the program is the first UFO program dealing with mouse and keyboard input. I have tried opening the project with VCpp but that ends up being a lot worse. Even though i'm able to follow the book's instructions and include the proper .lib file, I get a ton more compiler erros - things about not being able to open winnt.h and bad pragmas and such. It's really terrible. FYI, It's VCpp Express 2005.
Did you forget to include windows.h by any chance ?

The horrible error in VC++ Express 2005 came from either or both of those:

a) You don't have the Windows Platform SDK installed
b) The book uses non-standard C++.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
Advertisement
windows.h is included in Bitmap.h, which is included in the .cpp file I pasted the error from.

I've got the SDK installed.

The book's C++ is fine.

I can run the example program from the .exe on the book's CD without a hitch - but trying to compile and run the program from the provided source files just doesn't work.

Here is the entire log with Dev-C++:
Compiler: Default compilerBuilding Makefile: "C:\Documents and Settings\Owner\My Documents\Code\UFO\Makefile.win"Executing  make...make.exe -f "C:\Documents and Settings\Owner\My Documents\Code\UFO\Makefile.win" allg++.exe -c Bitmap.cpp -o Bitmap.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"  -I"C:/Dev-Cpp/include/allegro"   Bitmap.cpp: In member function `void Bitmap::Draw(HDC__*, int, int, BOOL, COLORREF)':Bitmap.cpp:225: error: `TransparentBlt' undeclared (first use this function)Bitmap.cpp:225: error: (Each undeclared identifier is reported only once for each function it appears in.)make.exe: *** [Bitmap.o] Error 1Execution terminated


Now here is the entire error log with the same project on VC++ Express 2005:
1>------ Build started: Project: UFO, Configuration: Debug Win32 ------1>Compiling...1>Bitmap.cpp1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3043) : warning C4103: 'c:\program files\microsoft visual studio 8\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3335) : warning C4103: 'c:\program files\microsoft visual studio 8\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3435) : warning C4068: unknown pragma1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3440) : warning C4068: unknown pragma1>c:\program files\microsoft visual studio 8\vc\include\windows.h(49) : fatal error C1083: Cannot open include file: 'wincon.h': No such file or directory1>GameEngine.cpp1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3043) : warning C4103: 'c:\program files\microsoft visual studio 8\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3335) : warning C4103: 'c:\program files\microsoft visual studio 8\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3435) : warning C4068: unknown pragma1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3440) : warning C4068: unknown pragma1>c:\program files\microsoft visual studio 8\vc\include\windows.h(49) : fatal error C1083: Cannot open include file: 'wincon.h': No such file or directory1>UFO.cpp1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3043) : warning C4103: 'c:\program files\microsoft visual studio 8\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3335) : warning C4103: 'c:\program files\microsoft visual studio 8\vc\include\winnt.h' : alignment changed after including header, may be due to missing #pragma pack(pop)1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3435) : warning C4068: unknown pragma1>c:\program files\microsoft visual studio 8\vc\include\winnt.h(3440) : warning C4068: unknown pragma1>c:\program files\microsoft visual studio 8\vc\include\windows.h(49) : fatal error C1083: Cannot open include file: 'wincon.h': No such file or directory1>Generating Code...1>Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Code\UFO\Debug\BuildLog.htm"1>UFO - 3 error(s), 12 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Well, it can't find the function and MSDN says it's defined in windows.h. So either you aren't including it, or your windows.h is borked. Try including wingdi.h, just to be sure.

The pragmas 'errors' are actually warning, which means that the book's C++ ISN'T fine. Especially if you consider that #pragma is compiler specific, and that pragma directive aren't guaranteed to be implemented in the same way on all compilers.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
You need to link some lib.(msimg32.lib?)
In vc, I use #pragma comment(lib, "somelib").

Hope this help.
I hope this doesn't count as spam, but I discovered the solution to my problem, and i'm just here now to share it in case anybody else has the same problem in the future. :D


Apparently, there was a discrepency between the code of the book and my compiler version... or something like that. Anyway, all I had to do was go into Dev-Cpp's include folder and open up windows.h. From there, I simply had to add the following code right after the first little chunk of codes that ends with #endif:

#ifndef WINVER
#define WINVER 0x0501
#else
#if defined(_WIN32_WINNT) && (WINVER 0x0400)
#error WINVER setting conflicts with _WIN32_WINNT setting
#endif
#endif

Voila, I was able to compile perfectly with Dev-cpp, with no need to hastle with the (IMO) inferior VC++. :P

This topic is closed to new replies.

Advertisement