myHDC.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:3k
- /////////////////////////////////////////////////////////////////////////////
- //
- #include "stdafx.h"
- #include "myHDC.h"
- #include "math.h"
- myHDC::myHDC()
- {
- //采用动态连接库方式时,
- //此初始化在第二次时不调用会,最后自己初始化
- hdc=NULL;
- outhdc=NULL;
- bmpBITMAP=NULL;
- outhBMP=NULL;
- Picname[0]=0;
- IDB_S=0;
- }
- myHDC::~myHDC()
- {
- DeleteDC(hdc);
- DeleteDC(outhdc);
- DeleteObject(outhBMP);
- DeleteObject(bmpBITMAP);
- }
- //独立函数,返回为空则为装载失败
- HBITMAP myHDC::loadPic(char * myFilename)
- {
- if(!strcmp(Picname,myFilename))//相同说明已经装载,则不装并返回
- return bmpBITMAP;
- strcpy(Picname,myFilename);
- DeleteObject(bmpBITMAP); //
- bmpBITMAP=(HBITMAP)LoadImage(0, myFilename, IMAGE_BITMAP,
- 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
- if(bmpBITMAP!=NULL)
- {
- DIBSECTION ds;
- DeleteObject(SelectObject(hdc,bmpBITMAP));
- BITMAPINFOHEADER &bm = ds.dsBmih;
- GetObject(bmpBITMAP,sizeof(ds),&ds);
- LoadPicWidth = bm.biWidth;
- LoadPicHeight = bm.biHeight;
- BitBlt(outhdc,0,0,LoadPicWidth, LoadPicHeight,hdc,0,0,SRCCOPY);
- }
- else
- {
- DeleteObject(bmpBITMAP);
- //MessageBox(0,"没找到!",myFilename,0);
- return NULL;
- }
- return bmpBITMAP;
- }
- //独立函数,返回为空则为装载失败
- HBITMAP myHDC::loadPic(HINSTANCE hInstDLL,int IDB_Source)
- {
- if(IDB_S==IDB_Source)//相同说明已经装载,则不装并返回
- return bmpBITMAP;
- IDB_S=IDB_Source;
- DeleteObject(bmpBITMAP); //
- bmpBITMAP=(HBITMAP)LoadBitmap(hInstDLL,MAKEINTRESOURCE(IDB_Source));
- if(bmpBITMAP!=NULL)
- {
- DIBSECTION ds;
- DeleteObject(SelectObject(hdc,bmpBITMAP));
- BITMAPINFOHEADER &bm = ds.dsBmih;
- GetObject(bmpBITMAP,sizeof(ds),&ds);
- LoadPicWidth = ds.dsBm.bmWidth;
- LoadPicHeight = ds.dsBm.bmHeight;
-
- BitBlt(outhdc,0,0,LoadPicWidth, LoadPicHeight,hdc,0,0,SRCCOPY);
- }
- else
- {
- DeleteObject(bmpBITMAP);
- //MessageBox(0,"没找到!",myFilename,0);
- return NULL;
- }
- return bmpBITMAP;
- }
- myHDC::reSelectBAKHDC()
- {
- DeleteObject(SelectObject(hdc,bmpBITMAP));
- }
- //一般情况下本函数不会失败,本类必须在调用了此函后才能使用
- myHDC ::StartHDC(HDC pFarHDC,long pFarWidth,long pFarHeight)
- {
- if(hdc!=NULL)
- {
- DeleteDC(hdc);
- DeleteObject(outhBMP);
- DeleteObject(bmpBITMAP);
- hdc=NULL;
- }
- hdc=NULL;
- bmpBITMAP=NULL;
- Picname[0]=0;
- Width=pFarWidth;
- Height=pFarHeight;
- outhBMP =CreateCompatibleBitmap(pFarHDC,Width, Height);
- bmpBITMAP =CreateCompatibleBitmap(pFarHDC,Width, Height);
- hdc =CreateCompatibleDC(pFarHDC);
- outhdc =CreateCompatibleDC(pFarHDC);
- DeleteObject(SelectObject(hdc,bmpBITMAP));
- BitBlt(hdc,0,0,1000,1000,0,0,0,WHITENESS);
- BitBlt(outhdc,0,0,1000, 1000,0,0,0,WHITENESS);
- DeleteObject(SelectObject(outhdc,outhBMP));
- }