Guest User

text editor sample

a guest
Apr 18th, 2026
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.02 KB | Source Code | 0 0
  1. pragma(lib, "user32.lib");
  2. pragma(lib, "gdi32.lib");
  3.  
  4. import core.sys.windows.windows;
  5. import std.string;
  6. import std.conv;
  7.  
  8. __gshared HWND hEdit;
  9.  
  10. enum ID_EDIT = 101;
  11.  
  12. extern(Windows) nothrow
  13. LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  14. {
  15.     switch (msg)
  16.     {
  17.         case WM_CREATE:
  18.         {
  19.             hEdit = CreateWindowEx(
  20.                 0,
  21.                 "EDIT",
  22.                 null,
  23.                 WS_CHILD | WS_VISIBLE |
  24.                 WS_VSCROLL | WS_HSCROLL |
  25.                 ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
  26.                 0, 0, 500, 400,
  27.                 hwnd,
  28.                 cast(HMENU) ID_EDIT,
  29.                 GetModuleHandle(null),
  30.                 null
  31.             );
  32.             return 0;
  33.         }
  34.  
  35.         case WM_SIZE:
  36.         {
  37.             int width = LOWORD(lParam);
  38.             int height = HIWORD(lParam);
  39.  
  40.             MoveWindow(hEdit, 0, 0, width, height, TRUE);
  41.             return 0;
  42.         }
  43.  
  44.         case WM_DESTROY:
  45.         {
  46.             PostQuitMessage(0);
  47.             return 0;
  48.         }
  49.  
  50.         default:
  51.             return DefWindowProc(hwnd, msg, wParam, lParam);
  52.     }
  53. }
  54.  
  55. void main()
  56. {
  57.     HINSTANCE hInstance = GetModuleHandle(null);
  58.  
  59.     WNDCLASS wc;
  60.     wc.style = CS_HREDRAW | CS_VREDRAW;
  61.     wc.lpfnWndProc = &WndProc;
  62.     wc.hInstance = hInstance;
  63.     wc.hCursor = LoadCursor(null, IDC_ARROW);
  64.     wc.hbrBackground = cast(HBRUSH)(COLOR_WINDOW + 1);
  65.     wc.lpszClassName = "DTextEditor";
  66.  
  67.     RegisterClass(&wc);
  68.  
  69.     HWND hwnd = CreateWindowEx(
  70.         0,
  71.         "DTextEditor",
  72.         "Mini Text Editor - D + Win32",
  73.         WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  74.         CW_USEDEFAULT,
  75.         CW_USEDEFAULT,
  76.         800,
  77.         600,
  78.         null,
  79.         null,
  80.         hInstance,
  81.         null
  82.     );
  83.  
  84.     ShowWindow(hwnd, SW_SHOW);
  85.     UpdateWindow(hwnd);
  86.  
  87.     MSG msg;
  88.     while (GetMessage(&msg, null, 0, 0))
  89.     {
  90.         TranslateMessage(&msg);
  91.         DispatchMessage(&msg);
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment