开发者

EndPaint hooking to draw text to a DirectX window

开发者 https://www.devze.com 2023-03-30 17:47 出处:网络
I want to draw text to a DirectX game, so I\'ve injected a DLL which hooks EndPaint. My logic was that since EndPaint is supposed to be the last step in the WM_PAINT operation, I could, in my hook, dr

I want to draw text to a DirectX game, so I've injected a DLL which hooks EndPaint. My logic was that since EndPaint is supposed to be the last step in the WM_PAINT operation, I could, in my hook, draw the text, and then call EndPaint myself. By doing this, I avoid the DX interface altogether.

The problem is that it is doing absolutely nothing. Here is my code.

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

static const TCHAR g_cszMessage[] = TEXT("utterly fantastic");

BOOL (WINAPI * _EndPaint)(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint) = EndPaint;

BOOL WINAPI EndPaintHook(__in HWND hWnd, __in const LPPAINTSTRUCT lpPaint)
{
  // write message
  TextOut(lpPaint->hdc, 0, 0, g_cszMessage, lstrlen(g_cszMessage));
  GdiFlush();

  // return original
  return _EndPaint(hWnd, lpPaint);
}

BOOL APIENTRY DllMain(__in HINSTANCE hModule, __in DWORD fdwReason, __in __reserved LPVOID lpvReserved)
{
  UNREFERENCED_PARAMETER(lpvReserved);

  switch (fdwReason)
  {
  case DLL_PROCESS_ATTACH:
    if (AttachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook))
    {
      DisableThreadLibraryCalls(hModule);
      break;
    }
    return FALSE;

  case D开发者_Python百科LL_PROCESS_DETACH:
    DetachHook(reinterpret_cast<PVOID*>(&_EndPaint), EndPaintHook);
    break;
  }
  return TRUE;
}

I know the issue isn't with my AttachHook/DetachHook functions because I've tested via message boxes and confirmed that the hooks are installed. The text simply isn't showing up.

Anyone have any idea? I don't really want to hook the DX interface. Shouldn't it work either way, since WM_PAINT is still used at the base level?

Thanks in advance.


You are better off hooking the present of DirectX and then using ID3DXFont to do some font rendering. AFAIK WM_PAINT is not used for DirectX rendering.

0

精彩评论

暂无评论...
验证码 换一张
取 消