| 1 | 
 #include "mailFromGui.h" | 
 
 
 
 
 
 | 2 | 
  | 
 
 
 
 
 
 | 3 | 
 #include <stdio.h> | 
 
 
 
 
 
 | 4 | 
 #include <stdint.h> | 
 
 
 
 
 
 | 5 | 
 #include <stdbool.h> | 
 
 
 
 
 
 | 6 | 
  | 
 
 
 
 
 
 | 7 | 
  | 
 
 
 
 
 
 | 8 | 
 #define WIN_WIDTH  450 | 
 
 
 
 
 
 | 9 | 
 #define WIN_HEIGHT 270 | 
 
 
 
 
 
 | 10 | 
  | 
 
 
 
 
 
 | 11 | 
 enum { | 
 
 
 
 
 
 | 12 | 
         TXT_INFO, | 
 
 
 
 
 
 | 13 | 
         TXT_MAIL, | 
 
 
 
 
 
 | 14 | 
         EDIT_MAIL, | 
 
 
 
 
 
 | 15 | 
         CHK_CC, | 
 
 
 
 
 
 | 16 | 
         BTN_SEND, | 
 
 
 
 
 
 | 17 | 
         BTN_ABORT | 
 
 
 
 
 
 | 18 | 
 } window_objects; | 
 
 
 
 
 
 | 19 | 
  | 
 
 
 
 
 
 | 20 | 
 bool isSendSelected = false; | 
 
 
 
 
 
 | 21 | 
 bool isCCSelected = false; | 
 
 
 
 
 
 | 22 | 
 char* emailFrom = 0; | 
 
 
 
 
 
 | 23 | 
  | 
 
 
 
 
 
 | 24 | 
 static HWND hwndEditMail; | 
 
 
 
 
 
 | 25 | 
  | 
 
 
 
 
 
 | 26 | 
 static bool verifyMail() { | 
 
 
 
 
 
 | 27 | 
         char* at = strchr(emailFrom, '@'); | 
 
 
 
 
 
 | 28 | 
         char* dot = strrchr(emailFrom, '.'); | 
 
 
 
 
 
 | 29 | 
         if (at == NULL || dot == NULL) | 
 
 
 
 
 
 | 30 | 
                 return false; | 
 
 
 
 
 
 | 31 | 
         if (dot <= at) | 
 
 
 
 
 
 | 32 | 
                 return false; | 
 
 
 
 
 
 | 33 | 
  | 
 
 
 
 
 
 | 34 | 
         unsigned int atPos = at - emailFrom; | 
 
 
 
 
 
 | 35 | 
         unsigned int dotPos = dot - emailFrom; | 
 
 
 
 
 
 | 36 | 
         if (atPos < 1 || (dotPos - atPos) < 2) | 
 
 
 
 
 
 | 37 | 
                 return false; | 
 
 
 
 
 
 | 38 | 
         if (dotPos >= strlen(emailFrom)-1) | 
 
 
 
 
 
 | 39 | 
                 return false; | 
 
 
 
 
 
 | 40 | 
  | 
 
 
 
 
 
 | 41 | 
         return true; | 
 
 
 
 
 
 | 42 | 
 } | 
 
 
 
 
 
 | 43 | 
  | 
 
 
 
 
 
 | 44 | 
 static void handleWindowCreate(HWND hwnd) { | 
 
 
 
 
 
 | 45 | 
         static LPCSTR txtInfo = "\ | 
 
 
 
 
 
 | 46 | 
 With this program you can request help from the AE\n\ | 
 
 
 
 
 
 | 47 | 
 support team if you have trouble installing the AE.\n\ | 
 
 
 
 
 
 | 48 | 
 \n\ | 
 
 
 
 
 
 | 49 | 
 Please only use this if you are asked to on the forum!\n\ | 
 
 
 
 
 
 | 50 | 
 \n\ | 
 
 
 
 
 
 | 51 | 
 The information that is sent is:\n\ | 
 
 
 
 
 
 | 52 | 
 - AEI updater's updater_output.log\n\ | 
 
 
 
 
 
 | 53 | 
 - AEI-ProxySettings.xml\n\ | 
 
 
 
 
 
 | 54 | 
 - A list of files within your AE/ folder"; | 
 
 
 
 
 
 | 55 | 
  | 
 
 
 
 
 
 | 56 | 
         int top = 0, left = 5; | 
 
 
 
 
 
 | 57 | 
         int height, width = WIN_WIDTH - 2*left - 4; | 
 
 
 
 
 
 | 58 | 
  | 
 
 
 
 
 
 | 59 | 
         top += 5; | 
 
 
 
 
 
 | 60 | 
         height = 150; | 
 
 
 
 
 
 | 61 | 
         CreateWindowA("STATIC", txtInfo,  | 
 
 
 
 
 
 | 62 | 
                 WS_CHILD | WS_VISIBLE | SS_LEFT, | 
 
 
 
 
 
 | 63 | 
                 left, top, width, height, | 
 
 
 
 
 
 | 64 | 
                 hwnd, (HMENU) TXT_INFO, NULL, NULL); | 
 
 
 
 
 
 | 65 | 
  | 
 
 
 
 
 
 | 66 | 
         top += height + 5; | 
 
 
 
 
 
 | 67 | 
         height = 20; | 
 
 
 
 
 
 | 68 | 
         width = 145; | 
 
 
 
 
 
 | 69 | 
         CreateWindowA("STATIC", "Your e-mail address:",  | 
 
 
 
 
 
 | 70 | 
                 WS_CHILD | WS_VISIBLE | SS_LEFT, | 
 
 
 
 
 
 | 71 | 
                 left, top, width, height, | 
 
 
 
 
 
 | 72 | 
                 hwnd, (HMENU) TXT_MAIL, NULL, NULL); | 
 
 
 
 
 
 | 73 | 
         left += width + 5; | 
 
 
 
 
 
 | 74 | 
         width = WIN_WIDTH - 20 - width; | 
 
 
 
 
 
 | 75 | 
         hwndEditMail = CreateWindowA("Edit", NULL,  | 
 
 
 
 
 
 | 76 | 
                 WS_CHILD | WS_VISIBLE | WS_BORDER, | 
 
 
 
 
 
 | 77 | 
                 left, top, width, height, hwnd, (HMENU) EDIT_MAIL, | 
 
 
 
 
 
 | 78 | 
                 NULL, NULL); | 
 
 
 
 
 
 | 79 | 
         left = 5; | 
 
 
 
 
 
 | 80 | 
         width = WIN_WIDTH - 2*left - 4; | 
 
 
 
 
 
 | 81 | 
  | 
 
 
 
 
 
 | 82 | 
         top += height + 5; | 
 
 
 
 
 
 | 83 | 
         height = 20; | 
 
 
 
 
 
 | 84 | 
         CreateWindowA("button", "Send a copy of the mail to you", | 
 
 
 
 
 
 | 85 | 
                 WS_VISIBLE | WS_CHILD | BS_CHECKBOX, | 
 
 
 
 
 
 | 86 | 
                 left, top, width, height, hwnd, (HMENU) CHK_CC,  | 
 
 
 
 
 
 | 87 | 
                 NULL, NULL); | 
 
 
 
 
 
 | 88 | 
  | 
 
 
 
 
 
 | 89 | 
         top += height + 5; | 
 
 
 
 
 
 | 90 | 
         height = 28; | 
 
 
 
 
 
 | 91 | 
         width = 100; | 
 
 
 
 
 
 | 92 | 
         left = WIN_WIDTH - 3*5 - 2*width; | 
 
 
 
 
 
 | 93 | 
         CreateWindowA("button", "Send request", | 
 
 
 
 
 
 | 94 | 
                 WS_VISIBLE | WS_CHILD , | 
 
 
 
 
 
 | 95 | 
                 left, top, width, height, | 
 
 
 
 
 
 | 96 | 
                 hwnd, (HMENU) BTN_SEND, NULL, NULL); | 
 
 
 
 
 
 | 97 | 
         left = WIN_WIDTH - 2*5 - 1*width; | 
 
 
 
 
 
 | 98 | 
         CreateWindowA("button", "Abort", | 
 
 
 
 
 
 | 99 | 
                 WS_VISIBLE | WS_CHILD , | 
 
 
 
 
 
 | 100 | 
                 left, top, width, height, | 
 
 
 
 
 
 | 101 | 
                 hwnd, (HMENU) BTN_ABORT, NULL, NULL); | 
 
 
 
 
 
 | 102 | 
 } | 
 
 
 
 
 
 | 103 | 
  | 
 
 
 
 
 
 | 104 | 
 static void handleWindowCommand(HWND hwnd, WPARAM wParam) { | 
 
 
 
 
 
 | 105 | 
         bool checked; | 
 
 
 
 
 
 | 106 | 
         int len; | 
 
 
 
 
 
 | 107 | 
          | 
 
 
 
 
 
 | 108 | 
         switch (LOWORD(wParam)) { | 
 
 
 
 
 
 | 109 | 
                 case BTN_SEND: | 
 
 
 
 
 
 | 110 | 
                         len = GetWindowTextLengthA(hwndEditMail) + 1; | 
 
 
 
 
 
 | 111 | 
                         emailFrom = malloc(len); | 
 
 
 
 
 
 | 112 | 
                         GetWindowTextA(hwndEditMail, emailFrom, len); | 
 
 
 
 
 
 | 113 | 
  | 
 
 
 
 
 
 | 114 | 
                         if (verifyMail()) { | 
 
 
 
 
 
 | 115 | 
                                 isSendSelected = true; | 
 
 
 
 
 
 | 116 | 
                                 ShowWindow(hwnd, SW_HIDE); | 
 
 
 
 
 
 | 117 | 
                                 PostQuitMessage(0); | 
 
 
 
 
 
 | 118 | 
                         } else { | 
 
 
 
 
 
 | 119 | 
                                 MessageBox(hwnd, "Please enter a valid e-mail address", "Invalid e-mail", MB_OK | MB_ICONEXCLAMATION); | 
 
 
 
 
 
 | 120 | 
                         } | 
 
 
 
 
 
 | 121 | 
                         break; | 
 
 
 
 
 
 | 122 | 
                 case BTN_ABORT: | 
 
 
 
 
 
 | 123 | 
                         PostQuitMessage(0); | 
 
 
 
 
 
 | 124 | 
                         break; | 
 
 
 
 
 
 | 125 | 
                 case CHK_CC: | 
 
 
 
 
 
 | 126 | 
                         checked = IsDlgButtonChecked(hwnd, CHK_CC); | 
 
 
 
 
 
 | 127 | 
                         if (checked) { | 
 
 
 
 
 
 | 128 | 
                                 CheckDlgButton(hwnd, CHK_CC, BST_UNCHECKED); | 
 
 
 
 
 
 | 129 | 
                                 isCCSelected = false; | 
 
 
 
 
 
 | 130 | 
                         } else { | 
 
 
 
 
 
 | 131 | 
                                 CheckDlgButton(hwnd, CHK_CC, BST_CHECKED); | 
 
 
 
 
 
 | 132 | 
                                 isCCSelected = true; | 
 
 
 
 
 
 | 133 | 
                         } | 
 
 
 
 
 
 | 134 | 
                         break; | 
 
 
 
 
 
 | 135 | 
         } | 
 
 
 
 
 
 | 136 | 
 } | 
 
 
 
 
 
 | 137 | 
  | 
 
 
 
 
 
 | 138 | 
 static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | 
 
 
 
 
 
 | 139 | 
 { | 
 
 
 
 
 
 | 140 | 
         switch(msg) | 
 
 
 
 
 
 | 141 | 
         { | 
 
 
 
 
 
 | 142 | 
                 case WM_CREATE: | 
 
 
 
 
 
 | 143 | 
                         handleWindowCreate(hwnd); | 
 
 
 
 
 
 | 144 | 
                         break; | 
 
 
 
 
 
 | 145 | 
  | 
 
 
 
 
 
 | 146 | 
                 case WM_COMMAND: | 
 
 
 
 
 
 | 147 | 
                         handleWindowCommand(hwnd, wParam); | 
 
 
 
 
 
 | 148 | 
                         break; | 
 
 
 
 
 
 | 149 | 
  | 
 
 
 
 
 
 | 150 | 
                 case WM_DESTROY: | 
 
 
 
 
 
 | 151 | 
                         PostQuitMessage(0); | 
 
 
 
 
 
 | 152 | 
                         return 0;       | 
 
 
 
 
 
 | 153 | 
         } | 
 
 
 
 
 
 | 154 | 
  | 
 
 
 
 
 
 | 155 | 
         return DefWindowProcW(hwnd, msg, wParam, lParam); | 
 
 
 
 
 
 | 156 | 
 } | 
 
 
 
 
 
 | 157 | 
  | 
 
 
 
 
 
 | 158 | 
  | 
 
 
 
 
 
 | 159 | 
 void mailFromGui(HMODULE hInstance, int nCmdShow) | 
 
 
 
 
 
 | 160 | 
 { | 
 
 
 
 
 
 | 161 | 
         static const LPCWSTR title = L"Request Help"; | 
 
 
 
 
 
 | 162 | 
  | 
 
 
 
 
 
 | 163 | 
         MSG  msg;     | 
 
 
 
 
 
 | 164 | 
         HWND hwnd; | 
 
 
 
 
 
 | 165 | 
         WNDCLASSW wc; | 
 
 
 
 
 
 | 166 | 
  | 
 
 
 
 
 
 | 167 | 
         wc.style         = CS_HREDRAW | CS_VREDRAW; | 
 
 
 
 
 
 | 168 | 
         wc.cbClsExtra    = 0; | 
 
 
 
 
 
 | 169 | 
         wc.cbWndExtra    = 0; | 
 
 
 
 
 
 | 170 | 
         wc.lpszClassName = L"Window"; | 
 
 
 
 
 
 | 171 | 
         wc.hInstance     = hInstance; | 
 
 
 
 
 
 | 172 | 
         wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); | 
 
 
 
 
 
 | 173 | 
         wc.lpszMenuName  = NULL; | 
 
 
 
 
 
 | 174 | 
         wc.lpfnWndProc   = WndProc; | 
 
 
 
 
 
 | 175 | 
         wc.hCursor       = LoadCursor(NULL, IDC_ARROW); | 
 
 
 
 
 
 | 176 | 
         wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION); | 
 
 
 
 
 
 | 177 | 
  | 
 
 
 
 
 
 | 178 | 
         RegisterClassW(&wc); | 
 
 
 
 
 
 | 179 | 
         hwnd = CreateWindowW( wc.lpszClassName, title, | 
 
 
 
 
 
 | 180 | 
                 WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_VISIBLE, | 
 
 
 
 
 
 | 181 | 
                 CW_USEDEFAULT, CW_USEDEFAULT, WIN_WIDTH, WIN_HEIGHT, NULL, NULL, hInstance, NULL);   | 
 
 
 
 
 
 | 182 | 
  | 
 
 
 
 
 
 | 183 | 
         ShowWindow(hwnd, nCmdShow); | 
 
 
 
 
 
 | 184 | 
         UpdateWindow(hwnd); | 
 
 
 
 
 
 | 185 | 
  | 
 
 
 
 
 
 | 186 | 
         while( GetMessage(&msg, NULL, 0, 0)) { | 
 
 
 
 
 
 | 187 | 
                 TranslateMessage(&msg); | 
 
 
 
 
 
 | 188 | 
                 DispatchMessage(&msg); | 
 
 
 
 
 
 | 189 | 
         } | 
 
 
 
 
 
 | 190 | 
 } | 
 
 
 
 
 
 | 191 | 
  |