Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "windows.h"
- #define MYMENU_EXIT (WM_APP + 101)
- #define MYMENU_MESSAGEBOX (WM_APP + 102)
- HINSTANCE inj_hModule; //Injected Modules Handle
- HWND prnt_hWnd; //Parent Window Handle
- //WndProc for the new window
- LRESULT CALLBACK DLLWindowProc(HWND, UINT, WPARAM, LPARAM);
- //Register our windows Class
- BOOL RegisterDLLWindowClass(wchar_t szClassName[])
- {
- WNDCLASSEX wc;
- wc.hInstance = inj_hModule;
- wc.lpszClassName = (LPCWSTR)L"InjectedDLLWindowClass";
- wc.lpszClassName = (LPCWSTR)szClassName;
- wc.lpfnWndProc = DLLWindowProc;
- wc.style = CS_DBLCLKS;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.lpszMenuName = NULL;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
- if (!RegisterClassEx(&wc))
- return 0;
- }
- //Creating our windows Menu
- HMENU CreateDLLWindowMenu()
- {
- HMENU hMenu;
- hMenu = CreateMenu();
- HMENU hMenuPopup;
- if (hMenu == NULL)
- return FALSE;
- hMenuPopup = CreatePopupMenu();
- AppendMenu(hMenuPopup, MF_STRING, MYMENU_EXIT, TEXT("Exit"));
- AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hMenuPopup, TEXT("File"));
- hMenuPopup = CreatePopupMenu();
- AppendMenu(hMenuPopup, MF_STRING, MYMENU_MESSAGEBOX, TEXT("MessageBox"));
- AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hMenuPopup, TEXT("Test"));
- return hMenu;
- }
- //The new thread
- DWORD WINAPI ThreadProc(LPVOID lpParam)
- {
- MSG messages;
- wchar_t *pString = reinterpret_cast<wchar_t * > (lpParam);
- HMENU hMenu = CreateDLLWindowMenu();
- RegisterDLLWindowClass(L"InjectedDLLWindowClass");
- prnt_hWnd = FindWindow(L"Window Injected Into ClassName", L"Window Injected Into Caption");
- HWND hwnd = CreateWindowEx(0, L"InjectedDLLWindowClass", pString, WS_EX_PALETTEWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, prnt_hWnd, hMenu, inj_hModule, NULL);
- ShowWindow(hwnd, SW_SHOWNORMAL);
- while (GetMessage(&messages, NULL, 0, 0))
- {
- TranslateMessage(&messages);
- DispatchMessage(&messages);
- }
- return 1;
- }
- //Our new windows proc
- LRESULT CALLBACK DLLWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_COMMAND:
- switch (wParam)
- {
- case MYMENU_EXIT:
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- break;
- 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;
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
- inj_hModule = hModule;
- CreateThread(0, NULL, ThreadProc, (LPVOID)L"Window Title", NULL, NULL);
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement