给计算器添加一个新菜单

#include 
#include 
#include 
 
#define IDM_TEST    12345
 
WNDPROC lpfnOldProc = 0;
 
 
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    return CallWindowProc(lpfnOldProc, hWnd, message, wParam, lParam);
}
 
DWORD WINAPI ThreadProc(PVOID pParam)
{
    HWND hwnd = FindWindow(NULL, _T("计算器"));
    HMENU hMenu = GetMenu(hwnd);
    AppendMenu(hMenu, MF_STRING, IDM_TEST, _T("注入菜单"));
    SetMenu(hwnd, hMenu);
    lpfnOldProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG)WndProc);
    return 0;
}
 
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        CreateThread(NULL,0,ThreadProc,NULL,0,NULL);
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

你可能感兴趣的:(给计算器添加一个新菜单)