0

嘿,我创建了一个 dll 将其注入我的应用程序以创建菜单和子菜单

我也下了订单,如果点击 subment 它应该显示消息

#include "stdafx.h"
#include "windows.h"

#define MYMENU_MESSAGEBOX   (WM_APP + 102) 
HINSTANCE inj_hMod;

HMENU CreateDLLWindowMenu() {
    HMENU hMenu;
    HWND hWnd = FindWindow(NULL, TEXT("MainSvrt on port 51752"));
    hMenu = GetMenu(hWnd);
    HMENU hMenuPopup;

    if (hMenu == NULL) {
        return FALSE;
    }

    hMenuPopup = CreateMenu();
    AppendMenu(hMenu, MF_POPUP, (UINT_PTR) hMenuPopup, TEXT("Test"));
    AppendMenu(hMenuPopup, MF_STRING, MYMENU_MESSAGEBOX, TEXT("MessageBox"));
    DrawMenuBar(hWnd);

    HWND prnt_hWnd;
    LRESULT CALLBACK DLLWindowProc(HWND, UINT, WPARAM, LPARAM);
    DLLWindowProc;
}

DWORD WINAPI ThreadProc(LPVOID lpParam) {
    MSG messages;
    wchar_t *pString = reinterpret_cast<wchar_t *>(lpParam);
    HMENU hMenu = CreateDLLWindowMenu();

    while (GetMessage(&messages, NULL, 0, 0)) {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }

    return 1;
}

LRESULT CALLBACK DLLWindowProc(HWND hwnd, UINT message, WPARAM wParam,
        LPARAM lParam) {
    switch (message) {
    case WM_COMMAND:
        switch (wParam) {
        case MYMENU_MESSAGEBOX:
            MessageBox(hwnd, L"Test", L"MessageBox", MB_OK);
            break;
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}

unsigned __stdcall Init(void* pArg) {
    return 1;
}

BOOL APIENTRY DllMain(HMODULE hMod, DWORD ul_reason, LPVOID lpRes) {
    if (ul_reason == DLL_PROCESS_ATTACH) {
        inj_hMod = hMod;
        CreateThread(0, NULL, ThreadProc, (LPVOID) L"MainSvrt", NULL, NULL);

        if (!CreateThread(0, 0, (LPTHREAD_START_ROUTINE) Init, &hMod, 0, 0)) {
            ::MessageBoxA(0, "CreateThread() failed", 0, MB_OK | MB_ICONSTOP);
        }
    }

    return TRUE;
}

在应用程序中成功添加菜单和子菜单

但是当我点击 MessageBox [Submenu] 它不显示消息框

MessageBox(hwnd, L"Test", L"MessageBox",MB_OK);
4

0 回答 0