fork download
  1. #pragma once
  2.  
  3. #include "..\..\..\Interfaces\OS\OS.h"
  4. #include "..\..\Render\Direct3D9\2D\Font.h"
  5. #include <Windows.h>
  6. #include <windowsx.h>
  7.  
  8.  
  9. namespace Wide {
  10. namespace Windows {
  11. class EditBox : public Wide::OS::EditBox {
  12. HWND box;
  13. std::unique_ptr<std::decay<decltype(*HFONT())>::type, decltype(&DeleteObject)> font;
  14. Math::AbsolutePoint curr_pos;
  15. Math::AbsolutePoint curr_dim;
  16. public:
  17. std::wstring GetText() const {
  18. std::wstring text;
  19. text.resize(Edit_GetTextLength(box) + 2);
  20. Edit_GetText(box, &text[0], text.size());
  21. return text;
  22. }
  23.  
  24. void SetText(std::wstring text) {
  25. Edit_SetText(box, text.c_str());
  26. }
  27.  
  28. Math::AbsolutePoint GetPosition() const { return curr_pos; }
  29. Math::AbsolutePoint GetDimensions() const { return curr_dim; }
  30.  
  31. void SetPosition(Math::AbsolutePoint new_pos) {
  32. curr_pos = new_pos;
  33. MoveWindow(box, curr_pos.x, curr_pos.y, curr_dim.x, curr_dim.y, false);
  34. }
  35. void SetDimensions(Math::AbsolutePoint new_dim) {
  36. curr_dim = new_dim;
  37. MoveWindow(box, curr_pos.x, curr_pos.y, curr_dim.x, curr_dim.y, false);
  38. }
  39.  
  40. void SetFont(std::shared_ptr<Render::Font> f) {
  41. font = decltype(this->font)(CreateFontIndirect(&dynamic_cast<Wide::Direct3D9::Font*>(f.get())->GetLogFont()), &DeleteObject);
  42. SendMessage(box, WM_SETFONT, reinterpret_cast<WPARAM>(font.get()), true);
  43. SendMessage(box, EM_SETMODIFY, true, 0);
  44. }
  45. EditBox(std::shared_ptr<Render::Font> font, HWND owner, Math::AbsolutePoint position, Math::AbsolutePoint dimensions, HINSTANCE hinst)
  46. : curr_pos(position), curr_dim(dimensions), font(CreateFontIndirect(&dynamic_cast<Wide::Direct3D9::Font*>(font.get())->GetLogFont()), &DeleteObject){
  47. box = CreateWindowEx(
  48. 0,
  49. L"EDIT",
  50. L"Type here",
  51. WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_LEFT,
  52. position.x,
  53. position.y,
  54. dimensions.x,
  55. dimensions.y,
  56. owner,
  57. 0,
  58. hinst,
  59. 0);
  60. /*SetWindowSubclass(box, [](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, UINT_PTR, DWORD_PTR) -> LRESULT {
  61.   if (msg != WM_PAINT)
  62.   return DefSubclassProc(hwnd, msg, wparam, lparam);
  63.   PAINTSTRUCT paint;
  64.   BeginPaint(hwnd, &paint);
  65.  
  66.   EndPaint(hwnd, &paint);
  67.   return 0;
  68.   }, 0, 0);*/
  69. // In principle, ES_LEFT should work, but it doesn't appear to actually want to work.
  70. /*PARAFORMAT f;
  71.   f.cbSize = sizeof(f);
  72.   f.dwMask = PFM_ALIGNMENT;
  73.   f.wAlignment = PFA_LEFT;
  74.   CHARRANGE range;
  75.   range.cpMin = 0;
  76.   range.cpMax = -1;
  77.   SendMessage(box, EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&range));
  78.   range.cpMax = 0;
  79.   SendMessage(box, EM_SETPARAFORMAT, 0, reinterpret_cast<LPARAM>(&f));
  80.   SendMessage(box, EM_EXSETSEL, 0, reinterpret_cast<LPARAM>(&range));*/
  81. SendMessage(box, WM_SETFONT, reinterpret_cast<WPARAM>(font.get()), true);
  82. SendMessage(box, EM_SETMODIFY, true, 0);
  83. }
  84. ~EditBox() { DestroyWindow(box); }
  85. };
  86. }
  87. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:9: warning: #pragma once in main file
prog.cpp:3:39: fatal error: ..\..\..\Interfaces\OS\OS.h: No such file or directory
compilation terminated.
stdout
Standard output is empty