Lazarus

Programming => General => Topic started by: creatxr on April 18, 2019, 03:37:20 pm

Title: how to draw a window or control base on "zero"
Post by: creatxr on April 18, 2019, 03:37:20 pm
is here someone read the source of lazarus or free pascal?

i want to know how to draw a window or control from a "zero" depends?

is it use the api of native sdk ?

or, it use the very low-level draw functions, as "line to", "move to" etc ?

thanks
Title: Re: how to draw a window or control base on "zero"
Post by: lucamar on April 18, 2019, 04:23:05 pm
Maybe I'm misunderstanding you but, what's wrong with SetBounds() or setting Left, Top, Width and/or Height?
Title: Re: how to draw a window or control base on "zero"
Post by: tr_escape on April 18, 2019, 04:28:50 pm
For windows:

Note: It is working without lazarus sandbox!

https://www.swissdelphicenter.ch/en/showcode.php?id=411
 (https://www.swissdelphicenter.ch/en/showcode.php?id=411)

Code: Pascal  [Select]
  1.  
  2. program Project1;
  3. uses
  4.   windows, messages;
  5.  
  6. {$mode objfpc}{$H+}
  7.  
  8. // Main Window Procedure
  9.  
  10. function MainWndProc(hWindow: HWND; Msg: UINT; wParam: wParam;
  11.   lParam: lParam): LRESULT; stdcall; export;
  12. var
  13.   ps: TPaintStruct;
  14. begin
  15.   Result := 0;
  16.   case Msg of
  17.     WM_PAINT:
  18.       begin
  19.         BeginPaint(hWindow, ps);
  20.         SetBkMode(ps.hdc, TRANSPARENT);
  21.         TextOut(ps.hdc, 10, 10, 'Hello, World!', 13);
  22.         EndPaint(hWindow, ps);
  23.       end;
  24.     WM_DESTROY: PostQuitMessage(0);
  25.     else
  26.       begin
  27.         Result := DefWindowProc(hWindow, Msg, wParam, lParam);
  28.         Exit;
  29.       end;
  30.   end;
  31. end;
  32.  
  33. // Main Procedure
  34.  
  35. var
  36.   wc: TWndClass;
  37.   hWindow: HWND;
  38.   Msg: TMsg;
  39. begin
  40.   wc.lpszClassName := 'YourAppClass';
  41.   wc.lpfnWndProc   := @MainWndProc;
  42.   wc.Style         := CS_VREDRAW or CS_HREDRAW;
  43.   wc.hInstance     := hInstance;
  44.   wc.hIcon         := LoadIcon(0, IDI_APPLICATION);
  45.   wc.hCursor       := LoadCursor(0, IDC_ARROW);
  46.   wc.hbrBackground := (COLOR_WINDOW + 1);
  47.   wc.lpszMenuName  := nil;
  48.   wc.cbClsExtra    := 0;
  49.   wc.cbWndExtra    := 0;
  50.   RegisterClass(wc);
  51.   hWindow := CreateWindowEx(WS_EX_CONTROLPARENT or WS_EX_WINDOWEDGE,
  52.     'YourAppClass',
  53.     'API',
  54.     WS_VISIBLE or WS_CLIPSIBLINGS or
  55.     WS_CLIPCHILDREN or WS_OVERLAPPEDWINDOW,
  56.     CW_USEDEFAULT, 0,
  57.     400, 300,
  58.     0,
  59.     0,
  60.     hInstance,
  61.     nil);
  62.  
  63.   ShowWindow(hWindow, CmdShow);
  64.   UpDateWindow(hWindow);
  65.  
  66.   while GetMessage(Msg, 0, 0, 0) do
  67.   begin
  68.     TranslateMessage(Msg);
  69.     DispatchMessage(Msg);
  70.   end;
  71.   Halt(Msg.wParam);
  72. end.
  73.  
  74.  



Untested:

https://stackoverflow.com/questions/10180016/creating-forms-without-using-vcl (https://stackoverflow.com/questions/10180016/creating-forms-without-using-vcl)
Title: Re: how to draw a window or control base on "zero"
Post by: creatxr on April 18, 2019, 05:28:10 pm
not that.

i want to find a idea to implement :

let video card to draw all the visible things, do not use cpu's Instructions.

it's means that to use hardware acceleration possible for the visible controls.

to give only a form design (e.g. .frm files) ,
Title: Re: how to draw a window or control base on "zero"
Post by: lucamar on April 18, 2019, 06:18:49 pm
let video card to draw all the visible things, do not use cpu's Instructions.

it's means that to use hardware acceleration possible for the visible controls.

to give only a form design (e.g. .frm files) ,

I think you should leave that to the OS and the video drivers. Games do that by using quite complex libraries (OpenGL, GLScene, etc.) which make it more easy at the cost of adding heavy dependencies to the application. For normal programs it is overkill. IMHO, of course.
Title: Re: how to draw a window or control base on "zero"
Post by: LemonParty on April 18, 2019, 06:48:44 pm
CPU can draw things faster then GPU in case when this things isn't a supercomplex 3d stuff, because:
But if you want to draw some unique interface in 3d then your choice have to be OpenGL component.
Title: Re: how to draw a window or control base on "zero"
Post by: 440bx on April 18, 2019, 07:03:35 pm
i want to find a idea to implement :

let video card to draw all the visible things, do not use cpu's Instructions.

it's means that to use hardware acceleration possible for the visible controls.

to give only a form design (e.g. .frm files) ,
For a window that uses any of the Windows "facilities" (caption, menus, borders, controls, bitmaps, anything that is Windows specific, etc), not really.  Windows already implements those features using GPU instructions (when possible and depending on the version of Windows).

If you take full control of the screen (as many/most games do) then Windows will, for the most part, stay out of your way.  Once you do that, forget "normal" windows and controls.  You have to do everything.