Changes between Version 5 and Version 6 of MiniCalcExample
- Timestamp:
- 11/18/07 17:49:00 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MiniCalcExample
v5 v6 10 10 11 11 {{{ 12 #!d13 12 /* Compile with: 14 13 * dmd MiniCalc gdi32.lib MiniCalc.def 17 16 import std.string; 18 17 import std.c.windows.windows; 18 19 extern (Windows) BOOL IsDialogMessage(HWND hDlg, LPMSG lpMsg); 19 20 20 21 const int IDC_BTN_PLUS = 103; 35 36 { 36 37 HWND hChapSelectorTree; 37 38 ghPlusBtn = CreateWindowA("BUTTON", "Plus", 39 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,40 5, 5, 53, 25, ghWndMain, cast(HMENU) IDC_BTN_PLUS, 38 39 ghPlusBtn = CreateWindowA("BUTTON", "Plus", 40 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_TEXT, 41 5, 5, 53, 25, ghWndMain, cast(HMENU) IDC_BTN_PLUS, 41 42 ghInstance, null); 42 43 43 ghMinusBtn = CreateWindowA("BUTTON", "Minus", 44 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,45 60, 5, 53, 25, ghWndMain, 46 cast(HMENU) IDC_BTN_MINUS, 44 ghMinusBtn = CreateWindowA("BUTTON", "Minus", 45 WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON | BS_TEXT, 46 60, 5, 53, 25, ghWndMain, 47 cast(HMENU) IDC_BTN_MINUS, 47 48 ghInstance, null); 48 49 49 ghFirstNumberEdit = CreateWindowA("EDIT", "0", 50 WS_CHILD | WS_VISIBLE | WS_ BORDER | ES_LEFT,51 5, 32, 110, 25, ghWndMain, 50 ghFirstNumberEdit = CreateWindowA("EDIT", "0", 51 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT, 52 5, 32, 110, 25, ghWndMain, 52 53 cast(HMENU) IDC_EDIT_FIRST_NUMBER, ghInstance, null); 53 54 54 ghSecondNumberEdit = CreateWindowA("EDIT", "20", 55 WS_CHILD | WS_VISIBLE | WS_ BORDER | ES_LEFT,56 5, 60, 110, 25, ghWndMain, 55 ghSecondNumberEdit = CreateWindowA("EDIT", "20", 56 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT, 57 5, 60, 110, 25, ghWndMain, 57 58 cast(HMENU) IDC_EDIT_SECOND_NUMBER, ghInstance, null); 58 59 ghResultNumberEdit = CreateWindowA("EDIT", "", 60 WS_CHILD | WS_VISIBLE | WS_ BORDER | ES_LEFT,61 5, 87, 110, 25, ghWndMain, 62 cast(HMENU) IDC_EDIT_RESULT_NUMBER, 59 60 ghResultNumberEdit = CreateWindowA("EDIT", "", 61 WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT, 62 5, 87, 110, 25, ghWndMain, 63 cast(HMENU) IDC_EDIT_RESULT_NUMBER, 63 64 ghInstance, null); 65 66 SendMessageA(ghFirstNumberEdit, EM_LIMITTEXT, 9, 0); 67 SendMessageA(ghSecondNumberEdit, EM_LIMITTEXT, 9, 0); 64 68 } 65 69 68 72 MSG msg; 69 73 while (GetMessageA(&msg, cast(HWND) null, 0, 0)) { 70 TranslateMessage(&msg); 71 DispatchMessageA(&msg); 74 if (!IsDialogMessage(ghWndMain, &msg)) { 75 TranslateMessage(&msg); 76 DispatchMessageA(&msg); 77 } 72 78 } 73 79 } 76 82 { 77 83 HWND hWnd; 78 hWnd = CreateWindowA("DWndClass", 79 "MiniCalc", 80 WS_THICKFRAME | WS_MAXIMIZEBOX 84 hWnd = CreateWindowA("DWndClass", 85 "MiniCalc", 86 WS_THICKFRAME | WS_MAXIMIZEBOX 81 87 | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE, 82 CW_USEDEFAULT, CW_USEDEFAULT, 88 CW_USEDEFAULT, CW_USEDEFAULT, 83 89 125, 150, HWND_DESKTOP, 84 90 cast(HMENU) null, ghInstance, null); 130 136 131 137 extern (Windows) 132 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 138 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 133 139 LPSTR lpCmdLine, int nCmdShow) 134 140 { 157 163 int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam) 158 164 { 159 char[ 8] firstNumber;160 char[ 8] secondNumber;165 char[10] firstNumber; 166 char[10] secondNumber; 161 167 int count; 162 168 long num1; 168 174 case IDC_BTN_PLUS: 169 175 if (HIWORD(wParam) == BN_CLICKED) { 170 count = SendMessageA(ghFirstNumberEdit, WM_GETTEXT, 171 6, cast(int)cast(char*)firstNumber);172 count = SendMessageA(ghSecondNumberEdit, WM_GETTEXT, 173 6, cast(int)cast(char*)secondNumber);176 count = SendMessageA(ghFirstNumberEdit, WM_GETTEXT, 177 10, cast(int)cast(char*)firstNumber); 178 count = SendMessageA(ghSecondNumberEdit, WM_GETTEXT, 179 10, cast(int)cast(char*)secondNumber); 174 180 num1 = atoi(cast(char[])firstNumber); 175 181 num2 = atoi(cast(char[])secondNumber); 176 SendMessageA(ghResultNumberEdit, WM_SETTEXT, 177 8, cast(int)cast(char*)toString(num1 + num2));182 SendMessageA(ghResultNumberEdit, WM_SETTEXT, 183 0, cast(int) toStringz(toString(num1 + num2))); 178 184 } 179 185 break; 180 186 case IDC_BTN_MINUS: 181 187 if (HIWORD(wParam) == BN_CLICKED) { 182 count = SendMessageA(ghFirstNumberEdit, 183 WM_GETTEXT, 8,188 count = SendMessageA(ghFirstNumberEdit, 189 WM_GETTEXT, 10, 184 190 cast(int)cast(char*)firstNumber); 185 count = SendMessageA(ghSecondNumberEdit, 186 WM_GETTEXT, 8,191 count = SendMessageA(ghSecondNumberEdit, 192 WM_GETTEXT, 10, 187 193 cast(int)cast(char*)secondNumber); 188 194 num1 = atoi(cast(char[])firstNumber); 189 195 num2 = atoi(cast(char[])secondNumber); 190 SendMessageA(ghResultNumberEdit, 191 WM_SETTEXT, 8, 192 cast(int)cast(char*)toString(num1 - num2)); 196 SendMessageA(ghResultNumberEdit, WM_SETTEXT, 197 0, cast(int) toStringz(toString(num1 - num2))); 193 198 } 194 199 break;