program NoFrameworkAppDemo; {$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF FPC} uses SysUtils, Windows, Messages; // If you want a program icon or use graphics, create this .res file. // {$R NoFrameworkAppDemo.res} function SHFullScreen(hwndRequester: hWnd; dwState: DWord): WINBOOL; external UserDLLAyg name 'SHFullScreen'; function SHSetNavBarText(hwndRequester: hWnd;pszText: PWideChar): WINBOOL; external UserDLLAyg name 'SHSetNavBarText'; const SHFS_SHOWTASKBAR = $01; SHFS_HIDETASKBAR = $02; SHFS_SHOWSIPBUTTON = $04; SHFS_HIDESIPBUTTON = $08; SHFS_SHOWSTARTICON = $10; SHFS_HIDESTARTICON = $20; type TWndMessageProc = function(hWnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LongInt; stdcall; var FWindowHandle: THandle; FLabelHandle: THandle; FButtonQuitHandle, FButtonTestHandle: THandle; function WndMessageProc(hWnd: HWND; Msg: UINT; wParam: wPARAM; lParam: LPARAM): LongInt; stdcall; var lw,hw: Word; begin Result := 0; case Msg of WM_CREATE: ; // add code to be run when window gets created here WM_DESTROY: PostQuitMessage(0); WM_ACTIVATE: ; // add code to be run whenever window gets activated here WM_CLOSE: ; // add code to be run when window gets closed here WM_NOTIFY: ; // Handle stuff like treeview selections here WM_SETTINGCHANGE: ; // common settings have been changed WM_NCCALCSIZE: ; // you should react to screen rotations or resizes here WM_COMMAND: begin lw := Lo(wParam); hw := Hi(wParam); if (lw=IDOK) or (lw=IDCLOSE) then PostQuitMessage(0); if (lParam=FButtonQuitHandle) then PostQuitMessage(0) else if (lParam=FButtonTestHandle) then SetWindowText(FLabelHandle, 'Hello FreePascal World!');; end; end; Result := DefWindowProc(hWnd,Msg,wParam,lParam); end; var msgMain: TMSG; FWindowClass: TWndClass; FClassName, FWindowTitle: WideString; dwStyle, dwExStyle: DWord; rectWindow: TRect; mbiMain: SHMenuBarInfo; shidi: SHINITDLGINFO; begin // Create main window FClassName := 'mytestappwindow'; FWindowTitle := 'My test app'; FWindowClass.hInstance := hInstance; with FWindowClass do begin style := 0; hIcon := LoadIcon(hInstance,'MAINICON'); lpfnWndProc := TWndMessageProc(@WndMessageProc); hbrBackground := COLOR_BTNFACE; lpszClassName := PWideChar(FClassName); cbClsExtra := 0; cbWndExtra := 0; {$IFDEF Win32} hCursor := LoadCursor(0,IDC_ARROW); lpszMenuName := ''; {$ENDIF Win32} end; RegisterClass(FWindowClass); dwStyle := WS_VISIBLE or WS_MAXIMIZE or WS_SYSMENU; dwExStyle := WS_EX_NODRAG or WS_EX_NOANIMATION or WS_EX_CAPTIONOKBTN; FWindowHandle := CreateWindowEx(dwExStyle, FWindowClass.lpszClassName, PWideChar(FWindowTitle), dwStyle, Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), 0, 0, hInstance, nil); if FWindowHandle = 0 then begin MessageBox(0, 'Could not create test app window!', 'Test app', MB_OK); UnRegisterClass(FWindowClass.lpszClassName, hInstance); Exit; end; // Create a menu to fill FillChar(mbiMain,SizeOf(mbiMain),Byte(0)); with mbiMain do begin cbSize := SizeOf(mbiMain); hwndParent := FWindowHandle; dwFlags := SHCMBF_EMPTYBAR; nToolBarID := 0; hInstRes := hInstance; nBmpId := 0; cBmpImages := 0; clrBk := 0; end; SHCreateMenuBar(@mbiMain); shidi.hDlg := FWindowHandle; shidi.dwMask := SHIDIM_FLAGS; shidi.dwFlags := SHIDIF_SIZEDLGFULLSCREEN or SHIDIF_DONEBUTTON; SHInitDialog(@shidi); SHFullScreen(FWindowHandle, SHFS_SHOWTASKBAR or SHFS_SHOWSIPBUTTON or SHFS_SHOWSTARTICON); SHSetNavBarText(FWindowHandle, PWideChar(FWindowTitle)); ShowWindow(FWindowHandle, SW_SHOW); UpdateWindow(FWindowHandle); GetWindowRect(FWindowHandle,@rectWindow); // Create some controls FLabelHandle := CreateWindow('STATIC', 'Hello World!', WS_VISIBLE or WS_CHILD or SS_NOTIFY or CS_CLASSDC, 4, 4, rectWindow.Right-8, 20, FWindowHandle, 0, hInstance, nil); FButtonTestHandle := CreateWindow('BUTTON', 'Test', WS_VISIBLE or WS_CHILD or WS_TABSTOP or BS_PUSHBUTTON or BS_TEXT, 4, 24, (rectWindow.Right div 2)-8, 23, FWindowHandle, 0, hInstance, nil); FButtonQuitHandle := CreateWindow('BUTTON', 'Quit', WS_VISIBLE or WS_CHILD or WS_TABSTOP or BS_PUSHBUTTON or BS_TEXT, (rectWindow.Right div 2)+4, 24, (rectWindow.Right div 2)-8, 23, FWindowHandle, 0, hInstance, nil); // Now enter main event loop while GetMessage(@msgMain,0,0,0) do begin TranslateMessage(@msgMain); DispatchMessage(@msgMain); end; end.