HelpInvisible Background

Posts 1–3 of 3 · Page 1 of 1
Invisible Background
Hi I recently started learning C++ and DirectX and now Im trying to make a simple Window with a transparent background. I have managed to get ride of the borders and make it click-through-able, now I just want a invisible background. I tried pSetLayeredWindowAttributes() and SetWindowLong() but then the whole window is invisible.. I want just the background. If there's something like a line.. a string or whatever on the window, they must stay visible Is there a way to do this? My Code is on the Spoiler. I hope I've been clear enough. Thanks


 
CODE
Code:
// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <dwmapi.h>
#include <d3dx9.h>


#define W_WIDTH 300
#define W_HEIGHT 300


#pragma comment(lib, "dwmapi.lib")
#pragma comment(lib,"d3d9.lib")
#ifdef _DEBUG
  #pragma comment(lib,"d3dx9d.lib")
#else
  #pragma comment(lib,"d3dx9.lib")
#endif


#define WS_EX_LAYERED   0x00080000
#define LWA_ALPHA       0x00000002




LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;


void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void); 


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


ID3DXFont *g_font=NULL;
HRESULT hr = D3D_OK;
typedef BOOL(WINAPI *SLWA)(HWND, COLORREF, BYTE, DWORD);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
    HWND hWnd;
	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 = NULL;
    wc.lpszClassName = L"WindowClass";


    RegisterClassEx(&wc);


    hWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_COMPOSITED | WS_EX_TRANSPARENT | WS_EX_LAYERED,
						  L"WindowClass", L"Direct3D Window Test",
						  WS_POPUP,
		                  300, 300, W_WIDTH, W_HEIGHT, NULL, NULL, hInstance, NULL);
    ShowWindow(hWnd, nCmdShow);


    initD3D(hWnd);


    MSG msg;


	hr = D3DXCreateFont(d3ddev,22, 0,FW_NORMAL, 1,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"Arial",&g_font);         //ppFont


    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }


        if(msg.message == WM_QUIT)
            break;


        render_frame();
    }


    cleanD3D();


    return msg.wParam;
}




LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }


    return DefWindowProc (hWnd, message, wParam, lParam);
}


void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface


    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information


    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D


    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
	d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);


}


void render_frame(void)
{
	RECT font_rect;
	SetRect(&font_rect,0,0,W_WIDTH, W_HEIGHT);


    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);


    d3ddev->BeginScene();


	g_font->DrawText(NULL, L"My String", -1, &font_rect,DT_LEFT|DT_NOCLIP , D3DCOLOR_XRGB(255,0,0));


    d3ddev->EndScene();


    d3ddev->Present(NULL, NULL, NULL, NULL);
}




void cleanD3D(void)
{
    d3ddev->Release();
    d3d->Release();
}


---------- Post added at 08:20 PM ---------- Previous post was at 06:27 PM ----------

Never Mind.. I've found a solution...

@Jorndel, Delete/Close ?
Quote Originally Posted by MarkHC View Post
Hi I recently started learning C++ and DirectX and now Im trying to make a simple Window with a transparent background. I have managed to get ride of the borders and make it click-through-able, now I just want a invisible background. I tried pSetLayeredWindowAttributes() and SetWindowLong() but then the whole window is invisible.. I want just the background. If there's something like a line.. a string or whatever on the window, they must stay visible Is there a way to do this? My Code is on the Spoiler. I hope I've been clear enough. Thanks


 
CODE
Code:
// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <dwmapi.h>
#include <d3dx9.h>


#define W_WIDTH 300
#define W_HEIGHT 300


#pragma comment(lib, "dwmapi.lib")
#pragma comment(lib,"d3d9.lib")
#ifdef _DEBUG
  #pragma comment(lib,"d3dx9d.lib")
#else
  #pragma comment(lib,"d3dx9.lib")
#endif


#define WS_EX_LAYERED   0x00080000
#define LWA_ALPHA       0x00000002




LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;


void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void); 


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


ID3DXFont *g_font=NULL;
HRESULT hr = D3D_OK;
typedef BOOL(WINAPI *SLWA)(HWND, COLORREF, BYTE, DWORD);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
    HWND hWnd;
	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 = NULL;
    wc.lpszClassName = L"WindowClass";


    RegisterClassEx(&wc);


    hWnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_COMPOSITED | WS_EX_TRANSPARENT | WS_EX_LAYERED,
						  L"WindowClass", L"Direct3D Window Test",
						  WS_POPUP,
		                  300, 300, W_WIDTH, W_HEIGHT, NULL, NULL, hInstance, NULL);
    ShowWindow(hWnd, nCmdShow);


    initD3D(hWnd);


    MSG msg;


	hr = D3DXCreateFont(d3ddev,22, 0,FW_NORMAL, 1,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,L"Arial",&g_font);         //ppFont


    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }


        if(msg.message == WM_QUIT)
            break;


        render_frame();
    }


    cleanD3D();


    return msg.wParam;
}




LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }


    return DefWindowProc (hWnd, message, wParam, lParam);
}


void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface


    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information


    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D


    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
	d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);


}


void render_frame(void)
{
	RECT font_rect;
	SetRect(&font_rect,0,0,W_WIDTH, W_HEIGHT);


    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);


    d3ddev->BeginScene();


	g_font->DrawText(NULL, L"My String", -1, &font_rect,DT_LEFT|DT_NOCLIP , D3DCOLOR_XRGB(255,0,0));


    d3ddev->EndScene();


    d3ddev->Present(NULL, NULL, NULL, NULL);
}




void cleanD3D(void)
{
    d3ddev->Release();
    d3d->Release();
}


---------- Post added at 08:20 PM ---------- Previous post was at 06:27 PM ----------

Never Mind.. I've found a solution...

@Jorndel, Delete/Close ?
Dude, I am a CoD Minion :P
I think: @Hassan is the Programming.
And higher staffs: @Liz @Thunder @master131
Quote Originally Posted by Jorndel View Post
Dude, I am a CoD Minion :P
I Know.. But most of them are offline, I saw you were online and I though you could do it... Anyway, I'm really sorry
Posts 1–3 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us