BITMAP.C
资源名称:MSDN_VC98.zip [点击查看]
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:6k
源码类别:
Windows编程
开发平台:
Visual C++
- /******************************************************************************
- * This is a part of the Microsoft Source Code Samples.
- * Copyright (C) 1992-1997 Microsoft Corporation.
- * All rights reserved.
- * This source code is only intended as a supplement to
- * Microsoft Development Tools and/or WinHelp documentation.
- * See these sources for detailed information regarding the
- * Microsoft samples programs.
- ******************************************************************************/
- /**************************************************************************
- * bitmap.c -- support for reading in and drawing bitmaps.
- **************************************************************************/
- #include <windows.h>
- #include <commdlg.h>
- #include "plgblt.h"
- /**************************************************************************
- *
- * function: DrawBitmap()
- *
- * input parameters: HDC, HBITMAP
- *
- * Draw the bitmap into the hdc. Source rectangle computed to include the
- * whole bitmap. Destination location is 0,0.
- *
- * global variables: none.
- *
- **************************************************************************/
- VOID DrawBitmap (HDC hdc, HBITMAP hbm)
- {
- BOOL f;
- HDC hdcBits;
- BITMAP bm;
- hdcBits = CreateCompatibleDC(hdc);
- GetObject (hbm, sizeof(BITMAP), &bm);
- SelectObject(hdcBits,hbm);
- f = BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
- DeleteDC(hdcBits);
- }
- /**************************************************************************
- *
- * function: GetBitmap()
- *
- * input parameters:
- * hdc - hdc to make the bitmap compatible with.
- * hInst - instance handle
- *
- * Put up a common dialog box to open a new *.BMP file.
- * Once this is complete, open the file, read in the information,
- * and create a compatible bitmap.
- *
- * returns: handle to the bitmap iff successful. NULL otherwise.
- *
- **************************************************************************/
- HBITMAP GetBitmap (HDC hdc, HANDLE hInst, BOOL monochrome)
- {
- HBITMAP hbm;
- PBITMAPFILEHEADER pbmfh;
- PBITMAPINFOHEADER pbmih;
- PBYTE pBits;
- int fh;
- int bfOffBits;
- int nbytes;
- OPENFILENAME of;
- char buffer [MAX_PATH];
- buffer[0] = 0;
- /* set up the OPENFILE structure,
- * then use the appropriate common dialog
- */
- of.lStructSize = sizeof (OPENFILENAME);
- of.hwndOwner = NULL;
- of.hInstance = hInst;
- of.lpstrCustomFilter = NULL;
- of.nMaxCustFilter = 0;
- of.nFilterIndex = 0;
- of.lpstrFile = buffer;
- of.nMaxFile = MAX_PATH;
- of.lpstrFileTitle = NULL;
- of.nMaxFileTitle = 0;
- of.lpstrInitialDir = "c:\nt\windows";
- of.lpstrTitle = NULL;
- of.Flags = OFN_HIDEREADONLY;
- of.nFileOffset = 0;
- of.nFileExtension = 0;
- of.lpstrDefExt = NULL;
- of.lCustData = 0;
- of.lpfnHook = NULL;
- of.lpTemplateName = NULL;
- if (PRIMARYLANGID(GetUserDefaultLangID ()) == LANG_JAPANESE)
- of.lpstrFilter = "宿