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.

421 lines
14 KiB

  1. /*---------------------------------------------------------------------------*\
  2. | INITIALIZATION MODULE
  3. | This module contains the one-time initialization routines.
  4. |
  5. | FUNCTIONS
  6. | ---------
  7. | InitFontFromIni
  8. | SaveFontToIni
  9. | SaveBkGndToIni
  10. | LoadIntlStrings
  11. | SaveWindowPlacement
  12. | ReadWindowPlacement
  13. | CreateTools
  14. | DeleteTools
  15. | CreateChildWindows
  16. |
  17. |
  18. | Copyright (c) Microsoft Corp., 1990-1993
  19. |
  20. | created: 01-Nov-91
  21. | history: 01-Nov-91 <clausgi> created.
  22. | 29-Dec-92 <chriswil> port to NT, cleanup.
  23. | 19-Oct-93 <chriswil> unicode enhancements from a-dianeo.
  24. |
  25. \*---------------------------------------------------------------------------*/
  26. #include <windows.h>
  27. #include <ddeml.h>
  28. #include <commdlg.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <commctrl.h>
  32. #include <tchar.h>
  33. #include "winchat.h"
  34. #include "globals.h"
  35. //#include "uniconv.h"
  36. static TBBUTTON tbButtons[] =
  37. {
  38. {0,0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  39. {0,IDM_DIAL ,TBSTATE_ENABLED,TBSTYLE_BUTTON,0},
  40. {1,IDM_ANSWER,TBSTATE_ENABLED,TBSTYLE_BUTTON,0},
  41. {2,IDM_HANGUP,TBSTATE_ENABLED,TBSTYLE_BUTTON,0},
  42. };
  43. #define cTbButtons sizeof(tbButtons)/sizeof(TBBUTTON)
  44. #ifdef WIN16
  45. #pragma alloc_text (_INIT, InitFontFromIni)
  46. #endif
  47. /*---------------------------------------------------------------------------*\
  48. | INITIALIZE FONT FROM INI FILE
  49. | This routine initializes the font information from the winchat.ini file.
  50. |
  51. | created: 11-Nov-91
  52. | history: 29-Dec-92 <chriswil> ported to NT.
  53. |
  54. \*---------------------------------------------------------------------------*/
  55. VOID FAR InitFontFromIni(VOID)
  56. {
  57. CHARSETINFO csi;
  58. DWORD dw = GetACP();
  59. if (!TranslateCharsetInfo((DWORD*)&dw, &csi, TCI_SRCCODEPAGE)) {
  60. csi.ciCharset = ANSI_CHARSET;
  61. }
  62. // font related stuff
  63. // CODEWORK - the following code defines some somewhat arbitrary
  64. // constants for a first shot font - we should default to the
  65. // system font in an easier more portable manner.
  66. //
  67. lfSnd.lfHeight = (int) GetPrivateProfileInt(szFnt,szHeight ,(UINT)-13 ,szIni);
  68. lfSnd.lfWeight = (int) GetPrivateProfileInt(szFnt,szWeight ,700 ,szIni);
  69. lfSnd.lfWidth = (int) GetPrivateProfileInt(szFnt,szWidth , 0 ,szIni);
  70. lfSnd.lfPitchAndFamily = (BYTE)GetPrivateProfileInt(szFnt,szPitchFam , 22 ,szIni);
  71. lfSnd.lfItalic = (BYTE)GetPrivateProfileInt(szFnt,szItalic , 0 ,szIni);
  72. lfSnd.lfUnderline = (BYTE)GetPrivateProfileInt(szFnt,szUnderline , 0 ,szIni);
  73. lfSnd.lfStrikeOut = (BYTE)GetPrivateProfileInt(szFnt,szStrikeOut , 0 ,szIni);
  74. lfSnd.lfCharSet = (BYTE)GetPrivateProfileInt(szFnt, szCharSet ,csi.ciCharset ,szIni);
  75. lfSnd.lfOutPrecision = (BYTE)GetPrivateProfileInt(szFnt,szOutPrecision,OUT_DEFAULT_PRECIS ,szIni);
  76. lfSnd.lfClipPrecision = (BYTE)GetPrivateProfileInt(szFnt,szClipPrec ,CLIP_DEFAULT_PRECIS,szIni);
  77. lfSnd.lfQuality = (BYTE)GetPrivateProfileInt(szFnt,szQuality ,DEFAULT_QUALITY ,szIni);
  78. lfSnd.lfEscapement = 0;
  79. lfSnd.lfOrientation = 0;
  80. #ifdef UNICODE
  81. if (gfDbcsEnabled) {
  82. GetPrivateProfileString(szFnt,szFontName,TEXT("MS Shell Dlg"),lfSnd.lfFaceName,LF_XPACKFACESIZE,szIni);
  83. }
  84. else {
  85. GetPrivateProfileString(szFnt,szFontName,TEXT("MS Shell Dlg"),lfSnd.lfFaceName,LF_XPACKFACESIZE,szIni);
  86. }
  87. #else
  88. GetPrivateProfileString(szFnt,szFontName,TEXT("MS Shell Dlg"),lfSnd.lfFaceName,LF_XPACKFACESIZE,szIni);
  89. #endif
  90. if(GetPrivateProfileString(szFnt,szColor,szNull,szBuf,SZBUFSIZ,szIni))
  91. SndColorref = myatol(szBuf);
  92. else
  93. SndColorref = GetSysColor(COLOR_WINDOWTEXT);
  94. return;
  95. }
  96. #ifdef WIN16
  97. #pragma alloc_text (_INIT, SaveFontToIni)
  98. #endif
  99. /*---------------------------------------------------------------------------*\
  100. | SAVE FONT TO INI FILE
  101. | This routine saves the font to the ini-file.
  102. |
  103. | created: 11-Nov-91
  104. | history: 29-Dec-92 <chriswil> ported to NT.
  105. |
  106. \*---------------------------------------------------------------------------*/
  107. VOID FAR SaveFontToIni(VOID)
  108. {
  109. wsprintf(szBuf, TEXT("%d"), lfSnd.lfHeight);
  110. WritePrivateProfileString(szFnt, szHeight, szBuf, szIni);
  111. wsprintf(szBuf, TEXT("%d"), lfSnd.lfWidth);
  112. WritePrivateProfileString(szFnt, szWidth, szBuf, szIni);
  113. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfCharSet);
  114. WritePrivateProfileString(szFnt, szCharSet, szBuf, szIni);
  115. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfOutPrecision);
  116. WritePrivateProfileString(szFnt, szOutPrecision, szBuf, szIni);
  117. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfClipPrecision);
  118. WritePrivateProfileString(szFnt, szClipPrec, szBuf, szIni);
  119. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfQuality);
  120. WritePrivateProfileString(szFnt, szQuality, szBuf, szIni);
  121. wsprintf(szBuf, TEXT("%d"), lfSnd.lfWeight);
  122. WritePrivateProfileString(szFnt, szWeight, szBuf, szIni);
  123. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfPitchAndFamily);
  124. WritePrivateProfileString(szFnt, szPitchFam, szBuf, szIni);
  125. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfItalic);
  126. WritePrivateProfileString(szFnt, szItalic, szBuf, szIni);
  127. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfUnderline);
  128. WritePrivateProfileString(szFnt, szUnderline, szBuf, szIni);
  129. wsprintf(szBuf, TEXT("%d"), (WORD)lfSnd.lfStrikeOut);
  130. WritePrivateProfileString(szFnt, szStrikeOut, szBuf, szIni);
  131. WritePrivateProfileString(szFnt, szFontName, lfSnd.lfFaceName, szIni);
  132. wsprintf(szBuf, TEXT("%ld"), (DWORD)SndColorref);
  133. WritePrivateProfileString(szFnt, szColor, szBuf, szIni);
  134. return;
  135. }
  136. #ifdef WIN16
  137. #pragma alloc_text (_INIT, SaveBkGndToIni)
  138. #endif
  139. /*---------------------------------------------------------------------------*\
  140. | SAVE BACKGROUND TO INI FILE
  141. | This routine saves the background-color to file.
  142. |
  143. | created: 27-Mar-95
  144. | history: 27-Mar-95 <chriswil> created.
  145. |
  146. \*---------------------------------------------------------------------------*/
  147. VOID FAR SaveBkGndToIni(VOID)
  148. {
  149. wsprintf(szBuf, TEXT("%ld"), (DWORD)SndBrushColor);
  150. WritePrivateProfileString(szPref, szBkgnd, szBuf, szIni);
  151. return;
  152. }
  153. #ifdef WIN16
  154. #pragma alloc_text (_INIT, LoadIntlStrings)
  155. #endif
  156. /*---------------------------------------------------------------------------*\
  157. | LOAD INTERNAL STRINGS
  158. | This routine loads the resources strings.
  159. |
  160. | created: 11-Nov-91
  161. | history: 29-Dec-92 <chriswil> ported to NT.
  162. |
  163. \*---------------------------------------------------------------------------*/
  164. VOID FAR LoadIntlStrings(VOID)
  165. {
  166. LoadString(hInst,IDS_HELV , szHelv , SMLRCBUF);
  167. LoadString(hInst,IDS_APPNAME , szAppName , SMLRCBUF);
  168. LoadString(hInst,IDS_SERVICENAME , szServiceName , SMLRCBUF);
  169. LoadString(hInst,IDS_SYSERR , szSysErr , BIGRCBUF);
  170. LoadString(hInst,IDS_DIALING , szDialing , BIGRCBUF);
  171. LoadString(hInst,IDS_CONNECTABANDON, szConnectAbandon, BIGRCBUF);
  172. LoadString(hInst,IDS_HANGINGUP , szHangingUp , BIGRCBUF);
  173. LoadString(hInst,IDS_HASTERMINATED , szHasTerminated , BIGRCBUF);
  174. LoadString(hInst,IDS_CONNECTEDTO , szConnectedTo , BIGRCBUF);
  175. LoadString(hInst,IDS_CONNECTING , szConnecting , BIGRCBUF);
  176. LoadString(hInst,IDS_ISCALLING , szIsCalling , BIGRCBUF);
  177. LoadString(hInst,IDS_DIALHELP , szDialHelp , BIGRCBUF);
  178. LoadString(hInst,IDS_ANSWERHELP , szAnswerHelp , BIGRCBUF);
  179. LoadString(hInst,IDS_HANGUPHELP , szHangUpHelp , BIGRCBUF);
  180. LoadString(hInst,IDS_NOCONNECT , szNoConnect , BIGRCBUF);
  181. LoadString(hInst,IDS_ALWAYSONTOP , szAlwaysOnTop , BIGRCBUF);
  182. LoadString(hInst,IDS_NOCONNECTTO , szNoConnectionTo, BIGRCBUF);
  183. LoadString(hInst,IDS_NONETINSTALLED, szNoNet , SZBUFSIZ);
  184. LoadString(hInst,IDS_INISECTION, szIniSection , SZBUFSIZ);
  185. LoadString(hInst,IDS_INIPREFKEY, szIniKey1 , BIGRCBUF);
  186. LoadString(hInst,IDS_INIFONTKEY, szIniKey2 , BIGRCBUF);
  187. LoadString(hInst,IDS_INIRINGIN , szIniRingIn , BIGRCBUF);
  188. LoadString(hInst,IDS_INIRINGOUT, szIniRingOut , BIGRCBUF);
  189. return;
  190. }
  191. #ifdef WIN16
  192. #pragma alloc_text (_INIT, SaveWindowPlacement)
  193. #endif
  194. /*---------------------------------------------------------------------------*\
  195. | SAVE WINDOW PLACEMENT
  196. | This routine saves the window position to the inifile.
  197. |
  198. | created: 11-Nov-91
  199. | history: 29-Dec-92 <chriswil> ported to NT.
  200. |
  201. \*---------------------------------------------------------------------------*/
  202. VOID FAR SaveWindowPlacement(PWINDOWPLACEMENT w)
  203. {
  204. wsprintf(szBuf,szPlcFmt,w->showCmd,
  205. w->ptMaxPosition.x,
  206. w->ptMaxPosition.y,
  207. w->rcNormalPosition.left,
  208. w->rcNormalPosition.top,
  209. w->rcNormalPosition.right,
  210. w->rcNormalPosition.bottom);
  211. WritePrivateProfileString(szPref,szPlacement,szBuf,szIni);
  212. return;
  213. }
  214. /*---------------------------------------------------------------------------*\
  215. | GET WINDOW PLACEMENT
  216. | This routine loads the window placement from the inifile.
  217. |
  218. | created: 11-Nov-91
  219. | history: 29-Dec-92 <chriswil> ported to NT.
  220. |
  221. \*---------------------------------------------------------------------------*/
  222. BOOL FAR ReadWindowPlacement(PWINDOWPLACEMENT w)
  223. {
  224. BOOL bRet;
  225. bRet = FALSE;
  226. if(GetPrivateProfileString(szPref,szPlacement,szNull,szBuf,SZBUFSIZ,szIni))
  227. {
  228. w->length = sizeof(WINDOWPLACEMENT);
  229. if(_stscanf(szBuf,szPlcFmt,&(w->showCmd),
  230. &(w->ptMaxPosition.x),
  231. &(w->ptMaxPosition.y),
  232. &(w->rcNormalPosition.left),
  233. &(w->rcNormalPosition.top),
  234. &(w->rcNormalPosition.right),
  235. &(w->rcNormalPosition.bottom)) == 7)
  236. {
  237. bRet = TRUE;
  238. }
  239. }
  240. return(bRet);
  241. }
  242. #ifdef WIN16
  243. #pragma alloc_text (_INIT, CreateTools)
  244. #endif
  245. /*---------------------------------------------------------------------------*\
  246. | CREATE TOOLS
  247. | This routine creates the visual tools for the interface.
  248. |
  249. | created: 11-Nov-91
  250. | history: 29-Dec-92 <chriswil> ported to NT.
  251. |
  252. \*---------------------------------------------------------------------------*/
  253. VOID FAR CreateTools(HWND hwnd)
  254. {
  255. HDC hdc;
  256. hdc = GetDC(hwnd);
  257. hMemDC = CreateCompatibleDC(hdc);
  258. hPhnBitmap = CreateCompatibleBitmap(hdc,cxIcon * 3,cyIcon);
  259. hOldMemObj = SelectObject(hMemDC,hPhnBitmap);
  260. ReleaseDC(hwnd,hdc);
  261. hHilitePen = CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNHIGHLIGHT));
  262. hShadowPen = CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNSHADOW));
  263. hFramePen = CreatePen(PS_SOLID,1,GetSysColor(COLOR_WINDOWFRAME));
  264. hBtnFaceBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  265. hEditSndBrush = CreateSolidBrush(SndBrushColor);
  266. hEditRcvBrush = CreateSolidBrush(RcvBrushColor);
  267. // Create the statusbar/toolbar for the interface.
  268. //
  269. hwndToolbar = CreateToolbarEx(hwnd,(ChatState.fToolBar ? WS_VISIBLE : 0) | WS_BORDER | TBSTYLE_TOOLTIPS,IDC_TOOLBAR,6,hInst,IDBITMAP,tbButtons,cTbButtons,0,0,0,0,sizeof(TBBUTTON));
  270. hwndStatus = CreateStatusWindow((ChatState.fStatusBar ? WS_VISIBLE : 0) | WS_BORDER | WS_CHILD,szNull,hwnd,IDSTATUS);
  271. // Load the application icons.
  272. //
  273. hPhones[0] = LoadIcon(hInst,TEXT("phone1"));
  274. hPhones[1] = LoadIcon(hInst,TEXT("phone2"));
  275. hPhones[2] = LoadIcon(hInst,TEXT("phone3"));
  276. // now build the parameters based on the font we will be using
  277. //
  278. dyBorder = GetSystemMetrics(SM_CYBORDER);
  279. return;
  280. }
  281. #ifdef WIN16
  282. #pragma alloc_text (_INIT, DeleteTools)
  283. #endif
  284. /*---------------------------------------------------------------------------*\
  285. | DELETES TOOLS
  286. | This routine deletes the visual tools for the interface.
  287. |
  288. | created: 11-Nov-91
  289. | history: 29-Dec-92 <chriswil> ported to NT.
  290. |
  291. \*---------------------------------------------------------------------------*/
  292. VOID FAR DeleteTools(HWND hwnd)
  293. {
  294. DestroyWindow(hwndStatus);
  295. DestroyWindow(hwndToolbar);
  296. if(hEditSndFont)
  297. DeleteObject(hEditSndFont);
  298. if(hEditRcvFont)
  299. DeleteObject(hEditRcvFont);
  300. DeleteObject(hHilitePen);
  301. DeleteObject(hShadowPen);
  302. DeleteObject(hFramePen);
  303. DeleteObject(hBtnFaceBrush);
  304. DeleteObject(hEditSndBrush);
  305. DeleteObject(hEditRcvBrush);
  306. SelectObject(hMemDC,hOldMemObj);
  307. DeleteObject(hPhnBitmap);
  308. DeleteDC(hMemDC);
  309. return;
  310. }
  311. #ifdef WIN16
  312. #pragma alloc_text (_INIT, CreateChildWindows)
  313. #endif
  314. /*---------------------------------------------------------------------------*\
  315. | CREATE CHILD WINDOWS
  316. | This routine creates the child-windows for the application.
  317. |
  318. | created: 11-Nov-91
  319. | history: 29-Dec-92 <chriswil> ported to NT.
  320. |
  321. \*---------------------------------------------------------------------------*/
  322. VOID FAR CreateChildWindows(HWND hwnd)
  323. {
  324. hwndSnd = CreateWindow (TEXT("edit"),
  325. NULL,
  326. WS_CHILD | WS_BORDER | WS_MAXIMIZE | WS_VISIBLE |
  327. WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY,
  328. 0, 0, 0, 0,
  329. hwnd,
  330. (HMENU)ID_EDITSND,
  331. hInst,
  332. NULL);
  333. hwndRcv = CreateWindow (TEXT("edit"),
  334. NULL,
  335. WS_CHILD | WS_BORDER | WS_MAXIMIZE | WS_VISIBLE |
  336. WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY,
  337. 0, 0, 0, 0,
  338. hwnd,
  339. (HMENU)ID_EDITRCV,
  340. hInst,
  341. NULL);
  342. // hook the send window...
  343. //
  344. lpfnOldEditProc = (WNDPROC)GetWindowLongPtr(hwndSnd,GWLP_WNDPROC);
  345. SetWindowLongPtr(hwndSnd,GWLP_WNDPROC,(LONG_PTR)EditProc);
  346. ShowWindow(hwndSnd,SW_SHOW);
  347. ShowWindow(hwndRcv,SW_SHOW);
  348. return;
  349. }