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

输入法编程

开发平台:

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. IDB_S=0;
  16. }
  17. myHDC::~myHDC()
  18. {
  19. DeleteDC(hdc);
  20. DeleteDC(outhdc);
  21. DeleteObject(outhBMP);
  22. DeleteObject(bmpBITMAP);
  23. }
  24. //独立函数,返回为空则为装载失败
  25. HBITMAP myHDC::loadPic(char * myFilename)
  26. {
  27. if(!strcmp(Picname,myFilename))//相同说明已经装载,则不装并返回
  28. return bmpBITMAP;
  29. strcpy(Picname,myFilename);
  30. DeleteObject(bmpBITMAP);   //
  31. bmpBITMAP=(HBITMAP)LoadImage(0, myFilename, IMAGE_BITMAP,
  32.  0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  33. if(bmpBITMAP!=NULL)
  34. {
  35. DIBSECTION ds;
  36. DeleteObject(SelectObject(hdc,bmpBITMAP));
  37. BITMAPINFOHEADER &bm = ds.dsBmih;
  38. GetObject(bmpBITMAP,sizeof(ds),&ds);
  39. LoadPicWidth = bm.biWidth;
  40. LoadPicHeight = bm.biHeight;
  41. BitBlt(outhdc,0,0,LoadPicWidth, LoadPicHeight,hdc,0,0,SRCCOPY);
  42. }
  43. else
  44. {
  45. DeleteObject(bmpBITMAP);
  46. //MessageBox(0,"没找到!",myFilename,0);
  47. return NULL;
  48. }
  49. return bmpBITMAP;
  50. }
  51. //独立函数,返回为空则为装载失败
  52. HBITMAP myHDC::loadPic(HINSTANCE hInstDLL,int IDB_Source)
  53. {
  54. if(IDB_S==IDB_Source)//相同说明已经装载,则不装并返回
  55. return bmpBITMAP;
  56. IDB_S=IDB_Source;
  57. DeleteObject(bmpBITMAP);   //
  58. bmpBITMAP=(HBITMAP)LoadBitmap(hInstDLL,MAKEINTRESOURCE(IDB_Source));
  59. if(bmpBITMAP!=NULL)
  60. {
  61. DIBSECTION ds;
  62. DeleteObject(SelectObject(hdc,bmpBITMAP));
  63. BITMAPINFOHEADER &bm = ds.dsBmih;
  64. GetObject(bmpBITMAP,sizeof(ds),&ds);
  65. LoadPicWidth = ds.dsBm.bmWidth;
  66. LoadPicHeight = ds.dsBm.bmHeight;
  67. BitBlt(outhdc,0,0,LoadPicWidth, LoadPicHeight,hdc,0,0,SRCCOPY);
  68. }
  69. else
  70. {
  71. DeleteObject(bmpBITMAP);
  72. //MessageBox(0,"没找到!",myFilename,0);
  73. return NULL;
  74. }
  75. return bmpBITMAP;
  76. }
  77. myHDC::reSelectBAKHDC()
  78. {
  79. DeleteObject(SelectObject(hdc,bmpBITMAP));
  80. }
  81. //一般情况下本函数不会失败,本类必须在调用了此函后才能使用
  82. myHDC ::StartHDC(HDC  pFarHDC,long pFarWidth,long pFarHeight)
  83. {
  84. if(hdc!=NULL)
  85. {
  86. DeleteDC(hdc);
  87. DeleteObject(outhBMP);
  88. DeleteObject(bmpBITMAP);
  89. hdc=NULL;
  90. }
  91. hdc=NULL;
  92. bmpBITMAP=NULL;
  93. Picname[0]=0;
  94. Width=pFarWidth;
  95. Height=pFarHeight;
  96. outhBMP   =CreateCompatibleBitmap(pFarHDC,Width, Height);
  97. bmpBITMAP =CreateCompatibleBitmap(pFarHDC,Width, Height);
  98. hdc       =CreateCompatibleDC(pFarHDC);
  99. outhdc    =CreateCompatibleDC(pFarHDC);
  100. DeleteObject(SelectObject(hdc,bmpBITMAP));
  101. BitBlt(hdc,0,0,1000,1000,0,0,0,WHITENESS);
  102. BitBlt(outhdc,0,0,1000, 1000,0,0,0,WHITENESS);
  103. DeleteObject(SelectObject(outhdc,outhBMP));
  104. }