Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Test.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5#include "StdAfx.h"
6
7#include <windows.h>
8
9#include "Resource.h"
10
12
13#include "Stroika/Frameworks/Led/Command.h"
14#include "Stroika/Frameworks/Led/Platform/Windows.h"
15#include "Stroika/Frameworks/Led/SimpleLed.h"
16#include "Stroika/Frameworks/Led/SimpleTextStore.h"
17#include "Stroika/Frameworks/Led/WordProcessor.h"
18
19#include "Test.h"
20
21using namespace Stroika::Foundation;
22using namespace Stroika::Frameworks;
23using namespace Stroika::Frameworks::Led;
24using namespace Stroika::Frameworks::Led::Platform;
25
26#define qBuildWP 1
27
28#if qBuildWP
29typedef SimpleLedWordProcessor _BASE_;
30#else
31typedef SimpleLedLineEditor _BASE_;
32#endif
33
34DISABLE_COMPILER_MSC_WARNING_START (4250) // inherits via dominance warning
35class MyLedWindow : public _BASE_ {
36private:
37 typedef _BASE_ inherited;
38
39public:
40 virtual LRESULT WndProc (UINT message, WPARAM wParam, LPARAM lParam) override;
41
42public:
43 MyLedWindow ()
44 : inherited ()
45 {
46 SetScrollBarType (h, eScrollBarAsNeeded);
47 SetScrollBarType (v, eScrollBarAlways);
48 }
49 virtual void OnNCDestroy_Msg () override;
50};
51DISABLE_COMPILER_MSC_WARNING_END (4250) // inherits via dominance warning
52
53void MyLedWindow::OnNCDestroy_Msg ()
54{
55 inherited::OnNCDestroy_Msg ();
56 delete this;
57}
58
59#define MAX_LOADSTRING 100
60
61// Global Variables:
62HINSTANCE hInst; // current instance
63TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
64TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
65
66inline const void* LoadAppResource (HINSTANCE hIntstance, long resID, LPCTSTR resType)
67{
68 HRSRC hrsrc = ::FindResource (hIntstance, MAKEINTRESOURCE (resID), resType);
69 AssertNotNull (hrsrc);
70 HGLOBAL hglobal = ::LoadResource (hIntstance, hrsrc);
71 AssertNotNull (hglobal);
72 const void* lockedData = ::LockResource (hglobal);
73 AssertNotNull (lockedData);
74 return (lockedData);
75}
76
77// Foward declarations of functions included in this code module:
78ATOM MyRegisterClass (HINSTANCE hInstance);
79BOOL InitInstance (HINSTANCE, int);
80LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
81LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
82
83int APIENTRY wWinMain (HINSTANCE hInstance, [[maybe_unused]] HINSTANCE hPrevInstance, [[maybe_unused]] LPTSTR lpCmdLine, int nCmdShow)
84{
85#if CRTDBG_MAP_ALLOC
86 _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
87#endif
88
89 // Initialize global strings
90 LoadString (hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
91 LoadString (hInstance, IDC_LEDTESTWIN32, szWindowClass, MAX_LOADSTRING);
92 MyRegisterClass (hInstance);
93
94 StandardUnknownTypeStyleMarker::sUnknownPict = (const Led_DIB*)LoadAppResource (hInstance, kUnknownEmbeddingPictID, RT_BITMAP);
95
96 // Perform application initialization:
97 if (!InitInstance (hInstance, nCmdShow)) {
98 return FALSE;
99 }
100
101 // Main message loop:
102 HACCEL hAccelTable = LoadAccelerators (hInstance, (LPCTSTR)IDC_LEDTESTWIN32);
103 MSG msg;
104 while (GetMessage (&msg, NULL, 0, 0)) {
105 if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg)) {
106 TranslateMessage (&msg);
107 DispatchMessage (&msg);
108 }
109 }
110
111 return static_cast<int> (msg.wParam);
112}
113
114//
115// FUNCTION: MyRegisterClass()
116//
117// PURPOSE: Registers the window class.
118//
119// COMMENTS:
120//
121// This function and its usage is only necessary if you want this code
122// to be compatible with Win32 systems prior to the 'RegisterClassEx'
123// function that was added to Windows 95. It is important to call this function
124// so that the application will get 'well formed' small icons associated
125// with it.
126//
127ATOM MyRegisterClass (HINSTANCE hInstance)
128{
129 WNDCLASSEX wcex;
130
131 wcex.cbSize = sizeof (WNDCLASSEX);
132
133 wcex.style = CS_HREDRAW | CS_VREDRAW;
134 wcex.lpfnWndProc = (WNDPROC)MyLedWindow::StaticWndProc;
135 wcex.cbClsExtra = 0;
136 wcex.cbWndExtra = 0;
137 wcex.hInstance = hInstance;
138 wcex.hIcon = LoadIcon (hInstance, (LPCTSTR)IDI_LEDTESTWIN32);
139 wcex.hCursor = LoadCursor (NULL, IDC_ARROW);
140 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
141 wcex.lpszMenuName = (LPCTSTR)IDC_LEDTESTWIN32;
142 wcex.lpszClassName = szWindowClass;
143 wcex.hIconSm = LoadIcon (wcex.hInstance, (LPCTSTR)IDI_SMALL);
144
145 return RegisterClassEx (&wcex);
146}
147
148//
149// FUNCTION: InitInstance(HANDLE, int)
150//
151// PURPOSE: Saves instance handle and creates main window
152//
153// COMMENTS:
154//
155// In this function, we save the instance handle in a global variable and
156// create and display the main program window.
157//
158BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
159{
160 hInst = hInstance; // Store instance handle in our global variable
161
162 MyLedWindow* myWindow = new MyLedWindow ();
163 myWindow->Create (szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance);
164 HWND hWnd = myWindow->GetHWND ();
165
166 ShowWindow (hWnd, nCmdShow);
167 UpdateWindow (hWnd);
168
169 return TRUE;
170}
171
172LRESULT MyLedWindow::WndProc (UINT message, WPARAM wParam, LPARAM lParam)
173{
174 switch (message) {
175 case WM_COMMAND: {
176 int wmId = LOWORD (wParam);
177 [[maybe_unused]] int wmEvent = HIWORD (wParam);
178 HWND hWnd = GetHWND ();
179 // Parse the menu selections:
180 switch (wmId) {
181 case IDM_ABOUT:
182 DialogBox (hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
183 break;
184 case IDM_EXIT:
185 DestroyWindow (hWnd);
186 break;
187 case ID_EDIT_UNDO: {
188 if (GetCommandHandler ()->CanUndo ())
189 OnUndoCommand ();
190 else
191 Led_BeepNotify ();
192 } break;
193 case ID_EDIT_REDO: {
194 if (GetCommandHandler ()->CanRedo ())
195 OnRedoCommand ();
196 else
197 Led_BeepNotify ();
198 } break;
199 case ID_EDIT_CUT:
200 OnCutCommand ();
201 break;
202 case ID_EDIT_COPY:
203 OnCopyCommand ();
204 break;
205 case ID_EDIT_PASTE:
206 OnPasteCommand ();
207 break;
208 case ID_EDIT_CLEAR:
209 OnClearCommand ();
210 break;
211 case ID_EDIT_SELECT_ALL:
212 OnSelectAllCommand ();
213 break;
214 default:
215 return DefWindowProc (message, wParam, lParam);
216 }
217 } break;
218
219 case WM_DESTROY:
220 PostQuitMessage (0);
221 break;
222
223 default:
224 return inherited::WndProc (message, wParam, lParam);
225 }
226 return 0;
227}
228
229// Mesage handler for about box.
230LRESULT CALLBACK About (HWND hDlg, UINT message, WPARAM wParam, [[maybe_unused]] LPARAM lParam)
231{
232 switch (message) {
233 case WM_INITDIALOG:
234 return TRUE;
235
236 case WM_COMMAND:
237 if (LOWORD (wParam) == IDOK || LOWORD (wParam) == IDCANCEL) {
238 EndDialog (hDlg, LOWORD (wParam));
239 return TRUE;
240 }
241 break;
242 }
243 return FALSE;
244}
#define AssertNotNull(p)
Definition Assertions.h:333