BOWView.cpp
上传用户:jinandeyu
上传日期:2007-01-05
资源大小:620k
文件大小:6k
源码类别:

远程控制编程

开发平台:

WINDOWS

  1. /*  Back Orifice 2000 - Remote Administration Suite
  2.     Copyright (C) 1999, Cult Of The Dead Cow
  3.     This program is free software; you can redistribute it and/or modify
  4.     it under the terms of the GNU General Public License as published by
  5.     the Free Software Foundation; either version 2 of the License, or
  6.     (at your option) any later version.
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.     GNU General Public License for more details.
  11.     You should have received a copy of the GNU General Public License
  12.     along with this program; if not, write to the Free Software
  13.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  14. The author of this program may be contacted at dildog@l0pht.com. */
  15. // BOWView.cpp : implementation of the CBOWView class
  16. //
  17. #include "stdafx.h"
  18. #include "bo2kgui.h"
  19. #include "BOWDoc.h"
  20. #include "BOWview.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CBOWView
  28. IMPLEMENT_DYNCREATE(CBOWView, CView)
  29. BEGIN_MESSAGE_MAP(CBOWView, CView)
  30. //{{AFX_MSG_MAP(CBOWView)
  31. ON_WM_ERASEBKGND()
  32. ON_WM_RBUTTONDOWN()
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CBOWView construction/destruction
  37. CBOWView::CBOWView()
  38. {
  39. m_dwSolidColor=AfxGetApp()->GetProfileInt("Background","Solid Color",RGB(40,40,40));
  40. m_bImage=AfxGetApp()->GetProfileInt("Background","Bkgnd Image",0);
  41. m_strImgFile=AfxGetApp()->GetProfileString("Background","Image File",NULL);
  42. m_bTile=AfxGetApp()->GetProfileInt("Background","Tile",0);
  43. m_pImgDC=NULL;
  44. }
  45. CBOWView::~CBOWView()
  46. {
  47. AfxGetApp()->WriteProfileInt("Background","Solid Color",m_dwSolidColor);
  48. AfxGetApp()->WriteProfileInt("Background","Bkgnd Image",m_bImage);
  49. AfxGetApp()->WriteProfileString("Background","Image File",m_strImgFile);
  50. AfxGetApp()->WriteProfileInt("Background","Tile",m_bTile);
  51. if(m_pImgDC!=NULL)
  52. delete m_pImgDC;
  53. }
  54. BOOL CBOWView::PreCreateWindow(CREATESTRUCT& cs)
  55. {
  56. // TODO: Modify the Window class or styles here by modifying
  57. //  the CREATESTRUCT cs
  58. return CView::PreCreateWindow(cs);
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CBOWView drawing
  62. void CBOWView::OnDraw(CDC* pDC)
  63. {
  64. CBOWDoc* pDoc = GetDocument();
  65. ASSERT_VALID(pDoc);
  66. // TODO: add draw code for native data here
  67. }
  68. /////////////////////////////////////////////////////////////////////////////
  69. // CBOWView diagnostics
  70. #ifdef _DEBUG
  71. void CBOWView::AssertValid() const
  72. {
  73. CView::AssertValid();
  74. }
  75. void CBOWView::Dump(CDumpContext& dc) const
  76. {
  77. CView::Dump(dc);
  78. }
  79. CBOWDoc* CBOWView::GetDocument() // non-debug version is inline
  80. {
  81. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBOWDoc)));
  82. return (CBOWDoc*)m_pDocument;
  83. }
  84. #endif //_DEBUG
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CBOWView message handlers
  87. void CBOWView::OnInitialUpdate() 
  88. {
  89. CView::OnInitialUpdate();
  90. if(m_bImage) {
  91. HBITMAP hbm=(HBITMAP)LoadImage(NULL,m_strImgFile,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
  92. if(hbm==NULL) {
  93. m_bImage=FALSE;
  94. } else {
  95. cbmBitmap.m_hObject=hbm;
  96. }
  97. }
  98. }
  99. BOOL CBOWView::OnEraseBkgnd(CDC* pDC) 
  100. {
  101. RECT r;
  102. GetClientRect(&r);
  103. int x,y;
  104. if(!(m_bTile && m_bImage)) {
  105. pDC->FillSolidRect(&r,m_dwSolidColor);
  106. }
  107. if(m_bImage) {
  108. if(m_pImgDC==NULL) {
  109. m_pImgDC=new CDC();
  110. m_pImgDC->CreateCompatibleDC(pDC);
  111. m_pImgDC->SelectObject(cbmBitmap);
  112. }
  113. BITMAP bmp;
  114. cbmBitmap.GetBitmap(&bmp);
  115. if(m_bTile) {
  116. for(y=0;y<(r.bottom-r.top);y+=bmp.bmHeight) {
  117. for(x=0;x<(r.right-r.left);x+=bmp.bmWidth) {
  118. pDC->BitBlt(x,y,bmp.bmWidth,bmp.bmHeight,m_pImgDC,0,0,SRCCOPY);
  119. }
  120. }
  121. } else {
  122. pDC->BitBlt(
  123. ((r.right-r.left)/2)-(bmp.bmWidth/2),
  124. ((r.bottom-r.top)/2)-(bmp.bmHeight/2),
  125. bmp.bmWidth, bmp.bmHeight, m_pImgDC, 0, 0, SRCCOPY);
  126. }
  127. }
  128. return TRUE;
  129. }
  130. void CBOWView::OnRButtonDown(UINT nFlags, CPoint point) 
  131. {
  132. // TODO: Add your message handler code here and/or call default
  133. HMENU hmenu=LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_BKGNDPOPUP));
  134. HMENU hsubmenu=GetSubMenu(hmenu,0);
  135. CheckMenuItem(hsubmenu,IDM_BITMAP,m_bImage?MF_CHECKED:MF_UNCHECKED);
  136. CheckMenuItem(hsubmenu,IDM_TILE,m_bTile?MF_CHECKED:MF_UNCHECKED);
  137. ClientToScreen(&point);
  138. int cmd=TrackPopupMenu(hsubmenu,TPM_RETURNCMD|TPM_RIGHTBUTTON,point.x,point.y,0,GetSafeHwnd(),NULL);
  139. switch(cmd) {
  140. case IDM_TILE:
  141. m_bTile=!m_bTile;
  142. break;
  143. case IDM_SOLIDCOLOR:
  144. {
  145. CColorDialog ccd;
  146. if(ccd.DoModal()==IDOK) {
  147. m_dwSolidColor=ccd.GetColor();
  148. }
  149. }
  150. break;
  151. case IDM_BITMAP:
  152. {
  153. m_bImage=!m_bImage;
  154. if(m_bImage) {
  155. CFileDialog cfd(TRUE,".bmp",m_strImgFile,OFN_PATHMUSTEXIST|OFN_NOCHANGEDIR|OFN_HIDEREADONLY,"Bitmap Files (*.bmp)|*.bmp||");
  156. if(cfd.DoModal()==IDOK) {
  157. m_strImgFile=cfd.GetPathName();
  158. } else {
  159. m_bImage=FALSE;
  160. }
  161. }
  162. }
  163. }
  164. DestroyMenu(hmenu);
  165. // Update bitmap/image
  166. if(m_bImage) {
  167. HBITMAP hbm=(HBITMAP)LoadImage(NULL,m_strImgFile,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
  168. if(hbm==NULL) {
  169. m_bImage=FALSE;
  170. } else {
  171. cbmBitmap.DeleteObject();
  172. cbmBitmap.m_hObject=hbm;
  173. delete m_pImgDC;
  174. m_pImgDC=NULL;
  175. }
  176. }
  177. Invalidate();
  178. }