Sumber Kode

Create a form with Windows API.

  • delphibasics
  • Nov 19' 14
  • Delphi
  • 38
  • 281
  • United States
Not using VCL results in a smaller executable file size. Therefore, it may be required to create a form using only Windows API calls. It is possible to add functionality to the form; this will be discussed in a later snippet.

program Project1;

uses
  
windows, messages;

// Main Window Procedure
function MainWndProc(hWindow: HWND; Msg: UINT; wParam: wParam;
  lParam: lParam): LRESULT; stdcallexport;
var
  
ps: TPaintStruct;
begin
  
Result := 0;
  case Msg of
    
WM_PAINT:
      begin
        
BeginPaint(hWindow, ps);
        SetBkMode(ps.hdc, TRANSPARENT);
        TextOut(ps.hdc, 10, 10, 'Hello, World!', 13);
        EndPaint(hWindow, ps);
      end;
    WM_DESTROY: PostQuitMessage(0);
    else
      begin
        
Result := DefWindowProc(hWindow, Msg, wParam, lParam);
        Exit;
      end;
  end;
end;

// Main Procedure
var
  
wc: TWndClass;
  hWindow: HWND;
  Msg: TMsg;
begin
  
wc.lpszClassName := 'YourAppClass';
  wc.lpfnWndProc   := @MainWndProc;
  wc.Style         := CS_VREDRAW or CS_HREDRAW;
  wc.hInstance     := hInstance;
  wc.hIcon         := LoadIcon(0, IDI_APPLICATION);
  wc.hCursor       := LoadCursor(0, IDC_ARROW);
  wc.hbrBackground := (COLOR_WINDOW + 1);
  wc.lpszMenuName  := nil;
  wc.cbClsExtra    := 0;
  wc.cbWndExtra    := 0;
  RegisterClass(wc);
  hWindow := CreateWindowEx(WS_EX_CONTROLPARENT or WS_EX_WINDOWEDGE,
    'YourAppClass',
    'API',
    WS_VISIBLE or WS_CLIPSIBLINGS or
    
WS_CLIPCHILDREN or WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, 0,
    400, 300,
    0,
    0,
    hInstance,
    nil);

  ShowWindow(hWindow, CmdShow);
  UpDateWindow(hWindow);

//Prevents the application from closing.
  while GetMessage(Msg, 0, 0, 0) do
  begin
    
TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;
  Halt(Msg.wParam);
end.
Powered by
Pasar Kode Partner

Share

  • Tags :
comments powered by Disqus

Kode Terkait

Drag and Drop

Retreive default browser path

Create a functioning form with Windows API.

HHUtils 1.0 - A collection of useful delphi functions.

Screen Capture with Pure Windows API

Programmatically talk using Microsoft Sam

Modify TEdit to include text alignment

Delphi RC4 Encryption Source Code

Update PE CheckSum

Enumerate Processes using Native Windows API



Kategori