2 window questions

This is a discussion on 2 window questions within the Windows Programming forums, part of the Platform Specific Boards category; Hi! How to change the transparency of a window? and How to make a window stay allways on top? thanx ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    363

    Question 2 window questions

    Hi!

    How to change the transparency of a window?
    and
    How to make a window stay allways on top?

    thanx for any help.
    Last edited by geek@02; 01-23-2007 at 06:47 AM.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  2. #2
    Registered User simguy's Avatar
    Join Date
    Jan 2007
    Location
    Dallas-Ft Worth, TX
    Posts
    10
    Here's some code from Visual C++ 6.0 that works:
    Code:
    BOOL CFullScrDlgDlg::OnInitDialog()
    {
        CDialog::OnInitDialog();
    
        //...
    
        int cx, cy; 
        HDC dc = ::GetDC(NULL); 
        cx = GetDeviceCaps(dc,HORZRES) + 
            GetSystemMetrics(SM_CXBORDER); 
        cy = GetDeviceCaps(dc,VERTRES) +
            GetSystemMetrics(SM_CYBORDER); 
        ::ReleaseDC(0,dc); 
    
        // Remove caption and border
        SetWindowLong(m_hWnd, GWL_STYLE, 
            GetWindowLong(m_hWnd, GWL_STYLE) & 
        (~(WS_CAPTION | WS_BORDER))); 
    
        // Put window on top and expand it to fill screen
        ::SetWindowPos(m_hWnd, HWND_TOPMOST, 
            -(GetSystemMetrics(SM_CXBORDER)+1), 
            -(GetSystemMetrics(SM_CYBORDER)+1), 
            cx+1,cy+1, SWP_NOZORDER); 
    
        //...
    
        return TRUE; 
    }
    This removes the window border (makes it immovable) and expands to fill up the entire screen. Hope this might help you.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    simguy, That is certainly not what he's looking for.

    To change the transparency of the window, it must have WS_EX_LAYERED extended style. You can add this style to to your CreateWindowEx's first parameter or you could do this:
    Code:
    SetWindowLong(hwnd,GWL_EXSTYLE,GetWindowLong(hwnd,GWL_EXSTYLE)|WS_EX_LAYERED);
    Now you can change it's transparency using SetLayeredWindowAttributes:
    Code:
    SetLayeredWindowAttributes(hwnd,0,150,LWA_ALPHA);
    150 is the transparency, which may be anything from 0 (totally transparent) to 255 (opaque).

    There are multiple ways to make your window stay on top. You can use the window extended style WS_EX_TOPMOST or you can do it with:
    Code:
    SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_NOMOVE);
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    363
    Thx max for the examples and thx anyways simguy for the post.
    However, my compiler doesn't recognize SetLayeredWindowAttributes() function or WS_EX_LAYERED style - must be my rather old sdk (2003). Is there another way to do it by any chance?
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    You can replace WS_EX_LAYERED with 0x80000 and you can import SetLayeredWindowAttributes something like this:
    Code:
    //at the beginning of the file...
    typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);
    PSLWA SetLayeredWindowAttributes;
    //in WinMain, before creating the window
    HMODULE hDLL = LoadLibrary ("user32");
    SetLayeredWindowAttributes=(PSLWA)GetProcAddress(hDLL,"SetLayeredWindowAttributes");
    And then you should be able to use SetLayeredWindowAttributes(). I am not sure if it works, I can't test it at the moment.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by geek@02
    However, my compiler doesn't recognize SetLayeredWindowAttributes() function or WS_EX_LAYERED style - must be my rather old sdk (2003)
    Your should update your psdk to a more recent version but that isn't the issue here. Note that SetLayeredWindowAttributes requires a minimum operating system of windows 2000 so, you must define _WIN32_WINNT to a suitable value in order for code which uses it to compile - see Using the Windows Headers for details.

    The approach described by maxorator gives an opportunity, with suitable checks, for the program using such code to sidestep the absence of SetLayeredWindowAttributes in user32.dll on pre-win2k systems.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 04:36 PM
  4. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21