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

📄 modifymenu.cpp

📁 此为本书的配套光盘.本书不但由浅入深地讲解了软件保护技术
💻 CPP
字号:
/********************************************************************

	Copyright (c) Beijing Feitian Technologies
	http://www.FTSafe.com

	File :		ModifyMenu.cpp	

	Created:	2003/11/04

	Author:		yihai
	
	Purpose:	?

	Revision:		
		2003-07-22 [Euphen Liu]
		  Implement the code about enable a appended menu item when 
		AFX can't find the Message Map of it.
		
*********************************************************************/

#include "stdafx.h"
#include <windows.h>

LRESULT CALLBACK WndHookProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK EnumThreadWndProc(HWND hwnd,LPARAM lParam);

char	g_szAppTitle[] = "ModifyMenu";
char    g_szMsgNoWnd[] = "Can't find any menu!";
char	g_szAboutMsg[] = "About WndProc Hook";

static  DWORD	g_dwThreadID = 0;
static  HANDLE	g_hThread = NULL; 


DWORD   g_wAppendItemID = 60000;

DWORD	g_dwMainThreadID;
HWND	g_hMainThreadWnd=NULL;
WNDPROC g_pMainWndProc=NULL;
BOOL	g_bHooked = FALSE;
HMENU	g_hMenu = NULL;

DWORD WINAPI SubThreadMainProc(LPVOID lpParameter)
{
	OutputDebugString("now in new thread\n");
	Sleep(3000);	
	
	while (1) 
	{		
		if(g_hMainThreadWnd==NULL)
		{
			EnumThreadWindows(g_dwMainThreadID,EnumThreadWndProc,NULL);
		}		
		if(g_hMainThreadWnd==NULL)
		{
			MessageBox(NULL,g_szMsgNoWnd,g_szAppTitle,MB_OK);
			break;
		}		
		if(!g_bHooked && g_hMainThreadWnd)
		{
			HMENU hMenuMain = GetMenu(g_hMainThreadWnd);			
			HMENU hSubMenu  = GetSubMenu(hMenuMain,0);

			g_hMenu = CreatePopupMenu();
			if(NULL == g_hMenu)
				OutputDebugString("Can not create popup menu.");
			
			if(AppendMenu(g_hMenu, MF_STRING, g_wAppendItemID, "Haha"))
				OutputDebugString("Append success\n");
			else
				OutputDebugString("Append fail\n");

			if(AppendMenu(hSubMenu,MF_POPUP,(UINT)g_hMenu,"NewItem"))
				OutputDebugString("Append success\n");
			else
				OutputDebugString("Append fail\n");

			g_bHooked = TRUE;
			g_pMainWndProc = (WNDPROC)SetWindowLong(g_hMainThreadWnd,GWL_WNDPROC,(LONG)WndHookProc);
			ExitThread(0);
		}				
		Sleep(1000);
	}
	return 0;
}


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{		

	g_dwMainThreadID = GetCurrentThreadId();

	g_hThread = CreateThread(NULL,0,SubThreadMainProc,hInstance,0,&g_dwThreadID);
	return 0;	
}


#define	ID_ABOUTBOX 57664

LRESULT CALLBACK WndHookProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if(hWnd == g_hMainThreadWnd)
	{
		if(message == WM_COMMAND)
		{
			WORD wMenuID = LOWORD(wParam);
			
			if(wMenuID == ID_ABOUTBOX )
			{
				MessageBox(g_hMainThreadWnd,g_szAboutMsg,g_szAppTitle,MB_OK);
				return 0;
			}
			else if(wMenuID == g_wAppendItemID)
			{
				MessageBox(g_hMainThreadWnd,"========;)",g_szAppTitle,MB_OK);
				return 0;
			}
		}
		else if(message == WM_INITMENUPOPUP)
		{
			HMENU hMenu = (HMENU)wParam;

			if(hMenu == g_hMenu)
			{
				CallWindowProc(g_pMainWndProc,hWnd,message,wParam,lParam);

				OutputDebugString("hMenu == g_hMenu");
				if(EnableMenuItem(hMenu,g_wAppendItemID,MF_BYCOMMAND|MF_ENABLED))
				{
					OutputDebugString("EnableMenuItem() ok.");
				}
				else
				{
					OutputDebugString("EnableMenuItem() failed.");
				}
				return 0;
			}
		}
	}
	return CallWindowProc(g_pMainWndProc,hWnd,message,wParam,lParam);
}

BOOL CALLBACK EnumThreadWndProc(HWND hWnd,LPARAM lParam)
{
	if(hWnd)
	{
		if(GetParent(hWnd) == NULL)
		{
			g_hMainThreadWnd = hWnd;			
			return FALSE;
		}
	}	
	return TRUE;
}

⌨️ 快捷键说明

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