1

I have tried this:

#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;

        case WM_DESTROY:
            PostQuitMessage(0);
        break;

        case WM_SIZE:
        case WM_MOVE:
        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            BeginPaint(hwnd, &ps);
            EndPaint(hwnd, &ps);
            return 0;
        }

        case WM_CTLCOLORSTATIC:
        {
            HDC hdc = (HDC) wParam; 
            SetBkMode (hdc, TRANSPARENT);
            return (LRESULT)(GetStockObject(NULL_BRUSH));
        }

        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int main()
{
    WNDCLASSEX wc;
    MSG Msg;

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = NULL;
    wc.hIcon         = NULL;
    wc.hCursor       = NULL;
    wc.hbrBackground = (HBRUSH)(GetStockObject(NULL_BRUSH));
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = L"MY CLASS";
    wc.hIconSm       = NULL;

    RegisterClassEx(&wc);

    HWND hwnd = CreateWindowEx(0, L"MY CLASS", NULL, WS_VISIBLE, 0, 0, 640, 480, NULL, NULL, NULL, NULL);
    HWND child = CreateWindowEx(0, L"STATIC", L"Text", WS_VISIBLE | WS_CHILD , 50, 50, 50, 50, hwnd, NULL, NULL, NULL);

    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return 0;
}

It creates window, which looks transparent, because it shows the same as on screen, however after moving window main window background stays the same. I want to ask, where the problem may be.

P.S. it is just test code, so, please, do not write advices not suited with my question.

Thanks.

EDIT: I want this because I'm going to make some helpers for users who don't know how to do some stuff. Result should be something like regular some program view with come spots marked, what means press here, when here, after that here and etc.

alk
  • 69,737
  • 10
  • 105
  • 255
ST3
  • 8,826
  • 3
  • 68
  • 92
  • 1
    "Transparent" is the wrong name here. It does not overwrite the original screen, that's all. Windows doesn't know that, so when moving your window, it merely moves what's on the screen. You will have to trigger a redraw for every move (and keep in mind that *all* underlying data needs to be redrawn, even that in different programs). – Jongware Sep 07 '13 at 20:41
  • What exactly are you trying to achieve by creating 'fully transparent window with not transparent content'? If you want to handle mouse/keyboard events in other windows you can use [hooks](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990.aspx). If you want really transparent window, use [regions](http://msdn.microsoft.com/en-us/library/windows/desktop/dd145102.aspx) or [color key](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633540.aspx) – nevermind Sep 07 '13 at 21:02
  • @nevermind I've made an edit to explain, why I need this. – ST3 Sep 07 '13 at 21:09
  • In this case I would just create separate 'tooltip' windows for each annotation and position them near controls in real application. You can use `SetWindowRgn` function to make custom-shaped windows (with beacons, arrows, etc.). If you want your annotations on a static image (not on real application), you can make a screenshot of otherapplication to in-memory bitmap and paint it (on WM_PAINT) with annotations inside your window – nevermind Sep 07 '13 at 21:34

1 Answers1

3

I think you start point should be with taking a look on Layered Windows

http://msdn.microsoft.com/en-us/library/ms997507.aspx

it is most common way for playing with custom shape and (semi)transparent windows.

UPD. There is also old API for making custom shaped windows:

int SetWindowRgn( HWND hWnd, HRGN hRgn, BOOL bRedraw );
vasylz
  • 177
  • 1
  • 4