Create a native window out of VCL

Source: Internet
Author: User

Program project1;

Uses
Windows,
Messages;

{Waiting for calling, used to draw text on the form}
Procedure onpaint (H: HDC );
Const
S = 'hello, world ';
Begin
Textout (H, 10, 10, pchar (s), length (s ));
End;

{Window callback process}
Function wndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer): integer; stdcall;
VaR
Handle: HDC;
PS: paintstruct;
Begin
Case MSG
Wm_paint: Begin
Handle: = beginpaint (WND, PS );
Onpaint (handle );
Endpaint (WND, PS );
Result: = 0;
End;
Wm_destroy: Begin
Postquitmessage (0 );
Result: = 0;
End;
Else
Result: = defwindowproc (WND, MSG, wparam, lparam );
End;
End;

{Main program}
VaR
Hwnd: thandle;
MSG: tmsg;
Mywndclass: twndclass;
Begin
Mywndclass. Style: = cs_hredraw or cs_vredraw;
Mywndclass. lpfnwndproc: = @ wndproc;
Mywndclass. cbclsextra: = 0;
Mywndclass. cbwndextra: = 0;
Mywndclass. hinstance: = hinstance;
Mywndclass. hicon: = loadicon (0, idi_question );
Mywndclass. hcursor: = loadcursor (0, idc_arrow );
Mywndclass. hbrbackground: = hbrush (getstockobject (white_brush ));
Mywndclass. lpszmenuname: = nil;
Mywndclass. lpszclassname: = 'mywindowclass ';

Registerclass (mywndclass );

Hwnd: = createwindow ('mywindowclass', 'This is the window title', ws_overlappedwindow,
100,100,250,150, 0, 0, hinstance, nil );

Showwindow (hwnd, sw_shownormal );
Updatewindow (hwnd );

While (getmessage (MSG, 0, 0, 0) do
Begin
Translatemessage (MSG );
Dispatchmessage (MSG );
End;
End.
You can directly complete the console program. You can also use a project without window.

------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.