Transparenter Hintergrund



  • Ich habe ein kleines Programm mit Hilfe des Internets geschrieben.

    Das Programm malt immer dort wo ich mit der Maus hin klicke ein Kreuz.
    Das funktioniert auch so wie es soll.
    Allerdings hätte ich es gerne das der Hintergrund des Fenster Transparent ist und ich den Desktop sehen kann.
    In Zeile 25 steht im Moment die WHITE_BRUSH, hier habe ich schon so mach anderes ausprobiert allerdings nicht mit dem gewünschten Ergebnis.
    Google bringt mich da auch irgendwie im Moment nicht weiter.
    Hat wer einen Tipp oder eine Lösung für mich?

    Danke für eure Hilfe!!:)

    MFG

    Prime

    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	PSTR szCmdLine, int iCmdShow)
    
    {
    	HWND         hWnd;
    	MSG          msg;
    	WNDCLASS     wc;
    
    	char         szAppName[] = "U+S";
    
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hInstance = hInstance;
    	wc.lpfnWndProc = WndProc;
    	wc.lpszClassName = szAppName;
    	wc.lpszMenuName = NULL;
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    
    	RegisterClass(&wc);
    
    	hWnd = 	CreateWindow(szAppName,
    		szAppName,
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		1920,
    		1080,
    
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
    
    	ShowWindow(hWnd, iCmdShow);
    	UpdateWindow(hWnd);
    
    	while (GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    
    {
    
    	static POINT    point;
    	static RECT     rect;
    	static HWND hButton;
    	static HWND hButton1;
    
    	switch (message)
    	{
    
    	case WM_CREATE:
    	{
    		hButton = CreateWindow("button",
    			"Disable",
    			WS_CHILD | WS_VISIBLE,
    			0, 0, 0, 0,
    			hWnd,
    			NULL,
    			((LPCREATESTRUCT)lParam)->hInstance,
    			NULL);
    		hButton1 = CreateWindow("button",
    			"Enable",
    			WS_CHILD | WS_VISIBLE,
    			0, 0, 0, 0,
    			hWnd,
    			NULL,
    			((LPCREATESTRUCT)lParam)->hInstance,
    			NULL);
    		point.x = -1;
    		point.y = -1;
    		return 0;
    	}
    
    	case WM_SIZE:
    	{
    
    		MoveWindow(hButton, LOWORD(lParam) / 2 - 80, HIWORD(lParam) - 30,
    			160, 22, TRUE);
    		MoveWindow(hButton1, LOWORD(lParam) / 2 + 120, HIWORD(lParam) - 30,
    			160, 22, TRUE);
    		return 0;
    	}
    
    		//BILD einfügen
    
    	case WM_DESTROY:
    	{
    		PostQuitMessage(0);
    		return 0;
    	}
    	case WM_RBUTTONDOWN:
    	{
    		InvalidateRect(hWnd, NULL, TRUE);
    		return 0;
    	}
    
    	case WM_LBUTTONDOWN:
    	{
    		InvalidateRect(hWnd, NULL, TRUE);
    
    		HDC  hDC = GetDC(hWnd);
    		SetPixel(hDC, LOWORD(lParam), HIWORD(lParam), RGB(255, 0, 0));
    		ReleaseDC(hWnd, hDC);
    		point.x = LOWORD(lParam);  
    		point.y = HIWORD(lParam);
    		return 0;
    	}
    	case WM_LBUTTONUP:
    	{
    		if (point.x != -1)
    		{
    			HDC   hDC = GetDC(hWnd);
    			MoveToEx(hDC, point.x, point.y, NULL);
    			LineTo(hDC, rect.right / 2 + 1920, point.y);
    			MoveToEx(hDC, point.x, point.y, NULL);
    			LineTo(hDC, rect.right / 2 + 0, point.y);
    
    			MoveToEx(hDC, point.x, point.y, NULL);
    			LineTo(hDC, point.x , rect.right / 2 + 1500);
    			MoveToEx(hDC, point.x, point.y, NULL);
    			LineTo(hDC,point.x, rect.right / 2 + 0);
    
    			/*MoveToEx(hDC, rect.right / 2 + 1920, rect.bottom / 2 + 550, NULL);
    			LineTo(hDC, rect.right / 2 + 0, rect.bottom / 2 + 550);
    			MoveToEx(hDC, rect.right / 2 + 1024, rect.bottom / 2 + 0, NULL);
    			LineTo(hDC, rect.right / 2 + 1024, rect.bottom / 2 + 1080);*/
    			ReleaseDC(hWnd, hDC);
    
    			point.x = -1;
    			point.y = -1;
    		}
    
    		return 0;
    	}
    	}
    
    	return DefWindowProc(hWnd, message, wParam, lParam);
    }
    


  • Dieser Thread wurde von Moderator/in Arcoth aus dem Forum C++ (alle ISO-Standards) in das Forum WinAPI verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • Schau mal hier: http://stackoverflow.com/a/3970218
    Dort wurde die Frage schon beantwortet.



  • Das hatte ich schon gefunden. Kam damit leider absolut nicht klar.

    Allerdings soweit ich das verstanden habe mache ich damit das ganze Fenster transparent und nicht nur den Hintergrund.

    Bin blutiger Anfänger!
    Kann mir das wer erläutern.

    Danke



  • Keiner der mir Helfen kann?



  • Den Tip mit Layered Windows hast du ja schon bekommen.
    Ist leider nicht ganz easy. Dummerweise ist es der einzige Weg den ich kenne wie man sowas machen kann.

    Entweder du kämpfst dich da durch, oder du suchst dir ne andere, einfachere Schlacht aus.

    Ich glaub' nicht dass es jemand für dich implementieren wird, nur weil ihm gerade langweilig ist.

    In kurz was du machen musst:

    1. Den Style WS_EX_LAYERED setzen
    2. UpdateLayeredWindow mit ULW_ALPHA aufrufen um einzustellen welche Bereiche des Fensters transparent sind und welche nicht.

    (2) musst du jedes mal wiederholen wenn ein neues Kreuzchen dazugekommen ist - bzw. sich sonstwie geändert hat was in dem Fenster zu sehen ist.




Anmelden zum Antworten