Continue yesterday's work! Start thinking that you can't make the picture in your own size in Bitblt ()! I am fainting! Today, I have to open the continued study of the book you have read! Reconme you again!
Void cBitmapView :: wtj_paint () {? CDC * PDC;? PDC = getdc () ;? cbitmap wtj_bitmap;? CDC DCMEMORY; / /? CDC * PDC;? WTJ_bitmap.LoadBitmap (idb_bitmap1) ;? Bitmap bminfo;? Wtj_bitmap. GetObject (sizeof (bmInfo), & bmInfo) ;? dcMemory.CreateCompatibleDC (pDC) ;? dcMemory.SelectObject (& wtj_bitmap) ;? pDC-> BitBlt (100,100, ?? bmInfo.bmWidth, ?? bmInfo.bmHeight, ?? & dcMemory, 0, 0, SRCCOPY);? ReleaseDC (PDC);} I still don't understand why the wtj_bitmap.getObject () function can be used, it can be said to use the wtj_bitmap information Copy to Bminfo. I was still thinking about yesterday, how can I take the length and wide information of the bitmap! Oh, solved!
Simplely remember how to display a bitmap:
1. Declare a CBITMAP object and add a picture from the resource.
2. Create a compatible DC, use the CDC's member function CreateCompatibleDC.
3. Select the bitmap into the compatible DC with the member function SelectObject of the CDC.
4. Output bitmaps with CDC's member function Bitblt.
Just, a complete bittap said it!
/
The following changes can make the bitmap all displayed in the window, automatically stretch!
Void cBitmapView :: wtj_paint () {? cdc * pdc;? crect Rect;? getWindowRect (Rect); //? getClientRect (Rect) ;? pdc = getdc () ;? cbitmap wtj_bitmap;? cdc dcmemory; //? CDC DcMemory; //? CDC * pDC;? wtj_bitmap.LoadBitmap (IDB_BITMAP1) ;? BITMAP bmInfo;? wtj_bitmap.GetObject (sizeof (bmInfo), & bmInfo) ;? dcMemory.CreateCompatibleDC (pDC) ;? dcMemory.SelectObject (& wtj_bitmap) ;? pDC-> StretchBlt ( 0, 0, ?? Rect.width (), Rect.height (), ?? & DCMemory, ?? 0, 0, ?? bminfo.bmwidth, bminfo.bmheight, ?? srccopy; //? PDC -> / *? PDC-> Bitblt (100, 100, ?? bminfo.bmwidth, ?? Bminfo.Bmheight, ?? & Dcmemory, 0, 0, srccopy; * / releasedc (pdc);
Among them, the red part, the book is very clear, one is to obtain the window customer area, one is to obtain the window activity area! What is the difference between the two? Not reflected in the actual application!
** Little a little problem, I see the instructions on the book, display the bitmap in Windows, which is related to the hardware of the computer, because different displays, different display cards have different results, more headache may be There will be some problems on the printer! I hope that I will summarize myself in the future, and I also refer to some examples of successful people! On some of MFC, technology is more mature! How to open a BMP file?
Let's improve this break code:
Void cBitmapView :: wtj_paint () {? cdc * pdc;? crect Rect;? getWindowRect (Rect); //? getClientRect (Rect) ;? pdc = getdc () ;? cbitmap wtj_bitmap;? cdc dcmemory; //? CDC DcMemory; //? CDC * PDC;
//?wtj_bitmap.loadbitmap (IDB_bitmap1);
? HBITMAP hbitmap = (HBITMAP) LoadImage (NULL, ?? m_bmPath, ?? IMAGE_BITMAP, ?? 0,0, ?? LR_LOADFROMFILE) ;? wtj_bitmap.Attach (hbitmap) ;? BITMAP bmInfo;? Wtj_bitmap.GetObject (sizeof (bmInfo ), & bminfo); DCMemory.createCompatibleDC (PDC); DCMemory.selectObject (& wtj_bitmap) ;? PDC-> StretchBLT (0, 0, ?? Rect.width (), Rect.Height (), ?? & Dcmemory,? ? 0, 0, ?? bminfo.bmwidth, bminfo.bmheight, ?? srcopy); //? Pdc -> / *? PDC-> Bitblt (100, 100, ?? bminfo.bmwidth, ?? bminfo.bmheight, ?? & DCMEMORY, 0, 0, SRCCOPY; * /? ReleaseDC (PDC); Some is just a member function of a ctoolbarctrlctoolbarctrl class!
Finally found:
The loadImage function loads an icon, cursor, or bitmap.
Handle LoadImage
Hinstance Hinst, // Handle of The Instance Containing the Image
LPCTSTR LPSZNAME, // Name or Identifier of Image
Uint utype, // type of image
INT cxdesired, // desired width
INT Cydesired, // Desired Height
Uint fuload // load flags
);
What will I do if I am loaded? IF (hbitmap) {...} else {...} may be useful! If the function succeeds, the return value is the handle of the newly loaded image.if The function fails, the return value is null. To get extended error Information, Call getLastError.
Ok, let's continue tomorrow!