Transperent



  • Wie macht man ein einfaches win_api fenster Transperent ???

    ich wuste das mal und hab auch schon mal im inet gegoogelt aber find nix !!!

    nur so superkomplizirte sachen ... ich weis das das mit 2 functionen ging die man in der "main" einfach reinbauen muss 😞

    😕 😕





  • schön hab ich ja schon aber ich will kein text oder nen bitmap transperentmachen sondern nur dieses stumpfe fenster !!!

    und über SetLayeredWindowAttributes() finde ich nix geascheites !!!

    min.5 FUNCTION KONNTEN DAS ERMÖGLICHEN !!!

    ich brauche kein ganzen code dafür 👎



  • Einmal SetLayeredWindowAttributes bei Google eingetippt und das hier kommt als erstes Ergebnis -> http://msdn2.microsoft.com/en-us/library/ms633540.aspx
    Also, wenn das nicht hilft, dann hilft gar nix. 🙄



  • so schön und gut aber jetzt will zickt meine " setLayeredWindowAttributes "

    setLayeredWindowAttributes(hwnd, 0, 255, 2);

    ICH ARBEITE MIT DEV C++ und meine fehlermeldung:

    62 C:\Dev-Cpp\main.cpp `setLayeredWindowAttributes' undeclared (first use this function)
    

    und so siht der code aus: 😞

    #include <Windows.h>
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
       setLayeredWindowAttributes(hwnd, 0, 255, 2);
    
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    
    }
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    
    BOOL SetLayeredWindowAttributes(      
        HWND hwnd,
        COLORREF crKey,
        BYTE bAlpha,
        DWORD dwFlags
    );
    

    PS: ja ich hab den linker libuser32.a drin !



  • ja meister dann such mal weiter bei google 😉

    da wirst du relativ schnell auf codeproject kommen, wo du lesen wirst, dass es keine funktions-deklaration für SetLayeredWindowAttributes gibt 😉
    also wirst du dir einen pointer zu der funktion aus der entsprechnenden USER32.DLL suchen müssen 😉

    aber weil ich mitleid mit dir und deiner inkompetenz, die sufu und google zu benutzen, hab, gebe ich dir ein paar hints...

    du brauchst folgende konstanten

    #define WS_EX_LAYERED           0x00080000
    #define LWA_COLORKEY            0x00000001
    #define LWA_ALPHA               0x00000002
    

    und zum holen der funktion

    GetModuleHandle
    

    sowie

    GetProcAddress
    

    dazu findest du garantiert etwas in der MSDN und bei google;)



  • sorry für doppel post, hab mir gerade deinen code angesehen... es sollte selbstverständlich sein, dass man funktionen definiert, BEVOR man sie aufruft, und dann auch mit richtigem Namen anspricht ... tipp: s != S



  • also ich hab das dingen jetzt mal

    #define setLayeredWindowAttributes
    

    und

    setLayeredWindowAttributes(hwnd, 0, 255,0);

    gegeben , jetzt tus der code aber es wird nicht transperent ... ps: ich bin noch anfänger hab ich vergessen zu erwähnen :p



  • Sorry, aber hast du auch Ahnung was du ueberhaupt machst?

    #define setLayeredWindowAttributes
    

    Das laesst alle Vorkommen von setLayeredWindowAttributes durch nichts ersetzen. Logisch, das da nichts passiert oder?
    Wenn du Posts auch mal (genauer) lesen wuerdest, haettest du gesehen, dass man dich schon darauf gestossen hat, dass die Funktion SetLayeredWindowAttributes und nicht setLayeredWindowAttributes heisst.



  • Verwende zuerst mal einen sinnvollen Compiler/IDE, der auch die Funktionen kennt.



  • BOOL setLayeredWindowAttributes(
    HWND hwnd,
    COLORREF crKey,
    BYTE bAlpha,
    DWORD dwFlags
    );

    FEHLER:

    5 C:\Dev-Cpp\main.cpp expected )' before "hwnd" 5 C:\\Dev-Cpp\\main.cpp expected,' or `;' before "hwnd"

    🙄 sorry das ich mich so blöd anstelle aber was jetzt ???



  • Copy&Paste 😋

    #include <windows.h>
    
    LRESULT WINAPI messageProcess(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
    	WNDCLASS windowClass = { };
    
    	windowClass.lpfnWndProc = messageProcess;
    	windowClass.hCursor = LoadCursor(0, IDC_ARROW); 
    	windowClass.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
        windowClass.lpszClassName = "Main";
    
    	RegisterClass(&windowClass);
    
    	HWND windowHandle = CreateWindowEx(WS_EX_LAYERED, "Main", "Test", WS_POPUP | WS_VISIBLE, 100, 100, 500, 500, 0, 0, 0, 0);
    
    	SetLayeredWindowAttributes(windowHandle, 0, 150, LWA_ALPHA);
    
    	MSG message = { };
    	while(GetMessage(&message, 0, 0, 0))
        {
    		TranslateMessage(&message);
    		DispatchMessage(&message);
        }
    }
    
    LRESULT WINAPI messageProcess(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam) 
    {
    	switch(message)
    	{
    	case WM_LBUTTONDOWN:
    		SendMessage(windowHandle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    	}
    
    	return DefWindowProc(windowHandle, message, wParam, lParam);
    }
    

    👍



  • komisch ey irgentiwe ist das nicht das gelbe von ei !!

    😞 😞 😞

    TUTS NICHT :

    19 C:\Dev-Cpp\main.cpp `LWA_ALPHA' undeclared (first use this function)

    19 C:\Dev-Cpp\main.cpp `SetLayeredWindowAttributes' undeclared (first use this function)

    😡 bor ey meine ****** was mach ich den falsch ????
    😞



  • pofix schrieb:

    bor ey meine ****** was mach ich den falsch ????
    😞

    ganz einfach: du liest nicht richtig bzw. liest überhaupt nicht und blendest vor deinem auge mancha posts einfach aus. ich hab dir doch bereits geschrieben, was du brauchst. wenn er LWA_ALPHA nicht kennt - dann musst du es eben selbst definieren. und diesen code habe ich dir bereits gepastet -.-
    und wenn er SetLayeredWindowAttributes nicht kennt, dann musst du entweder erstmal nen SDK update machen oder versuchen, dir die Adresse der Funktion aus der user32.dll zu holen - dazu hab ich dir bereits auch hints gegeben.
    augen auf und rtfm 😉



  • Hast du das aktuelle PSDK? Wenn nein dann siehe den ersten (angepinnten) Post hier im WinApi Forum.

    schirrmie



  • Damit wirst du etwas glücklicher:

    http://www.microsoft.com/express/download/#webInstall



  • 👍 so ich hab das teil jetzt gerade gebogen aber nun ein link error

    [Linker error] undefined reference to `SetLayeredWindowAttributes(HWND__*, unsigned long, unsigned char, unsigned long)'



  • user32.lib linken

    (langsam beginne ich TGGC immer besser zu verstehen...)



  • Hey @ll.

    Ich habe folgendes:

    HWND sendButton,
         myWnd;
    #define bmSend 1
    LPARAM lParam;
    HICON sendIcon
    
    sendButton = CreateWindowEx( WS_EX_TRANSPARENT, "BUTTON", "Senden", BS_ICON | BS_FLAT | WS_CHILD | WS_VISIBLE, 250, 245, 100, 25, myWnd, (HMENU)bmSend, ((LPCREATESTRUCT)lParam)->hInstance, NULL );
    

    Sieht ganz schön schlecht aus, also will ich nen Icon drauflegen

    if( 0 != sendButton )
        SendMessage( sendButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)sendIcon );
    

    Ist OK, aber den übergebliebenen bereich vom Button, würde ich gerne Transparent machen.

    brauche ich dazu unbedingt

    CreateWindowEx(WS_EX_LAYERED,...);
    

    denn wenn ich das dahinschreibe geht es nach dem create in die else von

    #define F04 err[3]
    
    if( 0 != sendButton )
    {
        SendMessage( sendButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)sendIcon );
        if( 0 == SetLayeredWindowAttributes( sendButton, 0, 255, 2 ) )
            printf( "%d\n", GetLastError() );
    }
    else
    {
        MessageBox( NULL, F04, appTitle, MB_ICONERROR | MB_SETFOREGROUND );
        endProg = true;
    }
    

    err[3] ist eine Fehlermeldung.

    Warum das ganze... Ich schreibe eine GUI für eine Konsolenanwendung, und die ist eigentlich fertig, aber da ich eh gerne sowas wissen würde und es ewig brauchen werde, dachte ich ich teste es an diesem Tool mal.

    Ahso,
    warum ich überhaupt poste: consolenausgabe ist "87" was "The parameter is incorrect." entspricht...
    Ich habe mir gedacht das liegt an "SetLayeredWindowAttributes" weil ich ja im CreateWindowEx nicht einen Layered style verwende ?!

    Kann mir da auch wer helfen?



  • 😃 😉 ICH HAB DES RÄTELS LÖSUNG :

    WindowTransparency (hwnd,220);
    

    !!!

    #include <Windows.h>
    
    typedef BOOL (WINAPI TRNZ)
    (
        HWND hwnd,
        COLORREF crKey,
        BYTE bAlpha,
        DWORD dwFlags
    );
    
    typedef TRNZ* TRANSPARENCY;
    
    BOOL WindowTransparency ( HWND hwnd, BYTE bAlpha )
    {
    	HINSTANCE    hCommonDLL;
    	TRANSPARENCY WndTrcy;
    
    	if ( NULL == ( hCommonDLL = LoadLibrary ( "user32.dll" ) ) )
    	{
    		return false;
    	}
    
    	WndTrcy = ( TRANSPARENCY ) GetProcAddress ( hCommonDLL, "SetLayeredWindowAttributes" );
    
    	SetWindowLong ( hwnd, (-20), 
                  GetWindowLong ( hwnd, (-20) ) | 0x80000 );
    
    	WndTrcy ( hwnd, RGB( 255, 255, 255 ), bAlpha, 2 ); 
    
    	return true;
    }
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
        WindowTransparency (hwnd,220);
    
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    
    }
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    

Anmelden zum Antworten