Witam.Przy pomocy kursu z neta napisałem ten kod. Problem w tym że chciałbym coś zrobić żeby to moje rysowanie dopasowywało się do okna, tzn. że gdy je przesunę po pulpicie to ten overlay przesunie się w te same miejsce, lub lepiej żeby to połączyć ze sobą.
http://scr.hu/3dxp/qx5yv
http://scr.hu/3dxp/altzc
Oto mój kod:
#include "hMain.h"
int s_width =800;
int s_height =600;
#define CENTERX (GetSystemMetrics(SM_CXSCREEN)/2)-(s_width/2)
#define CENTERY (GetSystemMetrics(SM_CYSCREEN)/2)-(s_height/2)
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
HWND hWnd;
const MARGINS margin = {0,0,s_width,s_height};
LPD3DXFONT pFont;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferWidth = s_width;
d3dpp.BackBufferHeight =s_height;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
D3DXCreateFont(d3ddev, 50, 0, FW_BOLD, 1, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &pFont);
}
void DrawString(int x, int y, DWORD color, LPD3DXFONT g_pFont, const char *fmt)
{
RECT FontPos = { x, y, x + 120, y + 16 };
char buf[1024] = {'\0'};
va_list va_alist;
va_start(va_alist, fmt);
vsprintf_s(buf, fmt, va_alist);
va_end(va_alist);
g_pFont->DrawText(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
}
void render()
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0, 0, 0), 1.0f, 0);
d3ddev->BeginScene();
DrawString(10,50,D3DCOLOR_ARGB(255,255,0,0),pFont,"halooo");
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
char* ReadINI(char* szSection, char* szKey, const char* szDefaultValue)
{
char* szResult = new char[255];
memset(szResult, 0x00, 255);
GetPrivateProfileString(szSection, szKey,
szDefaultValue, szResult, 255, ".\\conf.ini");
return szResult;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char * value=ReadINI("CONFIGURATION","WIN_NAME","none");
RECT rc;
HWND newhwnd=FindWindow(NULL,value);
if(newhwnd!=NULL){
GetWindowRect(newhwnd,&rc);
s_width= rc.right - rc.left;
s_height = rc.bottom - rc.top;
}else{
ExitProcess(0);
}
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)RGB(0,0,0);
wc.lpszClassName = "WindowClass";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(0,
"WindowClass",
"",
WS_EX_TOPMOST | WS_POPUP ,
rc.left, rc.top,
s_width, s_height,
NULL,
NULL,
hInstance,
NULL);
SetWindowLong(hWnd, GWL_EXSTYLE,(int)GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED |WS_EX_TRANSPARENT);
SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 0, ULW_COLORKEY);
SetLayeredWindowAttributes(hWnd, 0, 255, LWA_ALPHA);
ShowWindow(hWnd, nCmdShow);
initD3D(hWnd);
MSG msg;
::SetWindowPos(FindWindow(NULL,value) ,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
while(TRUE)
{
::SetWindowPos(hWnd ,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
if(!FindWindow(NULL,value))
ExitProcess(0);
render();
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(msg.message == WM_QUIT)
exit(0);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_PAINT:
{
DwmExtendFrameIntoClientArea(hWnd, &margin);
}break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}