Advertisement
thebad_cb

Create Form

Feb 20th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 9.10 KB | None | 0 0
  1. unit CreateForm_;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows,commctrl,Messages,SysUtils,
  7.   _Form,
  8.   Def;
  9.  
  10.   Procedure BeginFM;
  11.   //Objetos
  12.   Function CreateButton  (Nome: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  13.   Function CreateEdit    (Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  14.   Function CreateMemo    (Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  15.   Function CreateLabel   (Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  16.   Function CreateCheckBox(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  17.   Function CreateGroup   (Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  18.   Function CreateComboBox(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  19.   Function CreateRadBT   (Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  20.   Function CreateProgressBar(Nome: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  21.   Function CreateTabSet     (Nome: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  22.   function CriaToolTip      (TipoIcone : Integer; Titulo : PChar) : HWND;
  23.   Procedure AdicionaToolTip (Window, ToolTip: HWND;Texto: PChar);
  24.   ///
  25.   Function CreateFonte (Fonte:PwideChar;Size : Integer): HWND;
  26.   Function CreateForm  (Caption,Classe,Fonte,FSize: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  27.   function WindowProc  (hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM):LRESULT; stdcall;
  28.   ///Funções
  29.   function  TComboBoxStrings(Handle:HWND;S: string): Integer;
  30.   function  AddTab          (sCaption: string; iIndex: Integer; wnd: HWND): boolean;
  31.   ///
  32.  
  33. implementation
  34.  
  35. uses
  36.   hooks;
  37.  
  38. function CriaToolTip(TipoIcone : Integer; Titulo : PChar) : HWND;
  39. begin
  40. // Cria a janela balão
  41.   Result := CreateWindowEx(0, 'Tooltips_Class32', nil,
  42.     TTS_ALWAYSTIP or TTS_BALLOON, Integer(CW_USEDEFAULT),
  43.     Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),
  44.     Integer(CW_USEDEFAULT), MHandle, 0, hInstance, nil);
  45. // Traz a janela para a frente
  46.   if Result <> 0 then begin
  47.     SetWindowPos(Result, HWND_TOPMOST, 0, 0, 0, 0,
  48.       SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);
  49.     // Configura o título e ícone da dica
  50.     if (TipoIcone > 3) or (TipoIcone < 0) then
  51.       TipoIcone:= 0;
  52.     SendMessage(Result, TTM_SETTITLE, TipoIcone,
  53.         Integer(Titulo));
  54.   end;
  55. end;
  56.  
  57. procedure AdicionaToolTip(Window, ToolTip: HWND;Texto: PChar);
  58. var
  59.  Rect: TRect;
  60.  ti: TToolInfo;
  61. begin
  62.   if (Window <> 0) then begin
  63.     GetClientRect(Window, Rect);
  64. // Preenche a estrutura TToolInfo
  65.     FillChar(Ti,Sizeof(TToolInfo),0);
  66.     ti.cbSize := SizeOf(TToolInfo);
  67.     ti.uFlags :=  TTF_SUBCLASS;
  68.     ti.hInst := hInstance;
  69.     ti.hwnd := Window;
  70.     ti.Rect := Rect;
  71.     ti.lpszText := Texto;
  72. // Atribui a dica
  73.     SendMessage(ToolTip, TTM_ADDTOOL, 0, Integer(@ti));
  74.   end;
  75. end;
  76.  
  77. function TComboBoxStrings(Handle:HWND; S: string): Integer;
  78. var
  79.   EmptyStr: Char;
  80.   LString: string;
  81.   LPStr: LPARAM;
  82. begin
  83.   if S = '' then
  84.   begin
  85.     EmptyStr := #0;
  86.     LPStr := LPARAM(@EmptyStr)
  87.   end
  88.   else
  89.   begin
  90.     LString := S;
  91.     UniqueString(LString);
  92.     LPStr := LPARAM(LString);
  93.   end;
  94.   Result := SendMessage(Handle, CB_ADDSTRING, 0, LPStr);
  95. end;
  96.  
  97. function AddTab(sCaption: string; iIndex: Integer; wnd: HWND): boolean;
  98. var
  99.   aTabItem : TC_ITEM;
  100. begin
  101.   with aTabItem do
  102.   begin
  103.    mask := TCIF_TEXT or TCIF_IMAGE;
  104.    iImage := -1;
  105.    pszText :=  PWideChar(sCaption);
  106.   end;
  107.   Result := SendMessage(wnd, TCM_INSERTITEM, iIndex, Integer(@aTabItem)) <> -1;
  108. end;
  109.  
  110. procedure ReleaseResources;
  111. Var
  112. I: INTEGER;
  113. begin
  114.  for I := 0 to 50 do
  115.  begin
  116.   DestroyWindow(TButton[I]);
  117.   DestroyWindow(TLabel[I]);
  118.   DestroyWindow(TEdit[I]);
  119.  end;
  120.   DeleteObject(hFontText);
  121.   DeleteObject(hFontButton);
  122.   PostQuitMessage(0);
  123.   ExitProcess(0);
  124. end;
  125.  
  126. Function CreateButton(Nome: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  127. begin
  128.    Result:= CreateWindow('Button',Nome, WS_VISIBLE or WS_CHILD or BS_PUSHBUTTON or BS_TEXT, X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  129.    SendMessage(Result,WM_SETFONT,hFontButton,0);
  130. end;
  131.  
  132. Function CreateProgressBar(Nome: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  133. begin
  134.    Result:= CreateWindow('msctls_progress32', Nome, WS_CHILD or WS_VISIBLE, X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  135.    SendMessage(Result,WM_SETFONT,hFontButton,0);
  136. end;
  137.  
  138. Function CreateTabSet(Nome: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  139. var
  140.   aRect : TRect;
  141.   myFont : HWND;
  142. begin
  143.    Result := CreateWindow(WC_TABCONTROL, Nome,WS_CHILD or WS_CLIPSIBLINGS or WS_VISIBLE,X, Y, Altura, Altura,MHandle,0,hInstance,nil);
  144.   if (Result <> 0) then
  145.   begin
  146.     AddTab(Nome, 0, Result);
  147.     AddTab(Nome, 1, Result);
  148.     AddTab(Nome, 2, Result);
  149.   end;
  150.    SendMessage(Result,WM_SETFONT,hFontButton,0);
  151. end;
  152.  
  153. Function CreateLabel(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  154. begin
  155.    Result:= CreateWindow('Static',Text, WS_VISIBLE or WS_CHILD or SS_LEFT, X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  156.    SendMessage(Result,WM_SETFONT,hFontText,0);
  157. end;
  158.  
  159. Function CreateEdit(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  160. begin
  161.    Result:= CreateWindowEx(WS_EX_CLIENTEDGE,'Edit',Text, WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  162.    SendMessage(Result,WM_SETFONT,hFontText,0);
  163. end;
  164.  
  165. Function CreateMemo(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  166. begin
  167.    Result:= CreateWindowEx(WS_EX_CLIENTEDGE,'Edit',Text,WS_CHILD OR WS_VISIBLE OR ES_AUTOHSCROLL OR ES_NOHIDESEL OR ES_MULTILINE,X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  168.    SendMessage(Result,WM_SETFONT,hFontText,0);
  169. end;
  170.  
  171. Function CreateCheckBox(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  172. begin
  173.   Result:=  CreateWindowEx(0, 'Button', Text, WS_CHILD or WS_VISIBLE or BS_AUTOCHECKBOX, X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  174.   SendMessage(Result,WM_SETFONT,hFontText,0);
  175. end;
  176.  
  177. Function CreateGroup(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  178. begin
  179.   Result:=  CreateWindowEx(0, 'Button', Text, WS_CHILD or WS_VISIBLE or WS_CLIPCHILDREN or BS_GROUPBOX, X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  180.   SendMessage(Result,WM_SETFONT,hFontText,0);
  181. end;
  182.  
  183. Function CreateRadBT(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  184. begin
  185.   Result:=  CreateWindowEx(0, 'Button','Byte', WS_CHILD or WS_VISIBLE or BS_AUTORADIOBUTTON or BS_FLAT , X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  186.   SendMessage(Result,WM_SETFONT,hFontText,0);
  187. end;
  188.  
  189. Function CreateComboBox(Text: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  190. begin
  191.   Result:= CreateWindowEx(0,'COMBOBOX',Text,WS_VISIBLE or WS_CHILD or CBS_AUTOHSCROLL OR CBS_DROPDOWNLIST OR CBS_HASSTRINGS OR CBS_SORT OR CBS_UPPERCASE, X,Y,Altura,Largura,MHandle,0,hInstance,nil);
  192.   SendMessage(Result,WM_SETFONT,hFontText,0);
  193. end;
  194.  
  195. Function CreateForm(Caption,Classe,Fonte,FSize: PwideChar; X, Y, Altura,Largura : Integer): HWND;
  196. begin
  197.   TClass.hInstance := hInstance;
  198.   with TClass do
  199.     begin
  200.       lpszClassName := Classe;
  201.       Style         := CS_PARENTDC or CS_BYTEALIGNCLIENT;
  202.       hIcon         := LoadIcon(0, IDI_APPLICATION);
  203.       lpfnWndProc   := @WindowProc;
  204.       hbrBackground := COLOR_BTNFACE+1;
  205.       hCursor       := LoadCursor(0,IDC_ARROW);
  206.     end;
  207.   RegisterClass(TClass);
  208.   Result := CreateWindow(TClass.lpszClassName,Caption, WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE, X, Y, Altura,Largura,0,0,hInstance,nil);
  209.   hFontText   := CreateFonte(Fonte,StrToInt(FSize));
  210.   hFontButton := CreateFonte(Fonte,StrToInt(FSize));
  211.   SetWindowPos(Result, HWND_TOPMOST, X, Y, Altura, Largura, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
  212. end;
  213.  
  214. Function CreateFonte(Fonte:PwideChar;Size : Integer): HWND;
  215. begin
  216.  Result:= CreateFont(Size*2-1,     // Height
  217.     Size*2-10,                     // Width
  218.     0,                             // Angle of Rotation
  219.     0,                             // Orientation
  220.     0,                             // Weight
  221.     0,                             // Italic
  222.     0,                             // Underline
  223.     0,                             // Strike Out
  224.     DEFAULT_CHARSET,               // Char Set
  225.     OUT_DEFAULT_PRECIS,            // Precision
  226.     CLIP_DEFAULT_PRECIS,           // Clipping
  227.     DEFAULT_QUALITY,               // Render Quality
  228.     DEFAULT_PITCH or FF_DONTCARE,  // Pitch & FamilyFonte);
  229.     Fonte);
  230. end;
  231.  
  232. function WindowProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM):LRESULT; stdcall;
  233. Var
  234. Text : PwideChar;
  235. begin
  236.   case uMsg of
  237.   WM_COMMAND: CMD(lParam);   //controle
  238.  
  239.   end;
  240.   Result:=DefWindowProc(hWnd,uMsg,wParam,lParam);
  241. end;
  242.  
  243. Procedure BeginFM;
  244. begin
  245.   MHandle    := CreateForm('Polaris','BAD','Tahoma','8',125,125,253,168);
  246.  
  247.  TEdit[0]   := CreateEdit('',88,20,129,21);
  248.   TEdit[1]   := CreateEdit('100',16,96,49,21);
  249.   TButton[0] := CreateButton('NAME',8,8,65,33);
  250.   TButton[1] := CreateButton('NAME1',88,84,49,33);
  251.   TButton[2] := CreateButton('NAME2',168,84,49,33);
  252.   TCB[3]   := CreateCheckBox('NAME3',16,72,57,17);
  253.   TCB[7]   := CreateCheckBox('NAME4',16,48,57,17);
  254.  
  255.  
  256.     while GetMessage(Msg,0,0,0) do
  257.   begin
  258.     TranslateMessage(Msg);
  259.     DispatchMessage(Msg);
  260.   end;
  261. end;
  262.  
  263.  
  264. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement