myHDC.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:2k
源码类别:

输入法编程

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // 
  3. #include "stdafx.h"
  4. #include "myHDC.h" 
  5. #include "math.h" 
  6. myHDC::myHDC()
  7. {
  8. //采用动态连接库方式时,
  9. //此初始化在第二次时不调用会,最后自己初始化
  10. hdc=NULL;
  11. outhdc=NULL;
  12. bmpBITMAP=NULL;
  13. outhBMP=NULL;
  14. Picname[0]=0;
  15. }
  16. myHDC::~myHDC()
  17. {
  18. DeleteDC(hdc);
  19. DeleteDC(outhdc);
  20. DeleteObject(outhBMP);
  21. DeleteObject(bmpBITMAP);
  22. }
  23. //独立函数,返回为空则为装载失败
  24. HBITMAP myHDC::loadPic(char * myFilename)
  25. {
  26. if(!strcmp(Picname,myFilename))//相同说明已经装载,则不装并返回
  27. return bmpBITMAP;
  28. strcpy(Picname,myFilename);
  29. DeleteObject(bmpBITMAP);   //
  30. bmpBITMAP=(HBITMAP)LoadImage(0, myFilename, IMAGE_BITMAP,
  31.  0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  32. if(bmpBITMAP!=NULL)
  33. {
  34. DIBSECTION ds;
  35. DeleteObject(SelectObject(hdc,bmpBITMAP));
  36. BITMAPINFOHEADER &bm = ds.dsBmih;
  37. GetObject(bmpBITMAP,sizeof(ds),&ds);
  38. LoadPicWidth = bm.biWidth;
  39. LoadPicHeight = bm.biHeight;
  40. BitBlt(outhdc,0,0,LoadPicWidth, LoadPicHeight,hdc,0,0,SRCCOPY);
  41. }
  42. else
  43. {
  44. DeleteObject(bmpBITMAP);
  45. //MessageBox(0,"没找到!",myFilename,0);
  46. return NULL;
  47. }
  48. return bmpBITMAP;
  49. }
  50. myHDC::reSelectBAKHDC()
  51. {
  52. DeleteObject(SelectObject(hdc,bmpBITMAP));
  53. }
  54. //一般情况下本函数不会失败,本类必须在调用了此函后才能使用
  55. myHDC ::StartHDC(HDC  pFarHDC,long pFarWidth,long pFarHeight)
  56. {
  57. if(hdc!=NULL)
  58. {
  59. DeleteDC(hdc);
  60. DeleteObject(outhBMP);
  61. DeleteObject(bmpBITMAP);
  62. hdc=NULL;
  63. }
  64. hdc=NULL;
  65. bmpBITMAP=NULL;
  66. Picname[0]=0;
  67. Width=pFarWidth;
  68. Height=pFarHeight;
  69. outhBMP   =CreateCompatibleBitmap(pFarHDC,Width, Height);
  70. bmpBITMAP =CreateCompatibleBitmap(pFarHDC,Width, Height);
  71. hdc       =CreateCompatibleDC(0);
  72. outhdc    =CreateCompatibleDC(0);
  73. DeleteObject(SelectObject(hdc,bmpBITMAP));
  74. BitBlt(hdc,0,0,1000,1000,0,0,0,WHITENESS);
  75. DeleteObject(SelectObject(outhdc,outhBMP));
  76. }