Guest User

Untitled

a guest
Jan 9th, 2025
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.72 KB | None | 0 0
  1. #define _WIN32_IE 0x0600
  2. #include <windows.h>
  3. #include <commctrl.h>
  4.  
  5. #pragma comment(lib, "comctl32.lib")
  6. #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  7.  
  8. #define WM_MODAL_CLOSED (WM_USER + 1)
  9.  
  10. // Control identifiers
  11. #define IDC_BUTTON_ADD_NEW_PRODUCT 101
  12. #define IDC_BUTTON_ADD_NEW_ENTRIES 102
  13. #define IDC_BUTTON_MODIFY 103
  14. #define IDC_BUTTON_SELL 104
  15. #define IDC_BUTTON_CALCULATE 105
  16. #define IDC_BUTTON_DELETE 106
  17. #define IDC_LISTVIEW 107
  18. #define IDC_TABCONTROL 108
  19. #define IDC_EDIT_SEARCH 109
  20. #define IDC_STATIC_SEARCH 110
  21.  
  22. // Control identifiers "Add new product"
  23. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_CODE 111
  24. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_DESCRIPTION 112
  25. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_INITIAL_STOCK 113
  26. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_PRICE 114
  27. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_RETAIL_PRICE 115
  28. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR_LABEL 116
  29. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE_LABEL 117
  30. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL_LABEL 118
  31.  
  32. #define IDC_EDIT_MODAL_ADDNEWPRODUCT_CODE 119
  33. #define IDC_EDIT_MODAL_ADDNEWPRODUCT_DESCRIPTION 120
  34. #define IDC_EDIT_MODAL_ADDNEWPRODUCT_INITIAL_STOCK 121
  35. #define IDC_EDIT_MODAL_ADDNEWPRODUCT_PRICE 122
  36. #define IDC_EDIT_MODAL_ADDNEWPRODUCT_RETAIL_PRICE 123
  37. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR 124
  38. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE 125
  39. #define IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL 126
  40. #define IDC__MODAL_ADDNEWPRODUCT_BUTTON_ACCEPT 127
  41. #define IDC__MODAL_ADDNEWPRODUCT_BUTTON_CANCEL 128
  42.  
  43. // Control identifiers "Add new entries"
  44. #define IDC_STATIC_MODAL_ADDNEWENTRIES_CODE 129
  45. #define IDC_STATIC_MODAL_ADDNEWENTRIES_DESCRIPTION 130
  46. #define IDC_STATIC_MODAL_ADDNEWENTRIES_CURRENT_STOCK 132
  47. #define IDC_STATIC_MODAL_ADDNEWENTRIES_NEW_ENTRIES 133
  48.  
  49. #define IDC_STATIC_MODAL_ADDNEWENTRIES2_CODE 134
  50. #define IDC_STATIC_MODAL_ADDNEWENTRIES2_DESCRIPTION 135
  51. #define IDC_STATIC_MODAL_ADDNEWENTRIES2_CURRENT_STOCK 137
  52. #define IDC_EDIT_MODAL_ADDNEWENTRIES_NEW_ENTRIES 138
  53.  
  54. #define IDC__MODAL_ADDNEWENTRIES_BUTTON_ACCEPT 139
  55. #define IDC__MODAL_ADDNEWENTRIES_BUTTON_CANCEL 140
  56.  
  57. // Control identifiers "Modify Product"
  58. #define IDC_STATIC_MODAL_MODIFYPRODUCT_CODE 141
  59. #define IDC_STATIC_MODAL_MODIFYPRODUCT_DESCRIPTION 142
  60. #define IDC_STATIC_MODAL_MODIFYPRODUCT_INITIAL_STOCK 143
  61. #define IDC_STATIC_MODAL_MODIFYPRODUCT_CURRENT_STOCK 144
  62. #define IDC_STATIC_MODAL_MODIFYPRODUCT_NEW_ENTRIES 145
  63. #define IDC_STATIC_MODAL_MODIFYPRODUCT_SALES 146
  64. #define IDC_STATIC_MODAL_MODIFYPRODUCT_PRICE 147
  65. #define IDC_STATIC_MODAL_MODIFYPRODUCT_RETAIL_PRICE 148
  66. #define IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR_LABEL 149
  67. #define IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE_LABEL 150
  68. #define IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL_LABEL 151
  69.  
  70. #define IDC_EDIT_MODAL_MODIFYPRODUCT_CODE 152
  71. #define IDC_EDIT_MODAL_MODIFYPRODUCT_DESCRIPTION 153
  72. #define IDC_EDIT_MODAL_MODIFYPRODUCT_INITIAL_STOCK 154
  73. #define IDC_EDIT_MODAL_MODIFYPRODUCT_CURRENT_STOCK 155
  74. #define IDC_EDIT_MODAL_MODIFYPRODUCT_NEW_ENTRIES 156
  75. #define IDC_EDIT_MODAL_MODIFYPRODUCT_SALES 157
  76. #define IDC_EDIT_MODAL_MODIFYPRODUCT_PRICE 158
  77. #define IDC_EDIT_MODAL_MODIFYPRODUCT_RETAIL_PRICE 159
  78. #define IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR 160
  79. #define IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE 161
  80. #define IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL 162
  81. #define IDC__MODAL_MODIFYPRODUCT_BUTTON_ACCEPT 163
  82. #define IDC__MODAL_MODIFYPRODUCT_BUTTON_CANCEL 164
  83.  
  84. // Control identifiers "Sell Product"
  85. #define IDC_STATIC_MODAL_SELLPRODUCT_CODE 165
  86. #define IDC_STATIC_MODAL_SELLPRODUCT_DESCRIPTION 166
  87. #define IDC_STATIC_MODAL_SELLPRODUCT_CURRENT_STOCK 167
  88. #define IDC_STATIC_MODAL_SELLPRODUCT_SALES 168
  89. #define IDC_STATIC_MODAL_SELLPRODUCT_NEW_SALES 169
  90. #define IDC_STATIC_MODAL_SELLPRODUCT_PRICE 170
  91. #define IDC_STATIC_MODAL_SELLPRODUCT_RETAIL_PRICE 171
  92. #define IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR_LABEL 172
  93. #define IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE_LABEL 173
  94. #define IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL_LABEL 174
  95.  
  96. #define IDC_EDIT_MODAL_SELLPRODUCT_CODE 175
  97. #define IDC_STATIC_MODAL_SELLPRODUCT2_DESCRIPTION 176
  98. #define IDC_STATIC_MODAL_SELLPRODUCT2_CURRENT_STOCK 177
  99. #define IDC_STATIC_MODAL_SELLPRODUCT2_SALES 178
  100. #define IDC_EDIT_MODAL_SELLPRODUCT_NEW_SALES 179
  101. #define IDC_EDIT_MODAL_SELLPRODUCT_PRICE 180
  102. #define IDC_EDIT_MODAL_SELLPRODUCT_RETAIL_PRICE 181
  103. #define IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR 182
  104. #define IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE 183
  105. #define IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL 184
  106. #define IDC__MODAL_SELLPRODUCT_BUTTON_ACCEPT 185
  107. #define IDC__MODAL_SELLPRODUCT_BUTTON_CANCEL 186
  108.  
  109. // Control identifiers "Calculate Product"
  110. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_CODE 187
  111. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_DESCRIPTION 188
  112. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_PRICE 189
  113. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_RETAIL_PRICE 190
  114. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR_LABEL 191
  115. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE_LABEL 192
  116. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL_LABEL 193
  117.  
  118. #define IDC_STATIC_MODAL_CALCULATEPRODUCT2_CODE 194
  119. #define IDC_STATIC_MODAL_CALCULATEPRODUCT2_DESCRIPTION 195
  120. #define IDC_STATIC_MODAL_CALCULATEPRODUCT2_PRICE 196
  121. #define IDC_STATIC_MODAL_CALCULATEPRODUCT2_RETAIL_PRICE 197
  122. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR 198
  123. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE 199
  124. #define IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL 200
  125. #define IDC__MODAL_CALCULATEPRODUCT_BUTTON_ACCEPT 201
  126. #define IDC__MODAL_CALCULATEPRODUCT_BUTTON_CANCEL 202
  127.  
  128. // Define the maximum size of the buffer for the window text
  129. #define MAX_WINDOW_TEXT_LENGTH 256
  130.  
  131. // Message handling procedure prototype
  132. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  133. LRESULT CALLBACK AddProductModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  134. LRESULT CALLBACK AddNewEntriesModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  135. LRESULT CALLBACK ModifyProductModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  136. LRESULT CALLBACK SellProductModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  137. LRESULT CALLBACK CalculateModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  138. void ResizeControls(HWND hwnd, int width, int height);
  139. void SetControlFont(HWND hwndControl, int fontSize);
  140. void SetTabControlFont(HWND hwndTabControl, int fontSize);
  141. void SetListViewFont(HWND hwndListView, int fontSize);
  142. void ShowModalWindow(HWND hwndParent, int modalId);
  143. void CenterWindow(HWND hwnd);
  144. void ResizeAddProductModalControls(HWND hwnd);
  145. void ResizeAddNewEntriesModalControls(HWND hwnd);
  146. void ResizeModifyProductModalControls(HWND hwnd);
  147. void ResizeSellProductModalControls(HWND hwnd);
  148. void ResizeCalculateModalControls(HWND hwnd);
  149. void UpdateListViewColumns(HWND hwndListView, int selectedTab);
  150.  
  151. // Function to check if a character is a digit
  152. bool IsDigit(char c) {
  153. return c >= '0' && c <= '9';
  154. }
  155.  
  156. // Function to check if a string represents a positive integer
  157. bool IsPositiveInteger(const char* str) {
  158. if (str == NULL || *str == '\0') {
  159. return false;
  160. }
  161. for (const char* p = str; *p != '\0'; ++p) {
  162. if (!IsDigit(*p)) {
  163. return false;
  164. }
  165. }
  166. return true;
  167. }
  168.  
  169. // Function to check if a string is empty
  170. bool IsEmpty(const char* str) {
  171. return str == NULL || *str == '\0';
  172. }
  173.  
  174. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  175. INITCOMMONCONTROLSEX icc;
  176. icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
  177. icc.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES;
  178. InitCommonControlsEx(&icc);
  179.  
  180. const char CLASS_NAME[] = "Sample Window Class";
  181.  
  182. WNDCLASS wc = {0};
  183. wc.lpfnWndProc = WindowProc;
  184. wc.hInstance = hInstance;
  185. wc.lpszClassName = CLASS_NAME;
  186. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Window background
  187.  
  188. RegisterClass(&wc);
  189.  
  190. HWND hwnd = CreateWindowEx(
  191. 0,
  192. CLASS_NAME,
  193. "Inventory",
  194. WS_OVERLAPPEDWINDOW,
  195. CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
  196. NULL,
  197. NULL,
  198. hInstance,
  199. NULL
  200. );
  201.  
  202. if (hwnd == NULL) {
  203. return 0;
  204. }
  205.  
  206. CenterWindow(hwnd); // Center the main window
  207. ShowWindow(hwnd, nCmdShow);
  208.  
  209. MSG msg = {0};
  210. while (GetMessage(&msg, NULL, 0, 0)) {
  211. if (!IsDialogMessage(hwnd, &msg)) {
  212. TranslateMessage(&msg);
  213. DispatchMessage(&msg);
  214. }
  215. }
  216.  
  217. return 0;
  218. }
  219.  
  220. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  221. static HWND hTabControl;
  222. static HWND hListView;
  223. static HWND hEditSearch;
  224. static HWND hStaticSearch;
  225. static HWND hButtonAddNewProduct;
  226. static HWND hButtonAddNewEntries;
  227. static HWND hButtonModify;
  228. static HWND hButtonSell;
  229. static HWND hButtonCalculate;
  230. static HWND hButtonDelete;
  231.  
  232. switch (uMsg) {
  233. case WM_CREATE: {
  234. // Create tab control
  235. hTabControl = CreateWindowEx(
  236. 0, WC_TABCONTROL, NULL,
  237. WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_TABSTOP,
  238. 10, 10, 560, 40, // Increase the height of the TabControl
  239. hwnd, (HMENU)IDC_TABCONTROL, GetModuleHandle(NULL), NULL
  240. );
  241.  
  242. TCITEM tie;
  243. tie.mask = TCIF_TEXT;
  244. tie.pszText = "Inventory";
  245. TabCtrl_InsertItem(hTabControl, 0, &tie);
  246. tie.pszText = "Sales";
  247. TabCtrl_InsertItem(hTabControl, 1, &tie);
  248. tie.pszText = "Events";
  249. TabCtrl_InsertItem(hTabControl, 2, &tie);
  250.  
  251. // Create search label
  252. hStaticSearch = CreateWindowEx(
  253. 0, "STATIC", "Search:",
  254. WS_CHILD | WS_VISIBLE,
  255. 570, 20, 50, 25, // Adjust the position and height of the label
  256. hwnd, (HMENU)IDC_STATIC_SEARCH, GetModuleHandle(NULL), NULL
  257. );
  258.  
  259. // Create search text box
  260. hEditSearch = CreateWindowEx(
  261. 0, "EDIT", NULL,
  262. WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP,
  263. 620, 20, 160, 25, // Adjust the position and height of the text box
  264. hwnd, (HMENU)IDC_EDIT_SEARCH, GetModuleHandle(NULL), NULL
  265. );
  266.  
  267. // Create buttons
  268. hButtonAddNewProduct = CreateWindow(
  269. "BUTTON", "Add \nnew product",
  270. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_MULTILINE | WS_TABSTOP,
  271. 10, 450, 140, 50,
  272. hwnd, (HMENU)IDC_BUTTON_ADD_NEW_PRODUCT, GetModuleHandle(NULL), NULL
  273. );
  274. hButtonAddNewEntries = CreateWindow(
  275. "BUTTON", "Add \nnew entries",
  276. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_MULTILINE | WS_TABSTOP,
  277. 160, 450, 140, 50,
  278. hwnd, (HMENU)IDC_BUTTON_ADD_NEW_ENTRIES, GetModuleHandle(NULL), NULL
  279. );
  280. hButtonModify = CreateWindow(
  281. "BUTTON", "Modify",
  282. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  283. 310, 450, 80, 50,
  284. hwnd, (HMENU)IDC_BUTTON_MODIFY, GetModuleHandle(NULL), NULL
  285. );
  286. hButtonSell = CreateWindow(
  287. "BUTTON", "Sell",
  288. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  289. 400, 450, 80, 50,
  290. hwnd, (HMENU)IDC_BUTTON_SELL, GetModuleHandle(NULL), NULL
  291. );
  292. hButtonCalculate = CreateWindow(
  293. "BUTTON", "Calculate",
  294. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  295. 490, 450, 80, 50,
  296. hwnd, (HMENU)IDC_BUTTON_CALCULATE, GetModuleHandle(NULL), NULL
  297. );
  298. hButtonDelete = CreateWindow(
  299. "BUTTON", "Delete",
  300. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  301. 580, 450, 80, 50,
  302. hwnd, (HMENU)IDC_BUTTON_DELETE, GetModuleHandle(NULL), NULL
  303. );
  304.  
  305. // Create ListView
  306. hListView = CreateWindowEx(
  307. 0, WC_LISTVIEW, NULL,
  308. WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_EDITLABELS | WS_TABSTOP,
  309. 10, 60, 760, 380, // Adjust the position and height of the ListView
  310. hwnd, (HMENU)IDC_LISTVIEW, GetModuleHandle(NULL), NULL
  311. );
  312.  
  313. // Add columns to the ListView for the Inventory tab
  314. LVCOLUMN lvc;
  315. lvc.mask = LVCF_TEXT | LVCF_WIDTH;
  316. lvc.pszText = "Product Code";
  317. lvc.cx = 100;
  318. ListView_InsertColumn(hListView, 0, &lvc);
  319. lvc.pszText = "Product";
  320. lvc.cx = 200;
  321. ListView_InsertColumn(hListView, 1, &lvc);
  322. lvc.pszText = "Initial Stock";
  323. lvc.cx = 100;
  324. ListView_InsertColumn(hListView, 2, &lvc);
  325. lvc.pszText = "Current Stock";
  326. lvc.cx = 100;
  327. ListView_InsertColumn(hListView, 3, &lvc);
  328. lvc.pszText = "New Entries";
  329. lvc.cx = 100;
  330. ListView_InsertColumn(hListView, 4, &lvc);
  331. lvc.pszText = "Sales";
  332. lvc.cx = 100;
  333. ListView_InsertColumn(hListView, 5, &lvc);
  334. lvc.pszText = "Price";
  335. lvc.cx = 100;
  336. ListView_InsertColumn(hListView, 6, &lvc);
  337. lvc.pszText = "Retail Price";
  338. lvc.cx = 100;
  339. ListView_InsertColumn(hListView, 7, &lvc);
  340.  
  341. break;
  342. }
  343. case WM_NOTIFY: {
  344. LPNMHDR pnmh = (LPNMHDR)lParam;
  345. if (pnmh->hwndFrom == hTabControl && pnmh->code == TCN_SELCHANGE) {
  346. int selectedTab = TabCtrl_GetCurSel(hTabControl);
  347. UpdateListViewColumns(hListView, selectedTab);
  348. }
  349. break;
  350. }
  351. case WM_COMMAND: {
  352. if (HIWORD(wParam) == BN_CLICKED) {
  353. switch (LOWORD(wParam)) {
  354. case IDC_BUTTON_ADD_NEW_PRODUCT:
  355. ShowModalWindow(hwnd, IDC_BUTTON_ADD_NEW_PRODUCT);
  356. break;
  357. case IDC_BUTTON_ADD_NEW_ENTRIES:
  358. ShowModalWindow(hwnd, IDC_BUTTON_ADD_NEW_ENTRIES);
  359. break;
  360. case IDC_BUTTON_MODIFY:
  361. ShowModalWindow(hwnd, IDC_BUTTON_MODIFY);
  362. break;
  363. case IDC_BUTTON_SELL:
  364. ShowModalWindow(hwnd, IDC_BUTTON_SELL);
  365. break;
  366. case IDC_BUTTON_CALCULATE:
  367. ShowModalWindow(hwnd, IDC_BUTTON_CALCULATE);
  368. break;
  369. case IDC_BUTTON_DELETE: {
  370. int response = MessageBox(hwnd, "Are you sure you want to delete the selected product(s)?", "Confirm Deletion", MB_YESNO | MB_ICONQUESTION);
  371. if (response == IDYES) {
  372. // Here you can add the logic to delete the selected product(s)
  373. MessageBox(hwnd, "Product(s) deleted successfully.", "Success", MB_OK | MB_ICONINFORMATION);
  374. }
  375. break;
  376. }
  377. }
  378. }
  379. break;
  380. }
  381. case WM_SIZE: {
  382. RECT clientRect;
  383. GetClientRect(hwnd, &clientRect);
  384. int width = clientRect.right - clientRect.left;
  385. int height = clientRect.bottom - clientRect.top;
  386. ResizeControls(hwnd, width, height);
  387. break;
  388. }
  389. case WM_DESTROY:
  390. PostQuitMessage(0);
  391. return 0;
  392. }
  393.  
  394. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  395. }
  396.  
  397. void ResizeControls(HWND hwnd, int width, int height) {
  398. static HWND hTabControl = GetDlgItem(hwnd, IDC_TABCONTROL);
  399. static HWND hListView = GetDlgItem(hwnd, IDC_LISTVIEW);
  400. static HWND hEditSearch = GetDlgItem(hwnd, IDC_EDIT_SEARCH);
  401. static HWND hStaticSearch = GetDlgItem(hwnd, IDC_STATIC_SEARCH);
  402. static HWND hButtonAddNewProduct = GetDlgItem(hwnd, IDC_BUTTON_ADD_NEW_PRODUCT);
  403. static HWND hButtonAddNewEntries = GetDlgItem(hwnd, IDC_BUTTON_ADD_NEW_ENTRIES);
  404. static HWND hButtonModify = GetDlgItem(hwnd, IDC_BUTTON_MODIFY);
  405. static HWND hButtonSell = GetDlgItem(hwnd, IDC_BUTTON_SELL);
  406. static HWND hButtonCalculate = GetDlgItem(hwnd, IDC_BUTTON_CALCULATE);
  407. static HWND hButtonDelete = GetDlgItem(hwnd, IDC_BUTTON_DELETE);
  408.  
  409. // Calculate the font size based on the window size
  410. int fontSize = MulDiv(15, height, 600); // Adjust the font size proportionally
  411.  
  412. // Adjust the font of the controls
  413. SetControlFont(hButtonAddNewProduct, fontSize);
  414. SetControlFont(hButtonAddNewEntries, fontSize);
  415. SetControlFont(hButtonModify, fontSize);
  416. SetControlFont(hButtonSell, fontSize);
  417. SetControlFont(hButtonCalculate, fontSize);
  418. SetControlFont(hButtonDelete, fontSize);
  419. SetControlFont(hEditSearch, fontSize);
  420. SetControlFont(hStaticSearch, fontSize);
  421. SetTabControlFont(hTabControl, fontSize);
  422. SetListViewFont(hListView, fontSize);
  423.  
  424. // Resize and reposition controls
  425. MoveWindow(hTabControl, 10, 10, width - 20, 40, TRUE); // Adjust the height of the TabControl
  426. MoveWindow(hStaticSearch, width - 210, 20, 50, 25, TRUE); // Adjust the position and height of the label
  427. MoveWindow(hEditSearch, width - 160, 20, 140, 25, TRUE); // Adjust the position and height of the text box
  428. MoveWindow(hListView, 10, 60, width - 20, height - 120, TRUE); // Adjust the position and height of the ListView
  429. MoveWindow(hButtonAddNewProduct, 10, height - 60, 140, 60, TRUE);
  430. MoveWindow(hButtonAddNewEntries, 160, height - 60, 140, 60, TRUE);
  431. MoveWindow(hButtonModify, 310, height - 60, 80, 60, TRUE);
  432. MoveWindow(hButtonSell, 400, height - 60, 80, 60, TRUE);
  433. MoveWindow(hButtonCalculate, 490, height - 60, 80, 60, TRUE);
  434. MoveWindow(hButtonDelete, 580, height - 60, 80, 60, TRUE);
  435.  
  436. // Invalidate and update the window to ensure proper redrawing
  437. InvalidateRect(hwnd, NULL, TRUE);
  438. UpdateWindow(hwnd);
  439. }
  440.  
  441. void SetControlFont(HWND hwndControl, int fontSize) {
  442. HFONT hFont = CreateFont(
  443. fontSize, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  444. DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
  445. DEFAULT_QUALITY, VARIABLE_PITCH, TEXT("Segoe UI")
  446. );
  447. SendMessage(hwndControl, WM_SETFONT, (WPARAM)hFont, TRUE);
  448. }
  449.  
  450. void SetTabControlFont(HWND hwndTabControl, int fontSize) {
  451. HFONT hFont = CreateFont(
  452. fontSize, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  453. DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
  454. DEFAULT_QUALITY, VARIABLE_PITCH, TEXT("Segoe UI")
  455. );
  456. SendMessage(hwndTabControl, WM_SETFONT, (WPARAM)hFont, TRUE);
  457. }
  458.  
  459. void SetListViewFont(HWND hwndListView, int fontSize) {
  460. HFONT hFont = CreateFont(
  461. fontSize, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
  462. DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,
  463. DEFAULT_QUALITY, VARIABLE_PITCH, TEXT("Segoe UI")
  464. );
  465. SendMessage(hwndListView, WM_SETFONT, (WPARAM)hFont, TRUE);
  466.  
  467. // Adjust the font of the ListView columns
  468. LVCOLUMN lvc;
  469. lvc.mask = LVCF_SUBITEM;
  470. for (int i = 0; i < 8; i++) {
  471. lvc.iSubItem = i;
  472. ListView_SetColumn(hwndListView, i, &lvc);
  473. }
  474. }
  475.  
  476. void ShowModalWindow(HWND hwndParent, int modalId) {
  477. const char MODAL_CLASS_NAME[] = "Modal Window Class";
  478.  
  479. WNDCLASS wc = {0};
  480. wc.hInstance = GetModuleHandle(NULL);
  481. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  482.  
  483. switch (modalId) {
  484. case IDC_BUTTON_ADD_NEW_PRODUCT:
  485. wc.lpfnWndProc = AddProductModalWindowProc;
  486. break;
  487. case IDC_BUTTON_ADD_NEW_ENTRIES:
  488. wc.lpfnWndProc = AddNewEntriesModalWindowProc;
  489. break;
  490. case IDC_BUTTON_MODIFY:
  491. wc.lpfnWndProc = ModifyProductModalWindowProc;
  492. break;
  493. case IDC_BUTTON_SELL:
  494. wc.lpfnWndProc = SellProductModalWindowProc;
  495. break;
  496. case IDC_BUTTON_CALCULATE:
  497. wc.lpfnWndProc = CalculateModalWindowProc;
  498. break;
  499. default:
  500. MessageBox(hwndParent, "Invalid modal window ID", "Error", MB_OK | MB_ICONERROR);
  501. return;
  502. }
  503.  
  504. wc.lpszClassName = MODAL_CLASS_NAME;
  505.  
  506. RegisterClass(&wc);
  507.  
  508. HWND hwndModal = CreateWindowEx(
  509. 0,
  510. MODAL_CLASS_NAME,
  511. NULL, // No title used
  512. WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  513. CW_USEDEFAULT, CW_USEDEFAULT, 300, 320,
  514. hwndParent,
  515. NULL,
  516. GetModuleHandle(NULL),
  517. NULL
  518. );
  519.  
  520. if (hwndModal == NULL) {
  521. MessageBox(hwndParent, "Could not create modal window", "Error", MB_OK | MB_ICONERROR);
  522. return;
  523. }
  524.  
  525. CenterWindow(hwndModal); // Center the modal window
  526. EnableWindow(hwndParent, FALSE); // Disable the main window
  527.  
  528. // Ensure that the controls are resized correctly
  529. switch (modalId) {
  530. case IDC_BUTTON_ADD_NEW_PRODUCT:
  531. ResizeAddProductModalControls(hwndModal);
  532. break;
  533. case IDC_BUTTON_ADD_NEW_ENTRIES:
  534. ResizeAddNewEntriesModalControls(hwndModal);
  535. break;
  536. case IDC_BUTTON_MODIFY:
  537. ResizeModifyProductModalControls(hwndModal);
  538. break;
  539. case IDC_BUTTON_SELL:
  540. ResizeSellProductModalControls(hwndModal);
  541. break;
  542. case IDC_BUTTON_CALCULATE:
  543. ResizeCalculateModalControls(hwndModal);
  544. break;
  545. }
  546.  
  547. MSG msg = {0};
  548. while (GetMessage(&msg, NULL, 0, 0)) {
  549. if (!IsDialogMessage(hwndModal, &msg)) {
  550. TranslateMessage(&msg);
  551. DispatchMessage(&msg);
  552. }
  553. }
  554.  
  555. EnableWindow(hwndParent, TRUE); // Enable the main window
  556. SetForegroundWindow(hwndParent); // Bring the main window to the front
  557. DestroyWindow(hwndModal);
  558. UnregisterClass(MODAL_CLASS_NAME, GetModuleHandle(NULL));
  559. }
  560.  
  561. LRESULT CALLBACK AddProductModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  562. static HWND hEditCode;
  563. static HWND hEditDescription;
  564. static HWND hEditInitialStock;
  565. static HWND hEditPrice;
  566. static HWND hEditRetailPrice;
  567. static HWND hStaticProfitDollar;
  568. static HWND hStaticProfitPercentage;
  569. static HWND hStaticVatRetail;
  570. static HWND hButtonAccept;
  571. static HWND hButtonCancel;
  572.  
  573. switch (uMsg) {
  574. case WM_CREATE: {
  575. // Create labels and edit controls
  576. CreateWindowEx(0, "STATIC", "Product Code:", WS_CHILD | WS_VISIBLE, 10, 10, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_CODE, GetModuleHandle(NULL), NULL);
  577. hEditCode = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 10, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_ADDNEWPRODUCT_CODE, GetModuleHandle(NULL), NULL);
  578.  
  579. CreateWindowEx(0, "STATIC", "Description:", WS_CHILD | WS_VISIBLE, 10, 40, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_DESCRIPTION, GetModuleHandle(NULL), NULL);
  580. hEditDescription = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 140, 40, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_ADDNEWPRODUCT_DESCRIPTION, GetModuleHandle(NULL), NULL);
  581.  
  582. CreateWindowEx(0, "STATIC", "Initial Stock:", WS_CHILD | WS_VISIBLE, 10, 70, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_INITIAL_STOCK, GetModuleHandle(NULL), NULL);
  583. hEditInitialStock = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 70, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_ADDNEWPRODUCT_INITIAL_STOCK, GetModuleHandle(NULL), NULL);
  584.  
  585. CreateWindowEx(0, "STATIC", "Price:", WS_CHILD | WS_VISIBLE, 10, 100, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_PRICE, GetModuleHandle(NULL), NULL);
  586. hEditPrice = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 100, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_ADDNEWPRODUCT_PRICE, GetModuleHandle(NULL), NULL);
  587.  
  588. CreateWindowEx(0, "STATIC", "Retail Price:", WS_CHILD | WS_VISIBLE, 10, 130, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  589. hEditRetailPrice = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 130, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_ADDNEWPRODUCT_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  590.  
  591. CreateWindowEx(0, "STATIC", "Gain in $:", WS_CHILD | WS_VISIBLE, 10, 160, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR_LABEL, GetModuleHandle(NULL), NULL);
  592. hStaticProfitDollar = CreateWindowEx(0, "STATIC", "$0", WS_CHILD | WS_VISIBLE, 140, 160, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR, GetModuleHandle(NULL), NULL);
  593.  
  594. CreateWindowEx(0, "STATIC", "Gain in %:", WS_CHILD | WS_VISIBLE, 10, 190, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE_LABEL, GetModuleHandle(NULL), NULL);
  595. hStaticProfitPercentage = CreateWindowEx(0, "STATIC", "0%", WS_CHILD | WS_VISIBLE, 140, 190, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE, GetModuleHandle(NULL), NULL);
  596.  
  597. CreateWindowEx(0, "STATIC", "Retail VAT $:", WS_CHILD | WS_VISIBLE, 10, 220, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL_LABEL, GetModuleHandle(NULL), NULL);
  598. hStaticVatRetail = CreateWindowEx(0, "STATIC", "$0($0)", WS_CHILD | WS_VISIBLE, 140, 220, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL, GetModuleHandle(NULL), NULL);
  599.  
  600. // Create Accept and Cancel buttons
  601. hButtonAccept = CreateWindow(
  602. "BUTTON", "Accept",
  603. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  604. 10, 250, 80, 30,
  605. hwnd, (HMENU)IDC__MODAL_ADDNEWPRODUCT_BUTTON_ACCEPT, GetModuleHandle(NULL), NULL
  606. );
  607. hButtonCancel = CreateWindow(
  608. "BUTTON", "Cancel",
  609. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  610. 100, 250, 80, 30,
  611. hwnd, (HMENU)IDC__MODAL_ADDNEWPRODUCT_BUTTON_CANCEL, GetModuleHandle(NULL), NULL
  612. );
  613.  
  614. // Resize and center the controls
  615. ResizeAddProductModalControls(hwnd);
  616. break;
  617. }
  618. case WM_COMMAND: {
  619. if (HIWORD(wParam) == BN_CLICKED) {
  620. switch (LOWORD(wParam)) {
  621. case IDC__MODAL_ADDNEWPRODUCT_BUTTON_ACCEPT: {
  622. // Validate input fields
  623. char code[256];
  624. char description[256];
  625. char initialStock[256];
  626. char price[256];
  627. char retailPrice[256];
  628.  
  629. GetWindowTextA(hEditCode, code, sizeof(code));
  630. GetWindowTextA(hEditDescription, description, sizeof(description));
  631. GetWindowTextA(hEditInitialStock, initialStock, sizeof(initialStock));
  632. GetWindowTextA(hEditPrice, price, sizeof(price));
  633. GetWindowTextA(hEditRetailPrice, retailPrice, sizeof(retailPrice));
  634.  
  635. if (IsEmpty(code) || IsEmpty(description) || IsEmpty(initialStock) ||
  636. IsEmpty(price) || IsEmpty(retailPrice)) {
  637. MessageBox(hwnd, "The registration could not be completed because there are empty fields.", "Error", MB_OK | MB_ICONERROR);
  638. break;
  639. }
  640.  
  641. if (!IsPositiveInteger(code) || !IsPositiveInteger(initialStock) ||
  642. !IsPositiveInteger(price) || !IsPositiveInteger(retailPrice)) {
  643. MessageBox(hwnd, "Invalid values have been entered for the required field.", "Error", MB_OK | MB_ICONERROR);
  644. break;
  645. }
  646.  
  647. // Here you can add the logic to handle the Accept button
  648. DestroyWindow(hwnd);
  649. break;
  650. }
  651. case IDC__MODAL_ADDNEWPRODUCT_BUTTON_CANCEL:
  652. DestroyWindow(hwnd);
  653. break;
  654. }
  655. }
  656. break;
  657. }
  658. case WM_SIZE: {
  659. // Resize and center the controls
  660. ResizeAddProductModalControls(hwnd);
  661. break;
  662. }
  663. case WM_CLOSE:
  664. DestroyWindow(hwnd);
  665. return 0;
  666. case WM_DESTROY:
  667. PostQuitMessage(0);
  668. return 0;
  669. }
  670. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  671. }
  672.  
  673. LRESULT CALLBACK AddNewEntriesModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  674. static HWND hEditCode;
  675. static HWND hEditDescription;
  676. static HWND hEditCurrentStock;
  677. static HWND hEditNewEntries;
  678. static HWND hButtonAccept;
  679. static HWND hButtonCancel;
  680.  
  681. switch (uMsg) {
  682. case WM_CREATE: {
  683. // Create labels and edit controls
  684. CreateWindowEx(0, "STATIC", "Product Code:", WS_CHILD | WS_VISIBLE, 10, 10, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWENTRIES_CODE, GetModuleHandle(NULL), NULL);
  685. hEditCode = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 140, 10, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWENTRIES2_CODE, GetModuleHandle(NULL), NULL);
  686.  
  687. CreateWindowEx(0, "STATIC", "Description:", WS_CHILD | WS_VISIBLE, 10, 40, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWENTRIES_DESCRIPTION, GetModuleHandle(NULL), NULL);
  688. hEditDescription = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 140, 40, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWENTRIES2_DESCRIPTION, GetModuleHandle(NULL), NULL);
  689.  
  690. CreateWindowEx(0, "STATIC", "Current Stock:", WS_CHILD | WS_VISIBLE, 10, 100, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWENTRIES_CURRENT_STOCK, GetModuleHandle(NULL), NULL);
  691. hEditCurrentStock = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 140, 100, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWENTRIES2_CURRENT_STOCK, GetModuleHandle(NULL), NULL);
  692.  
  693. CreateWindowEx(0, "STATIC", "New Entries:", WS_CHILD | WS_VISIBLE, 10, 130, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_ADDNEWENTRIES_NEW_ENTRIES, GetModuleHandle(NULL), NULL);
  694. hEditNewEntries = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 130, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_ADDNEWENTRIES_NEW_ENTRIES, GetModuleHandle(NULL), NULL);
  695.  
  696. // Create Accept and Cancel buttons
  697. hButtonAccept = CreateWindow(
  698. "BUTTON", "Accept",
  699. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  700. 10, 160, 80, 30,
  701. hwnd, (HMENU)IDC__MODAL_ADDNEWENTRIES_BUTTON_ACCEPT, GetModuleHandle(NULL), NULL
  702. );
  703. hButtonCancel = CreateWindow(
  704. "BUTTON", "Cancel",
  705. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  706. 100, 160, 80, 30,
  707. hwnd, (HMENU)IDC__MODAL_ADDNEWENTRIES_BUTTON_CANCEL, GetModuleHandle(NULL), NULL
  708. );
  709.  
  710. // Resize and center the controls
  711. ResizeAddNewEntriesModalControls(hwnd);
  712. break;
  713. }
  714. case WM_COMMAND: {
  715. if (HIWORD(wParam) == BN_CLICKED) {
  716. switch (LOWORD(wParam)) {
  717. case IDC__MODAL_ADDNEWENTRIES_BUTTON_ACCEPT: {
  718. // Validate input fields
  719. char code[256];
  720. char description[256];
  721. char currentStock[256];
  722. char newEntries[256];
  723.  
  724. GetWindowTextA(hEditCode, code, sizeof(code));
  725. GetWindowTextA(hEditDescription, description, sizeof(description));
  726. GetWindowTextA(hEditCurrentStock, currentStock, sizeof(currentStock));
  727. GetWindowTextA(hEditNewEntries, newEntries, sizeof(newEntries));
  728.  
  729. if (IsEmpty(code) || IsEmpty(description) ||
  730. IsEmpty(currentStock) || IsEmpty(newEntries)) {
  731. MessageBox(hwnd, "The registration could not be completed because there are empty fields.", "Error", MB_OK | MB_ICONERROR);
  732. break;
  733. }
  734.  
  735. if (!IsPositiveInteger(code) ||
  736. !IsPositiveInteger(currentStock) || !IsPositiveInteger(newEntries)) {
  737. MessageBox(hwnd, "Invalid values have been entered for the required field.", "Error", MB_OK | MB_ICONERROR);
  738. break;
  739. }
  740.  
  741. // Here you can add the logic to handle the Accept button
  742. DestroyWindow(hwnd);
  743. break;
  744. }
  745. case IDC__MODAL_ADDNEWENTRIES_BUTTON_CANCEL:
  746. DestroyWindow(hwnd);
  747. break;
  748. }
  749. }
  750. break;
  751. }
  752. case WM_SIZE: {
  753. // Resize and center the controls
  754. ResizeAddNewEntriesModalControls(hwnd);
  755. break;
  756. }
  757. case WM_CLOSE:
  758. DestroyWindow(hwnd);
  759. return 0;
  760. case WM_DESTROY:
  761. PostQuitMessage(0);
  762. return 0;
  763. }
  764. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  765. }
  766.  
  767. LRESULT CALLBACK ModifyProductModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  768. static HWND hEditCode;
  769. static HWND hEditDescription;
  770. static HWND hEditInitialStock;
  771. static HWND hEditCurrentStock;
  772. static HWND hEditNewEntries;
  773. static HWND hEditSales;
  774. static HWND hEditPrice;
  775. static HWND hEditRetailPrice;
  776. static HWND hStaticProfitDollar;
  777. static HWND hStaticProfitPercentage;
  778. static HWND hStaticVatRetail;
  779. static HWND hButtonAccept;
  780. static HWND hButtonCancel;
  781.  
  782. switch (uMsg) {
  783. case WM_CREATE: {
  784. // Create labels and edit controls
  785. CreateWindowEx(0, "STATIC", "Product Code:", WS_CHILD | WS_VISIBLE, 10, 10, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_CODE, GetModuleHandle(NULL), NULL);
  786. hEditCode = CreateWindowEx(0, "COMBOBOX", NULL, WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_TABSTOP, 140, 10, 200, 200, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_CODE, GetModuleHandle(NULL), NULL);
  787.  
  788. CreateWindowEx(0, "STATIC", "Description:", WS_CHILD | WS_VISIBLE, 10, 40, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_DESCRIPTION, GetModuleHandle(NULL), NULL);
  789. hEditDescription = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 140, 40, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_DESCRIPTION, GetModuleHandle(NULL), NULL);
  790.  
  791. CreateWindowEx(0, "STATIC", "Initial Stock:", WS_CHILD | WS_VISIBLE, 10, 70, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_INITIAL_STOCK, GetModuleHandle(NULL), NULL);
  792. hEditInitialStock = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 70, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_INITIAL_STOCK, GetModuleHandle(NULL), NULL);
  793.  
  794. CreateWindowEx(0, "STATIC", "Current Stock:", WS_CHILD | WS_VISIBLE, 10, 100, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_CURRENT_STOCK, GetModuleHandle(NULL), NULL);
  795. hEditCurrentStock = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 100, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_CURRENT_STOCK, GetModuleHandle(NULL), NULL);
  796.  
  797. CreateWindowEx(0, "STATIC", "New Entries:", WS_CHILD | WS_VISIBLE, 10, 130, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_NEW_ENTRIES, GetModuleHandle(NULL), NULL);
  798. hEditNewEntries = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 130, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_NEW_ENTRIES, GetModuleHandle(NULL), NULL);
  799.  
  800. CreateWindowEx(0, "STATIC", "Sales:", WS_CHILD | WS_VISIBLE, 10, 160, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_SALES, GetModuleHandle(NULL), NULL);
  801. hEditSales = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 160, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_SALES, GetModuleHandle(NULL), NULL);
  802.  
  803. CreateWindowEx(0, "STATIC", "Price:", WS_CHILD | WS_VISIBLE, 10, 190, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_PRICE, GetModuleHandle(NULL), NULL);
  804. hEditPrice = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 190, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_PRICE, GetModuleHandle(NULL), NULL);
  805.  
  806. CreateWindowEx(0, "STATIC", "Retail Price:", WS_CHILD | WS_VISIBLE, 10, 220, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  807. hEditRetailPrice = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 220, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_MODIFYPRODUCT_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  808.  
  809. CreateWindowEx(0, "STATIC", "Gain in $:", WS_CHILD | WS_VISIBLE, 10, 250, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR_LABEL, GetModuleHandle(NULL), NULL);
  810. hStaticProfitDollar = CreateWindowEx(0, "STATIC", "$0", WS_CHILD | WS_VISIBLE, 140, 250, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR, GetModuleHandle(NULL), NULL);
  811.  
  812. CreateWindowEx(0, "STATIC", "Gain in %:", WS_CHILD | WS_VISIBLE, 10, 280, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE_LABEL, GetModuleHandle(NULL), NULL);
  813. hStaticProfitPercentage = CreateWindowEx(0, "STATIC", "0%", WS_CHILD | WS_VISIBLE, 140, 280, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE, GetModuleHandle(NULL), NULL);
  814.  
  815. CreateWindowEx(0, "STATIC", "Retail VAT $:", WS_CHILD | WS_VISIBLE, 10, 310, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL_LABEL, GetModuleHandle(NULL), NULL);
  816. hStaticVatRetail = CreateWindowEx(0, "STATIC", "$0($0)", WS_CHILD | WS_VISIBLE, 140, 310, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL, GetModuleHandle(NULL), NULL);
  817.  
  818. // Create Accept and Cancel buttons
  819. hButtonAccept = CreateWindow(
  820. "BUTTON", "Accept",
  821. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  822. 10, 340, 80, 30,
  823. hwnd, (HMENU)IDC__MODAL_MODIFYPRODUCT_BUTTON_ACCEPT, GetModuleHandle(NULL), NULL
  824. );
  825. hButtonCancel = CreateWindow(
  826. "BUTTON", "Cancel",
  827. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  828. 100, 340, 80, 30,
  829. hwnd, (HMENU)IDC__MODAL_MODIFYPRODUCT_BUTTON_CANCEL, GetModuleHandle(NULL), NULL
  830. );
  831.  
  832. // Resize and center the controls
  833. ResizeModifyProductModalControls(hwnd);
  834. break;
  835. }
  836. case WM_COMMAND: {
  837. if (HIWORD(wParam) == BN_CLICKED) {
  838. switch (LOWORD(wParam)) {
  839. case IDC__MODAL_MODIFYPRODUCT_BUTTON_ACCEPT: {
  840. // Validate input fields
  841. char code[256];
  842. char description[256];
  843. char initialStock[256];
  844. char currentStock[256];
  845. char newEntries[256];
  846. char sales[256];
  847. char price[256];
  848. char retailPrice[256];
  849.  
  850. GetWindowTextA(hEditCode, code, sizeof(code));
  851. GetWindowTextA(hEditDescription, description, sizeof(description));
  852. GetWindowTextA(hEditInitialStock, initialStock, sizeof(initialStock));
  853. GetWindowTextA(hEditCurrentStock, currentStock, sizeof(currentStock));
  854. GetWindowTextA(hEditNewEntries, newEntries, sizeof(newEntries));
  855. GetWindowTextA(hEditSales, sales, sizeof(sales));
  856. GetWindowTextA(hEditPrice, price, sizeof(price));
  857. GetWindowTextA(hEditRetailPrice, retailPrice, sizeof(retailPrice));
  858.  
  859. if (IsEmpty(code) || IsEmpty(description) || IsEmpty(initialStock) ||
  860. IsEmpty(currentStock) || IsEmpty(newEntries) || IsEmpty(sales) ||
  861. IsEmpty(price) || IsEmpty(retailPrice)) {
  862. MessageBox(hwnd, "The registration could not be completed because there are empty fields.", "Error", MB_OK | MB_ICONERROR);
  863. break;
  864. }
  865.  
  866. if (!IsPositiveInteger(code) || !IsPositiveInteger(initialStock) ||
  867. !IsPositiveInteger(currentStock) || !IsPositiveInteger(newEntries) ||
  868. !IsPositiveInteger(sales) || !IsPositiveInteger(price) || !IsPositiveInteger(retailPrice)) {
  869. MessageBox(hwnd, "Invalid values have been entered for the required field.", "Error", MB_OK | MB_ICONERROR);
  870. break;
  871. }
  872.  
  873. // Here you can add the logic to handle the Accept button
  874. DestroyWindow(hwnd);
  875. break;
  876. }
  877. case IDC__MODAL_MODIFYPRODUCT_BUTTON_CANCEL:
  878. DestroyWindow(hwnd);
  879. break;
  880. }
  881. }
  882. break;
  883. }
  884. case WM_SIZE: {
  885. // Resize and center the controls
  886. ResizeModifyProductModalControls(hwnd);
  887. break;
  888. }
  889. case WM_CLOSE:
  890. DestroyWindow(hwnd);
  891. return 0;
  892. case WM_DESTROY:
  893. PostQuitMessage(0);
  894. return 0;
  895. }
  896. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  897. }
  898.  
  899. LRESULT CALLBACK SellProductModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  900. static HWND hEditCode;
  901. static HWND hEditDescription;
  902. static HWND hEditCurrentStock;
  903. static HWND hEditSales;
  904. static HWND hEditNewSales;
  905. static HWND hEditPrice;
  906. static HWND hEditRetailPrice;
  907. static HWND hStaticProfitDollar;
  908. static HWND hStaticProfitPercentage;
  909. static HWND hStaticVatRetail;
  910. static HWND hButtonAccept;
  911. static HWND hButtonCancel;
  912.  
  913. switch (uMsg) {
  914. case WM_CREATE: {
  915. // Create labels and edit controls
  916. CreateWindowEx(0, "STATIC", "Product Code:", WS_CHILD | WS_VISIBLE, 10, 10, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_CODE, GetModuleHandle(NULL), NULL);
  917. hEditCode = CreateWindowEx(0, "COMBOBOX", NULL, WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_TABSTOP, 140, 10, 200, 200, hwnd, (HMENU)IDC_EDIT_MODAL_SELLPRODUCT_CODE, GetModuleHandle(NULL), NULL);
  918.  
  919. CreateWindowEx(0, "STATIC", "Description:", WS_CHILD | WS_VISIBLE, 10, 40, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_DESCRIPTION, GetModuleHandle(NULL), NULL);
  920. hEditDescription = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 140, 40, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT2_DESCRIPTION, GetModuleHandle(NULL), NULL);
  921.  
  922. CreateWindowEx(0, "STATIC", "Current Stock:", WS_CHILD | WS_VISIBLE, 10, 70, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_CURRENT_STOCK, GetModuleHandle(NULL), NULL);
  923. hEditCurrentStock = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 70, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT2_CURRENT_STOCK, GetModuleHandle(NULL), NULL);
  924.  
  925. CreateWindowEx(0, "STATIC", "Registered Sales:", WS_CHILD | WS_VISIBLE, 10, 100, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_SALES, GetModuleHandle(NULL), NULL);
  926. hEditSales = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 100, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT2_SALES, GetModuleHandle(NULL), NULL);
  927.  
  928. CreateWindowEx(0, "STATIC", "New Sales:", WS_CHILD | WS_VISIBLE, 10, 130, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_NEW_SALES, GetModuleHandle(NULL), NULL);
  929. hEditNewSales = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 130, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_SELLPRODUCT_NEW_SALES, GetModuleHandle(NULL), NULL);
  930.  
  931. CreateWindowEx(0, "STATIC", "Price:", WS_CHILD | WS_VISIBLE, 10, 160, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_PRICE, GetModuleHandle(NULL), NULL);
  932. hEditPrice = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 160, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_SELLPRODUCT_PRICE, GetModuleHandle(NULL), NULL);
  933.  
  934. CreateWindowEx(0, "STATIC", "Retail Price:", WS_CHILD | WS_VISIBLE, 10, 190, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  935. hEditRetailPrice = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | WS_TABSTOP, 140, 190, 200, 20, hwnd, (HMENU)IDC_EDIT_MODAL_SELLPRODUCT_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  936.  
  937. CreateWindowEx(0, "STATIC", "Gain in $:", WS_CHILD | WS_VISIBLE, 10, 220, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR_LABEL, GetModuleHandle(NULL), NULL);
  938. hStaticProfitDollar = CreateWindowEx(0, "STATIC", "$0", WS_CHILD | WS_VISIBLE, 140, 220, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR, GetModuleHandle(NULL), NULL);
  939.  
  940. CreateWindowEx(0, "STATIC", "Gain in %:", WS_CHILD | WS_VISIBLE, 10, 250, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE_LABEL, GetModuleHandle(NULL), NULL);
  941. hStaticProfitPercentage = CreateWindowEx(0, "STATIC", "0%", WS_CHILD | WS_VISIBLE, 140, 250, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE, GetModuleHandle(NULL), NULL);
  942.  
  943. CreateWindowEx(0, "STATIC", "Retail VAT $:", WS_CHILD | WS_VISIBLE, 10, 280, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL_LABEL, GetModuleHandle(NULL), NULL);
  944. hStaticVatRetail = CreateWindowEx(0, "STATIC", "$0($0)", WS_CHILD | WS_VISIBLE, 140, 280, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL, GetModuleHandle(NULL), NULL);
  945.  
  946. // Create Accept and Cancel buttons
  947. hButtonAccept = CreateWindow(
  948. "BUTTON", "Accept",
  949. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  950. 10, 310, 80, 30,
  951. hwnd, (HMENU)IDC__MODAL_SELLPRODUCT_BUTTON_ACCEPT, GetModuleHandle(NULL), NULL
  952. );
  953. hButtonCancel = CreateWindow(
  954. "BUTTON", "Cancel",
  955. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  956. 100, 310, 80, 30,
  957. hwnd, (HMENU)IDC__MODAL_SELLPRODUCT_BUTTON_CANCEL, GetModuleHandle(NULL), NULL
  958. );
  959.  
  960. // Resize and center the controls
  961. ResizeSellProductModalControls(hwnd);
  962. break;
  963. }
  964. case WM_COMMAND: {
  965. if (HIWORD(wParam) == BN_CLICKED) {
  966. switch (LOWORD(wParam)) {
  967. case IDC__MODAL_SELLPRODUCT_BUTTON_ACCEPT: {
  968. // Validate input fields
  969. char code[256];
  970. char description[256];
  971. char currentStock[256];
  972. char sales[256];
  973. char newSales[256];
  974. char price[256];
  975. char retailPrice[256];
  976.  
  977. GetWindowTextA(hEditCode, code, sizeof(code));
  978. GetWindowTextA(hEditDescription, description, sizeof(description));
  979. GetWindowTextA(hEditCurrentStock, currentStock, sizeof(currentStock));
  980. GetWindowTextA(hEditSales, sales, sizeof(sales));
  981. GetWindowTextA(hEditNewSales, newSales, sizeof(newSales));
  982. GetWindowTextA(hEditPrice, price, sizeof(price));
  983. GetWindowTextA(hEditRetailPrice, retailPrice, sizeof(retailPrice));
  984.  
  985. if (IsEmpty(code) || IsEmpty(description) || IsEmpty(currentStock) ||
  986. IsEmpty(sales) || IsEmpty(newSales) || IsEmpty(price) || IsEmpty(retailPrice)) {
  987. MessageBox(hwnd, "The registration could not be completed because there are empty fields.", "Error", MB_OK | MB_ICONERROR);
  988. break;
  989. }
  990.  
  991. if (!IsPositiveInteger(code) || !IsPositiveInteger(currentStock) ||
  992. !IsPositiveInteger(sales) || !IsPositiveInteger(newSales) ||
  993. !IsPositiveInteger(price) || !IsPositiveInteger(retailPrice)) {
  994. MessageBox(hwnd, "Invalid values have been entered for the required field.", "Error", MB_OK | MB_ICONERROR);
  995. break;
  996. }
  997.  
  998. // Here you can add the logic to handle the Accept button
  999. DestroyWindow(hwnd);
  1000. break;
  1001. }
  1002. case IDC__MODAL_SELLPRODUCT_BUTTON_CANCEL:
  1003. DestroyWindow(hwnd);
  1004. break;
  1005. }
  1006. }
  1007. break;
  1008. }
  1009. case WM_SIZE: {
  1010. // Resize and center the controls
  1011. ResizeSellProductModalControls(hwnd);
  1012. break;
  1013. }
  1014. case WM_CLOSE:
  1015. DestroyWindow(hwnd);
  1016. return 0;
  1017. case WM_DESTROY:
  1018. PostQuitMessage(0);
  1019. return 0;
  1020. }
  1021. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  1022. }
  1023.  
  1024. LRESULT CALLBACK CalculateModalWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  1025. static HWND hEditCode;
  1026. static HWND hEditDescription;
  1027. static HWND hEditPrice;
  1028. static HWND hEditRetailPrice;
  1029. static HWND hStaticProfitDollar;
  1030. static HWND hStaticProfitPercentage;
  1031. static HWND hStaticVatRetail;
  1032. static HWND hButtonAccept;
  1033. static HWND hButtonCancel;
  1034.  
  1035. switch (uMsg) {
  1036. case WM_CREATE: {
  1037. // Create labels and edit controls
  1038. CreateWindowEx(0, "STATIC", "Product Code:", WS_CHILD | WS_VISIBLE, 10, 10, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_CODE, GetModuleHandle(NULL), NULL);
  1039. hEditCode = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE, 140, 10, 200, 200, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT2_CODE, GetModuleHandle(NULL), NULL);
  1040.  
  1041. CreateWindowEx(0, "STATIC", "Description:", WS_CHILD | WS_VISIBLE, 10, 40, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_DESCRIPTION, GetModuleHandle(NULL), NULL);
  1042. hEditDescription = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE, 140, 40, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT2_DESCRIPTION, GetModuleHandle(NULL), NULL);
  1043.  
  1044. CreateWindowEx(0, "STATIC", "Price:", WS_CHILD | WS_VISIBLE, 10, 70, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_PRICE, GetModuleHandle(NULL), NULL);
  1045. hEditPrice = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE, 140, 70, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT2_PRICE, GetModuleHandle(NULL), NULL);
  1046.  
  1047. CreateWindowEx(0, "STATIC", "Retail Price:", WS_CHILD | WS_VISIBLE, 10, 100, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  1048. hEditRetailPrice = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE, 140, 100, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT2_RETAIL_PRICE, GetModuleHandle(NULL), NULL);
  1049.  
  1050. CreateWindowEx(0, "STATIC", "Gain in $:", WS_CHILD | WS_VISIBLE, 10, 130, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR_LABEL, GetModuleHandle(NULL), NULL);
  1051. hStaticProfitDollar = CreateWindowEx(0, "STATIC", "$0", WS_CHILD | WS_VISIBLE, 140, 130, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR, GetModuleHandle(NULL), NULL);
  1052.  
  1053. CreateWindowEx(0, "STATIC", "Gain in %:", WS_CHILD | WS_VISIBLE, 10, 160, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE_LABEL, GetModuleHandle(NULL), NULL);
  1054. hStaticProfitPercentage = CreateWindowEx(0, "STATIC", "0%", WS_CHILD | WS_VISIBLE, 140, 160, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE, GetModuleHandle(NULL), NULL);
  1055.  
  1056. CreateWindowEx(0, "STATIC", "Retail VAT $:", WS_CHILD | WS_VISIBLE, 10, 190, 120, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL_LABEL, GetModuleHandle(NULL), NULL);
  1057. hStaticVatRetail = CreateWindowEx(0, "STATIC", "$0($0)", WS_CHILD | WS_VISIBLE, 140, 190, 200, 20, hwnd, (HMENU)IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL, GetModuleHandle(NULL), NULL);
  1058.  
  1059. // Create Accept and Cancel buttons
  1060. hButtonAccept = CreateWindow(
  1061. "BUTTON", "Accept",
  1062. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  1063. 10, 220, 80, 30,
  1064. hwnd, (HMENU)IDC__MODAL_CALCULATEPRODUCT_BUTTON_ACCEPT, GetModuleHandle(NULL), NULL
  1065. );
  1066. hButtonCancel = CreateWindow(
  1067. "BUTTON", "Cancel",
  1068. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | WS_TABSTOP,
  1069. 100, 220, 80, 30,
  1070. hwnd, (HMENU)IDC__MODAL_CALCULATEPRODUCT_BUTTON_CANCEL, GetModuleHandle(NULL), NULL
  1071. );
  1072.  
  1073. // Resize and center the controls
  1074. ResizeCalculateModalControls(hwnd);
  1075. break;
  1076. }
  1077. case WM_COMMAND: {
  1078. if (HIWORD(wParam) == BN_CLICKED) {
  1079. switch (LOWORD(wParam)) {
  1080. case IDC__MODAL_CALCULATEPRODUCT_BUTTON_ACCEPT: {
  1081. // Validate input fields
  1082. char code[256];
  1083. char description[256];
  1084. char price[256];
  1085. char retailPrice[256];
  1086.  
  1087. GetWindowTextA(hEditCode, code, sizeof(code));
  1088. GetWindowTextA(hEditDescription, description, sizeof(description));
  1089. GetWindowTextA(hEditPrice, price, sizeof(price));
  1090. GetWindowTextA(hEditRetailPrice, retailPrice, sizeof(retailPrice));
  1091.  
  1092. if (IsEmpty(code) || IsEmpty(description) || IsEmpty(price) || IsEmpty(retailPrice)) {
  1093. MessageBox(hwnd, "The registration could not be completed because there are empty fields.", "Error", MB_OK | MB_ICONERROR);
  1094. break;
  1095. }
  1096.  
  1097. if (!IsPositiveInteger(code) || !IsPositiveInteger(price) || !IsPositiveInteger(retailPrice)) {
  1098. MessageBox(hwnd, "Invalid values have been entered for the required field.", "Error", MB_OK | MB_ICONERROR);
  1099. break;
  1100. }
  1101.  
  1102. // Here you can add the logic to handle the Accept button
  1103. DestroyWindow(hwnd);
  1104. break;
  1105. }
  1106. case IDC__MODAL_CALCULATEPRODUCT_BUTTON_CANCEL:
  1107. DestroyWindow(hwnd);
  1108. break;
  1109. }
  1110. }
  1111. break;
  1112. }
  1113. case WM_SIZE: {
  1114. // Resize and center the controls
  1115. ResizeCalculateModalControls(hwnd);
  1116. break;
  1117. }
  1118. case WM_CLOSE:
  1119. DestroyWindow(hwnd);
  1120. return 0;
  1121. case WM_DESTROY:
  1122. PostQuitMessage(0);
  1123. return 0;
  1124. }
  1125. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  1126. }
  1127.  
  1128. void ResizeAddProductModalControls(HWND hwnd) {
  1129. RECT clientRect;
  1130. GetClientRect(hwnd, &clientRect);
  1131. int width = clientRect.right - clientRect.left;
  1132. int height = clientRect.bottom - clientRect.top;
  1133.  
  1134. // Calculate the font size based on the window size
  1135. int fontSize = MulDiv(15, height, 300); // Adjust the font size proportionally
  1136.  
  1137. // Adjust the font of the controls
  1138. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_CODE), fontSize);
  1139. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_CODE), fontSize);
  1140.  
  1141. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_DESCRIPTION), fontSize);
  1142. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_DESCRIPTION), fontSize);
  1143.  
  1144. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_INITIAL_STOCK), fontSize);
  1145. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_INITIAL_STOCK), fontSize);
  1146.  
  1147. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PRICE), fontSize);
  1148. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_PRICE), fontSize);
  1149.  
  1150. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_RETAIL_PRICE), fontSize);
  1151. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_RETAIL_PRICE), fontSize);
  1152.  
  1153. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR_LABEL), fontSize);
  1154. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR), fontSize);
  1155.  
  1156. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE_LABEL), fontSize);
  1157. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE), fontSize);
  1158.  
  1159. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL_LABEL), fontSize);
  1160. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL), fontSize);
  1161.  
  1162. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_ADDNEWPRODUCT_BUTTON_ACCEPT), fontSize);
  1163. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_ADDNEWPRODUCT_BUTTON_CANCEL), fontSize);
  1164.  
  1165. // Resize and reposition controls
  1166. int labelWidth = 120;
  1167. int editWidth = (width * 40) / 100;
  1168. int editHeight = MulDiv(20, height, 300); // Adjust the height of the edits proportionally
  1169. int buttonWidth = (width - 30) / 2; // Leave a margin of 10 pixels between the buttons
  1170. int buttonHeight = MulDiv(30, height, 300); // Adjust the height of the button proportionally
  1171.  
  1172. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_CODE), 14, (height * 2) / 100, editWidth, editHeight, TRUE);
  1173. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_CODE), editWidth + (width * 8) / 100, (height * 2) / 100, editWidth, editHeight, TRUE);
  1174.  
  1175. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_DESCRIPTION), 14, (height * 10) / 100, editWidth, editHeight, TRUE);
  1176. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_DESCRIPTION), editWidth + (width * 8) / 100, (height * 10) / 100, editWidth, editHeight, TRUE);
  1177.  
  1178. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_INITIAL_STOCK), 14, (height * 18) / 100, editWidth, editHeight, TRUE);
  1179. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_INITIAL_STOCK), editWidth + (width * 8) / 100, (height * 18) / 100, editWidth, editHeight, TRUE);
  1180.  
  1181. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PRICE), 14, (height * 26) / 100, editWidth, editHeight, TRUE);
  1182. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_PRICE), editWidth + (width * 8) / 100, (height * 26) / 100, editWidth, editHeight, TRUE);
  1183.  
  1184. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_RETAIL_PRICE), 14, (height * 34) / 100, editWidth, editHeight, TRUE);
  1185. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWPRODUCT_RETAIL_PRICE), editWidth + (width * 8) / 100, (height * 34) / 100, editWidth, editHeight, TRUE);
  1186.  
  1187. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR_LABEL), 14, (height * 42) / 100, editWidth, editHeight, TRUE);
  1188. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_DOLLAR), editWidth + (width * 8) / 100, (height * 42) / 100, editWidth, editHeight, TRUE);
  1189.  
  1190. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE_LABEL), 14, (height * 50) / 100, editWidth, editHeight, TRUE);
  1191. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_PROFIT_PERCENTAGE), editWidth + (width * 8) / 100, (height * 50) / 100, editWidth, editHeight, TRUE);
  1192.  
  1193. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL_LABEL), 14, (height * 58) / 100, editWidth, editHeight, TRUE);
  1194. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWPRODUCT_VAT_RETAIL), editWidth + (width * 8) / 100, (height * 58) / 100, editWidth, editHeight, TRUE);
  1195.  
  1196. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_ADDNEWPRODUCT_BUTTON_ACCEPT), 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1197. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_ADDNEWPRODUCT_BUTTON_CANCEL), width - buttonWidth - 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1198.  
  1199. // Invalidate and update the window to ensure proper redrawing
  1200. InvalidateRect(hwnd, NULL, TRUE);
  1201. UpdateWindow(hwnd);
  1202. }
  1203.  
  1204. void ResizeAddNewEntriesModalControls(HWND hwnd) {
  1205. RECT clientRect;
  1206. GetClientRect(hwnd, &clientRect);
  1207. int width = clientRect.right - clientRect.left;
  1208. int height = clientRect.bottom - clientRect.top;
  1209.  
  1210. // Calculate the font size based on the window size
  1211. int fontSize = MulDiv(15, height, 300); // Adjust the font size proportionally
  1212.  
  1213. // Adjust the font of the controls
  1214. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_CODE), fontSize);
  1215. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES2_CODE), fontSize);
  1216.  
  1217. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_DESCRIPTION), fontSize);
  1218. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES2_DESCRIPTION), fontSize);
  1219.  
  1220. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_CURRENT_STOCK), fontSize);
  1221. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES2_CURRENT_STOCK), fontSize);
  1222.  
  1223. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_NEW_ENTRIES), fontSize);
  1224. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWENTRIES_NEW_ENTRIES), fontSize);
  1225.  
  1226. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_ADDNEWENTRIES_BUTTON_ACCEPT), fontSize);
  1227. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_ADDNEWENTRIES_BUTTON_CANCEL), fontSize);
  1228.  
  1229. // Resize and reposition controls
  1230. int labelWidth = 120;
  1231. int editWidth = (width * 40) / 100;
  1232. int editHeight = MulDiv(20, height, 300); // Adjust the height of the edits proportionally
  1233. int buttonWidth = (width - 30) / 2; // Leave a margin of 10 pixels between the buttons
  1234. int buttonHeight = MulDiv(30, height, 300); // Adjust the height of the button proportionally
  1235.  
  1236. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_CODE), 14, (height * 2) / 100, editWidth, editHeight, TRUE);
  1237. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES2_CODE), editWidth + (width * 8) / 100, (height * 2) / 100, editWidth, editHeight, TRUE);
  1238.  
  1239. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_DESCRIPTION), 14, (height * 10) / 100, editWidth, editHeight, TRUE);
  1240. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES2_DESCRIPTION), editWidth + (width * 8) / 100, (height * 10) / 100, editWidth, editHeight, TRUE);
  1241.  
  1242. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_CURRENT_STOCK), 14, (height * 26) / 100, editWidth, editHeight, TRUE);
  1243. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES2_CURRENT_STOCK), editWidth + (width * 8) / 100, (height * 26) / 100, editWidth, editHeight, TRUE);
  1244.  
  1245. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_ADDNEWENTRIES_NEW_ENTRIES), 14, (height * 34) / 100, editWidth, editHeight, TRUE);
  1246. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_ADDNEWENTRIES_NEW_ENTRIES), editWidth + (width * 8) / 100, (height * 34) / 100, editWidth, editHeight, TRUE);
  1247.  
  1248. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_ADDNEWENTRIES_BUTTON_ACCEPT), 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1249. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_ADDNEWENTRIES_BUTTON_CANCEL), width - buttonWidth - 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1250.  
  1251. // Invalidate and update the window to ensure proper redrawing
  1252. InvalidateRect(hwnd, NULL, TRUE);
  1253. UpdateWindow(hwnd);
  1254. }
  1255.  
  1256. void ResizeModifyProductModalControls(HWND hwnd) {
  1257. RECT clientRect;
  1258. GetClientRect(hwnd, &clientRect);
  1259. int width = clientRect.right - clientRect.left;
  1260. int height = clientRect.bottom - clientRect.top;
  1261.  
  1262. // Calculate the font size based on the window size
  1263. int fontSize = MulDiv(15, height, 300); // Adjust the font size proportionally
  1264.  
  1265. // Adjust the font of the controls
  1266. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_CODE), fontSize);
  1267. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_CODE), fontSize);
  1268.  
  1269. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_DESCRIPTION), fontSize);
  1270. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_DESCRIPTION), fontSize);
  1271.  
  1272. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_INITIAL_STOCK), fontSize);
  1273. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_INITIAL_STOCK), fontSize);
  1274.  
  1275. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_CURRENT_STOCK), fontSize);
  1276. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_CURRENT_STOCK), fontSize);
  1277.  
  1278. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_NEW_ENTRIES), fontSize);
  1279. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_NEW_ENTRIES), fontSize);
  1280.  
  1281. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_SALES), fontSize);
  1282. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_SALES), fontSize);
  1283.  
  1284. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PRICE), fontSize);
  1285. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_PRICE), fontSize);
  1286.  
  1287. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_RETAIL_PRICE), fontSize);
  1288. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_RETAIL_PRICE), fontSize);
  1289.  
  1290. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR_LABEL), fontSize);
  1291. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR), fontSize);
  1292.  
  1293. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE_LABEL), fontSize);
  1294. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE), fontSize);
  1295.  
  1296. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL_LABEL), fontSize);
  1297. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL), fontSize);
  1298.  
  1299. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_MODIFYPRODUCT_BUTTON_ACCEPT), fontSize);
  1300. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_MODIFYPRODUCT_BUTTON_CANCEL), fontSize);
  1301.  
  1302. // Resize and reposition controls
  1303. int labelWidth = 120;
  1304. int editWidth = (width * 40) / 100;
  1305. int editHeight = MulDiv(20, height, 300); // Adjust the height of the edits proportionally
  1306. int buttonWidth = (width - 30) / 2; // Leave a margin of 10 pixels between the buttons
  1307. int buttonHeight = MulDiv(30, height, 300); // Adjust the height of the button proportionally
  1308.  
  1309. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_CODE), 14, (height * 2) / 100, editWidth, editHeight, TRUE);
  1310. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_CODE), editWidth + (width * 8) / 100, (height * 2) / 100, editWidth, editHeight, TRUE);
  1311.  
  1312. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_DESCRIPTION), 14, (height * 10) / 100, editWidth, editHeight, TRUE);
  1313. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_DESCRIPTION), editWidth + (width * 8) / 100, (height * 10) / 100, editWidth, editHeight, TRUE);
  1314.  
  1315. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_INITIAL_STOCK), 14, (height * 18) / 100, editWidth, editHeight, TRUE);
  1316. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_INITIAL_STOCK), editWidth + (width * 8) / 100, (height * 18) / 100, editWidth, editHeight, TRUE);
  1317.  
  1318. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_CURRENT_STOCK), 14, (height * 26) / 100, editWidth, editHeight, TRUE);
  1319. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_CURRENT_STOCK), editWidth + (width * 8) / 100, (height * 26) / 100, editWidth, editHeight, TRUE);
  1320.  
  1321. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_NEW_ENTRIES), 14, (height * 34) / 100, editWidth, editHeight, TRUE);
  1322. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_NEW_ENTRIES), editWidth + (width * 8) / 100, (height * 34) / 100, editWidth, editHeight, TRUE);
  1323.  
  1324. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_SALES), 14, (height * 42) / 100, editWidth, editHeight, TRUE);
  1325. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_SALES), editWidth + (width * 8) / 100, (height * 42) / 100, editWidth, editHeight, TRUE);
  1326.  
  1327. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PRICE), 14, (height * 50) / 100, editWidth, editHeight, TRUE);
  1328. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_PRICE), editWidth + (width * 8) / 100, (height * 50) / 100, editWidth, editHeight, TRUE);
  1329.  
  1330. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_RETAIL_PRICE), 14, (height * 58) / 100, editWidth, editHeight, TRUE);
  1331. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_MODIFYPRODUCT_RETAIL_PRICE), editWidth + (width * 8) / 100, (height * 58) / 100, editWidth, editHeight, TRUE);
  1332.  
  1333. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR_LABEL), 14, (height * 66) / 100, editWidth, editHeight, TRUE);
  1334. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_DOLLAR), editWidth + (width * 8) / 100, (height * 66) / 100, editWidth, editHeight, TRUE);
  1335.  
  1336. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE_LABEL), 14, (height * 74) / 100, editWidth, editHeight, TRUE);
  1337. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_PROFIT_PERCENTAGE), editWidth + (width * 8) / 100, (height * 74) / 100, editWidth, editHeight, TRUE);
  1338.  
  1339. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL_LABEL), 14, (height * 82) / 100, editWidth, editHeight, TRUE);
  1340. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_MODIFYPRODUCT_VAT_RETAIL), editWidth + (width * 8) / 100, (height * 82) / 100, editWidth, editHeight, TRUE);
  1341.  
  1342. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_MODIFYPRODUCT_BUTTON_ACCEPT), 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1343. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_MODIFYPRODUCT_BUTTON_CANCEL), width - buttonWidth - 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1344.  
  1345. // Invalidate and update the window to ensure proper redrawing
  1346. InvalidateRect(hwnd, NULL, TRUE);
  1347. UpdateWindow(hwnd);
  1348. }
  1349.  
  1350. void ResizeSellProductModalControls(HWND hwnd) {
  1351. RECT clientRect;
  1352. GetClientRect(hwnd, &clientRect);
  1353. int width = clientRect.right - clientRect.left;
  1354. int height = clientRect.bottom - clientRect.top;
  1355.  
  1356. // Calculate the font size based on the window size
  1357. int fontSize = MulDiv(15, height, 300); // Adjust the font size proportionally
  1358.  
  1359. // Adjust the font of the controls
  1360. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_CODE), fontSize);
  1361. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_CODE), fontSize);
  1362.  
  1363. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT2_DESCRIPTION), fontSize);
  1364. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT2_CURRENT_STOCK), fontSize);
  1365.  
  1366. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_CURRENT_STOCK), fontSize);
  1367. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT2_CURRENT_STOCK), fontSize);
  1368.  
  1369. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_NEW_SALES), fontSize);
  1370. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_NEW_SALES), fontSize);
  1371.  
  1372. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PRICE), fontSize);
  1373. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_PRICE), fontSize);
  1374.  
  1375. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_RETAIL_PRICE), fontSize);
  1376. SetControlFont(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_RETAIL_PRICE), fontSize);
  1377.  
  1378. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR_LABEL), fontSize);
  1379. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR), fontSize);
  1380.  
  1381. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE_LABEL), fontSize);
  1382. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE), fontSize);
  1383.  
  1384. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL_LABEL), fontSize);
  1385. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL), fontSize);
  1386.  
  1387. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_SELLPRODUCT_BUTTON_ACCEPT), fontSize);
  1388. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_SELLPRODUCT_BUTTON_CANCEL), fontSize);
  1389.  
  1390. // Resize and reposition controls
  1391. int labelWidth = 120;
  1392. int editWidth = (width * 40) / 100;
  1393. int editHeight = MulDiv(20, height, 300); // Adjust the height of the edits proportionally
  1394. int buttonWidth = (width - 30) / 2; // Leave a margin of 10 pixels between the buttons
  1395. int buttonHeight = MulDiv(30, height, 300); // Adjust the height of the button proportionally
  1396.  
  1397. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_CODE), 14, (height * 2) / 100, editWidth, editHeight, TRUE);
  1398. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_CODE), editWidth + (width * 8) / 100, (height * 2) / 100, editWidth, editHeight, TRUE);
  1399.  
  1400. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT2_DESCRIPTION), 14, (height * 10) / 100, editWidth, editHeight, TRUE);
  1401. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT2_DESCRIPTION), editWidth + (width * 8) / 100, (height * 10) / 100, editWidth, editHeight, TRUE);
  1402.  
  1403. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_CURRENT_STOCK), 14, (height * 18) / 100, editWidth, editHeight, TRUE);
  1404. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT2_CURRENT_STOCK), editWidth + (width * 8) / 100, (height * 18) / 100, editWidth, editHeight, TRUE);
  1405.  
  1406. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_NEW_SALES), 14, (height * 26) / 100, editWidth, editHeight, TRUE);
  1407. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_NEW_SALES), editWidth + (width * 8) / 100, (height * 26) / 100, editWidth, editHeight, TRUE);
  1408.  
  1409. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PRICE), 14, (height * 34) / 100, editWidth, editHeight, TRUE);
  1410. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_PRICE), editWidth + (width * 8) / 100, (height * 34) / 100, editWidth, editHeight, TRUE);
  1411.  
  1412. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_RETAIL_PRICE), 14, (height * 42) / 100, editWidth, editHeight, TRUE);
  1413. MoveWindow(GetDlgItem(hwnd, IDC_EDIT_MODAL_SELLPRODUCT_RETAIL_PRICE), editWidth + (width * 8) / 100, (height * 42) / 100, editWidth, editHeight, TRUE);
  1414.  
  1415. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR_LABEL), 14, (height * 50) / 100, editWidth, editHeight, TRUE);
  1416. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_DOLLAR), editWidth + (width * 8) / 100, (height * 50) / 100, editWidth, editHeight, TRUE);
  1417.  
  1418. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE_LABEL), 14, (height * 58) / 100, editWidth, editHeight, TRUE);
  1419. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_PROFIT_PERCENTAGE), editWidth + (width * 8) / 100, (height * 58) / 100, editWidth, editHeight, TRUE);
  1420.  
  1421. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL_LABEL), 14, (height * 66) / 100, editWidth, editHeight, TRUE);
  1422. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_SELLPRODUCT_VAT_RETAIL), editWidth + (width * 8) / 100, (height * 66) / 100, editWidth, editHeight, TRUE);
  1423.  
  1424. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_SELLPRODUCT_BUTTON_ACCEPT), 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1425. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_SELLPRODUCT_BUTTON_CANCEL), width - buttonWidth - 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1426.  
  1427. // Invalidate and update the window to ensure proper redrawing
  1428. InvalidateRect(hwnd, NULL, TRUE);
  1429. UpdateWindow(hwnd);
  1430. }
  1431.  
  1432. void ResizeCalculateModalControls(HWND hwnd) {
  1433. RECT clientRect;
  1434. GetClientRect(hwnd, &clientRect);
  1435. int width = clientRect.right - clientRect.left;
  1436. int height = clientRect.bottom - clientRect.top;
  1437.  
  1438. // Calculate the font size based on the window size
  1439. int fontSize = MulDiv(15, height, 300); // Adjust the font size proportionally
  1440.  
  1441. // Adjust the font of the controls
  1442. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_CODE), fontSize);
  1443. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_CODE), fontSize);
  1444.  
  1445. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_DESCRIPTION), fontSize);
  1446. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_DESCRIPTION), fontSize);
  1447.  
  1448. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PRICE), fontSize);
  1449. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_PRICE), fontSize);
  1450.  
  1451. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_RETAIL_PRICE), fontSize);
  1452. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_RETAIL_PRICE), fontSize);
  1453.  
  1454. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR_LABEL), fontSize);
  1455. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR), fontSize);
  1456.  
  1457. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE_LABEL), fontSize);
  1458. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE), fontSize);
  1459.  
  1460. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL_LABEL), fontSize);
  1461. SetControlFont(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL), fontSize);
  1462.  
  1463. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_CALCULATEPRODUCT_BUTTON_ACCEPT), fontSize);
  1464. SetControlFont(GetDlgItem(hwnd, IDC__MODAL_CALCULATEPRODUCT_BUTTON_CANCEL), fontSize);
  1465.  
  1466. // Resize and reposition controls
  1467. int labelWidth = 120;
  1468. int editWidth = (width * 40) / 100;
  1469. int editHeight = MulDiv(20, height, 300); // Adjust the height of the edits proportionally
  1470. int buttonWidth = (width - 30) / 2; // Leave a margin of 10 pixels between the buttons
  1471. int buttonHeight = MulDiv(30, height, 300); // Adjust the height of the button proportionally
  1472.  
  1473. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_CODE), 14, (height * 2) / 100, editWidth, editHeight, TRUE);
  1474. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_CODE), editWidth + (width * 8) / 100, (height * 2) / 100, editWidth, editHeight, TRUE);
  1475.  
  1476. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_DESCRIPTION), 14, (height * 10) / 100, editWidth, editHeight, TRUE);
  1477. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_DESCRIPTION), editWidth + (width * 8) / 100, (height * 10) / 100, editWidth, editHeight, TRUE);
  1478.  
  1479. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PRICE), 14, (height * 18) / 100, editWidth, editHeight, TRUE);
  1480. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_PRICE), editWidth + (width * 8) / 100, (height * 18) / 100, editWidth, editHeight, TRUE);
  1481.  
  1482. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_RETAIL_PRICE), 14, (height * 26) / 100, editWidth, editHeight, TRUE);
  1483. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT2_RETAIL_PRICE), editWidth + (width * 8) / 100, (height * 26) / 100, editWidth, editHeight, TRUE);
  1484.  
  1485. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR_LABEL), 14, (height * 34) / 100, editWidth, editHeight, TRUE);
  1486. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_DOLLAR), editWidth + (width * 8) / 100, (height * 34) / 100, editWidth, editHeight, TRUE);
  1487.  
  1488. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE_LABEL), 14, (height * 42) / 100, editWidth, editHeight, TRUE);
  1489. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_PROFIT_PERCENTAGE), editWidth + (width * 8) / 100, (height * 42) / 100, editWidth, editHeight, TRUE);
  1490.  
  1491. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL_LABEL), 14, (height * 50) / 100, editWidth, editHeight, TRUE);
  1492. MoveWindow(GetDlgItem(hwnd, IDC_STATIC_MODAL_CALCULATEPRODUCT_VAT_RETAIL), editWidth + (width * 8) / 100, (height * 50) / 100, editWidth, editHeight, TRUE);
  1493.  
  1494. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_CALCULATEPRODUCT_BUTTON_ACCEPT), 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1495. MoveWindow(GetDlgItem(hwnd, IDC__MODAL_CALCULATEPRODUCT_BUTTON_CANCEL), width - buttonWidth - 10, height - buttonHeight - 10, buttonWidth, buttonHeight, TRUE);
  1496.  
  1497. // Invalidate and update the window to ensure proper redrawing
  1498. InvalidateRect(hwnd, NULL, TRUE);
  1499. UpdateWindow(hwnd);
  1500. }
  1501.  
  1502. void CenterWindow(HWND hwnd) {
  1503. RECT rc;
  1504. GetWindowRect(hwnd, &rc);
  1505.  
  1506. int width = rc.right - rc.left;
  1507. int height = rc.bottom - rc.top;
  1508.  
  1509. int screenWidth = GetSystemMetrics(SM_CXSCREEN);
  1510. int screenHeight = GetSystemMetrics(SM_CYSCREEN);
  1511.  
  1512. int x = (screenWidth - width) / 2;
  1513. int y = (screenHeight - height) / 2;
  1514.  
  1515. SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  1516. }
  1517.  
  1518. void UpdateListViewColumns(HWND hwndListView, int selectedTab) {
  1519. // Here you can add the logic to update the columns of the ListView based on the selected tab
  1520. }
  1521.  
Advertisement
Add Comment
Please, Sign In to add comment