Leaked source code of windows server 2003
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.

1382 lines
34 KiB

  1. /* File: D:\WACKER\tdll\statusbr.c (Created: 02-Dec-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 9 $
  7. * $Date: 7/08/02 6:48p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <commctrl.h>
  12. #include <time.h>
  13. #include <term\res.h>
  14. #include "assert.h"
  15. #include "stdtyp.h"
  16. #include "session.h"
  17. #include "globals.h"
  18. #include "statusbr.h"
  19. #include "cnct.h"
  20. #include "capture.h"
  21. #include "print.h"
  22. #include "tdll.h"
  23. #include "htchar.h"
  24. #include "mc.h"
  25. #include "load_res.h"
  26. #include "timers.h"
  27. #include "com.h"
  28. #include <emu\emuid.h>
  29. #include <emu\emu.h>
  30. #include <emu\emudlgs.h>
  31. #include <xfer\itime.h>
  32. // Static function prototypes...
  33. //
  34. STATIC_FUNC void sbrSubclassStatusbarWindow(HWND hwnd, HSESSION hSession);
  35. STATIC_FUNC void sbrCnctStatus (const HWND hwnd, const pSBR pSBRData);
  36. STATIC_FUNC void sbrSetToNoParts (const HWND hwnd, LPTSTR pszStr);
  37. STATIC_FUNC void sbrRefresh (const HWND hwnd, const int iPart, const pSBR pSBRData);
  38. STATIC_FUNC BOOL sbrNeedToSetParts (const HWND hwnd);
  39. STATIC_FUNC void sbrSetParts (const HWND hwnd, const pSBR pSBRData);
  40. STATIC_FUNC void sbrTimerRefresh (const HWND hwnd, const pSBR pSBRData);
  41. STATIC_FUNC void sbrDrawCnctPart (const HWND hwnd, const int iCnctStatus,
  42. LPTSTR pszStr);
  43. STATIC_FUNC void sbrSetPartsOnce (const HWND hwnd, const pSBR pSBRData);
  44. STATIC_FUNC int sbrGetSizeInPixels (const HWND hwnd, LPTSTR pszStr);
  45. STATIC_FUNC int sbrCalcPartSize (const HWND hwnd, const int iId);
  46. STATIC_FUNC void sbrCachString (pSBR pSBRData,
  47. unsigned int iPart,
  48. LPTSTR pach);
  49. STATIC_FUNC BOOL sbrCnctTimeToSystemTime(const HWND hwnd,
  50. LPSYSTEMTIME lpSysTime,
  51. const pSBR pSBRData);
  52. STATIC_FUNC void sbrEmulatorName (const HWND hwnd, const pSBR pSBRData);
  53. STATIC_FUNC void sbrScrolLock (const HWND hwnd, const pSBR pSBRData);
  54. STATIC_FUNC void sbrCapsLock (const HWND hwnd, const pSBR pSBRData);
  55. STATIC_FUNC void sbrNumLock (const HWND hwnd, const pSBR pSBRData);
  56. STATIC_FUNC void sbrCapture (const HWND hwnd, const pSBR pSBRData);
  57. STATIC_FUNC void sbrPrintEcho (const HWND hwnd, const pSBR pSBRData);
  58. STATIC_FUNC BOOL sbrCreateTimer (const HWND hwnd, const pSBR pSBRData);
  59. STATIC_FUNC void sbrCom (const HWND hwnd, const pSBR pSBRData);
  60. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61. * FUNCTION:
  62. * sbrCreateSessionStatusbar
  63. *
  64. * DESCRIPTION:
  65. * Not much now but will get more complicated later.
  66. *
  67. * ARGUMENTS:
  68. * hwndSession - session window handle
  69. *
  70. * RETURNS:
  71. * Handle to status window or zero on error.
  72. *
  73. */
  74. HWND sbrCreateSessionStatusbar(HSESSION hSession)
  75. {
  76. HWND hwnd = (HWND)0;
  77. //int aBorders[3];
  78. HDC hDC;
  79. TEXTMETRIC tm;
  80. HWND hwndSession = (HWND)0;
  81. hwndSession = sessQueryHwnd(hSession);
  82. if (!IsWindow(hwndSession))
  83. return (HWND)0;
  84. hwnd = CreateStatusWindow(WS_CHILD | WS_CLIPSIBLINGS | SBARS_SIZEGRIP,
  85. 0,
  86. hwndSession,
  87. IDC_STATUS_WIN);
  88. if (IsWindow(hwnd))
  89. {
  90. #if 0
  91. aBorders[0] = WINDOWSBORDERWIDTH;
  92. aBorders[1] = WINDOWSBORDERHEIGHT;
  93. aBorders[2] = WINDOWSBORDERWIDTH;
  94. SendMessage(hwnd, SB_SETBORDERS, 0, (LPARAM)aBorders);
  95. #endif
  96. hDC = GetDC(hwnd);
  97. GetTextMetrics(hDC, &tm);
  98. ReleaseDC(hwnd, hDC);
  99. SendMessage(hwnd, SB_SETMINHEIGHT, (WPARAM)tm.tmHeight, 0);
  100. ShowWindow(hwnd, SW_SHOWNA);
  101. sbrSubclassStatusbarWindow(hwnd, hSession);
  102. }
  103. return hwnd;
  104. }
  105. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  106. * FUNCTION:
  107. * sbrSubclassStatusbarWindow
  108. *
  109. * DESCRIPTION:
  110. * Subclass the Status Bar and init the data structure.
  111. *
  112. * ARGUMENTS:
  113. * hwnd - window handle.
  114. * hSession - the session handle.
  115. *
  116. * RETURNS:
  117. *
  118. */
  119. STATIC_FUNC void sbrSubclassStatusbarWindow(HWND hwnd, HSESSION hSession)
  120. {
  121. ATOM atom = (ATOM)0;
  122. pSBR pSBRData;
  123. atom = AddAtom((LPCTSTR)SBR_ATOM_NAME);
  124. if (atom == 0)
  125. {
  126. assert(FALSE);
  127. return;
  128. }
  129. pSBRData = (pSBR)LocalAlloc(LPTR, sizeof(SBR));
  130. if (pSBRData == NULL)
  131. {
  132. assert(FALSE);
  133. return;
  134. }
  135. // Initialize statusbar data structure...
  136. //
  137. pSBRData->hSession = hSession;
  138. pSBRData->hwnd = hwnd;
  139. pSBRData->hTimer = (HTIMER)0;
  140. pSBRData->pachCNCT = (LPTSTR)0;
  141. pSBRData->pachCAPL = (LPTSTR)0;
  142. pSBRData->pachNUML = (LPTSTR)0;
  143. pSBRData->pachSCRL = (LPTSTR)0;
  144. pSBRData->pachCAPT = (LPTSTR)0;
  145. pSBRData->pachPECHO = (LPTSTR)0;
  146. // Do the subclass...
  147. //
  148. pSBRData->wpOrigStatusbarWndProc =
  149. (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)sbrWndProc);
  150. SetProp(hwnd, (LPCTSTR)atom, (HANDLE)pSBRData);
  151. }
  152. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  153. * FUNCTION:
  154. * sbrWndProc
  155. *
  156. * DESCRIPTION:
  157. * Our own statusbar window proc.
  158. *
  159. * ARGUMENTS:
  160. * Standard window proc parameters.
  161. *
  162. * RETURNS:
  163. * Standard return value.
  164. *
  165. */
  166. LRESULT APIENTRY sbrWndProc(HWND hwnd, UINT uMsg, WPARAM wPar, LPARAM lPar)
  167. {
  168. ATOM atom = (ATOM)0;
  169. pSBR pSBRData;
  170. int nRet;
  171. LRESULT lpResult = 0;
  172. atom = FindAtom((LPCTSTR)SBR_ATOM_NAME);
  173. pSBRData = (pSBR)GetProp(hwnd, (LPCTSTR)atom);
  174. if (pSBRData != NULL && IsWindow(hwnd))
  175. {
  176. switch (uMsg)
  177. {
  178. case SBR_NTFY_INITIALIZE:
  179. sbrCreateTimer(hwnd, pSBRData);
  180. sbrSetPartsOnce(hwnd, pSBRData);
  181. sbrRefresh(hwnd, SBR_MAX_PARTS, pSBRData);
  182. break;
  183. case SBR_NTFY_REFRESH:
  184. if (IsWindowVisible(hwnd))
  185. sbrRefresh(hwnd, LOWORD(wPar), pSBRData);
  186. /* Fall through */
  187. case SBR_NTFY_TIMER:
  188. if (IsWindowVisible(hwnd) && !sbrNeedToSetParts(hwnd))
  189. sbrTimerRefresh(hwnd, pSBRData);
  190. return 0;
  191. case SBR_NTFY_NOPARTS:
  192. if (IsWindowVisible(hwnd))
  193. sbrSetToNoParts(hwnd, (LPTSTR)lPar);
  194. return 0;
  195. case WM_DESTROY:
  196. if (atom)
  197. {
  198. RemoveProp(hwnd, (LPCTSTR)atom);
  199. DeleteAtom(atom);
  200. atom = (ATOM)0;
  201. }
  202. // Remove subclass from the statusbar window
  203. //
  204. SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)pSBRData->wpOrigStatusbarWndProc);
  205. // Destroy the timer...
  206. //
  207. if (pSBRData->hTimer)
  208. {
  209. nRet = TimerDestroy(&pSBRData->hTimer);
  210. assert(nRet == TIMER_OK);
  211. }
  212. if (pSBRData->pachCNCT)
  213. {
  214. free(pSBRData->pachCNCT);
  215. pSBRData->pachCNCT = NULL;
  216. }
  217. if (pSBRData->pachCAPL)
  218. {
  219. free(pSBRData->pachCAPL);
  220. pSBRData->pachCAPL = NULL;
  221. }
  222. if (pSBRData->pachNUML)
  223. {
  224. free(pSBRData->pachNUML);
  225. pSBRData->pachNUML = NULL;
  226. }
  227. if (pSBRData->pachSCRL)
  228. {
  229. free(pSBRData->pachSCRL);
  230. pSBRData->pachSCRL = NULL;
  231. }
  232. if (pSBRData->pachCAPT)
  233. {
  234. free(pSBRData->pachCAPT);
  235. pSBRData->pachCAPT = NULL;
  236. }
  237. if (pSBRData->pachPECHO)
  238. {
  239. free(pSBRData->pachPECHO);
  240. pSBRData->pachPECHO = NULL;
  241. }
  242. LocalFree(pSBRData);
  243. pSBRData = NULL;
  244. default:
  245. break;
  246. }
  247. }
  248. if (pSBRData != NULL)
  249. {
  250. lpResult = CallWindowProc(pSBRData->wpOrigStatusbarWndProc,
  251. hwnd, uMsg, wPar, lPar);
  252. }
  253. return lpResult;
  254. }
  255. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  256. * FUNCTION:
  257. * sbrSetToNoParts
  258. *
  259. * DESCRIPTION:
  260. * Show status bar with no parts. This is usefull in showing help for
  261. * menu items on the statusbar.
  262. *
  263. * ARGUMENTS:
  264. * hwnd - window handle.
  265. * pszStr - text to display on the status bar.
  266. *
  267. * RETURNS:
  268. * void.
  269. *
  270. */
  271. STATIC_FUNC void sbrSetToNoParts(const HWND hwnd, LPTSTR pszStr)
  272. {
  273. if (IsWindow(hwnd))
  274. {
  275. int aWidths[1];
  276. aWidths[0] = -1;
  277. SendMessage(hwnd, SB_SETPARTS, (WPARAM)1, (LPARAM)aWidths);
  278. SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)pszStr);
  279. ShowWindow(hwnd, SW_SHOWNA);
  280. }
  281. }
  282. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  283. * FUNCTION:
  284. * sbrRefresh
  285. *
  286. * DESCRIPTION:
  287. * Figure out what has changed and display status info appropriately.
  288. *
  289. * ARGUMENTS:
  290. * hwnd - window handle.
  291. * iPart - a part number for a part we want to explicitly refresh.
  292. * It can be SBR_MAX_PARTS, in which case all parts are refreshed and
  293. * it can be SBR_KEY_PARTS, in which case all KEY parts are refreshed.
  294. * In some cases it makes sense to just refresh only one part instead
  295. * of refreshing all of them.
  296. *
  297. * RETURNS:
  298. * void.
  299. *
  300. */
  301. STATIC_FUNC void sbrRefresh(const HWND hwnd, const int iPart, const pSBR pSBRData)
  302. {
  303. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  304. IsWindow(hwnd))
  305. {
  306. // Make sure we are displaying the correct # of parts
  307. //
  308. if (sbrNeedToSetParts(hwnd))
  309. sbrSetParts(hwnd, pSBRData);
  310. switch (iPart)
  311. {
  312. case SBR_KEY_PARTS:
  313. sbrScrolLock(hwnd, pSBRData);
  314. sbrCapsLock(hwnd, pSBRData);
  315. sbrNumLock(hwnd, pSBRData);
  316. break;
  317. case SBR_CNCT_PART_NO:
  318. sbrCnctStatus(hwnd, pSBRData);
  319. break;
  320. case SBR_EMU_PART_NO:
  321. sbrEmulatorName(hwnd, pSBRData);
  322. break;
  323. case SBR_COM_PART_NO:
  324. sbrCom(hwnd, pSBRData);
  325. break;
  326. case SBR_SCRL_PART_NO:
  327. sbrScrolLock(hwnd, pSBRData);
  328. break;
  329. case SBR_CAPL_PART_NO:
  330. sbrCapsLock(hwnd, pSBRData);
  331. break;
  332. case SBR_NUML_PART_NO:
  333. sbrNumLock(hwnd, pSBRData);
  334. break;
  335. case SBR_CAPT_PART_NO:
  336. sbrCapture(hwnd, pSBRData);
  337. break;
  338. case SBR_PRNE_PART_NO:
  339. sbrPrintEcho(hwnd, pSBRData);
  340. break;
  341. default:
  342. sbrCnctStatus(hwnd, pSBRData);
  343. sbrEmulatorName(hwnd, pSBRData);
  344. sbrCom(hwnd, pSBRData);
  345. sbrScrolLock(hwnd, pSBRData);
  346. sbrCapsLock(hwnd, pSBRData);
  347. sbrNumLock(hwnd, pSBRData);
  348. sbrCapture(hwnd, pSBRData);
  349. sbrPrintEcho(hwnd, pSBRData);
  350. break;
  351. }
  352. }
  353. return;
  354. }
  355. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  356. * FUNCTION:
  357. * sbrNeedToSetParts
  358. *
  359. * DESCRIPTION:
  360. * Check the number of parts shown in the status bar. If it is less then
  361. * expected, i.e., the maximum parts we usually show, then we need to reset
  362. * the status bar parts. This happens, for example, when help text is
  363. * displayed for menu items, i.e., parts are set to 0.
  364. *
  365. * ARGUMENTS:
  366. * hwnd - window handle.
  367. *
  368. * RETURNS:
  369. * TRUE if parts need to be set/re-set.
  370. * FALSE otherwise.
  371. *
  372. */
  373. STATIC_FUNC BOOL sbrNeedToSetParts(const HWND hwnd)
  374. {
  375. BOOL bRet = FALSE;
  376. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && IsWindow(hwnd))
  377. {
  378. int nParts = 0;
  379. int aWidths[SBR_MAX_PARTS+1];
  380. memset(aWidths, 0, (SBR_MAX_PARTS+1) * sizeof(int));
  381. nParts = (int)SendMessage(hwnd, SB_GETPARTS, (WPARAM)SBR_MAX_PARTS+1,
  382. (LPARAM)aWidths);
  383. if (nParts != SBR_MAX_PARTS)
  384. {
  385. bRet = TRUE;
  386. }
  387. }
  388. return bRet;
  389. }
  390. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  391. * FUNCTION:
  392. * sbrSetParts
  393. *
  394. * DESCRIPTION:
  395. * Set parts in the statusbar.
  396. *
  397. * ARGUMENTS:
  398. * hwnd - window handle.
  399. *
  400. * RETURNS:
  401. * void.
  402. *
  403. */
  404. STATIC_FUNC void sbrSetParts(const HWND hwnd, const pSBR pSBRData)
  405. {
  406. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  407. IsWindow(hwnd))
  408. {
  409. SendMessage(hwnd, SB_SETPARTS, (WPARAM)SBR_MAX_PARTS,
  410. (LPARAM)pSBRData->aWidths);
  411. }
  412. return;
  413. }
  414. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  415. * FUNCTION:
  416. * sbrSetPartsOnce
  417. *
  418. * DESCRIPTION:
  419. * Set parts in the statusbar according to the length of strings to be
  420. * displayed in the appropriate parts. This function should be called only
  421. * once to figure out the part lengths, from then on the part rigth edges are
  422. * stored in the statusbar data structure.
  423. *
  424. * ARGUMENTS:
  425. * hwnd - window handle.
  426. *
  427. * RETURNS:
  428. * void
  429. */
  430. STATIC_FUNC void sbrSetPartsOnce(const HWND hwnd, const pSBR pSBRData)
  431. {
  432. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  433. IsWindow(hwnd))
  434. {
  435. int aWidths[SBR_MAX_PARTS] = {1, 1, 1, 1, 1, 1, 1, 1};
  436. int iNewWidth = 0, i;
  437. TCHAR ach[256];
  438. unsigned int iPart = 0;
  439. int aiBorders[3];
  440. // To make sure that we always have enough space to display the text
  441. // in the appropriate statusbar part read the text corresponding to each
  442. // part and check its length, adjust the size of the part if needed.
  443. //
  444. for (i = 0; i < SBR_MAX_PARTS; i++)
  445. {
  446. switch (i)
  447. {
  448. default:
  449. case SBR_CNCT_PART_NO:
  450. case SBR_EMU_PART_NO:
  451. iNewWidth = sbrCalcPartSize(hwnd, i);
  452. break;
  453. case SBR_COM_PART_NO: iPart = IDS_STATUSBR_COM; break;
  454. case SBR_SCRL_PART_NO: iPart = IDS_STATUSBR_SCRL; break;
  455. case SBR_CAPL_PART_NO: iPart = IDS_STATUSBR_CAPL; break;
  456. case SBR_NUML_PART_NO: iPart = IDS_STATUSBR_NUML; break;
  457. case SBR_CAPT_PART_NO: iPart = IDS_STATUSBR_CAPTUREON; break;
  458. case SBR_PRNE_PART_NO: iPart = IDS_STATUSBR_PRINTECHOON; break;
  459. }
  460. if (i != SBR_CNCT_PART_NO && i != SBR_EMU_PART_NO)
  461. {
  462. // Get the width for the current part string...
  463. //
  464. iNewWidth = 0;
  465. LoadString(glblQueryDllHinst(), iPart, ach,
  466. sizeof(ach) / sizeof(TCHAR));
  467. sbrCachString(pSBRData, iPart, ach);
  468. iNewWidth = (int)sbrGetSizeInPixels(hwnd, ach);
  469. }
  470. aWidths[i] = iNewWidth;
  471. }
  472. // When computing widths, we need to take the borders into account.
  473. //
  474. memset(aiBorders, 0, sizeof(aiBorders));
  475. SendMessage(hwnd, SB_GETBORDERS, 0, (LPARAM)aiBorders);
  476. // Calculate right edges of the statusbar parts...
  477. // put them back into aWidths.
  478. //
  479. aWidths[0] += aiBorders[1];
  480. for (i = 1; i < SBR_MAX_PARTS; i++)
  481. aWidths[i] += aWidths[i-1] + aiBorders[2];
  482. MemCopy(pSBRData->aWidths, aWidths, SBR_MAX_PARTS * sizeof(int));
  483. SendMessage(hwnd, SB_SETPARTS, (WPARAM)SBR_MAX_PARTS,
  484. (LPARAM)pSBRData->aWidths);
  485. }
  486. }
  487. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  488. * FUNCTION:
  489. * sbrCachString
  490. *
  491. * DESCRIPTION:
  492. * Save the string we've just loaded from the resource file in our internal
  493. * statusbar structure for future use. This way we minimize the
  494. * LoadStirng() calls.
  495. *
  496. * ARGUMENTS:
  497. * pSBRData - handle to internal structure.
  498. * iPart - part identifier.
  499. * pach - label for that part.
  500. *
  501. * RETURNS:
  502. * void.
  503. *
  504. */
  505. STATIC_FUNC void sbrCachString(pSBR pSBRData, unsigned int iPart, LPTSTR pach)
  506. {
  507. unsigned int pachSize;
  508. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL)
  509. {
  510. pachSize = (StrCharGetByteCount(pach) + 1) * sizeof(TCHAR);
  511. switch (iPart)
  512. {
  513. case IDS_STATUSBR_CONNECT_FORMAT:
  514. if (pSBRData->pachCNCT)
  515. {
  516. free(pSBRData->pachCNCT);
  517. pSBRData->pachCNCT = NULL;
  518. }
  519. pSBRData->pachCNCT = malloc(pachSize);
  520. StrCharCopyN(pSBRData->pachCNCT, pach, pachSize);
  521. break;
  522. case IDS_STATUSBR_SCRL:
  523. if (pSBRData->pachSCRL)
  524. {
  525. free(pSBRData->pachSCRL);
  526. pSBRData->pachSCRL = NULL;
  527. }
  528. pSBRData->pachSCRL = malloc(pachSize);
  529. StrCharCopyN(pSBRData->pachSCRL, pach, pachSize);
  530. break;
  531. case IDS_STATUSBR_CAPL:
  532. if (pSBRData->pachCAPL)
  533. {
  534. free(pSBRData->pachCAPL);
  535. pSBRData->pachCAPL = NULL;
  536. }
  537. pSBRData->pachCAPL = malloc(pachSize);
  538. StrCharCopyN(pSBRData->pachCAPL, pach, pachSize);
  539. break;
  540. case IDS_STATUSBR_NUML:
  541. if (pSBRData->pachNUML)
  542. {
  543. free(pSBRData->pachNUML);
  544. pSBRData->pachNUML = NULL;
  545. }
  546. pSBRData->pachNUML = malloc(pachSize);
  547. StrCharCopyN(pSBRData->pachNUML, pach, pachSize);
  548. break;
  549. case IDS_STATUSBR_CAPTUREON:
  550. if (pSBRData->pachCAPT)
  551. {
  552. free(pSBRData->pachCAPT);
  553. pSBRData->pachCAPT = NULL;
  554. }
  555. pSBRData->pachCAPT = malloc(pachSize);
  556. StrCharCopyN(pSBRData->pachCAPT, pach, pachSize);
  557. break;
  558. case IDS_STATUSBR_PRINTECHOON:
  559. if (pSBRData->pachPECHO)
  560. {
  561. free(pSBRData->pachPECHO);
  562. pSBRData->pachPECHO = NULL;
  563. }
  564. pSBRData->pachPECHO = malloc(pachSize);
  565. StrCharCopyN(pSBRData->pachPECHO, pach, pachSize);
  566. break;
  567. default:
  568. break;
  569. }
  570. }
  571. return;
  572. }
  573. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  574. * FUNCTION:
  575. * sbrGetSizeInPixels
  576. *
  577. * DESCRIPTION:
  578. * Caluclate the length of the string in pixels. Adjust the
  579. * length by some extra space to appear on the right of the string in the
  580. * statusbar part.
  581. *
  582. * ARGUMENTS:
  583. * hwnd - window handle.
  584. * pszStr - pointer to a string.
  585. *
  586. * RETURNS:
  587. * sz.cx - the size of the strings in pixels.
  588. *
  589. */
  590. STATIC_FUNC int sbrGetSizeInPixels(const HWND hwnd, LPTSTR pszStr)
  591. {
  592. if (IsWindow(hwnd))
  593. {
  594. HDC hDC;
  595. SIZE sz;
  596. // Select the font of the statusbar...
  597. //
  598. hDC = GetDC(hwnd);
  599. GetTextExtentPoint32(hDC,
  600. (LPCTSTR)pszStr,
  601. StrCharGetStrLength(pszStr),
  602. &sz);
  603. sz.cx += (EXTRASPACE * WINDOWSBORDERWIDTH);
  604. ReleaseDC(hwnd, hDC);
  605. return (sz.cx);
  606. }
  607. else
  608. {
  609. return 0;
  610. }
  611. }
  612. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  613. * FUNCTION:
  614. * sbrCalcPartSize
  615. *
  616. * DESCRIPTION:
  617. * Calculate the largest string that may be displayed in a given
  618. * statusbar part. This function is called to calculate the length of the
  619. * emulator part and the connection status part. Depending on the translation
  620. * of the strings in the resources these parts will have to be of different
  621. * length.
  622. *
  623. * ARGUMENTS:
  624. * hwnd - window handle
  625. * iId - part identifier
  626. *
  627. * RETURNS:
  628. * iLongest - the maximum size, in pixels, for the given part
  629. */
  630. STATIC_FUNC int sbrCalcPartSize(const HWND hwnd, const int iId)
  631. {
  632. int iLongest = 0;
  633. if (IsWindow(hwnd))
  634. {
  635. unsigned int aCnctTable[]= {IDS_STATUSBR_CONNECT,
  636. IDS_STATUSBR_CONNECT_FORMAT,
  637. IDS_STATUSBR_CONNECT_FORMAT_X,
  638. IDS_STATUSBR_DISCONNECT,
  639. IDS_STATUSBR_CONNECTING,
  640. IDS_STATUSBR_DISCONNECTING};
  641. TCHAR ach[100],
  642. achText[100];
  643. int i;
  644. int iRet = 0;
  645. int nLimit;
  646. if (iId == SBR_CNCT_PART_NO)
  647. {
  648. TCHAR_Fill(ach, TEXT('\0'), sizeof(ach) / sizeof(TCHAR));
  649. nLimit = sizeof(aCnctTable) / sizeof(int);
  650. for (i = 0; i < nLimit; i++)
  651. {
  652. LoadString(glblQueryDllHinst(), aCnctTable[i], ach, sizeof(ach) / sizeof(TCHAR));
  653. if ((iRet = sbrGetSizeInPixels(hwnd, ach)) > iLongest)
  654. iLongest = iRet;
  655. }
  656. }
  657. else
  658. {
  659. #if 0
  660. DWORD nLen;
  661. BYTE *pv;
  662. if (resLoadDataBlock(glblQueryDllHinst(), IDT_EMU_NAMES,
  663. (LPVOID *)&pv, &nLen))
  664. {
  665. return 0;
  666. }
  667. nEmuCount = *(RCDATA_TYPE *)pv;
  668. pv += sizeof(RCDATA_TYPE);
  669. for (i = 0 ; i < nEmuCount ; i++)
  670. {
  671. if ((nLen = (DWORD)StrCharGetByteCount((LPTSTR)pv) + (DWORD)sizeof(BYTE)) == 0)
  672. {
  673. return 0;
  674. }
  675. if ((iRet = sbrGetSizeInPixels(hwnd, pv)) > iLongest)
  676. iLongest = iRet;
  677. pv += (nLen + (DWORD)sizeof(RCDATA_TYPE));
  678. }
  679. #else 0
  680. int nLen;
  681. for (i = IDS_EMUNAME_BASE ; i < IDS_EMUNAME_BASE + NBR_EMULATORS; i++)
  682. {
  683. nLen = LoadString(glblQueryDllHinst(), (unsigned int)i, achText, sizeof(achText) / sizeof(TCHAR));
  684. if (nLen == 0)
  685. {
  686. return (0);
  687. }
  688. if ((iRet = sbrGetSizeInPixels(hwnd, achText)) > iLongest)
  689. iLongest = iRet;
  690. }
  691. #endif // 0
  692. }
  693. }
  694. return (iLongest);
  695. }
  696. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  697. * FUNCTION:
  698. * sbrTimerRefresh
  699. *
  700. * DESCRIPTION:
  701. * Refresh the timer display if we are connected.
  702. *
  703. * ARGUMENTS:
  704. * hwnd - window handle.
  705. *
  706. * RETURNS:
  707. * void.
  708. *
  709. */
  710. STATIC_FUNC void sbrTimerRefresh(const HWND hwnd, const pSBR pSBRData)
  711. {
  712. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  713. IsWindow(hwnd))
  714. {
  715. TCHAR ach[256], achFormat[256];
  716. TCHAR achTime[256];
  717. int iRet = -1;
  718. HCNCT hCnct = (HCNCT)0;
  719. SYSTEMTIME stSystem;
  720. hCnct = sessQueryCnctHdl(pSBRData->hSession);
  721. if (hCnct)
  722. {
  723. iRet = cnctQueryStatus(hCnct);
  724. }
  725. if (iRet == CNCT_STATUS_TRUE)
  726. {
  727. pSBRData->iLastCnctStatus = iRet;
  728. sbrCnctTimeToSystemTime(hwnd, &stSystem, pSBRData);
  729. achTime[0] = TEXT('\0');
  730. if (GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
  731. TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT,
  732. &stSystem, NULL, achTime, sizeof(achTime)) == 0)
  733. {
  734. DbgShowLastError();
  735. sbrDrawCnctPart(hwnd, iRet, 0);
  736. return;
  737. }
  738. // Load the "Connected %s" format string...
  739. // Since this operation is costly, cach the connected format
  740. // string...
  741. //
  742. if (pSBRData->pachCNCT)
  743. {
  744. wsprintf(ach, pSBRData->pachCNCT, achTime);
  745. }
  746. else
  747. {
  748. LoadString(glblQueryDllHinst(), IDS_STATUSBR_CONNECT_FORMAT,
  749. achFormat, sizeof(achFormat) / sizeof(TCHAR));
  750. sbrCachString(pSBRData, IDS_STATUSBR_CONNECT_FORMAT, achFormat);
  751. wsprintf(ach, achFormat, achTime);
  752. }
  753. sbrDrawCnctPart(hwnd, -1, (LPTSTR)ach);
  754. }
  755. else
  756. {
  757. if (iRet != pSBRData->iLastCnctStatus)
  758. {
  759. pSBRData->iLastCnctStatus = iRet;
  760. sbrDrawCnctPart(hwnd, iRet, 0);
  761. }
  762. }
  763. }
  764. return;
  765. }
  766. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  767. * FUNCTION:
  768. * sbrCnctTimeToSystemTime
  769. *
  770. * DESCRIPTION:
  771. * Get the connection elapsed time and express it in the SYSTEMTIME structure.
  772. *
  773. * ARGUMENTS:
  774. * hwnd - statusbar window handle.
  775. * lpSysTime - pointer to the SYSTEMTIME structure to fill.
  776. *
  777. * RETURNS:
  778. * void.
  779. *
  780. */
  781. STATIC_FUNC BOOL sbrCnctTimeToSystemTime(const HWND hwnd,
  782. LPSYSTEMTIME lpSysTime, const pSBR pSBRData)
  783. {
  784. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  785. IsWindow(hwnd))
  786. {
  787. HCNCT hCnct = (HCNCT)0;
  788. time_t tElapsed_time = (time_t)0;
  789. WORD wElapsed;
  790. hCnct = sessQueryCnctHdl(pSBRData->hSession);
  791. if (hCnct == (HCNCT)0)
  792. return FALSE;
  793. // Get the elapsed time from the connection driver...
  794. //
  795. if (cnctQueryElapsedTime(hCnct, &tElapsed_time) != 0)
  796. {
  797. assert(FALSE);
  798. return FALSE;
  799. }
  800. // Do the neccessary conversion to get SYSTEMTIME from the elapsed time.
  801. //
  802. wElapsed = (WORD)tElapsed_time;
  803. memset(lpSysTime, 0, sizeof(SYSTEMTIME));
  804. lpSysTime->wMonth = 1; // Jan=1 so it can't be zero.
  805. lpSysTime->wHour = wElapsed/3600;
  806. lpSysTime->wMinute = (wElapsed%3600)/60;
  807. lpSysTime->wSecond = (wElapsed%3600)%60;
  808. return TRUE;
  809. }
  810. else
  811. {
  812. return FALSE;
  813. }
  814. }
  815. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  816. * FUNCTION:
  817. * sbrCnctStatus
  818. *
  819. * DESCRIPTION:
  820. * Refresh the contents of the connection part.
  821. * Query the connection status and display appropriate text in the connection
  822. * part.
  823. *
  824. * ARGUMENTS:
  825. * hwnd - window handle.
  826. *
  827. * RETURNS:
  828. * void.
  829. *
  830. */
  831. STATIC_FUNC void sbrCnctStatus(const HWND hwnd, const pSBR pSBRData)
  832. {
  833. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  834. IsWindow(hwnd))
  835. {
  836. int iRet = -1;
  837. HCNCT hCnct = (HCNCT)0;
  838. hCnct = sessQueryCnctHdl(pSBRData->hSession);
  839. if (hCnct)
  840. iRet = cnctQueryStatus(hCnct);
  841. sbrDrawCnctPart(hwnd, iRet, (LPTSTR)0);
  842. }
  843. return;
  844. }
  845. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  846. * FUNCTION:
  847. * sbrDrawCnctPart
  848. *
  849. * DESCRIPTION:
  850. * Draw a string in the connection part.
  851. *
  852. * ARGUMENTS:
  853. * hwnd - window handle.
  854. * iCnctStatus - connection status.
  855. * pszStr - if this string exists, then display it in the connection part,
  856. * otherwise read the string from the resource file according to
  857. * the value of the iCnctStatus parameter.
  858. *
  859. * RETURNS:
  860. *
  861. */
  862. STATIC_FUNC void sbrDrawCnctPart(const HWND hwnd, const int iCnctStatus,
  863. LPTSTR pszStr)
  864. {
  865. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && IsWindow(hwnd))
  866. {
  867. TCHAR ach[100];
  868. UINT iResId;
  869. if (pszStr)
  870. {
  871. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_CNCT_PART_NO, (LPARAM)pszStr);
  872. return;
  873. }
  874. switch (iCnctStatus)
  875. {
  876. case CNCT_STATUS_TRUE:
  877. iResId = IDS_STATUSBR_CONNECT;
  878. break;
  879. case CNCT_STATUS_CONNECTING:
  880. iResId = IDS_STATUSBR_CONNECTING;
  881. break;
  882. case CNCT_STATUS_DISCONNECTING:
  883. iResId = IDS_STATUSBR_DISCONNECTING;
  884. break;
  885. case CNCT_STATUS_ANSWERING:
  886. iResId = IDS_STATUSBR_ANSWERING;
  887. break;
  888. default:
  889. iResId = IDS_STATUSBR_DISCONNECT;
  890. break;
  891. }
  892. // For Far-East version nothing would have to be done here since we are
  893. // just reading a string from the resource and sending it to the common
  894. // control which should be able to display a string containing DB chars.
  895. //
  896. LoadString(glblQueryDllHinst(),
  897. iResId,
  898. ach,
  899. sizeof(ach) / sizeof(TCHAR));
  900. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_CNCT_PART_NO, (LPARAM)(LPCTSTR)ach);
  901. }
  902. return;
  903. }
  904. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  905. * FUNCTION:
  906. * sbrEmulatorName
  907. *
  908. * DESCRIPTION:
  909. * Refresh the contents of the emulator part.
  910. * Get the emulator name and display it in the emulator part.
  911. *
  912. * ARGUMENTS:
  913. * hwnd - window handle.
  914. *
  915. * RETURNS:
  916. * void.
  917. *
  918. */
  919. STATIC_FUNC void sbrEmulatorName(const HWND hwnd, const pSBR pSBRData)
  920. {
  921. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  922. IsWindow(hwnd))
  923. {
  924. TCHAR ach[100];
  925. HEMU hEmu = (HEMU)0;
  926. hEmu = sessQueryEmuHdl(pSBRData->hSession);
  927. ach[0] = TEXT('\0');
  928. if (hEmu)
  929. emuQueryName(hEmu, ach, sizeof(ach));
  930. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_EMU_PART_NO,
  931. (LPARAM)(LPCTSTR)ach);
  932. }
  933. return;
  934. }
  935. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  936. * FUNCTION:
  937. * sbrCom
  938. *
  939. * DESCRIPTION:
  940. * Handles the Com portion of the status bar
  941. *
  942. * ARGUMENTS:
  943. * hwnd - statusbar window handle
  944. * pSBRData - data for this instance
  945. *
  946. * RETURNS:
  947. * void
  948. *
  949. */
  950. STATIC_FUNC void sbrCom(const HWND hwnd, const pSBR pSBRData)
  951. {
  952. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  953. IsWindow(hwnd))
  954. {
  955. TCHAR ach[100];
  956. if (cnctGetComSettingsString(sessQueryCnctHdl(pSBRData->hSession), ach,
  957. sizeof(ach) / sizeof(TCHAR)) == 0)
  958. {
  959. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_COM_PART_NO, (LPARAM)ach);
  960. }
  961. }
  962. return;
  963. }
  964. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  965. * FUNCTION:
  966. * sbrScrolLock
  967. *
  968. * DESCRIPTION:
  969. * Display the status of the scroll lock key in the status bar.
  970. *
  971. * ARGUMENTS:
  972. * hwnd - window handle.
  973. *
  974. * RETURNS:
  975. * void.
  976. *
  977. */
  978. STATIC_FUNC void sbrScrolLock(const HWND hwnd, const pSBR pSBRData)
  979. {
  980. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  981. IsWindow(hwnd))
  982. {
  983. int iScrl = 0, nFlag = 0;
  984. iScrl = (GetKeyState(VK_SCROLL) & 1);
  985. nFlag = (iScrl == 0) ? SBT_OWNERDRAW : 0;
  986. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_SCRL_PART_NO | nFlag,
  987. (LPARAM)(LPCTSTR)pSBRData->pachSCRL);
  988. }
  989. return;
  990. }
  991. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  992. * FUNCTION:
  993. * sbrCapsLock
  994. *
  995. * DESCRIPTION:
  996. * Refresh the display of the scroll lock key state in the status bar.
  997. *
  998. * ARGUMENTS:
  999. * hwnd - window handle.
  1000. *
  1001. * RETURNS:
  1002. * void.
  1003. *
  1004. */
  1005. STATIC_FUNC void sbrCapsLock(const HWND hwnd, const pSBR pSBRData)
  1006. {
  1007. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  1008. IsWindow(hwnd))
  1009. {
  1010. int iCap = 0, nFlag = 0;
  1011. iCap = (GetKeyState(VK_CAPITAL) & 1);
  1012. nFlag = (iCap == 0) ? SBT_OWNERDRAW : 0;
  1013. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_CAPL_PART_NO | nFlag,
  1014. (LPARAM)(LPCTSTR)pSBRData->pachCAPL);
  1015. }
  1016. return;
  1017. }
  1018. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1019. * FUNCTION:
  1020. * sbrNumLock
  1021. *
  1022. * DESCRIPTION:
  1023. * Display the current status for the Num Lock key on the status bar.
  1024. *
  1025. * ARGUMENTS:
  1026. * hwnd - window handle.
  1027. *
  1028. * RETURNS:
  1029. * void.
  1030. *
  1031. */
  1032. STATIC_FUNC void sbrNumLock(const HWND hwnd, const pSBR pSBRData)
  1033. {
  1034. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  1035. IsWindow(hwnd))
  1036. {
  1037. int iNum = 0, nFlag = 0;
  1038. iNum = (GetKeyState(VK_NUMLOCK) & 1);
  1039. nFlag = (iNum == 0) ? SBT_OWNERDRAW : 0;
  1040. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_NUML_PART_NO | nFlag,
  1041. (LPARAM)(LPCTSTR)pSBRData->pachNUML);
  1042. }
  1043. return;
  1044. }
  1045. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1046. * FUNCTION:
  1047. * sbrCapture
  1048. *
  1049. * DESCRIPTION:
  1050. * Refresh Caputre part on the status bar.
  1051. *
  1052. * ARGUMENTS:
  1053. * hwnd - window handle.
  1054. *
  1055. * RETURNS:
  1056. * void.
  1057. *
  1058. */
  1059. STATIC_FUNC void sbrCapture(const HWND hwnd, const pSBR pSBRData)
  1060. {
  1061. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  1062. IsWindow(hwnd))
  1063. {
  1064. HCAPTUREFILE hCapt;
  1065. int nCapState = 0, nFlag = 0;
  1066. hCapt = sessQueryCaptureFileHdl(pSBRData->hSession);
  1067. if (hCapt != (HCAPTUREFILE)0)
  1068. nCapState = cpfGetCaptureState(hCapt);
  1069. nFlag = (nCapState & CPF_CAPTURE_ON) ? 0 : SBT_OWNERDRAW;
  1070. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_CAPT_PART_NO | nFlag,
  1071. (LPARAM)(LPCTSTR)pSBRData->pachCAPT);
  1072. }
  1073. return;
  1074. }
  1075. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1076. * FUNCTION:
  1077. * sbrPrintEcho
  1078. *
  1079. * DESCRIPTION:
  1080. * Display the status of the print echo in the status bar.
  1081. *
  1082. * ARGUMENTS:
  1083. * hwnd - window handle.
  1084. *
  1085. * RETURNS:
  1086. * void.
  1087. *
  1088. */
  1089. STATIC_FUNC void sbrPrintEcho(const HWND hwnd, const pSBR pSBRData)
  1090. {
  1091. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  1092. IsWindow(hwnd))
  1093. {
  1094. TCHAR ach[50];
  1095. HEMU hEmu;
  1096. int nPrneStatus = 0, nFlag = 0;
  1097. hEmu = sessQueryEmuHdl(pSBRData->hSession);
  1098. ach[0] = TEXT('\0');
  1099. if (hEmu != 0)
  1100. nPrneStatus = printQueryStatus(emuQueryPrintEchoHdl(hEmu));
  1101. nFlag = (nPrneStatus) ? 0 : SBT_OWNERDRAW;
  1102. SendMessage(hwnd, SB_SETTEXT, (WPARAM)SBR_PRNE_PART_NO | nFlag,
  1103. (LPARAM)(LPCTSTR)pSBRData->pachPECHO);
  1104. }
  1105. return;
  1106. }
  1107. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1108. * FUNCTION:
  1109. * sbrCreateTimer
  1110. *
  1111. * DESCRIPTION:
  1112. * Create timer in order to show the connected time on the statusbar.
  1113. *
  1114. * ARGUMENTS:
  1115. * HWND hwnd - statusbar window handle.
  1116. *
  1117. * RETURNS:
  1118. * TRUE - is success, FALSE - if failure
  1119. *
  1120. */
  1121. STATIC_FUNC BOOL sbrCreateTimer(const HWND hwnd, const pSBR pSBRData)
  1122. {
  1123. int nRet;
  1124. BOOL bRet = FALSE;
  1125. if (FindAtom((LPCTSTR)SBR_ATOM_NAME) != 0 && pSBRData != NULL &&
  1126. IsWindow(hwnd))
  1127. {
  1128. nRet = TimerCreate(pSBRData->hSession,
  1129. &pSBRData->hTimer,
  1130. 1000,
  1131. sbrTimerProc,
  1132. (void *)pSBRData);
  1133. if (nRet == TIMER_OK)
  1134. {
  1135. bRet =TRUE;
  1136. }
  1137. }
  1138. return bRet;
  1139. }
  1140. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1141. * FUNCTION:
  1142. * sbrTimerProc
  1143. *
  1144. * DESCRIPTION:
  1145. * Timer callback that simply notifies the status line to check its
  1146. * display components.
  1147. *
  1148. * ARGUMENTS:
  1149. * DWORD dwhWnd - window handle of status line.
  1150. * long uTime - not used.
  1151. *
  1152. * RETURNS:
  1153. * void.
  1154. *
  1155. */
  1156. void CALLBACK sbrTimerProc(void *pvData, long uTime)
  1157. {
  1158. pSBR pSBRData = (SBR *)pvData;
  1159. if (pSBRData != NULL && IsWindow(pSBRData->hwnd))
  1160. {
  1161. SendMessage((HWND)pSBRData->hwnd, SBR_NTFY_TIMER, 0, 0L);
  1162. }
  1163. return;
  1164. }
  1165. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1166. * FUNCTION:
  1167. * sbr_WM_DRAWITEM
  1168. *
  1169. * DESCRIPTION:
  1170. * When SB_SETTEXT message is sent to the statusbar with SBT_OWNERDRAW flag
  1171. * set a WM_DRAWITEM is posted to the parent window, in our case the session
  1172. * window. This function is called from there with the data needed to draw,
  1173. * i.e., the pointer to DRAWITEMSTRUCT structure.
  1174. *
  1175. * ARGUMENTS:
  1176. * hwnd - statusbar window handle.
  1177. * lpdis - pointer to a DRAWITEMSTRUCT structure filled with useful
  1178. * information needed to draw the item.
  1179. *
  1180. * RETURNS:
  1181. * void.
  1182. *
  1183. */
  1184. void sbr_WM_DRAWITEM(HWND hwnd, LPDRAWITEMSTRUCT lpdis)
  1185. {
  1186. COLORREF crSave;
  1187. int nBkMode;
  1188. if (IsWindow(hwnd))
  1189. {
  1190. // Save and set text color, mode, etc...
  1191. //
  1192. crSave = GetTextColor(lpdis->hDC);
  1193. SetTextColor(lpdis->hDC, GetSysColor(COLOR_3DSHADOW));
  1194. nBkMode = GetBkMode(lpdis->hDC);
  1195. SetBkMode(lpdis->hDC, TRANSPARENT);
  1196. //
  1197. // OK, draw the text...
  1198. //
  1199. TextOut(lpdis->hDC, lpdis->rcItem.left + 2 * WINDOWSBORDERWIDTH,
  1200. lpdis->rcItem.top, (LPTSTR)lpdis->itemData,
  1201. StrCharGetStrLength((LPTSTR)lpdis->itemData));
  1202. SetTextColor(lpdis->hDC, crSave);
  1203. SetBkMode(lpdis->hDC, nBkMode);
  1204. }
  1205. return;
  1206. }