Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

513 lines
16 KiB

  1. /*===========================================================================*/
  2. /* */
  3. /* Windows DynaComm version 1.x -- Dynamic Communications for Windows 2.x */
  4. /* */
  5. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  6. /* Houston, Texas */
  7. /*---------------------------------------------------------------------------*/
  8. /* This material is an unpublished work containing trade secrets which are */
  9. /* the property of Future Soft Engineering, Inc., and is subject to a */
  10. /* license therefrom. It may not be disclosed, reproduced, adapted, merged, */
  11. /* translated, or used in any manner without prior written consent from FSE. */
  12. /*===========================================================================*/
  13. #define NOLSTRING TRUE /* jtf win3 mod */
  14. #include <windows.h>
  15. #include "port1632.h"
  16. #include "dcrc.h"
  17. #include "dynacomm.h"
  18. #include "task.h"
  19. #include "dcdata.h"
  20. #include "video.h"
  21. #include "printfil.h"
  22. /*---------------------------------------------------------------------------*/
  23. /* mainProcess() - main process loop; called from _INITCODE:WINMAIN [mbb] */
  24. /*---------------------------------------------------------------------------*/
  25. VOID FAR mainProcess()
  26. {
  27. DWORD dwThreadID;
  28. doneFlag =
  29. gbThreadDoneFlag = FALSE;
  30. CommThreadExit = FALSE;
  31. dwTimerRes = 100;
  32. commThread = CreateThread(NULL, 0, checkCommEvent,
  33. IntToPtr(dwTimerRes), CREATE_SUSPENDED | STANDARD_RIGHTS_REQUIRED,
  34. &dwThreadID);
  35. if (commThread)
  36. {
  37. SetThreadPriority(commThread, THREAD_PRIORITY_BELOW_NORMAL);
  38. ResumeThread(commThread);
  39. }
  40. overlapEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  41. hMutex = CreateMutex(NULL, FALSE, NULL);
  42. repeat
  43. {
  44. mainEventLoop();
  45. }
  46. until(doneFlag);
  47. // terminate threads here, not just close handles!!!!
  48. // TerminateThread(hwndThread, (DWORD)0);
  49. // CloseHandle(hwndThread);
  50. // while(WaitForSingleObject(hMutex, 1000) != 0)
  51. // {
  52. // Sleep((DWORD)50);
  53. // MessageBeep(0);
  54. // }
  55. if (WaitForSingleObject(hMutex, 2000) != 0)
  56. {
  57. // the comevent thread did not comeout in 2 sec, something wrong
  58. // Just kill it and indicate by Beep (for the timebeing) that
  59. // we have this wierd condition
  60. MessageBeep(0);
  61. TerminateThread(commThread, (DWORD)0);
  62. }
  63. else
  64. {
  65. // just in case if that thread as not done ExitThread(), kill it
  66. // maybe this is a overkill!
  67. TerminateThread(commThread, (DWORD)0);
  68. ReleaseMutex(hMutex);
  69. }
  70. CloseHandle(commThread);
  71. CloseHandle(hMutex);
  72. }
  73. /*---------------------------------------------------------------------------*/
  74. /* mainEventLoop() - Main input from the application queue [mbb] */
  75. /*---------------------------------------------------------------------------*/
  76. VOID FAR mainEventLoop()
  77. {
  78. idleProcess();
  79. if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  80. {
  81. if(!IsDialogMessage(hdbmyControls, &msg) &&
  82. !IsDialogMessage(hdbXferCtrls, &msg))
  83. {
  84. DispatchMessage(&msg);
  85. }
  86. }
  87. }
  88. DWORD xSndThread (LPVOID lpParameter)
  89. {
  90. DWORD parentId = PtrToInt(lpParameter);
  91. AttachThreadInput (GetCurrentThreadId(), parentId, TRUE);
  92. xSndBFile();
  93. xferEnd();
  94. MessageBeep(10);
  95. gbXferActive = FALSE;
  96. return 0;
  97. }
  98. DWORD xRcvThread (LPVOID lpParameter)
  99. {
  100. DWORD parentId = PtrToInt(lpParameter);
  101. AttachThreadInput (GetCurrentThreadId(), parentId, TRUE);
  102. xRcvBFile();
  103. xferEnd();
  104. MessageBeep(10);
  105. gbXferActive = FALSE;
  106. return 0;
  107. }
  108. /*---------------------------------------------------------------------------*/
  109. /* idleProcess() - [mbb] */
  110. /*---------------------------------------------------------------------------*/
  111. void APIENTRY idleProcess(VOID)
  112. {
  113. // sdj: was unref local - LONG secs;
  114. // sdj: was unref local - LONG finalTicks;
  115. // sdj: was unref local - HWND hwnd;
  116. static HANDLE hThread;
  117. static DWORD dwId;
  118. updateTimer();
  119. if(!gbXferActive)
  120. {
  121. if (xferFlag == XFRBSND)
  122. {
  123. gbXferActive = TRUE;
  124. hThread = CreateThread (NULL,
  125. 0,
  126. xSndThread,
  127. IntToPtr(GetCurrentThreadId()),
  128. TRUE,
  129. &dwId);
  130. }
  131. else if(xferFlag == XFRBRCV)
  132. {
  133. gbXferActive = TRUE;
  134. hThread = CreateThread (NULL,
  135. 0,
  136. xRcvThread,
  137. IntToPtr(GetCurrentThreadId()),
  138. TRUE,
  139. &dwId);
  140. }
  141. else
  142. {
  143. if (activTerm)
  144. termSpecial ();
  145. if(mdmConnect())
  146. {
  147. modemReset();
  148. timerAction(mdmOnLine, mdmOnLine); /* mbbx 1.03 */
  149. }
  150. cursorAdjust();
  151. if(activTerm)
  152. blinkCursor();
  153. }
  154. }
  155. Sleep((DWORD)10);
  156. }
  157. /*---------------------------------------------------------------------------*/
  158. /* updateTimer() - [mbb] */
  159. /*---------------------------------------------------------------------------*/
  160. VOID FAR updateTimer() /* mbbx 2.00: fkeys... */
  161. {
  162. #ifdef WIN32
  163. WPARAM wParam;
  164. #endif
  165. /* rjs bug2 001 */
  166. if(GetCurrentTime() - gIdleTimer >= 900)
  167. {
  168. gIdleTimer = GetCurrentTime();
  169. if((hItWnd != NULL) && IsWindowVisible(hdbmyControls))
  170. #ifdef ORGCODE
  171. updateFKeyButton(MAKELONG(GetDlgItem(hdbmyControls, IDTIMER), BN_PAINT), FKB_UPDATE_TIMER);
  172. #else
  173. // sdj: 10/8/91 for bug#3277 changed
  174. // wParam = MAKELONG(BN_PAINT, NULL); /* set HIWORD to cmd, LOWORD not used*/
  175. // to:
  176. wParam = MAKELONG(NULL,BN_PAINT); /* set HIWORD to cmd, LOWORD not used*/
  177. updateFKeyButton(wParam,(LPARAM)GetDlgItem(hdbmyControls, IDTIMER), FKB_UPDATE_TIMER);
  178. #endif
  179. }
  180. }
  181. /*---------------------------------------------------------------------------*/
  182. /* updateFKeyButton() - [mbb] */
  183. /*---------------------------------------------------------------------------*/
  184. /* *****NOTE NOTE ****** this function will not work under win16, as */
  185. /* I removed the textExtent variable and replaced with iHeigth and iWidth */
  186. /* and didn't ifdef ORGCODE around the old code (JAP)*/
  187. BOOL updateFKeyButton(WPARAM wParam ,LPARAM lParam,WORD status) /* mbbx 2.01.163 ... */
  188. {
  189. BOOL updateFKeyButton = FALSE;
  190. HDC hDC;
  191. RECT timerRect, saveRect;
  192. DOSTIME time;
  193. LONG delta;
  194. BYTE text[80];
  195. HBRUSH hBrush, hOldBrush;
  196. #ifdef ORGCODE
  197. DWORD textExtent;
  198. #else
  199. int iHeight;
  200. int iWidth;
  201. #endif
  202. LONG secs; /* rjs bugs 004 */
  203. if(IsWindowVisible((HWND)GET_WM_COMMAND_HWND(wParam, lParam)))
  204. {
  205. hDC = GetWindowDC((HWND) GET_WM_COMMAND_HWND(wParam, lParam));
  206. GetClientRect(GET_WM_COMMAND_HWND(wParam,lParam), (LPRECT)&timerRect);
  207. CopyRect( &saveRect, &timerRect);
  208. InflateRect(&timerRect, -1, -1);
  209. switch(GET_WM_COMMAND_CMD(wParam, lParam))
  210. {
  211. case BN_CLICKED:
  212. if(updateFKeyButton = !(status & FKB_DISABLE_CTRL))
  213. {
  214. InvertRect(hDC, (LPRECT) &timerRect);
  215. delay(6, NULL);
  216. InvertRect(hDC, (LPRECT) &timerRect);
  217. }
  218. else
  219. sysBeep();
  220. break;
  221. case BN_PAINT:
  222. if(status & FKB_UPDATE_TIMER)
  223. {
  224. readDateTime(&time);
  225. if(timerActiv)
  226. {
  227. date2secs(&time, &delta);
  228. date2secs(startTimer, &secs);
  229. delta -= secs;
  230. if(delta < 0) /* rjs - msoft 4061 */
  231. {
  232. delta = 0;
  233. readDateTime(&startTimer);
  234. }
  235. time.hour = delta / 3600;
  236. delta -= (LONG) time.hour * 3600;
  237. time.minute = delta / 60;
  238. time.second = delta - time.minute * 60;
  239. sprintf(text, "%2.2d:%2.2d:%2.2d", time.hour, time.minute, time.second);
  240. }
  241. else
  242. getTimeString(text, &time);
  243. if(time.hour != lastTime.hour)
  244. status |= FKB_UPDATE_BKGD;
  245. }
  246. else
  247. SendMessage((HWND)GET_WM_COMMAND_HWND(wParam, lParam), WM_GETTEXT, 80, (LPARAM) text);
  248. if(status & FKB_UPDATE_BKGD)
  249. {
  250. hBrush = CreateSolidBrush(RGB(vidAttr[ANORMAL & AMASK].bkgd[VID_RED],
  251. vidAttr[ANORMAL & AMASK].bkgd[VID_GREEN],
  252. vidAttr[ANORMAL & AMASK].bkgd[VID_BLUE]));
  253. hOldBrush = (HBRUSH) SelectObject(hDC, hBrush);
  254. RoundRect(hDC, timerRect.left, timerRect.top,
  255. timerRect.right, timerRect.bottom, 10, 10);
  256. SelectObject(hDC, hOldBrush);
  257. DeleteObject(hBrush);
  258. }
  259. if((status & FKB_UPDATE_BKGD) || (time.second != lastTime.second))
  260. {
  261. InflateRect(&timerRect, -4, -1);
  262. MGetTextExtent(hDC, (LPSTR) text, strlen(text), &iHeight, &iWidth);
  263. SetBkColor(hDC, RGB(vidAttr[ANORMAL & AMASK].bkgd[VID_RED],
  264. vidAttr[ANORMAL & AMASK].bkgd[VID_GREEN],
  265. vidAttr[ANORMAL & AMASK].bkgd[VID_BLUE]));
  266. if(!(status & FKB_DISABLE_CTRL))
  267. {
  268. SetTextColor(hDC, RGB(vidAttr[ANORMAL & AMASK].text[VID_RED],
  269. vidAttr[ANORMAL & AMASK].text[VID_GREEN],
  270. vidAttr[ANORMAL & AMASK].text[VID_BLUE]));
  271. }
  272. else
  273. {
  274. SetTextColor(hDC, (COLORREF)GetSysColor(COLOR_GRAYTEXT));
  275. }
  276. DrawText(hDC, (LPSTR) text, strlen(text), (LPRECT) &timerRect,
  277. (iWidth < (timerRect.right - timerRect.left)) ?
  278. DT_CENTER | DT_SINGLELINE | DT_VCENTER : DT_LEFT | DT_SINGLELINE | DT_VCENTER);
  279. if(status & FKB_UPDATE_TIMER)
  280. lastTime = time;
  281. }
  282. break;
  283. }
  284. ReleaseDC((HWND)GET_WM_COMMAND_HWND(wParam, lParam), hDC);
  285. }
  286. return(updateFKeyButton);
  287. }
  288. /*---------------------------------------------------------------------------*/
  289. /* getTimeString() - [mbb] */
  290. /*---------------------------------------------------------------------------*/
  291. VOID getTimeString(BYTE *str, DOSTIME *time)
  292. {
  293. BYTE work[16];
  294. BYTE str1[MINRESSTR], str2[MINRESSTR];
  295. work[0] = 0;
  296. //sdj: the bug is about terminal not updating the timeformat
  297. //sdj: when control panel changes, it only updates while coming
  298. //sdj: up, when it inits the intlData elements. To fix this
  299. //sdj: update the iTime structure element before generating the
  300. //sdj: string, so that it reflects the current state saved by
  301. //sdj: the control panel applet. It is expensive to do this
  302. //sdj: because each time the paint msg comes, getprofile is called
  303. //sdj: but the other way is too complecated where you can wait
  304. //sdj: for the change in this value in the registry and signal
  305. //sdj: the change and call profile apis only when this flag is set
  306. //sdj: saving grace is that, this performance hit is only present
  307. //sdj: when bn_paint is received AND the timer mode is not on!
  308. LoadString(hInst, STR_INI_INTL, (LPSTR) str1, MINRESSTR);
  309. LoadString(hInst, STR_INI_IDATE, (LPSTR) str2, MINRESSTR);
  310. intlData.iDate = GetProfileInt((LPSTR) str1, (LPSTR) str2, 0);
  311. LoadString(hInst, STR_INI_SDATE, (LPSTR) str2, MINRESSTR);
  312. GetProfileString((LPSTR) str1, (LPSTR) str2, (LPSTR) "/", (LPSTR) intlData.sDate, 2);
  313. LoadString(hInst, STR_INI_ITIME, (LPSTR) str2, MINRESSTR);
  314. intlData.iTime = GetProfileInt((LPSTR) str1, (LPSTR) str2, 0);
  315. LoadString(hInst, STR_INI_STIME, (LPSTR) str2, MINRESSTR);
  316. GetProfileString((LPSTR) str1, (LPSTR) str2, (LPSTR) ":", (LPSTR) intlData.sTime, 2);
  317. LoadString(hInst, STR_INI_S1159, (LPSTR) str2, MINRESSTR);
  318. GetProfileString((LPSTR) str1, (LPSTR) str2, (LPSTR) "AM", (LPSTR) intlData.s1159, 4);
  319. LoadString(hInst, STR_INI_S2359, (LPSTR) str2, MINRESSTR);
  320. GetProfileString((LPSTR) str1, (LPSTR) str2, (LPSTR) "PM", (LPSTR) intlData.s2359, 4);
  321. if(!intlData.iTime) /* 12 Hour Clock */
  322. {
  323. if(time->hour < 12)
  324. {
  325. if(intlData.s1159[0] != 0)
  326. sprintf(work, " %s", intlData.s1159);
  327. }
  328. else
  329. {
  330. time->hour -= 12;
  331. if(intlData.s2359[0] != 0)
  332. sprintf(work, " %s", intlData.s2359);
  333. }
  334. if(time->hour == 0)
  335. time->hour = 12;
  336. }
  337. sprintf(str, "%02d%s%02d%s%02d%s", time->hour, intlData.sTime, time->minute, intlData.sTime, time->second, work);
  338. }
  339. /*---------------------------------------------------------------------------*/
  340. /* cursorAdjust() - Catch terminal paint up with received characters. [scf] */
  341. /*---------------------------------------------------------------------------*/
  342. VOID FAR cursorAdjust ()
  343. {
  344. if(termDirty || (nScroll != 0)) /* mbbx: termLine -> termDirty */
  345. termCleanUp();
  346. }
  347. /*---------------------------------------------------------------------------*/
  348. /* blinkCursor() - [scf]*/
  349. /*---------------------------------------------------------------------------*/
  350. VOID NEAR blinkCursor()
  351. {
  352. RECT rect;
  353. // BUG: Does not handle timer wraparound
  354. if(activTerm && (cursorOn > 0) && (GetCurrentTime() >= cursorTick)) /* mbbx 1.10: use msec... */
  355. {
  356. rectCursor(&rect);
  357. if(cursBlinkOn && memcmp(&cursorRect, &rect, sizeof(RECT)))
  358. toggleCursor(&cursorRect);
  359. cursorRect = rect;
  360. if(!cursBlinkOn || trmParams.cursorBlink) /* mbbx 1.10: CUA */
  361. toggleCursor(&cursorRect);
  362. cursorTick = GetCurrentTime() + GetCaretBlinkTime(); /* mbbx 1.10: lilly... */
  363. }
  364. }
  365. /*---------------------------------------------------------------------------*/
  366. /* checkInputBuffer() - support keystroke buffering (type-ahead) [mbb] */
  367. /*---------------------------------------------------------------------------*/
  368. #ifdef OLDCODE
  369. #define MAX_INPUT_BUFFER 64 /* allows 32 keystrokes */
  370. WORD inputBufferItems = 0;
  371. MSG inputBuffer[MAX_INPUT_BUFFER];
  372. BOOL NEAR checkInputBuffer(MSG *msg)
  373. {
  374. WORD ndx;
  375. if((kbdLock == KBD_BUFFER) || ((kbdLock == KBD_WAIT) ) ||
  376. ((inputBufferItems > 0) ))
  377. {
  378. while(PeekMessage(msg, NULL, WM_KEYFIRST, WM_KEYLAST, TRUE))
  379. {
  380. if((msg->message == WM_KEYUP) && (inputBufferItems == 0))
  381. return(TRUE);
  382. else if(((msg->message == WM_KEYDOWN) || (msg->message == WM_KEYUP)) &&
  383. (((msg->wParam >= '0') && (msg->wParam <= 'Z')) || (msg->wParam >= 0x80)))
  384. {
  385. /* mbbx 2.00: new xlate scheme... */
  386. if(!TranslateMessage(msg) || !PeekMessage(msg, NULL, WM_CHAR, WM_CHAR, TRUE))
  387. continue;
  388. }
  389. if(inputBufferItems < MAX_INPUT_BUFFER)
  390. inputBuffer[inputBufferItems++] = *msg;
  391. else
  392. sysBeep();
  393. }
  394. }
  395. else if(PeekMessage(msg, NULL, WM_CHAR, WM_CHAR, TRUE))
  396. {
  397. return(TRUE);
  398. }
  399. else if(inputBufferItems > 0)
  400. {
  401. *msg = inputBuffer[0];
  402. msg->hwnd = GetFocus();
  403. inputBufferItems -= 1;
  404. for(ndx = 0; ndx < inputBufferItems; ndx++)
  405. inputBuffer[ndx] = inputBuffer[ndx+1];
  406. return(TRUE);
  407. }
  408. return(FALSE);
  409. }
  410. #endif