博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
给记事本添加接口,并通过菜单来执行自定义的功能
阅读量:5285 次
发布时间:2019-06-14

本文共 4819 字,大约阅读时间需要 16 分钟。

思路:通过反汇编确定记事本的窗口过程地址,把它替换为我们自己的窗口过程地址,在自己窗口过程中先判断是否是自定义的消息,

是则执行相应的操作,不是则把流程转到记事本原来的窗口过程中进行处理。

添加的功能:转换大小写,加解密文本,统计字数。

源代码编译成DLL

// ExNotepad.cpp : Defines the entry point for the DLL application.//#include "stdafx.h"#include "resource.h"#include 
#define IDR_UPPER (128)/*转换为大写*/#define IDR_LOWER (129)/*转换为小写*/#define IDR_ENCRYPT (130)/*加解密*/#define IDR_COUNT (131)/*计算字数*/HINSTANCE hDll;HWND g_hEdit = NULL;//编辑框句柄DWORD ExWndProc(CONST DWORD Reserved, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);VOID WINAPI TO_UPPER(HWND hWnd);//转换到大写VOID WINAPI TO_LOWER(HWND hWnd);//转换到小写VOID WINAPI EnCrypt(HWND hWnd);//简单加密BOOL WINAPI EnCryptProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);VOID WINAPI OnEnCryptCommand(HWND hDlg, UINT uID, HWND hCtrl, UINT uNotifyCode);VOID WINAPI Count(HWND hWnd);//计算字数BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ){ hDll = (HINSTANCE)hModule; return TRUE;}DWORD ExWndProc(CONST DWORD Reserved, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch (uMsg) { case WM_COMMAND: { switch (LOWORD(wParam)) { case IDR_UPPER: { TO_UPPER(hWnd); } break; case IDR_LOWER: { TO_LOWER(hWnd); } break; case IDR_ENCRYPT: { EnCrypt(hWnd); } break; case IDR_COUNT: { Count(hWnd); } break; } } break; } return 0;}VOID WINAPI TO_UPPER(HWND hWnd){ //读取编辑框句柄 if (g_hEdit = GetDlgItem(hWnd, 0xF)) { INT len = GetWindowTextLength(g_hEdit); if (len > 0) { LPTSTR pstrBuffer = new TCHAR[len+2]; memset(pstrBuffer, 0, sizeof(TCHAR)*(len+2)); GetWindowText(g_hEdit, pstrBuffer, len+2); SendMessage(g_hEdit, EM_SETMODIFY, (WPARAM)TRUE, 0); CharUpper(pstrBuffer); SetWindowText(g_hEdit, pstrBuffer); delete []pstrBuffer; } }}VOID WINAPI TO_LOWER(HWND hWnd){ //读取编辑框句柄 if (g_hEdit = GetDlgItem(hWnd, 0xF)) { INT len = GetWindowTextLength(g_hEdit); if (len > 0) { LPTSTR pstrBuffer = new TCHAR[len+2]; memset(pstrBuffer, 0, sizeof(TCHAR)*(len+2)); GetWindowText(g_hEdit, pstrBuffer, len+2); SendMessage(g_hEdit, EM_SETMODIFY, (WPARAM)TRUE, 0); CharLower(pstrBuffer); SetWindowText(g_hEdit, pstrBuffer); delete []pstrBuffer; } }}VOID WINAPI EnCrypt(HWND hWnd){ if (g_hEdit = GetDlgItem(hWnd, 0xF)) { INT len = GetWindowTextLength(g_hEdit); if (len > 0) { DialogBoxParam(hDll, MAKEINTRESOURCE(IDD_DLG_ENCRYPT), hWnd, EnCryptProc, NULL); } }}BOOL WINAPI EnCryptProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch (uMsg) { case WM_CLOSE: EndDialog(hDlg, 0); break; case WM_COMMAND: { OnEnCryptCommand(hDlg, LOWORD(wParam), (HWND)lParam, HIWORD(wParam)); } break; default: return FALSE; } return TRUE;}VOID WINAPI OnEnCryptCommand(HWND hDlg, UINT uID, HWND hCtrl, UINT uNotifyCode){ switch (uID) { case IDC_BTN_ENCRYPT://加密 { HWND hEncryptEdit = GetDlgItem(hDlg, IDC_EDT_KEY); INT nKeyLen = GetWindowTextLength(hEncryptEdit); if (nKeyLen > 0) { LPTSTR pstrKey = new TCHAR[nKeyLen+2]; memset(pstrKey, 0, nKeyLen+2); GetWindowText(hEncryptEdit, pstrKey, nKeyLen+2); INT len = GetWindowTextLength(g_hEdit); LPTSTR pstrText = new TCHAR[len+2]; memset(pstrText, 0, len+2); GetWindowText(g_hEdit, pstrText, len+2); SendMessage(g_hEdit, EM_SETMODIFY, (WPARAM)TRUE, 0); DWORD dwKey = 0; for (INT j = 0; j < nKeyLen; j++) { dwKey += pstrKey[j]; } dwKey %= 32; for (INT i = 0; i < len; i++) { pstrText[i] -= (TCHAR)dwKey; } SetWindowText(g_hEdit, pstrText); delete []pstrText; delete []pstrKey; } } break; case IDC_BTN_DECRYPT://解密 { HWND hEncryptEdit = GetDlgItem(hDlg, IDC_EDT_KEY); INT nKeyLen = GetWindowTextLength(hEncryptEdit); if (nKeyLen > 0) { LPTSTR pstrKey = new TCHAR[nKeyLen+2]; memset(pstrKey, 0, nKeyLen+2); GetWindowText(hEncryptEdit, pstrKey, nKeyLen+2); SendMessage(g_hEdit, EM_SETMODIFY, (WPARAM)TRUE, 0); INT len = GetWindowTextLength(g_hEdit); LPTSTR pstrText = new TCHAR[len+2]; memset(pstrText, 0, len+2); GetWindowText(g_hEdit, pstrText, len+2); DWORD dwKey = 0; for (INT j = 0; j < nKeyLen; j++) { dwKey += pstrKey[j]; } dwKey %= 32; for (INT i = 0; i < len; i++) { pstrText[i] += (TCHAR)dwKey; } SetWindowText(g_hEdit, pstrText); delete []pstrText; delete []pstrKey; } } break; } return;}VOID WINAPI Count(HWND hWnd){ if (g_hEdit = GetDlgItem(hWnd, 0xF)) { INT len = GetWindowTextLength(g_hEdit); if (len > 0) { TCHAR strText[MAX_PATH]; memset(strText, 0, sizeof(TCHAR)*MAX_PATH); wsprintf(strText, _T("当前总字数为: %d"), len); MessageBox(hWnd, strText, _T("字数统计"), MB_OK); } }}

 

 

转载于:https://www.cnblogs.com/microzone/p/3258460.html

你可能感兴趣的文章
1.2 基础知识——关于猪皮(GP,Generic Practice)
查看>>
迭代器Iterator
查看>>
java易错题----静态方法的调用
查看>>
php建立MySQL数据表
查看>>
最简单的线程同步的例子
查看>>
旅途上看的电影和观后感
查看>>
Ztree异步树加载
查看>>
关于IE和火狐,谷歌,Safari对Html标签Object和Embed的支持问题
查看>>
poj3320 Jessica's Reading Problem(尺取思路+STL)
查看>>
分布式计算开源框架Hadoop介绍
查看>>
安卓平台接口剖析
查看>>
坏的事情不都会带来坏的结果
查看>>
RPC的基础:调研EOS插件http_plugin
查看>>
第二次团队冲刺第二天
查看>>
bzoj 2257 (JSOI 2009) 瓶子与燃料
查看>>
11)Java abstract class 和 interface
查看>>
使用xrdp或Xmanager 远程连接 CentOS6
查看>>
Linux误删恢复
查看>>
Unity调用Windows窗口句柄,选择文件和目录
查看>>
HashMap循环遍历方式
查看>>