Sign in to follow this  

How do i overlay text and images over all programs/desktop?

This topic is 4695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm developing a voice comms program, and am interested in displaying information relative to whose speaking ontop of all program surface of a computer in the easiest way possible. One possibility i read was just setting a forms opacity to 0, and gdi drawing on that form...i have yet to test this. After some googling i found the following example :http://www.angelcode.com/dev/overlay/, and was wondering if their were any other good ones the people of this forum might of collected over time.

Share this post


Link to post
Share on other sites
There is a fairly easy/complicated way of doing this that works really great, however it doesn't likely go ontop of exclusive DirectX applications... but nothing does that as far I as know...

And that is in XP (and perhaps 2000) there is functionality for setting transparency and more advanced properties to a window... one is also colorkeying... if this is done correctly, you can even make it overlay-like, meaning that it cannot be clicked on... all clicks go through.

And by having an external listening DLL you can make it stay on-top of top-most windows too.

If you are interested I might have some old code for this.

Share this post


Link to post
Share on other sites
OK, I admin this code is crappy as hell, but... I wrote like 3-4 years ago and it wasn't meant for anything :)

Well here you have the code, should be more or less working with a little tinkering.

Code for the main window, color-keying and transparency is used. (I believe there is an some mistake in this code that makes the caption etc appear at sometimes, think it is easily fixed)

MSG msg;
WNDCLASS wcClass;

wcClass.style = CS_OWNDC;
wcClass.lpfnWndProc = WindowProc;
wcClass.cbClsExtra = 0;
wcClass.cbWndExtra = 0;
wcClass.hInstance = hInstance;
wcClass.hIcon = NULL;
wcClass.hCursor = NULL;
wcClass.hbrBackground = CreateSolidBrush(lngBackground);
wcClass.lpszMenuName = NULL;
wcClass.lpszClassName = APP_CLASSNAME;

if(!RegisterClass(&wcClass)) { MessageBox(NULL, "Unable to construct the help window.\r\nError: RegisterClass()", "dsf", MB_OK | MB_ICONERROR | MB_TASKMODAL); _exit(FALSE); }

// WS_EX_NOACTIVATE is not needed but migth solve some problems
// WS_EX_TOOLWINDOW is only for improved support with some virtual workspaces
if(!(wndWindow = CreateWindowEx(WS_EX_TRANSPARENT, APP_CLASSNAME, NULL, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL))) MessageBox(NULL,"Umm, fel","",0);

// Select colors for the rectangle function
SelectObject(hdcWindow, GetStockObject(DC_BRUSH));
SelectObject(hdcWindow, GetStockObject(DC_PEN));
SetDCBrushColor(hdcWindow, lngBackground);
SetDCPenColor(hdcWindow, lngBackground);

// Remove any default WS styles, e.g. the caption
SetWindowLong(wndWindow, GWL_STYLE, 0);

// Setup window position and hook to match specifications
if(intZOrder == ZORDER_DESKTOP) {
SetWindowPos(wndWindow, HWND_BOTTOM, 900, 0, intSizeX, intSizeY, SWP_NOACTIVATE | SWP_NOCOPYBITS);
}
else if ((intZOrder == ZORDER_TOPMOST) || (intZOrder == ZORDER_OVERLAY)) {
SetWindowPos(wndWindow, HWND_TOPMOST, 900, 0, intSizeX, intSizeY, SWP_NOACTIVATE | SWP_NOCOPYBITS);

// Attach the hook DLL to monitor window positioning
if(intZOrder == ZORDER_OVERLAY) {
if(!(hHookDLL = LoadLibrary("HookDLL.dll"))) MessageBox(NULL,"Umm, fel","",0);
if(!(hHookProc = (HOOKPROC)GetProcAddress(hHookDLL, "CallWndProc"))) MessageBox(NULL,"Umm, fel","",0);
if(!(hHook = SetWindowsHookEx(WH_CALLWNDPROC, hHookProc, hHookDLL, 0))) MessageBox(NULL,"Umm, fel","",0);
}
}


// Set proper window attributes for layered window
DWORD dwLayeredStyle = 0;

// Activate alpha if alpha value is inside bounds
if(intAlpha > 0 && intAlpha < 255)
dwLayeredStyle |= LWA_ALPHA;

// Activate transparent window if clear value is valid
if(lngBackground >= 0)
dwLayeredStyle |= LWA_COLORKEY;

if(!(SetLayeredWindowAttributes(wndWindow, lngBackground, (INT)intAlpha, dwLayeredStyle))) MessageBox(NULL,"Umm, fel","",0);

// Make the window visible, but do not activate (caption bug)
ShowWindow(wndWindow, SW_SHOWNOACTIVATE);

// Wait until this instance has been closed
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}



This is the code for the DLL (optional, but makes sure no top-most window gets on top of ours)

HWND wndWindow;

BOOL WINAPI DllMain(HINSTANCE hDllInst, DWORD dwReason, LPVOID lpvReserved)
{
switch(dwReason) {
case DLL_PROCESS_ATTACH:
// Search for the main window, terminate otherwise
if(!(wndWindow = FindWindow(APP_CLASSNAME, NULL)))
return FALSE;
break;

case DLL_PROCESS_DETACH:
break;

case DLL_THREAD_ATTACH:
break;

case DLL_THREAD_DETACH:
break;
}

return TRUE;
}

LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Extract real parameter structure
PCWPSTRUCT sParam;
sParam = (PCWPSTRUCT)lParam;

// Make sure we recieved a set of valid arguments
if(sParam)
{
switch(sParam->message)
{
case WM_WINDOWPOSCHANGED:
// Do not check the main window or we'll create an infinite loop
if(sParam->hwnd == wndWindow)
break;

// Collect information about the new window position
LPWINDOWPOS winPosition;
winPosition = (LPWINDOWPOS)sParam->lParam;

// If the window hasn't been put on top we don't need to reposition
if((winPosition->hwndInsertAfter != HWND_TOP) && (winPosition->hwndInsertAfter != HWND_TOPMOST))
break;

//case WM_INITMENUPOPUP:
//case WM_CREATE:

// Tell the application to go on top of all windows
PostMessage(wndWindow, WM_REPOSITION, NULL, NULL);
break;
}
}

// CallNextHookEx does not need the hhk argument
return CallNextHookEx(NULL, nCode, wParam, lParam);
}

Share this post


Link to post
Share on other sites

This topic is 4695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this