Jump to content

Glass Window with C(WinApi)

- - - - -

  • Please log in to reply
4 replies to this topic

#1
se7en

se7en

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
Here is a source for a Glass window implemented with C(WinApi)

Posted Image

#pragma comment(lib, "dwmapi.lib")
#include <windows.h>
#include <dwmapi.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE
hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
    HBRUSH hbrush = CreateSolidBrush(RGB(0,0,0));
    MSG msg ;
    WNDCLASS wc = {0};
    wc.lpszClassName = TEXT( "stdio Glass Trial" );
    wc.hInstance = hInstance ;
    wc.hbrBackground = hbrush;
    wc.lpfnWndProc = WndProc ;
    wc.hCursor = LoadCursor(0,IDC_ARROW);
    RegisterClass(&wc);
    CreateWindow( wc.lpszClassName, TEXT("stdio Glass Trial"),
    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    200, 200, 400, 400, 0, 0, hInstance, 0);
    while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
    return (int) msg.wParam;
}
HRESULT ExtendIntoClientAll(HWND hwnd)
{
   // Negative margins have special meaning to DwmExtendFrameIntoClientArea.
   // Negative margins create the "sheet of glass" effect, where the client area
   //  is rendered as a solid surface with no window border.
   MARGINS margins = {-1};
   HRESULT hr = S_OK;

   // Extend frame across entire window.
   hr = DwmExtendFrameIntoClientArea(hwnd,&margins);
   if (SUCCEEDED(hr))
   {
      //do more things
    
   }
   return hr;
}


LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam,LPARAM lParam )
{
    
    switch(msg)
    {
        case WM_CREATE:
        {
            
            return 0;
        }
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
        case WM_PAINT:
            {
                ExtendIntoClientAll(hwnd);
                break;
            }
    }
return DefWindowProc(hwnd, msg, wParam, lParam);
}

Feel free to ask any question since it is not commented.

Edited by Alexander, 08 April 2011 - 02:45 PM.
(Moved to classes and code snippets)


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
This is very nice, do you have to define any thing extra to make it a glass window over the normal window style, or are they all default like this in newer Windows?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
se7en

se7en

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
sorry dude but I dont understand what you mean.

#4
Jrb

Jrb

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Alexander, it probably depends on what versions of windows you're on. If you're on Vista/7 and you have the Aero theme turned on, then by default it would be like that. Win XP and classic themes on Vista/7 won't appear like this.

#5
se7en

se7en

    Learning Programmer

  • Members
  • PipPipPip
  • 30 posts
oh i see, yes jrb is right.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users