|
Note that I stated "If you have an HBITMAP (a DDB or a DIBSection)..." you
could use that code. You are using a DIB.
dipen.rana wrote: here it attaches hBitmap but wat file it saves a test.bmp is it the hBitmap file dat it saves as test.bmp?
// Create uninitialized DIB bitmap.
//.................................
hBitmap = CreateDIBitmap( hDC,
&bi,
0,
0,
(LPBITMAPINFO) lpbi,
DIB_RGB_COLORS);
CImage image;
image.Attach(hBitmap);
image.Save("c:\\test.bmp"); // save as BMP
image.Detach();
Here you're creating a DDB from a DIB and then attaching it to a CImage object to save it.
I'm not sure the creation is succeeding though. Is hBitmap NULL?
This might be a good case to use a DIBsection instead of a DIB since you need both an HBITMAP
and direct access to the pixel bits. Something like this (changes I made to your code are
in red):
void Create_DIB( HWND hWnd )
{
HDC hDC;
unsigned char i;
long k,j, NumBytes;
LPBITMAPINFO info;
unsigned char *dat;
DWORD error;
hDC = GetDC (hWnd) ;
bi.biSize = sizeof (BITMAPINFOHEADER) ;
bi.biWidth = W;
bi.biHeight = -H;
bi.biPlanes = 1;
bi.biBitCount = COLORBITS;
bi.biCompression = BI_RGB;
bi.biSizeImage = ( ALIGNLONG( (W * COLORBITS)/8 ) * H);
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 256;
bi.biClrImportant = 256;
<code>
NumBytes = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);</code>
lpbi = (BITMAPINFOHEADER*)GlobalAlloc( GPTR, NumBytes );
if( lpbi == NULL )
{
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
exit( EXIT_FAILURE );
}
*lpbi = bi;
info = (LPBITMAPINFO) lpbi;
for ( i=0; i<255; i++ )
{
info->bmiColors[i].rgbRed = i;
info->bmiColors[i].rgbBlue = i;
info->bmiColors[i].rgbGreen = i;
info->bmiColors[i].rgbReserved = 0;
}
<code>
hBitmap = ::CreateDIBSection(hDC, (LPBITMAPINFO) lpbi, DIB_RGB_COLORS, (VOID **)&lpstBitmap, NULL, 0);</code>
dat = (unsigned char*)lpstBitmap;
<code>
for ( k=0; k< H; k++ )
for ( j = 0; j < W; j++ )
*dat++ = (unsigned char)k;
<code>
CImage image;
image.Attach(hBitmap);
image.Save("c:\\test.bmp");
image.Detach();
error = GetLastError();
ReleaseDC( hWnd, hDC);
}
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Hi Mark
I am now able to get it run as required also able to save multiple images thankz a lot for all ur help
Dipen
|
|
|
|
|
I've found a few articles mentioning 64-bit programming in C++, however, none of them focus explicitly on how to properly design a 64-bit program to take advantage of the performance benefits, aside from compiler and keyword optimizations.
Microsoft 64-bit Game Programming Article
Apple OSX 64-bit Programming Article
Microsoft 64-bit Basics Article
I remember back in the day, when 64-bit was a pretty new thing, there were benchmarks flung around (primarily math-intensive and computational), that demonstrated performance could scale up to twice the performance when compared to the 32-bit version. Does anyone know of any good articles that specifically discuss this?
|
|
|
|
|
If I use the 'OpenURL' function of a CInternetSession
lets say to open 'www.codeproject.com'.
Is the request logged on the server logs at Codeproject?
If so, what info does it show?
Thanks,
Roy
|
|
|
|
|
Even though I have windows.h included in my project, I can't seem to get this macro working. It is not in the same file as LOWORD() and HIWORD() either. Does anyone know where this might be?
Searching the web gives me the alternative of using (int)(short)LOWORD(lParam), which, from personal testing, seems to be the same as GET_X_LPARAM, however, I'd still be interested in knowing why I'm missing this macro, regardless.
|
|
|
|
|
windowsX.h
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
on VS 2003 .NET
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I've never heard of this file before... everything in the MSDN docs tells you to use windows.h, but windowsX.h?
Interesting... thanks.
|
|
|
|
|
I'm just the messenger
Only two non-MFC files include windowsX.h - dshow.h and MqMail.h
I just checked the PSDK 2003 R2 - same there as well!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi,
I want to use Visual Studio 2005 to stat developing in c++ again, I saw that I can create mfc apps, but was wondering how do I add a refrence so that I can use iostream.h?
I general how and where do I link to the stdard header files?
Thanks
Michael
Thanks,
Michael Wassermann
m12 Systems
|
|
|
|
|
#include <iostream>
That's all you have to do. Whatever libraries you need for standard libraries like that one will be automatically linked in any Visual Studio 2005 project.
|
|
|
|
|
You may find namespaces new (or new namespaces)
iostream stuff will be in the std namespace. If you don't want to explicitly resolve the
namespace everywhere (with the scope resolution operator) then you can add this to your
source (CPP! ) files:
using namespace std;
Mark
-- modified at 20:02 Wednesday 20th June, 2007
*edited in red*
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: using namespace std;
This construct should be avoided at global scope in header files however. If you do put one in at global scope in a header file then anyone that includes your header loses some control over the namespace composition and it may make it hard from them to resolve name clashes – which is what namespaces were designed to solve.
Steve
|
|
|
|
|
Stephen Hewitt wrote: This construct should be avoided at global scope in header files however
Ack! That's what I meant - I could have sworn I put "(CPP)" in there to qualify it - that was
another post
Thanks for the reminder and heads-up Steve!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I write an ActiveX control,it is tested ok with test container in either debug or release mode,but when i use it in my project, the release one can run,but the debug one can not,I don`t know why.If you can help me,please leave your email,I will send the code to you so you can test it,thanks!
|
|
|
|
|
Your project may be built on release mode
|| ART OF LIVING ||
|
|
|
|
|
Thank U,but my project is on debug mode,the release control can use,but the debug one can not
|
|
|
|
|
kingliub wrote: but the debug one can not
Right, and ?? What is the problem ? You get a crash, a compilation error, a blue cow coming out of your screen, ... ?
Please, be more specific and explain what the problem is.
|
|
|
|
|
Cedric Moonen wrote: a blue cow coming out of your screen, ...
He's gonna need a bigger debugger!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you,the problem is: when I use the debug one in my project,an error_dialog comes out the moment I change the property`s value,on the dialog:
Debug Assertion Failed!
Program:...\MSDev98\bin\MSDEV.EXE
File:afxwin2.inl
Line:171
For information...
then is three buttons: stop retry ignore
but the release one is ok.
|
|
|
|
|
My email Id is shivditya@yahoo.co.in
Let me tell you thing which I am not sure.
You can not use ActiveX controls developed in debug mode.
Because it is not possible to debug activex control.
It is possible to have debug dll but not debug activex control.
Any way you can send I will try to resolve.
|| ART OF LIVING ||
|
|
|
|
|
Hi
Has anyone ever tried to implement xp theme for menu?
I am getting good results with all class types exept MENU.
OpenThemeData(hWnd, "MENU");
Am not able to get a handle to the MENU theme.
Any commends would be of great help.
Regards
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
I am building application as secondary identification server for ATMs.
My application is fine. But just for pictorial representation I want to show
ATM line on dialog who alls thread is currently active. I am planning to
show on dialog it self. (Or I have to develop separate ActiveX for doing so,please suggest)
while showing on dialog , I am not getting crash of GetWindowRect and device context
of dialog window may not proper.It crashes at ::GetWindowRect Of groupbox in which I was planning to show the running threads.
I am not sure why crash is occuring. I am not sure devicecontext I can obtain.
|| ART OF LIVING ||
|
|
|
|
|
Why wouldn't you use a custom window for that?
|
|
|
|
|
Custom window means what exactly you want to suggest.
|| ART OF LIVING ||
|
|
|
|
|
shivditya wrote: I am not getting device context
of dialog window properly
You can draw on the dialog just like any other window.
GetDC() gets a DC to the client area of the window
GetWindowDC() gets a DC to the entire window
If you draw in response to WM_PAINT, BeginPaint()/EndPaint() can be used to acquuire a DC
or you can use the above APIs and handle the invalid region yourself.
If you draw in response to WM_ERASEBKGND, a DC is provided.
There's no threadsafe GDI - all drawing must be synchronized (and flushed) if you're using
multiple threads for drawing.
shivditya wrote: and it crashes at ::GetWindowRect Of groupbox
Crashes how and why?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|