delphi 窗体创建

//-----------------------方式一

procedure Tfomr1.Excute_Form();
begin
    with Tfomr1.Create(Application) do
    begin
      try
        Init;
        ShowModal;
      finally
        Free;
      end;
    end
end;

 

//-------------------------------方式二

unit UMydany;

interface

uses
  System.SysUtils, Vcl.Dialogs;
 

type
  TMydany = class
    class function THIS: TMydany;
  private
  public
    constructor Create();
    destructor Destroy(); override;
    procedure f1();
  end;

implementation

var
  _Mydany: TMydany;

constructor TMydany.Create;
begin
  //
end;

destructor TMydany.Destroy;
begin

  inherited;
end;

procedure TMydany.f1;
begin
  showmessage('11');
end;

class function TMydany.THIS: TMydany;
begin
  Result := _Mydany;
end;

initialization
begin
  _Mydany := TMydany.Create();
end;

finalization
begin
  if Assigned(_Mydany) then
    FreeAndNil(_Mydany);
end;

end.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
program Hackdiy; uses Windows, Messages; var TheMessage: TMsg; const ClassName = 'MainForm_FOrm1'; // 窗体过程回调函数 function FormProc(hForm, MsgID, WParam, LParam: LongWord): LongWord; stdcall; const {$J+} TempFont: DWORD = 0; {$J-} ControlID1 = 1; ControlID2 = 2; ControlID3 = 3; var EditText: array[0..30] of Char; begin Result := DefWindowProc(hForm, MsgID, WParam, LParam); // 标准处理 case MsgID of WM_CREATE: begin TempFont := CreateFont(12, 6, 0, 0, FW_EXTRALIGHT, Byte(FALSE), Byte(FALSE), Byte(FALSE), GB2312_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, '宋体'); CreateWindowEx(0, 'BUTTON', '退出程序', WS_CHILD or WS_VISIBLE, 60, 20, 70, 25, hForm, ControlID2, HInstance, nil); SendMessage(GetDlgItem(hForm, ControlID2), WM_SETFONT, TempFont, 1); end; WM_COMMAND: begin if (HIWORD(wParam) = BN_CLICKED) then // 单击按钮 begin case LOWORD(wParam) of // 控件ID ControlID1: begin end; ControlID2: SendMessage(hForm, WM_CLOSE, 0, 0); end; end; end; WM_DESTROY: begin PostQuitMessage(0); DeleteObject(TempFont); end; end; end; // 注册窗体类 procedure Register_MainForm; var FormClass: TWndClass; begin FormClass.Style := CS_HREDRAW or CS_VREDRAW; FormClass.lpfnWndProc := @FormProc; FormClass.cbClsExtra := 0; FormClass.cbWndExtra := 0; FormClass.hInstance := SysInit.HInstance; FormClass.hIcon := LoadIcon(HInstance, 'Cool'); FormClass.hCursor := LoadCursor(0, IDC_ARROW); FormClass.hbrBackground := COLOR_WINDOW; FormClass.lpszMenuName := nil; FormClass.lpszClassName := ClassName; RegisterClass(FormClass); end; // 注销窗体类 procedure Unregister_MainForm; begin UnregisterClass(ClassName, HInstance); end; // 建立主窗体 procedure Create_MainForm; begin CreateWindowEx(WS_EX_TOPMOST, ClassName, 'Form1', WS_VISIBLE or WS_TILED or WS_SYSMENU or WS_MINIMIZEBOX or WS_SIZEBOX, 200, 200, 200, 100, 0, 0, HInstance, nil); end; begin Register_MainForm; Create_MainForm; while GetMessage(TheMessage, 0, 0, 0) do begin TranslateMessage(TheMessage); DisPatchMessage(TheMessage); end; end.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值