To create a window without a frame, system menu and title, but with the shadow of Aero, you need to do the following:
- Create window with
WS_CAPTION style - A
DwmExtendFrameIntoClientArea WDM API call passing with a 1 pixel top margin - Handle the
WM_NCCALCSIZE message, do not divert the DefWindowProc call while processing this message, but simply return 0
Here is a simple example that creates such a window using a pure Windows API written in Delphi:
program BorderlessWindow; uses DwmApi, Winapi.UxTheme, Windows, SysUtils, Messages; {$R *.res} var Msg : TMSG; LWndClass : TWndClass; hMainHandle: HWND; lMargins: TMargins; procedure ReleaseResources; begin PostQuitMessage(0); end; function WindowProc(hWnd,Msg:Longint; wParam : WPARAM; lParam: LPARAM):Longint; stdcall; begin case Msg of WM_DESTROY: ReleaseResources; WM_NCHITTEST: Exit(HTCAPTION); // This is needed only to move window with mouse WM_NCCALCSIZE: Exit(0); // This line will hide default window border and caption end; Result:=DefWindowProc(hWnd,Msg,wParam,lParam); end; begin //create the window LWndClass.hInstance := hInstance; with LWndClass do begin lpszClassName := 'MyWinApiWnd'; Style := 0;//CS_PARENTDC or CS_BYTEALIGNCLIENT; hIcon := LoadIcon(hInstance,'MAINICON'); lpfnWndProc := @WindowProc; hbrBackground := COLOR_BTNFACE+1; hCursor := LoadCursor(0,IDC_ARROW); end; RegisterClass(LWndClass); hMainHandle := CreateWindow(LWndClass.lpszClassName,nil, WS_CAPTION or WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) div 2)-190, (GetSystemMetrics(SM_CYSCREEN) div 2)-170, 386,200,0,0,hInstance,nil); if DwmCompositionEnabled then begin // This API call adds aero shadow lMargins.cyTopHeight := 1; DwmExtendFrameIntoClientArea(hMainHandle, lMargins); end; //message loop while GetMessage(Msg,0,0,0) do begin TranslateMessage(Msg); DispatchMessage(Msg); end; end.
source share