如何创建没有透明内容的完全透明的窗口? [英] How to create fully transparent window which has not transparent content?

查看:591
本文介绍了如何创建没有透明内容的完全透明的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个:

  #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));
}

默认值:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}

int main()
{
WNDCLASSEX wc;
MSG Msg; $ b¥b
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 = LMY CLASS;
wc.hIconSm = NULL;

RegisterClassEx(& wc);

HWND hwnd = CreateWindowEx(0,LMY CLASS,NULL,WS_VISIBLE,0,0,640,480,NULL,NULL,NULL,NULL)
HWND child = CreateWindowEx(0,LSTATIC,LText,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;
}

它创建窗口,看起来透明,因为它显示与屏幕上相同,但是在移动窗口后主窗口背景保持不变。我想问问题可能在哪里。





感谢。

p> EDIT:我想要这个,因为我会为不知道如何做一些东西的用户做一些帮助。结果应该像常规的一些程序视图,带有标记的点,什么意思在这里,在这里,之后,在这里等。

解决方案

我认为你的起点应该是在分层Windows上查看



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



它是使用自定义形状和(半)透明窗口的最常见的方式。



UPD。还有用于制作自定义窗口的旧API:

  int SetWindowRgn(HWND hWnd,HRGN hRgn,BOOL bRedraw); 


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.

解决方案

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 );

这篇关于如何创建没有透明内容的完全透明的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆