SHARE
TWEET

Untitled

HemulGM Jan 15th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program Plain2;
  2.  
  3. uses
  4.   Windows,
  5.   Messages;
  6.  
  7. const
  8.   id_Button = 100;
  9.  
  10. function PlainWinProc (hWnd: THandle; nMsg: UINT;
  11.   wParam, lParam: Cardinal): Cardinal; export; stdcall;
  12. var
  13.   Rect: TRect;
  14. begin
  15.   Result := 0;
  16.   case nMsg of
  17.     wm_Create:
  18.       // create button
  19.       CreateWindowEx (0, // extended styles
  20.         'BUTTON', // predefined class
  21.         '&Click here', // caption
  22.         ws_Child or ws_Visible or ws_Border
  23.           or bs_PushButton, // styles
  24.         0, 0, // position: see wm_Size
  25.         200, 80, // size
  26.         hwnd, // parent
  27.         id_Button, // identifier (not a menu handle)
  28.         hInstance, // application id
  29.         nil); // init info pointer
  30.     wm_Size:
  31.     begin
  32.       // get the size of the client window
  33.       GetClientRect (hWnd, Rect);
  34.       // move the button window
  35.       SetWindowPos (
  36.         GetDlgItem (hWnd, id_Button), // button handle
  37.         0, // zOrder
  38.         Rect.Right div 2 - 100,
  39.         Rect.Bottom div 2 - 40,
  40.         0, 0, // new size
  41.         swp_NoZOrder or swp_NoSize);
  42.     end;
  43.     wm_Command:
  44.       // if it comes from the button
  45.       if LoWord (wParam) = id_Button then
  46.         // if it is a click
  47.         if HiWord (wParam) = bn_Clicked then
  48.           MessageBox (hWnd, 'Button Clicked',
  49.             'Plain API 2', MB_OK);
  50.     wm_Destroy:
  51.       PostQuitMessage (0);
  52.     else
  53.       Result := DefWindowProc (hWnd, nMsg, wParam, lParam);
  54.   end;
  55. end;
  56.  
  57. procedure WinMain;
  58. var
  59.   hWnd: THandle;
  60.   Msg: TMsg;
  61.   WndClassEx: TWndClassEx;
  62. begin
  63.   // initialize the window class structure
  64.   WndClassEx.cbSize := sizeOf (TWndClassEx);
  65.   WndClassEx.lpszClassName := 'PlainWindow';
  66.   WndClassEx.style := cs_VRedraw or cs_HRedraw;
  67.   WndClassEx.hInstance := HInstance;
  68.   WndClassEx.lpfnWndProc := @PlainWinProc;
  69.   WndClassEx.cbClsExtra := 0;
  70.   WndClassEx.cbWndExtra := 0;
  71.   WndClassEx.hIcon := LoadIcon (hInstance,
  72.     MakeIntResource ('MAINICON'));
  73.   WndClassEx.hIconSm  := LoadIcon (hInstance,
  74.     MakeIntResource ('MAINICON'));
  75.   WndClassEx.hCursor := LoadCursor (0, idc_Arrow);;
  76.   WndClassEx.hbrBackground := GetStockObject (white_Brush);
  77.   WndClassEx.lpszMenuName := nil;
  78.   // register the class
  79.   if RegisterClassEx (WndClassEx) = 0 then
  80.     MessageBox (0, 'Invalid class registration',
  81.       'Plain API', MB_OK)
  82.   else
  83.   begin
  84.     hWnd := CreateWindowEx (
  85.       ws_Ex_OverlappedWindow, // extended styles
  86.       WndClassEx.lpszClassName, // class name
  87.       'Plain API Demo', // title
  88.       ws_OverlappedWindow, // styles
  89.       cw_UseDefault, 0, // position
  90.       cw_UseDefault, 0, // size
  91.       0, // parent window
  92.       0, // menu
  93.       HInstance, // instance handle
  94.       nil); // initial parameters
  95.     if hWnd = 0 then
  96.       MessageBox (0, 'Window not created',
  97.         'Plain API', MB_OK)
  98.     else
  99.     begin
  100.       ShowWindow (hWnd, sw_ShowNormal);
  101.       while GetMessage (Msg, 0, 0, 0) do
  102.       begin
  103.         TranslateMessage (Msg);
  104.         DispatchMessage (Msg);
  105.       end;
  106.     end;
  107.   end;
  108. end;
  109.  
  110. begin
  111.   WinMain;
  112. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top