最近广海很火得画板绘制

发表于 2018-01-19  471 次阅读


经vxk补充:实际上窗口模式下(全屏独占不同)的DX设备绘制的目标窗口句柄是保存在r3的(经过实验也的确如此)。
VOID MsPaintSetWindowLong(HWND hwnd,int windowlong,int exwindowlong){
if (windowlong!=0)
{
SetWindowLongA(hwnd, -16, windowlong);
}
if (exwindowlong != 0)
{
SetWindowLongA(hwnd, -20, exwindowlong);
}
}
void CreateDxObject(HWND hwnd,int w,int h, IDirect3DDevice9**devcie){
D3DPRESENT_PARAMETERS parames;
parames.BackBufferWidth = w;
parames.BackBufferHeight = h;
parames.BackBufferFormat = D3DFMT_A8R8G8B8;
parames.BackBufferCount = 2;
parames.MultiSampleType = D3DMULTISAMPLE_NONE;
parames.MultiSampleQuality = 0;
parames.SwapEffect = D3DSWAPEFFECT_DISCARD;
parames.hDeviceWindow = hwnd;
parames.Windowed = 2;
parames.EnableAutoDepthStencil = 1;
parames.AutoDepthStencilFormat = D3DFMT_D24S8;
parames.Flags = 0;
parames.FullScreen_RefreshRateInHz = 0;
parames.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
IDirect3D9*pd3d = Direct3DCreate9(D3D_SDK_VERSION);

pd3d->CreateDevice(NULL, D3DDEVTYPE_HAL,hwnd,32,&parames,devcie);
return ;
}

IDirect3DDevice9 * CreateMsPaintWindowDx(){
IDirect3DDevice9 *dxdev;
w = GetSystemMetrics(SM_CXFULLSCREEN);
h = GetSystemMetrics(SM_CYFULLSCREEN);
HANDLE mspid= GetPid(L"mspaint.exe");

if (!mspid)
{

WinExec("C:\\Windows\\System32\\mspaint.exe", SW_HIDE);
}else{

TerminateProcess(mspid, 4);
WinExec("C:\\Windows\\System32\\mspaint.exe", SW_HIDE);
}
Sleep(1000);
mspaint= FindWindowA("MSPaintApp", NULL);
if (!mspaint)
{
MessageBoxA(NULL, NULL, NULL, NULL);
}
MoveWindow(mspaint, 0, 0, w, h, 0);
//init dx
MsPaintSetWindowLong(mspaint, NULL, 2048);
MsPaintSetWindowLong(mspaint, 335546368, NULL);
SetWindowLongA(mspaint, -20, 589992);
SetWindowLongA(mspaint, -20, 524288|GetWindowLongA(mspaint,-20));
SetLayeredWindowAttributes(mspaint, 0, 1, LWA_ALPHA);
SetLayeredWindowAttributes(mspaint, 0, RGB(0, 0, 0), LWA_COLORKEY);
UpdateWindow(mspaint);
ShowWindow(mspaint, SW_SHOWNORMAL);

MARGINS margins = { -1,-1,-1,-1 };
DwmExtendFrameIntoClientArea(mspaint, &margins);//aero
CreateDxObject(mspaint, w, h, &dxdev);
return dxdev;
}

bool Setup(IDirect3DDevice9 *dxdev)
{ //填充D3DXFONT_DESC结构
D3DXFONT_DESC df;
ZeroMemory(&df, sizeof(D3DXFONT_DESC));
df.Height = 12;
df.Width = 12;
df.MipLevels = D3DX_DEFAULT;
df.Italic = false;
df.CharSet = DEFAULT_CHARSET;
df.OutputPrecision = 0;
df.Quality = 0;
df.PitchAndFamily = 0;
wcscpy(df.FaceName, L"TIME NEW ROMAN");
//创建ID3DXFont对象
D3DXCreateFontIndirect(dxdev, &df, &font);
D3DXCreateLine(dxdev, &line);
return true;

}
void DrawString(int x, int y, DWORD color, const char *fmt, ...)
{
char buf[1024] = { 0 };
va_list va_alist;
RECT FontPos = { x, y, x + 120, y + 16 };
va_start(va_alist, fmt);
vsprintf_s(buf, fmt, va_alist);
va_end(va_alist);
font->DrawTextA(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
}
void DrawLine(float x, float y, float xx, float yy, D3DCOLOR color)
{
D3DXVECTOR2 dLine[2];

line->SetWidth(1.f);

dLine[0].x = x;
dLine[0].y = y;

dLine[1].x = xx;
dLine[1].y = yy;

line->Draw(dLine, 2, color);

}
void DrawBox(float x, float y, float width, float height, D3DCOLOR color)
{
D3DXVECTOR2 points[5];
points[0] = D3DXVECTOR2(x, y);
points[1] = D3DXVECTOR2(x + width, y);
points[2] = D3DXVECTOR2(x + width, y + height);
points[3] = D3DXVECTOR2(x, y + height);
points[4] = D3DXVECTOR2(x, y);
line->SetWidth(1);
line->Draw(points, 5, color);
}
bool GetWindowScreen(HWND hwnd,LONG *W, LONG*H){
RECT rect;
bool ret;
ret= GetClientRect(hwnd, &rect);
*W = rect.right;
*H = rect.bottom;
return ret;
}
bool GetWindowScreenPoint(HWND hwnd, LPPOINT point){

bool ret;
ret=ClientToScreen(hwnd, point);

return ret;
}
bool GetGameWindowScrenn(){
HWND hwnd = FindWindowA("UnrealWindow", 0);
GetWindowScreen(hwnd, &W, &H);//取得窗内大小
GetWindowScreenPoint(hwnd, &p);
GameWindowLeft = p.x;
GameWindowTop = p.y;
GameWindowCenterX = W*0.5;
GameWindowCenterY = H*0.5;
myrec.x = W / 2 - w / 9;
myrec.y = H / 2 - H / 9;
myrec.w = W / 2 + W / 9 - (W / 2 - W / 9);
myrec.h= H / 2 + H / 9 - (H / 2 - H / 9);
return TRUE;
}
bool MsPaintWindowReset(HWND hwnd){
RECT tSize;
DWORD WindowX = 1920;
DWORD WindowY = 1080;
HWND GameHwnd = FindWindowA("UnrealWindow", 0);
if(GameHwnd){
DWORD dwStyle = GetWindowLong(GameHwnd, GWL_STYLE);
if ((dwStyle & WS_BORDER) != 0)
{
GetWindowRect(GameHwnd, &tSize);
int x = GetSystemMetrics(32) * 2;
int y = GetSystemMetrics(4) + GetSystemMetrics(33) * 2;

tSize.left += x;
tSize.top += y;
WindowX = tSize.right - tSize.left - 10;
WindowY = tSize.bottom - tSize.top - 10;
MoveWindow(hwnd, tSize.left, tSize.top, WindowX, WindowY, TRUE);

}
else
{
WindowX = GetSystemMetrics(SM_CXSCREEN);
WindowY = GetSystemMetrics(SM_CYSCREEN);
MoveWindow(hwnd, 0, 0, WindowX, WindowY, TRUE);

}
}
return TRUE;
}

int main(){
IDirect3DDevice9 *dxdev= CreateMsPaintWindowDx();
Setup(dxdev);
while (1)
{
// GetGameWindowScrenn();//
// MsPaintWindowReset(mspaint);//貌似是窗口检测的证据。
MARGINS margins = { -1,-1,-1,-1 };
DwmExtendFrameIntoClientArea(mspaint, &margins);//aero
Uwold = ReadMem64(pid, Base + uworld);
Gname = ReadMem64(pid, Base + gnames);
InitData(uworld);
SetWindowPos(mspaint, (HWND)-1, 0, 0, 0, 0, 3);
dxdev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
dxdev->BeginScene();
//绘制文本
dxdev->EndScene();
dxdev->Present(0, 0, 0, 0);

}
}

本站文章基于国际协议BY-NA-SA 4.0协议共享;
如未特殊说明,本站文章皆为原创文章,请规范转载。

0

博客管理员