⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transfile.cpp

📁 这是网络信息安全课程写的一个给文件加密传输的源代码
💻 CPP
字号:
// TransFile.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "TransFile.h"
#include "TransFileDlg.h"
#include "Afxsock.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTransFileApp

extern HHOOK  hWndHook ;
HRESULT __stdcall DefWindowProc1(HWND hWnd,UINT Msg,WPARAM wParam, 
								 LPARAM lParam )
{
	CPoint pt;
	CDrawButton *pButton=(CDrawButton*)GetWindowLong(hWnd,GWL_USERDATA);
	switch (Msg)
	{
	case WM_LBUTTONDBLCLK:  //屏蔽双击事件
		{
			return TRUE;
			break;
		}
		case WM_PAINT:
			{
				if (pButton->m_Style>0)
					return pButton->OnPaint( hWnd);
				else
					return  CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);
				break;
			}
		case WM_LBUTTONDOWN:
			{
				pt.x = LOWORD(lParam);
				pt.y = HIWORD(lParam);
				if (pButton->m_Style>0)
					return pButton->OnLButtonDown( hWnd, 0, pt );
				else
					return  CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);
				break;
			}
		case WM_LBUTTONUP:
			{
				pt.x = LOWORD(lParam);
				pt.y = HIWORD(lParam);
				if (pButton->m_Style>0)
					return pButton->OnLButtonUp( hWnd, 0,pt );
				else
					return  CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);
				break;
			}
		case WM_MOUSEMOVE:
			{

				pt.x = LOWORD(lParam);
				pt.y = HIWORD(lParam);
				if (pButton->m_Style>0)
					return pButton->OnMouseMove(hWnd,0, pt);
				else
					return  CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);

				break;
			}

		case WM_DESTROY:
			{				
			  	 WNDPROC procOld=pButton->m_OldProc;
				 SetWindowLong(hWnd,GWL_WNDPROC,(long)procOld); //恢复原来的窗口函数

				 pButton->m_Flag = 1;
			     LRESULT ret = ::CallWindowProc(procOld,hWnd,Msg,wParam,lParam);
				 return ret;
			}
		default :
			{
				break;
			}
	}
	return CallWindowProc(pButton->m_OldProc, hWnd, Msg, wParam, lParam );
}


//定义钩子函数
LRESULT CALLBACK HOOKProc( int nCode, WPARAM wParam, LPARAM lParam )
{
	PCWPSTRUCT	wc = (PCWPSTRUCT) lParam;
	HWND  hWnd = wc->hwnd;
	if( hWnd ) 
	{
		char ClassName[MAX_PATH] = "";
		GetClassName( hWnd, ClassName, MAX_PATH );
		if( strcmp( ClassName, "Button" ) == 0 )
		{
			CWnd	*pWnd = CWnd::FromHandle( hWnd );
			
			BOOL IsDefaultButton = pWnd->GetStyle()&BS_DEFPUSHBUTTON; 
			BOOL IsGroupButton   = pWnd->GetStyle()&BS_GROUPBOX;
			
			int  CommonButton = ((CButton*)pWnd)->GetButtonStyle();
			if (IsDefaultButton )
				if (CommonButton!=7)
				pWnd->ModifyStyle(BS_DEFPUSHBUTTON,0,0);

			WNDPROC	WndProc;
			WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
			
			CDrawButton *pButton = NULL;
			pButton =(CDrawButton*)GetWindowLong(hWnd,GWL_USERDATA);
			if (pButton != NULL&& pButton->m_Flag==1 )
			{
					SetWindowLong(hWnd,GWL_USERDATA,0);
					SetWindowLong( hWnd, GWL_WNDPROC, (LONG)pButton->m_OldProc );

					pButton->m_OldProc = NULL;
					delete pButton;	
			}
			else if (pButton == NULL ) 
			{
				if( WndProc !=DefWindowProc1 )
				{
					if (!IsGroupButton)
					{
						pButton = new CDrawButton;
						pButton->m_OldProc = WndProc;
						SetWindowLong(hWnd,GWL_USERDATA,(long)pButton);
						WndProc =  (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) DefWindowProc1);
					}
				}
			}
		}
	}
	return CallNextHookEx( hWndHook, nCode, wParam, lParam );
}

//安装钩子
BOOL  RunHook( HMODULE hModule, DWORD dwThreadID)
{
	hWndHook = SetWindowsHookEx(
		WH_CALLWNDPROC, (HOOKPROC) HOOKProc, hModule, dwThreadID );
	return TRUE;
}

//卸载钩子
BOOL  StopHook()
{
	UnhookWindowsHookEx(hWndHook);
	return TRUE;
}




BEGIN_MESSAGE_MAP(CTransFileApp, CWinApp)
	//{{AFX_MSG_MAP(CTransFileApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTransFileApp construction

CTransFileApp::CTransFileApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CTransFileApp object

CTransFileApp theApp;
int CDrawButton::m_Style = 1;
HHOOK  hWndHook ;
/////////////////////////////////////////////////////////////////////////////
// CTransFileApp initialization

BOOL CTransFileApp::InitInstance()
{
	AfxEnableControlContainer();

#ifdef _AFXDLL
	Enable3dControls();	
#else
	Enable3dControlsStatic();
#endif
	HINSTANCE hModule = GetModuleHandle( NULL );
	//RunHook ( hModule, GetCurrentThreadId() );
	//初始化套接字
	WSAData data;
	WSAStartup(2,&data);

	CTransFileDlg dlg;
	m_pMainWnd = &dlg;
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK)
	{

	}
	else if (nResponse == IDCANCEL)
	{
	}
	return FALSE;
	
}
int CTransFileApp::ExitInstance() 
{
	//StopHook();	
	return CWinApp::ExitInstance();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -