Delphi World - это проект, являющийся сборником статей и малодокументированных возможностей  по программированию в среде Delphi. Здесь вы найдёте работы по следующим категориям: delphi, delfi, borland, bds, дельфи, делфи, дэльфи, дэлфи, programming, example, программирование, исходные коды, code, исходники, source, sources, сорцы, сорсы, soft, programs, программы, and, how, delphiworld, базы данных, графика, игры, интернет, сети, компоненты, классы, мультимедиа, ос, железо, программа, интерфейс, рабочий стол, синтаксис, технологии, файловая система...
Создание формы и кнопки на чистом API


Разговаривают в троллейбусе два студента-хаккера:
- У меня вчера вечером мать сдохла. Я с ней всю ночь протрахался, а она так и не ожила...
Старушка по соседству:
- ВО ИЗВЕРГИ!!!


program Plain2;

uses
  Windows,
  Messages;

const
  id_Button = 100;

function PlainWinProc (hWnd: THandle; nMsg: UINT;
  wParam, lParam: Cardinal): Cardinal; export; stdcall;
var
  Rect: TRect;
begin
  Result := 0;
  case nMsg of
    wm_Create:
      // create button
      CreateWindowEx (0, // extended styles
        'BUTTON', // predefined class
        '&Click here', // caption
        ws_Child or ws_Visible or ws_Border
          or bs_PushButton, // styles
        0, 0, // position: see wm_Size
        200, 80, // size
        hwnd, // parent
        id_Button, // identifier (not a menu handle)
        hInstance, // application id
        nil); // init info pointer
    wm_Size:
    begin
      // get the size of the client window
      GetClientRect (hWnd, Rect);
      // move the button window
      SetWindowPos (
        GetDlgItem (hWnd, id_Button), // button handle
        0, // zOrder
        Rect.Right div 2 - 100,
        Rect.Bottom div 2 - 40,
        0, 0, // new size
        swp_NoZOrder or swp_NoSize);
    end;
    wm_Command:
      // if it comes from the button
      if LoWord (wParam) = id_Button then
        // if it is a click
        if HiWord (wParam) = bn_Clicked then
          MessageBox (hWnd, 'Button Clicked',
            'Plain API 2', MB_OK);
    wm_Destroy:
      PostQuitMessage (0);
    else
      Result := DefWindowProc (hWnd, nMsg, wParam, lParam);
  end;
end;

procedure WinMain;
var
  hWnd: THandle;
  Msg: TMsg;
  WndClassEx: TWndClassEx;
begin
  // initialize the window class structure
  WndClassEx.cbSize := sizeOf (TWndClassEx);
  WndClassEx.lpszClassName := 'PlainWindow';
  WndClassEx.style := cs_VRedraw or cs_HRedraw;
  WndClassEx.hInstance := HInstance;
  WndClassEx.lpfnWndProc := @PlainWinProc;
  WndClassEx.cbClsExtra := 0;
  WndClassEx.cbWndExtra := 0;
  WndClassEx.hIcon := LoadIcon (hInstance,
    MakeIntResource ('MAINICON'));
  WndClassEx.hIconSm  := LoadIcon (hInstance,
    MakeIntResource ('MAINICON'));
  WndClassEx.hCursor := LoadCursor (0, idc_Arrow);;
  WndClassEx.hbrBackground := GetStockObject (white_Brush);
  WndClassEx.lpszMenuName := nil;
  // register the class
  if RegisterClassEx (WndClassEx) = 0 then
    MessageBox (0, 'Invalid class registration',
      'Plain API', MB_OK)
  else
  begin
    hWnd := CreateWindowEx (
      ws_Ex_OverlappedWindow, // extended styles
      WndClassEx.lpszClassName, // class name
      'Plain API Demo', // title
      ws_OverlappedWindow, // styles
      cw_UseDefault, 0, // position
      cw_UseDefault, 0, // size
      0, // parent window
      0, // menu
      HInstance, // instance handle
      nil); // initial parameters
    if hWnd = 0 then
      MessageBox (0, 'Window not created',
        'Plain API', MB_OK)
    else
    begin
      ShowWindow (hWnd, sw_ShowNormal);
      while GetMessage (Msg, 0, 0, 0) do
      begin
        TranslateMessage (Msg);
        DispatchMessage (Msg);
      end;
    end;
  end;
end;

begin
  WinMain;
end.

Загрузить исходный код проекта

Проект Delphi World © Выпуск 2002 - 2024
Автор проекта: USU Software
Вы можете выкупить этот проект.