Drawing HBITMAP into CWnd, Acquired from "screenshot"

This is a discussion on Drawing HBITMAP into CWnd, Acquired from "screenshot" within the Windows Programming forums, part of the Platform Specific Boards category; Hello everyone,
So I have my own "simpleBitmap" class which I use to acquire screenshots, and in turn I to ...

Drawing HBITMAP into CWnd, Acquired from "screenshot"

Hello everyone,

So I have my own "simpleBitmap" class which I use to acquire screenshots, and in turn I to a lot of low level manipulation of the pixels (the reason for making a class). Now I know my "screenshots" are working fine, I can save them to file, I can analyze individual pixels etc.

Now I want to be able to draw these simpleBitmap objects into a CWnd, however I want my class to remain MFC independant. Following is the code used to acquire the screenshot.

Now the member variables hMemDC, and hBmp are stored within the class. Here is my... attempt at drawing to a window. Note however that this custom CWnd class is drawn onto a dialog, I know the class is capable of drawing succesfully (I have used simple CDC drawing stuff like coloring the background white).

Sorry for the large amount of code, just trying to be complete in my question. So of course the question is... what would be the appropriate way to draw an HBITMAP/HDC acquired in the above manner to a simple CWnd class. I have looked around a lot, but there seem to be a huge number of combinations to draw Bitmaps, none of which have worked for me yet.

CDC::FromHandle in winapi

I am trying to convert all my mfc codes to my own class (pure winapi). Since MFC is actually wrapping around the WinAPI. But I am having problem with CDC::FromHandle, there is no equivalent in WinAPI. I know, I can replace any call CDC::FromHandle and directly get the DC from ::GetDC, but it means I have to change all my code as well. Is there any way to replace CDC::FromHandle with pure WinAPI ? or any clue ?

I am trying to convert all my mfc codes to my own class (pure winapi). Since MFC is actually wrapping around the WinAPI. But I am having problem with CDC::FromHandle, there is no equivalent in WinAPI. I know, I can replace any call CDC::FromHandle and directly get the DC from ::GetDC, but it means I have to change all my code as well. Is there any way to replace CDC::FromHandle with pure WinAPI ? or any clue ?

thx

Please start your own thread, not necro others (which is against the forum rules)....

What EXACTLY are you trying to do?

BitBlt()? just use the HDC.
Change GDI objects? use SelectObject(), catching the released GDI object so you can clean up correctly.

Without details it is hard to give a meaningful response.

You appear to want to know how to construct a CDC (an MFC object) in pure WIN32, which is impossible.

CDC::FromHandle(HDC ) takes a WIN32 handle to a DC (a HDC) and returns a pointer to an MFC class CDC, initialised with that DC. You can't use a CDC in pure WIN32.

Please start your own thread, not necro others (which is against the forum rules)....

Well, because I see the comment above me about CDC::FromHandle. Sorry if it is misplaced.

You appear to want to know how to construct a CDC (an MFC object) in pure WIN32, which is impossible.

We have managed already all dialog based and its derived common controls (CWnd and its derived), and we are doing CDC, but got stuck with CDC::FromHandle. I believe there is nothing impossible in here

CDC::FromHandle(HDC ) takes a WIN32 handle to a DC (a HDC) and returns a pointer to an MFC class CDC, initialised with that DC. You can't use a CDC in pure WIN32.

This is what I am guessing. CDC::FromHandle is static, and it accept only HDC as input, so it means MFC somehow have all attach HDCs in a global array or link list (so it can search from static function). MSDN said if the HDC is not attach when calling CDC::FromHandle, then it will attach to it. If i can know where MS start attaching HDC to MFC and put it in MFC object or when the array been created, then I can do similarity for it, and I can handle CDC::FromHandle (Like dialog based CWnd, we assume MFC has to store HWND somewhere in an array during the class initialization and enum all the childs so that all control child members variable can be attached to the right HWND).

Well you are probably right, it is not the right thread. again my apology for it (I just doesnt want to duplicate theread), and I will not attempt to reply this thread again, if u need to comment this post just pm me ). thx