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.

3776 lines
102 KiB

  1. /* originally named PIF.C in Win3.1 -- changed to make build 32 happy */
  2. #define NOSOUND
  3. #define NOCOMM
  4. #define WIN31
  5. #include "pifedit.h"
  6. #include "commdlg.h"
  7. #include "shellapi.h"
  8. #include "mods.h"
  9. extern BOOL IsLastPifedit(void);
  10. extern int MemCopy(LPSTR,LPSTR,int);
  11. extern int MaybeSaveFile(void);
  12. extern int InitPifStruct(void);
  13. extern int UpdatePifScreen(void);
  14. extern int UpdatePifScreenAdv(void);
  15. extern int UpdatePifScreenNT(void);
  16. extern BOOL UpdatePifStruct(void);
  17. extern int LoadPifFile(PSTR);
  18. extern int SavePifFile(PSTR, int);
  19. extern BOOL SetInitialMode(void);
  20. extern int CountLines(LPSTR);
  21. extern int Warning(int,WORD);
  22. extern PIF386EXT UNALIGNED *AllocInit386Ext(void);
  23. extern PIFWNTEXT UNALIGNED *AllocInitNTExt(void);
  24. extern void SetFileOffsets(unsigned char *,WORD *,WORD *);
  25. extern void SetNTDlgItem(int);
  26. /*
  27. * extern PIF286EXT31 *AllocInit286Ext31(void);
  28. */
  29. extern PIF286EXT30 UNALIGNED *AllocInit286Ext30(void);
  30. extern BOOL DoFieldsWork(BOOL);
  31. extern BOOL DoFieldsWorkNT(BOOL);
  32. extern BOOL DoFieldsWorkAdv(BOOL);
  33. extern BOOL UpdatePif386Struc(void);
  34. extern BOOL UpdatePifNTStruc(void);
  35. #define SBUMAIN 0 // Scroll Bar update on Main
  36. #define SBUADV 1 // Scroll Bar update on Advanced
  37. #define SBUNT 2 // Scroll Bar update on NT
  38. #define SBUMAINADVNT 3 // Scroll Bar Update on Main, Advanced, and NT
  39. #define SBUSZMAIN 4 // SIZE and Scroll Bar update on Main
  40. #define SBUSZADV 5 // SIZE and Scroll Bar update on Advanced
  41. #define SBUSZNT 6 // SIZE and Scroll Bar update on NT
  42. #define SBUSZMAINADVNT 7 // SIZE and Scroll Bar update on Main, Advanced, and NT
  43. int SwitchAdvance386(HWND);
  44. int SwitchNT(HWND);
  45. unsigned char *PutUpDB(int);
  46. int DoHelp(unsigned int,unsigned int);
  47. int Disable386Advanced(HWND, HWND);
  48. int SetMainWndSize(int);
  49. int MainScroll(HWND, int, int, int, int);
  50. int ChangeHotKey(void);
  51. int SetHotKeyLen(void);
  52. int SetHotKeyState(WPARAM,LONG);
  53. int SetHotKeyTextFromPIF(void);
  54. int CmdArgAddCorrectExtension(unsigned char *);
  55. int SetHotKeyTextFromInMem(void);
  56. void CpyCmdStr( LPSTR szDst, LPSTR szSrc );
  57. CHAR szOldAutoexec[PIFDEFPATHSIZE*4];
  58. CHAR szOldConfig[PIFDEFPATHSIZE*4];
  59. BOOL CurrMode386; /* true if in Windows 386 mode, False if in Windows 286 mode */
  60. BOOL SysMode386; /* true if running Windows 386, False if running Windows 286 */
  61. BOOL ModeAdvanced = FALSE; /* true if in advanced PIF mode */
  62. BOOL AdvClose = FALSE; /* true if advanced PIF mode and Cancel = Close */
  63. BOOL NTClose = FALSE; /* true if NT PIF mode and Cancel = Close */
  64. BOOL FileChanged = FALSE;
  65. BOOL EditHotKey = FALSE;
  66. BOOL NewHotKey = FALSE;
  67. BOOL DoingMsg = FALSE;
  68. BOOL InitShWind = FALSE; /* true if initial ShowWindow has been done */
  69. BOOL CompleteKey = FALSE;
  70. BOOL SizingFlag = FALSE; /* Semaphore to prevent re-entrant sizing */
  71. /* invalid filename flags for NT autoexec & config files */
  72. BOOL fNoNTAWarn = FALSE;
  73. BOOL fNTAWarnne = FALSE;
  74. BOOL fNoNTCWarn = FALSE;
  75. BOOL fNTCWarnne = FALSE;
  76. HWND hwndPrivControl = (HWND)NULL;
  77. HWND hwndHelpDlgParent = (HWND)NULL; // This is actually mostly a flag that says
  78. // we have the help engine up
  79. unsigned char MenuMnemonic1;
  80. unsigned char MenuMnemonic2;
  81. unsigned char MenuMnemonic3;
  82. unsigned char KeySepChr;
  83. unsigned char CurrHotKeyTxt[160];
  84. int CurrHotKeyTxtLen = 0;
  85. WORD fileoffset = 0;
  86. WORD extoffset = 0;
  87. WORD tmpfileoffset = 0;
  88. WORD tmpextoffset = 0;
  89. typedef VOID (FAR PASCAL *LPFNREGISTERPENAPP)(WORD, BOOL);
  90. static LPFNREGISTERPENAPP lpfnRegisterPenApp = NULL;
  91. #define NUM286ALIASES 8
  92. unsigned int Aliases286 [(NUM286ALIASES * 2)] = { IDI_MEMREQ,IDI_MEMREQ_286ALIAS,
  93. IDI_XMAREQ,IDI_XMAREQ_286ALIAS,
  94. IDI_XMADES,IDI_XMADES_286ALIAS,
  95. /*
  96. * IDI_EMSREQ,IDI_EMSREQ_286ALIAS,
  97. * IDI_EMSDES,IDI_EMSDES_286ALIAS,
  98. */
  99. IDI_ALTTAB,IDI_ALTTAB_286ALIAS,
  100. IDI_ALTESC,IDI_ALTESC_286ALIAS,
  101. IDI_ALTPRTSC,IDI_ALTPRTSC_286ALIAS,
  102. IDI_PRTSC,IDI_PRTSC_286ALIAS,
  103. IDI_CTRLESC,IDI_CTRLESC_286ALIAS };
  104. unsigned TmpHotKeyScan;
  105. unsigned TmpHotKeyShVal;
  106. unsigned TmpHotKeyShMsk = 0x000F; /* Either CTRL, ALT or SHIFT */
  107. unsigned char TmpHotKeyVal;
  108. unsigned InMemHotKeyScan = 0;
  109. unsigned InMemHotKeyShVal = 0;
  110. unsigned InMemHotKeyShMsk = 0;
  111. unsigned char InMemHotKeyVal;
  112. BOOL ChangeHkey = FALSE; /* Prevent re-entrancy */
  113. BOOL bMouse;
  114. HCURSOR hArrowCurs;
  115. HCURSOR hWaitCurs;
  116. int SysCharHeight;
  117. int SysCharWidth;
  118. HFONT HotKyFnt = 0;
  119. int HotKyFntHgt = 0;
  120. HFONT SysFixedFont;
  121. int SysFixedHeight;
  122. int SysFixedWidth;
  123. HINSTANCE hPifInstance;
  124. HWND hwndPifDlg = (HWND)NULL;
  125. HWND hwndNTPifDlg = (HWND)NULL;
  126. HWND hwndAdvPifDlg = (HWND)NULL;
  127. HWND hParentWnd = (HWND)NULL;
  128. HWND hwndFocusMain = (HWND)NULL;
  129. HWND hwndFocusAdv = (HWND)NULL;
  130. HWND hwndFocusNT = (HWND)NULL;
  131. BOOL bNTDlgOpen = FALSE;
  132. BOOL bAdvDlgOpen = FALSE;
  133. int FocusIDMain = IDI_ENAME;
  134. int FocusIDMainMenu = 0;
  135. int FocusIDAdvMenu = 0;
  136. int FocusIDAdv = IDI_BPRI;
  137. int FocusIDNTMenu = 0;
  138. int FocusIDNT = IDI_AUTOEXEC;
  139. HWND hwndFocus = (HWND)NULL;
  140. int FocusID = IDI_ENAME;
  141. unsigned char FocStatTextMain[PIFSTATUSLEN*2] = { 0 };
  142. unsigned char FocStatTextAdv[PIFSTATUSLEN*2] = { 0 };
  143. unsigned char FocStatTextNT[PIFSTATUSLEN*2] = { 0 };
  144. PIFSTATUSPAINT StatusPntData;
  145. RECT StatRecSizeMain;
  146. RECT StatRecSizeAdv;
  147. RECT StatRecSizeNT;
  148. HWND hMainwnd = (HWND)NULL;
  149. int MainScrollRange = 0;
  150. int MainScrollLineSz = 0;
  151. int MainWndLines = 0;
  152. int MaxMainNeg = 0;
  153. int MainWndSize = SIZENORMAL;
  154. int AdvScrollRange = 0;
  155. int AdvScrollLineSz = 0;
  156. int AdvWndLines = 0;
  157. int MaxAdvNeg = 0;
  158. int AdvWndSize = SIZENORMAL;
  159. int NTScrollRange = 0;
  160. int NTScrollLineSz = 0;
  161. int NTWndLines = 0;
  162. int MaxNTNeg = 0;
  163. int NTWndSize = SIZENORMAL;
  164. HACCEL hAccel;
  165. unsigned char CurPifFile[256]; /* this is name IN ANSI!! */
  166. unsigned char PifBuf[PIFEDITMAXPIF*2];
  167. unsigned char NTSys32Root[PIFDEFPATHSIZE*2];
  168. PIFNEWSTRUCT UNALIGNED *PifFile;
  169. PIF386EXT UNALIGNED *Pif386ext = (PIF386EXT *)NULL;
  170. /*
  171. * PIF286EXT31 *Pif286ext31 = (PIF286EXT31 *)NULL;
  172. */
  173. PIF286EXT30 UNALIGNED *Pif286ext30 = (PIF286EXT30 *)NULL;
  174. PIFWNTEXT UNALIGNED *PifNText = (PIFWNTEXT *)NULL;
  175. OFSTRUCT ofReopen;
  176. unsigned char rgchInsMem[320];
  177. unsigned char rgchTitle[60];
  178. unsigned char szExtSave[] = "\\*.PIF";
  179. HMENU hSysMenuMain = (HMENU)NULL;
  180. HMENU hFileMenu = (HMENU)NULL;
  181. HMENU hModeMenu = (HMENU)NULL;
  182. HMENU hHelpMenu = (HMENU)NULL;
  183. HMENU hSysMenuAdv = (HMENU)NULL;
  184. HMENU hSysMenuNT = (HMENU)NULL;
  185. DLGPROC lpfnPifWnd;
  186. DLGPROC lpfnAdvPifWnd;
  187. DLGPROC lpfnNTPifWnd;
  188. void InvalidateStatusBar(HWND hwnd)
  189. {
  190. RECT rc;
  191. if((hwnd == hwndAdvPifDlg) && AdvScrollRange) /* No status bar if scroll bar */
  192. return;
  193. if((hwnd == hwndNTPifDlg) && NTScrollRange) /* No status bar if scroll bar */
  194. return;
  195. GetClientRect(hwnd, &rc);
  196. if(rc.bottom >= (StatusPntData.dyStatus + StatusPntData.dyBorderx2)) {
  197. rc.top = rc.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  198. InvalidateRect(hwnd,(CONST RECT *)&rc,FALSE);
  199. }
  200. }
  201. void InvalidateAllStatus(void)
  202. {
  203. if(hMainwnd) {
  204. InvalidateStatusBar(hMainwnd);
  205. }
  206. if(hwndAdvPifDlg) {
  207. InvalidateStatusBar(hwndAdvPifDlg);
  208. }
  209. if(hwndNTPifDlg) {
  210. InvalidateStatusBar(hwndNTPifDlg);
  211. }
  212. }
  213. void SetStatusText(HWND hwnd,int FocID,BOOL redrawflg)
  214. {
  215. unsigned char *dst;
  216. if(hwnd == hMainwnd) {
  217. dst = FocStatTextMain;
  218. } else if (hwnd == hwndAdvPifDlg) {
  219. dst = FocStatTextAdv;
  220. } else {
  221. dst = FocStatTextNT;
  222. }
  223. if((FocID == IDADVCANCEL) && AdvClose) {
  224. FocID = IDI_CANCLOSE;
  225. }
  226. if(!LoadString(hPifInstance, FocID, dst, PIFSTATUSLEN-1)) {
  227. /* if string not defined above, try getting the generic string */
  228. if(!LoadString(hPifInstance, IDI_GENSTAT, dst, PIFDEFPATHSIZE-1)) {
  229. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  230. }
  231. }
  232. if(redrawflg) {
  233. InvalidateStatusBar(hwnd);
  234. }
  235. }
  236. void PaintStatus(HWND hwnd)
  237. {
  238. HDC hdc;
  239. RECT rc, rcTemp, rcTemp2;
  240. HBRUSH hBrush;
  241. PAINTSTRUCT ps;
  242. BOOL bEGA;
  243. unsigned char *txtpnt;
  244. unsigned char blank[] = " ";
  245. if((hwnd == hwndAdvPifDlg) && AdvScrollRange) /* No status bar if scroll bar */
  246. return;
  247. if((hwnd == hwndNTPifDlg) && NTScrollRange) /* No status bar if scroll bar */
  248. return;
  249. hdc = BeginPaint(hwnd, &ps);
  250. GetClientRect(hwnd, &rc);
  251. StatusPntData.hFontStatus = SelectObject(hdc, StatusPntData.hFontStatus);
  252. rc.top = rc.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  253. bEGA = GetNearestColor(hdc, GetSysColor(COLOR_BTNHIGHLIGHT)) ==
  254. GetNearestColor(hdc, GetSysColor(COLOR_BTNFACE));
  255. if (bEGA) {
  256. /* EGA type display */
  257. SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
  258. SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
  259. } else {
  260. /* VGA type display */
  261. /* draw the frame */
  262. /* Border color */
  263. hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  264. /* top and bottom border */
  265. /* Top */
  266. rcTemp = rc;
  267. rcTemp.bottom = rcTemp.top + StatusPntData.dyBorderx3;
  268. rcTemp.top += StatusPntData.dyBorder;
  269. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  270. /* Bottom */
  271. rcTemp = rc;
  272. rcTemp.top = rcTemp.bottom - StatusPntData.dyBorderx2;
  273. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  274. /* left and right border */
  275. /* Left */
  276. rcTemp = rc;
  277. rcTemp.right = 8 * StatusPntData.dyBorder;
  278. rcTemp.top += StatusPntData.dyBorder;
  279. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  280. /* Right */
  281. rcTemp = rc;
  282. rcTemp.left = rcTemp.right - (8 * StatusPntData.dyBorder);
  283. rcTemp.top += StatusPntData.dyBorder;
  284. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  285. DeleteObject((HGDIOBJ)hBrush);
  286. /* Shadow color */
  287. hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNSHADOW));
  288. /* Top and left shadow */
  289. /* Top */
  290. rcTemp.left = 8 * StatusPntData.dyBorder;
  291. rcTemp.right = rcTemp.right - 8 * StatusPntData.dyBorder;
  292. rcTemp.top = rc.top + StatusPntData.dyBorderx3;
  293. rcTemp.bottom = rcTemp.top + StatusPntData.dyBorder;
  294. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  295. /* Left */
  296. rcTemp = rc;
  297. rcTemp.left = 8 * StatusPntData.dyBorder;
  298. rcTemp.right = rcTemp.left + StatusPntData.dyBorder;
  299. rcTemp.top += StatusPntData.dyBorderx3;
  300. rcTemp.bottom -= StatusPntData.dyBorderx2;
  301. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  302. DeleteObject((HGDIOBJ)hBrush);
  303. /* Hilight color */
  304. hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNHIGHLIGHT));
  305. /* Right and bottom hilight */
  306. /* Bottom */
  307. rcTemp = rc;
  308. rcTemp.left = 8 * StatusPntData.dyBorder;
  309. rcTemp.right = rcTemp.right - 8 * StatusPntData.dyBorder;
  310. rcTemp.top = rc.bottom - 3 * StatusPntData.dyBorder;
  311. rcTemp.bottom = rcTemp.top + StatusPntData.dyBorder;
  312. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  313. /* Right */
  314. rcTemp = rc;
  315. rcTemp.left = rcTemp.right - 9 * StatusPntData.dyBorder;
  316. rcTemp.right = rcTemp.left + StatusPntData.dyBorder;
  317. rcTemp.top += StatusPntData.dyBorderx3;
  318. rcTemp.bottom -= StatusPntData.dyBorderx2;
  319. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  320. DeleteObject((HGDIOBJ)hBrush);
  321. SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
  322. SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
  323. }
  324. /* solid black line across top */
  325. hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOWTEXT));
  326. rcTemp = rc;
  327. rcTemp.bottom = rcTemp.top;
  328. rcTemp.bottom += StatusPntData.dyBorder;
  329. FillRect(hdc, (CONST RECT *)&rcTemp, hBrush);
  330. DeleteObject((HGDIOBJ)hBrush);
  331. /* now the text, with the button face background */
  332. rcTemp.top = rc.top + ((1+2+1) * StatusPntData.dyBorder);
  333. rcTemp.bottom = rc.bottom - StatusPntData.dyBorderx3;
  334. rcTemp.left = 9 * StatusPntData.dyBorder;
  335. rcTemp.right = rc.right - 9 * StatusPntData.dyBorder;
  336. if (bEGA) {
  337. rcTemp2 = rc;
  338. rcTemp2.top += StatusPntData.dyBorder;
  339. } else {
  340. rcTemp2 = rcTemp;
  341. }
  342. if(DoingMsg) {
  343. txtpnt = blank;
  344. } else {
  345. if(hwnd == hMainwnd) {
  346. txtpnt = FocStatTextMain;
  347. } else if(hwnd == hwndAdvPifDlg) {
  348. txtpnt = FocStatTextAdv;
  349. } else {
  350. txtpnt = FocStatTextNT;
  351. }
  352. }
  353. ExtTextOut(hdc, rcTemp.left + StatusPntData.dyBorderx2, rcTemp.top,
  354. ETO_OPAQUE | ETO_CLIPPED, (CONST RECT *)&rcTemp2, (LPSTR)txtpnt,
  355. lstrlen((LPSTR)txtpnt), NULL);
  356. StatusPntData.hFontStatus = SelectObject(hdc, StatusPntData.hFontStatus);
  357. EndPaint(hwnd, (CONST PAINTSTRUCT *)&ps);
  358. }
  359. void HourGlass(BOOL bOn)
  360. {
  361. /* toggle hourglass cursor */
  362. if(!bMouse) /* Turn cursor on/off if no mouse */
  363. ShowCursor(bOn);
  364. SetCursor(bOn ? hWaitCurs : hArrowCurs);
  365. }
  366. void SetMainTitle(void)
  367. {
  368. int i;
  369. int j;
  370. HANDLE hFile;
  371. unsigned char buf[(MAX_PATH*2)+360];
  372. unsigned char buf2[360];
  373. unsigned char *pch;
  374. WIN32_FIND_DATA fd;
  375. if(!(i = LoadString(hPifInstance, PIFCAPTION, (LPSTR)buf, sizeof(buf)))) {
  376. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  377. }
  378. if(hwndAdvPifDlg) {
  379. if(!(j = LoadString(hPifInstance, PIFCAPTIONADV, (LPSTR)buf2, sizeof(buf2)))) {
  380. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  381. }
  382. }
  383. else if(hwndNTPifDlg) {
  384. if(!(j = LoadString(hPifInstance, PIFCAPTIONNT, (LPSTR)buf2, sizeof(buf2)))) {
  385. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  386. }
  387. }
  388. if(CurPifFile[0] == 0) {
  389. if(!LoadString(hPifInstance, NOTITLE, (LPSTR)(buf+i), (sizeof(buf)-i))) {
  390. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  391. }
  392. /*
  393. * if(hwndAdvPifDlg) {
  394. * if(!LoadString(hPifInstance, NOTITLE, (LPSTR)(buf2+j), (sizeof(buf2)-j))) {
  395. * Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  396. * }
  397. * }
  398. */
  399. } else {
  400. if((hFile = FindFirstFile(CurPifFile, &fd)) != INVALID_HANDLE_VALUE) {
  401. lstrcat((LPSTR)buf, fd.cFileName);
  402. FindClose(hFile);
  403. }
  404. else {
  405. pch = CurPifFile+fileoffset;
  406. lstrcat((LPSTR)buf, (LPSTR)pch);
  407. }
  408. /*
  409. * if(hwndAdvPifDlg)
  410. * lstrcat((LPSTR)buf2, (LPSTR)pch);
  411. */
  412. }
  413. SetWindowText(hMainwnd,(LPSTR)buf);
  414. if(hwndAdvPifDlg) {
  415. SetWindowText(hwndAdvPifDlg,(LPSTR)buf2);
  416. }
  417. else if(hwndNTPifDlg) {
  418. SetWindowText(hwndNTPifDlg,(LPSTR)buf2);
  419. }
  420. }
  421. UndoNTClose(void)
  422. {
  423. unsigned char chBuf[40];
  424. if(NTClose && hwndNTPifDlg) {
  425. if(!LoadString(hPifInstance, PIFCANCELSTRNG , (LPSTR)chBuf, sizeof(chBuf))) {
  426. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  427. } else {
  428. SetDlgItemText(hwndNTPifDlg,IDNTCANCEL,(LPSTR)chBuf);
  429. }
  430. NTClose = FALSE;
  431. if(FocusIDNT == IDNTCANCEL) {
  432. SetStatusText(hwndNTPifDlg,FocusIDNT,TRUE);
  433. }
  434. return(TRUE);
  435. }
  436. return(FALSE);
  437. }
  438. UndoAdvClose(void)
  439. {
  440. unsigned char chBuf[40];
  441. if(AdvClose && hwndAdvPifDlg) {
  442. if(!LoadString(hPifInstance, PIFCANCELSTRNG , (LPSTR)chBuf, sizeof(chBuf))) {
  443. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  444. } else {
  445. SetDlgItemText(hwndAdvPifDlg,IDADVCANCEL,(LPSTR)chBuf);
  446. }
  447. AdvClose = FALSE;
  448. if(FocusIDAdv == IDADVCANCEL) {
  449. SetStatusText(hwndAdvPifDlg,FocusIDAdv,TRUE);
  450. }
  451. return(TRUE);
  452. }
  453. return(FALSE);
  454. }
  455. DoDlgCommand(HWND hwnd, WPARAM wParam, LONG lParam)
  456. {
  457. unsigned int value;
  458. char buf[PIFDEFPATHSIZE*2];
  459. int len, cmd;
  460. int ivalue;
  461. BOOL result;
  462. BOOL OldFileChanged;
  463. cmd = LOWORD(wParam);
  464. switch (cmd) {
  465. /* case IDI_PSNONE:
  466. * case IDI_PSTEXT:
  467. * case IDI_PSGRAPH:
  468. * CheckRadioButton(hwnd, IDI_PSFIRST, IDI_PSLAST, cmd);
  469. * break;
  470. */
  471. case IDI_PSTEXT:
  472. case IDI_PSGRAPH:
  473. CheckRadioButton(hwnd, IDI_PSTEXT, IDI_PSGRAPH, cmd);
  474. break;
  475. /*
  476. * case IDI_SENONE:
  477. * case IDI_SETEXT:
  478. * case IDI_SEGRAPH:
  479. * CheckRadioButton(hwnd, IDI_SEFIRST, IDI_SELAST, cmd);
  480. * break;
  481. */
  482. case IDI_ADVANCED:
  483. if(CurrMode386) {
  484. HourGlass(TRUE);
  485. SwitchAdvance386(hwnd);
  486. HourGlass(FALSE);
  487. } else {
  488. }
  489. break;
  490. case IDI_NT:
  491. if(CurrMode386) {
  492. HourGlass(TRUE);
  493. SwitchNT(hwnd);
  494. HourGlass(FALSE);
  495. } else {
  496. }
  497. break;
  498. case IDI_PSNONE:
  499. case IDI_SENONE:
  500. /* case IDI_DMSCREEN: */
  501. /* case IDI_DMMEM: */
  502. case IDI_DMCOM1:
  503. case IDI_DMCOM2:
  504. case IDI_DMCOM3:
  505. case IDI_DMCOM4:
  506. case IDI_DMKBD:
  507. case IDI_EXIT:
  508. case IDI_BACK:
  509. case IDI_EXCL:
  510. case IDI_NOSAVVID:
  511. case IDI_NTTIMER:
  512. CheckDlgButton(hwnd, cmd, !IsDlgButtonChecked(hwnd, cmd));
  513. break;
  514. case IDI_POLL:
  515. case IDI_ALTTAB:
  516. case IDI_ALTESC:
  517. case IDI_CTRLESC:
  518. case IDI_ALTSPACE:
  519. case IDI_ALTENTER:
  520. case IDI_ALTPRTSC:
  521. case IDI_PRTSC:
  522. case IDI_NOHMA:
  523. case IDI_INT16PST:
  524. case IDI_VMLOCKED:
  525. case IDI_XMSLOCKED:
  526. case IDI_EMSLOCKED:
  527. case IDI_TEXTEMULATE:
  528. case IDI_RETAINALLO:
  529. case IDI_TRAPTXT:
  530. case IDI_TRAPLRGRFX:
  531. case IDI_TRAPHRGRFX:
  532. CheckDlgButton(hwnd, cmd, !IsDlgButtonChecked(hwnd, cmd));
  533. UndoAdvClose();
  534. break;
  535. case IDI_VMODETXT:
  536. CheckRadioButton(hwnd, IDI_VMODETXT, IDI_VMODEHRGRFX, IDI_VMODETXT);
  537. break;
  538. case IDI_VMODELRGRFX:
  539. CheckRadioButton(hwnd, IDI_VMODETXT, IDI_VMODEHRGRFX, IDI_VMODELRGRFX);
  540. break;
  541. case IDI_VMODEHRGRFX:
  542. CheckRadioButton(hwnd, IDI_VMODETXT, IDI_VMODEHRGRFX, IDI_VMODEHRGRFX);
  543. break;
  544. case IDI_CLOSE:
  545. CheckDlgButton(hwnd, cmd, !IsDlgButtonChecked(hwnd, cmd));
  546. if(IsDlgButtonChecked(hwnd, cmd)) {
  547. value = Warning(WARNCLOSE,MB_ICONHAND | MB_OKCANCEL);
  548. if(value == IDCANCEL) {
  549. CheckDlgButton(hwnd, cmd, FALSE);
  550. }
  551. }
  552. UndoAdvClose();
  553. break;
  554. case IDI_FSCR:
  555. case IDI_WND:
  556. CheckRadioButton(hwnd, IDI_WND, IDI_FSCR, cmd);
  557. break;
  558. case IDI_FPRI:
  559. case IDI_BPRI:
  560. if (HIWORD(wParam) == EN_CHANGE) {
  561. len = GetDlgItemText(hwnd, cmd, (LPSTR)buf, sizeof(buf));
  562. value = GetDlgItemInt(hwnd, cmd, (BOOL FAR *)&result, FALSE);
  563. if((!result) && (len == 0)) {
  564. UndoAdvClose();
  565. } else if((!result) || (value == 0) || (value > 10000)) {
  566. MessageBeep(0);
  567. Warning(errBadNumberP,MB_ICONEXCLAMATION | MB_OK);
  568. SetDlgItemInt(hwnd, cmd,
  569. (cmd == IDI_FPRI ? Pif386ext->PfFPriority : Pif386ext->PfBPriority),
  570. FALSE);
  571. } else {
  572. UndoAdvClose();
  573. }
  574. }
  575. break;
  576. case IDI_MEMDES:
  577. case IDI_MEMREQ:
  578. if (HIWORD(wParam) == EN_CHANGE) {
  579. len = GetDlgItemText(hwnd, cmd, (LPSTR)buf, sizeof(buf));
  580. ivalue = (int)GetDlgItemInt(hwnd, cmd, (BOOL FAR *)&result, TRUE);
  581. if(((!result) && (len == 0)) || ((!result) && (len == 1) && (buf[0] == '-'))) {
  582. } else if((!result) || (ivalue < -1) || (ivalue > 640)) {
  583. MessageBeep(0);
  584. if(cmd == IDI_MEMREQ)
  585. Warning(errBadNumberMR,MB_ICONEXCLAMATION | MB_OK);
  586. else
  587. Warning(errBadNumberMD,MB_ICONEXCLAMATION | MB_OK);
  588. if(CurrMode386)
  589. SetDlgItemInt(hwnd, cmd,
  590. (cmd == IDI_MEMDES ? Pif386ext->maxmem : Pif386ext->minmem),
  591. TRUE);
  592. else
  593. SetDlgItemInt(hwnd, cmd,
  594. (cmd == IDI_MEMDES ? PifFile->maxmem : PifFile->minmem),
  595. TRUE);
  596. }
  597. }
  598. break;
  599. case IDI_EMSDES:
  600. case IDI_XMADES:
  601. if (HIWORD(wParam) == EN_CHANGE) {
  602. len = GetDlgItemText(hwnd, cmd, (LPSTR)buf, sizeof(buf));
  603. ivalue = (int)GetDlgItemInt(hwnd, cmd, (BOOL FAR *)&result, TRUE);
  604. if(((!result) && (len == 0)) || ((!result) && (len == 1) && (buf[0] == '-'))) {
  605. } else if((!result) || ((ivalue < -1) || (ivalue > 16384))) {
  606. MessageBeep(0);
  607. Warning(errBadNumberXEMSD,MB_ICONEXCLAMATION | MB_OK);
  608. if(CurrMode386) {
  609. if(Pif386ext) {
  610. switch (cmd) {
  611. case IDI_EMSDES:
  612. SetDlgItemInt(hwnd, cmd, Pif386ext->PfMaxEMMK,TRUE);
  613. break;
  614. case IDI_XMADES:
  615. SetDlgItemInt(hwnd, cmd, Pif386ext->PfMaxXmsK,TRUE);
  616. break;
  617. }
  618. }
  619. } else {
  620. /*
  621. *switch (cmd) {
  622. *
  623. * case IDI_EMSDES:
  624. * if(Pif286ext31)
  625. * SetDlgItemInt(hwnd, cmd, Pif286ext31->PfMaxEmsK,TRUE);
  626. * break;
  627. *
  628. * case IDI_XMADES:
  629. */
  630. if(Pif286ext30)
  631. SetDlgItemInt(hwnd, cmd, Pif286ext30->PfMaxXmsK,TRUE);
  632. /*
  633. * break;
  634. *}
  635. */
  636. }
  637. }
  638. }
  639. break;
  640. case IDI_EMSREQ:
  641. case IDI_XMAREQ:
  642. if (HIWORD(wParam) == EN_CHANGE) {
  643. len = GetDlgItemText(hwnd, cmd, (LPSTR)buf, sizeof(buf));
  644. value = GetDlgItemInt(hwnd, cmd, (BOOL FAR *)&result, FALSE);
  645. if((!result) && (len == 0)) {
  646. } else if((!result) || (value > 16384)) {
  647. MessageBeep(0);
  648. Warning(errBadNumberXEMSR,MB_ICONEXCLAMATION | MB_OK);
  649. if(CurrMode386) {
  650. if(Pif386ext) {
  651. switch (cmd) {
  652. case IDI_EMSREQ:
  653. SetDlgItemInt(hwnd, cmd, Pif386ext->PfMinEMMK,FALSE);
  654. break;
  655. case IDI_XMAREQ:
  656. SetDlgItemInt(hwnd, cmd, Pif386ext->PfMinXmsK,FALSE);
  657. break;
  658. }
  659. }
  660. } else {
  661. /*
  662. *switch (cmd) {
  663. *
  664. * case IDI_EMSREQ:
  665. * if(Pif286ext31)
  666. * SetDlgItemInt(hwnd, cmd, Pif286ext31->PfMinEmsK,FALSE);
  667. * break;
  668. *
  669. * case IDI_XMAREQ:
  670. */
  671. if(Pif286ext30)
  672. SetDlgItemInt(hwnd, cmd, Pif286ext30->PfMinXmsK,FALSE);
  673. /*
  674. * break;
  675. *}
  676. */
  677. }
  678. }
  679. }
  680. break;
  681. case IDCANCEL:
  682. case IDNTCANCEL:
  683. case IDADVCANCEL:
  684. if((hwnd == hwndAdvPifDlg) || (hwnd == hwndNTPifDlg)) {
  685. SendMessage(hwnd,WM_PRIVCLOSECANCEL,0,0L);
  686. }
  687. break;
  688. case IDOK:
  689. case IDNTOK:
  690. if(hwnd == hwndAdvPifDlg) {
  691. if(CurrMode386) {
  692. if(UpdatePif386Struc())
  693. FileChanged = TRUE;
  694. }
  695. if(!DoFieldsWorkAdv(FALSE))
  696. break;
  697. SendMessage(hwnd,WM_PRIVCLOSEOK,0,0L);
  698. }
  699. else if(hwnd == hwndNTPifDlg) {
  700. if(CurrMode386) {
  701. if(UpdatePifNTStruc()) {
  702. OldFileChanged = FileChanged;
  703. FileChanged = TRUE;
  704. }
  705. }
  706. if(!DoFieldsWorkNT(FALSE)) {
  707. FileChanged = OldFileChanged;
  708. break;
  709. }
  710. SendMessage(hwnd,WM_PRIVCLOSEOK,0,0L);
  711. }
  712. break;
  713. }
  714. return(TRUE);
  715. }
  716. long GetNTDlgSize(HWND hwnd)
  717. {
  718. int i = 0;
  719. RECT rc2;
  720. RECT rc3;
  721. RECT rc4;
  722. /* get right side from the OK button */
  723. GetWindowRect(GetDlgItem(hwnd,IDNTOK),(LPRECT)&rc2);
  724. /* get left & bottom sides from the IDI_NTTIMER check box */
  725. GetWindowRect(GetDlgItem(hwnd,IDI_NTTIMER),(LPRECT)&rc3);
  726. GetWindowRect(hwnd,(LPRECT)&rc4);
  727. if(NTScrollRange && (i = GetScrollPos(hwnd,SB_VERT))) {
  728. i = min((i * NTScrollLineSz),MaxNTNeg);
  729. }
  730. return(MAKELONG((rc2.right - rc4.left) +
  731. SysCharWidth -
  732. GetSystemMetrics(SM_CXFRAME),
  733. (rc3.bottom - rc4.top) +
  734. (SysCharHeight/2) +
  735. i -
  736. (GetSystemMetrics(SM_CYCAPTION) +
  737. GetSystemMetrics(SM_CYBORDER) +
  738. GetSystemMetrics(SM_CYFRAME)) +
  739. (StatusPntData.dyStatus + StatusPntData.dyBorderx2)));
  740. }
  741. long GetAdvDlgSize(HWND hwnd)
  742. {
  743. int i = 0;
  744. RECT rc2;
  745. RECT rc3;
  746. GetWindowRect(GetDlgItem(hwnd,IDI_OTHGRP),(LPRECT)&rc2);
  747. GetWindowRect(hwnd,(LPRECT)&rc3);
  748. if(AdvScrollRange && (i = GetScrollPos(hwnd,SB_VERT))) {
  749. i = min((i * AdvScrollLineSz),MaxAdvNeg);
  750. }
  751. return(MAKELONG((rc2.right - rc3.left) +
  752. SysCharWidth -
  753. GetSystemMetrics(SM_CXFRAME),
  754. (rc2.top-rc3.top) +
  755. (rc2.bottom - rc2.top) +
  756. (SysCharHeight/2) +
  757. i -
  758. (GetSystemMetrics(SM_CYCAPTION) +
  759. GetSystemMetrics(SM_CYBORDER) +
  760. GetSystemMetrics(SM_CYFRAME)) +
  761. (StatusPntData.dyStatus + StatusPntData.dyBorderx2)));
  762. }
  763. ReEnableAdvButton(void)
  764. {
  765. HWND hwndctl;
  766. if(hwndPifDlg && CurrMode386) {
  767. if(!bNTDlgOpen) {
  768. hwndctl = GetDlgItem(hwndPifDlg,IDI_NT);
  769. if(hwndFocusMain == hwndctl)
  770. SendMessage(hwndctl,BM_SETSTYLE,BS_DEFPUSHBUTTON,1L);
  771. else
  772. SendMessage(hwndctl,BM_SETSTYLE,BS_PUSHBUTTON,1L);
  773. EnableWindow(hwndctl,TRUE);
  774. }
  775. if(!bAdvDlgOpen) {
  776. hwndctl = GetDlgItem(hwndPifDlg,IDI_ADVANCED);
  777. if(hwndFocusMain == hwndctl)
  778. SendMessage(hwndctl,BM_SETSTYLE,BS_DEFPUSHBUTTON,1L);
  779. else
  780. SendMessage(hwndctl,BM_SETSTYLE,BS_PUSHBUTTON,1L);
  781. EnableWindow(hwndctl,TRUE);
  782. }
  783. }
  784. return(TRUE);
  785. }
  786. DoOpenPifFile(HDROP DropHnd)
  787. {
  788. HWND hwnd2;
  789. unsigned char *pchBuf = (unsigned char *)NULL;
  790. unsigned char *pch;
  791. if (MaybeSaveFile()) {
  792. if(DropHnd) {
  793. if(!(pchBuf = (unsigned char *)LocalAlloc(LPTR, 132))) {
  794. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  795. } else {
  796. if(!(DragQueryFile(DropHnd,0,(LPSTR)pchBuf,132))) {
  797. LocalFree((HANDLE)pchBuf);
  798. pchBuf = (unsigned char *)NULL;
  799. } else {
  800. SetFileOffsets(pchBuf,&tmpfileoffset,&tmpextoffset);
  801. }
  802. }
  803. } else {
  804. pchBuf = PutUpDB(DTOPEN);
  805. }
  806. }
  807. if(pchBuf) {
  808. AnsiUpper((LPSTR)pchBuf);
  809. pch = pchBuf+tmpextoffset;
  810. if((tmpextoffset == 0) || (lstrcmp((LPSTR)pch, (LPSTR)"PIF"))) {
  811. if( Warning(errWrongExt,MB_ICONEXCLAMATION | MB_OKCANCEL | MB_DEFBUTTON2) == IDCANCEL) {
  812. LocalFree((HANDLE)pchBuf);
  813. pchBuf = (unsigned char *)NULL;
  814. }
  815. }
  816. }
  817. if(pchBuf) {
  818. HourGlass(TRUE);
  819. LoadPifFile(pchBuf);
  820. LocalFree((HANDLE)pchBuf);
  821. SendMessage(hwndPifDlg,WM_NEXTDLGCTL,
  822. (WPARAM)(hwnd2 = GetDlgItem(hwndPifDlg,IDI_ENAME)),1L);
  823. SetFocus(hwnd2);
  824. HourGlass(FALSE);
  825. SetMainTitle();
  826. }
  827. if(DropHnd)
  828. DragFinish(DropHnd);
  829. return(TRUE);
  830. }
  831. int FAR PASCAL PifNTWndProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
  832. {
  833. LPPOINT ppnt3;
  834. LPPOINT ppnt4;
  835. int width;
  836. int height;
  837. long size;
  838. BOOL ChngFlg;
  839. HMENU hmenu;
  840. RECT rc;
  841. CHAR buf[PIFDEFPATHSIZE*2];
  842. int tmpFOCID;
  843. switch (message) {
  844. case WM_INITDIALOG:
  845. if((hmenu = GetSystemMenu(hwnd,FALSE))) {
  846. DeleteMenu(hmenu, SC_RESTORE, MF_BYCOMMAND);
  847. DeleteMenu(hmenu, SC_SIZE, MF_BYCOMMAND);
  848. DeleteMenu(hmenu, SC_MINIMIZE, MF_BYCOMMAND);
  849. DeleteMenu(hmenu, SC_MAXIMIZE, MF_BYCOMMAND);
  850. } else {
  851. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  852. }
  853. lstrcpy(szOldAutoexec, (LPSTR)(PifNText->achAutoexecFile));
  854. lstrcpy(szOldConfig, (LPSTR)(PifNText->achConfigFile));
  855. hwndFocusNT = (HWND)wParam;
  856. bNTDlgOpen = TRUE;
  857. FocusIDNT = GetDlgCtrlID((HWND)wParam);
  858. OemToAnsi((LPSTR)PifNText->achAutoexecFile, buf);
  859. SetDlgItemText(hwnd, IDI_AUTOEXEC,(LPSTR)buf);
  860. OemToAnsi((LPSTR)PifNText->achConfigFile, buf);
  861. SetDlgItemText(hwnd, IDI_CONFIG, (LPSTR)buf);
  862. SendDlgItemMessage(hwnd, IDI_AUTOEXEC, EM_LIMITTEXT, PIFDEFPATHSIZE-1, 0L);
  863. SendDlgItemMessage(hwnd, IDI_CONFIG, EM_LIMITTEXT, PIFDEFPATHSIZE-1, 0L);
  864. CheckDlgButton(hwnd, IDI_NTTIMER, (PifNText->dwWNTFlags & COMPAT_TIMERTIC ? TRUE : FALSE));
  865. SetStatusText(hwnd,FocusIDNT,FALSE);
  866. if(InitShWind) {
  867. SetFocus((HWND)wParam); /* Give focus to wparam item */
  868. SendMessage((HWND)wParam,EM_SETSEL,0,MAKELONG(0,0x7FFF));
  869. return(FALSE);
  870. } else {
  871. return(FALSE); /* Do not set focus until init show */
  872. }
  873. break;
  874. case WM_PAINT:
  875. PaintStatus(hwnd);
  876. return(FALSE);
  877. break;
  878. case WM_COMMAND:
  879. SetStatusText(hwnd,FocusIDNT,TRUE);
  880. FocusIDNTMenu = 0;
  881. DoDlgCommand(hwnd, wParam, lParam);
  882. break;
  883. case WM_SYSCOLORCHANGE:
  884. InvalidateStatusBar(hwnd);
  885. break;
  886. case WM_MENUSELECT:
  887. tmpFOCID = FocusIDNTMenu;
  888. if((HIWORD(wParam) == 0xFFFF) && (lParam == (LPARAM)NULL)) { // was menu closed?
  889. SetStatusText(hwnd,FocusIDNT,TRUE);
  890. tmpFOCID = FocusIDNTMenu = 0;
  891. } else if(lParam == 0) { /* ignore these */
  892. } else if(HIWORD(wParam) & MF_POPUP) {
  893. if((HMENU)lParam == hSysMenuNT)
  894. FocusIDNTMenu = M_SYSMENUNT;
  895. } else {
  896. if(LOWORD(wParam) != 0) /* separators have wparam of 0 */
  897. FocusIDNTMenu = LOWORD(wParam);
  898. if(FocusIDNTMenu == SC_CLOSE)
  899. FocusIDNTMenu = SC_NTCLOSE;
  900. }
  901. if(tmpFOCID != FocusIDNTMenu)
  902. SetStatusText(hwnd,FocusIDNTMenu,TRUE);
  903. break;
  904. case WM_SIZE:
  905. GetClientRect(hwnd, &rc);
  906. rc.top = rc.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  907. if(rc.top < StatRecSizeNT.top) {
  908. /* Window SHRANK, need to invalidate current status rect */
  909. InvalidateRect(hwnd, (CONST RECT *)&rc,FALSE);
  910. } else {
  911. /* Window GREW, need to invalidate prev status rect */
  912. InvalidateRect(hwnd, (CONST RECT *)&StatRecSizeNT,TRUE);
  913. }
  914. switch (wParam) {
  915. case SIZEFULLSCREEN:
  916. case SIZENORMAL:
  917. NTWndSize = wParam;
  918. SetMainWndSize(SBUNT);
  919. /* NOTE FALL THROUGH */
  920. default:
  921. return(FALSE);
  922. break;
  923. }
  924. break;
  925. case WM_VSCROLL:
  926. if(NTScrollRange)
  927. MainScroll(hwnd, (int)(LOWORD(wParam)), (int)(HIWORD(wParam)), 0, 0);
  928. return(TRUE);
  929. break;
  930. case WM_PRIVCLOSECANCEL:
  931. CompleteKey = FALSE;
  932. EditHotKey = FALSE;
  933. NewHotKey = FALSE;
  934. lstrcpy((LPSTR)(PifNText->achAutoexecFile), szOldAutoexec);
  935. SetDlgItemText(hwnd, IDI_AUTOEXEC, szOldAutoexec);
  936. lstrcpy((LPSTR)(PifNText->achConfigFile), szOldConfig);
  937. SetDlgItemText(hwnd, IDI_CONFIG, szOldConfig);
  938. SetNTDlgItem(IDI_AUTOEXEC);
  939. UpdatePifScreenNT(); /* DISCARD any changes in NT */
  940. /* NOTE FALL THROUGH */
  941. case WM_PRIVCLOSEOK:
  942. bNTDlgOpen = FALSE;
  943. ChngFlg = UpdatePifStruct();
  944. if(ChngFlg)
  945. FileChanged = ChngFlg;
  946. hwndNTPifDlg = (HWND)NULL;
  947. hSysMenuNT = (HMENU)NULL;
  948. /*
  949. * WHAT IS THIS RANDOM SetFocus DOING HERE??? Well the advanced
  950. * window is WS_OVERLAPPED, and Windows CAN get all confused
  951. * about where the Focus should go on Destroy with this style.
  952. * The style probably should be changed to WS_POPUP, but that
  953. * is a change that may cause other problems.
  954. */
  955. SetFocus(hMainwnd);
  956. DragAcceptFiles(hwnd,FALSE);
  957. DestroyWindow(hwnd);
  958. ReEnableAdvButton();
  959. NTScrollRange = 0;
  960. ModeAdvanced = FALSE;
  961. return(TRUE);
  962. break;
  963. case WM_SYSCOMMAND:
  964. switch (wParam) {
  965. case SC_CLOSE:
  966. SendMessage(hwnd,WM_PRIVCLOSECANCEL,0,0L);
  967. return(TRUE);
  968. default:
  969. return(FALSE);
  970. }
  971. break;
  972. case WM_PRIVGETSIZE: /* return correct size for client area */
  973. *(long FAR *)lParam = GetNTDlgSize(hwnd);
  974. break;
  975. case WM_GETMINMAXINFO:
  976. GetClientRect(hwnd, &StatRecSizeNT);
  977. StatRecSizeNT.top = StatRecSizeNT.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  978. size = GetNTDlgSize(hwnd);
  979. width = LOWORD(size) +
  980. (2 * GetSystemMetrics(SM_CXFRAME)) +
  981. GetSystemMetrics(SM_CXVSCROLL) +
  982. GetSystemMetrics(SM_CXBORDER);
  983. height = HIWORD(size) +
  984. GetSystemMetrics(SM_CYCAPTION) +
  985. (2 * GetSystemMetrics(SM_CYFRAME));
  986. ppnt3 = ppnt4 = (LPPOINT)lParam;
  987. ppnt3 += 3;
  988. ppnt4 += 4;
  989. if(height > (ppnt4->y - (4 * SysCharHeight)))
  990. height = ppnt4->y - (4 * SysCharHeight);
  991. ppnt3->y = height;
  992. ppnt3->x = width;
  993. return(TRUE);
  994. break;
  995. case WM_DROPFILES:
  996. DoOpenPifFile((HDROP)wParam);
  997. break;
  998. default:
  999. return(FALSE);
  1000. }
  1001. return(TRUE);
  1002. }
  1003. int FAR PASCAL PifAdvWndProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
  1004. {
  1005. LPPOINT ppnt3;
  1006. LPPOINT ppnt4;
  1007. int width;
  1008. int height;
  1009. long size;
  1010. BOOL ChngFlg;
  1011. HMENU hmenu;
  1012. RECT rc;
  1013. int tmpFOCID;
  1014. switch (message) {
  1015. case WM_INITDIALOG:
  1016. if((hmenu = GetSystemMenu(hwnd,FALSE))) {
  1017. DeleteMenu(hmenu, SC_RESTORE, MF_BYCOMMAND);
  1018. DeleteMenu(hmenu, SC_SIZE, MF_BYCOMMAND);
  1019. DeleteMenu(hmenu, SC_MINIMIZE, MF_BYCOMMAND);
  1020. DeleteMenu(hmenu, SC_MAXIMIZE, MF_BYCOMMAND);
  1021. } else {
  1022. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1023. }
  1024. hwndFocusAdv = (HWND)wParam;
  1025. bAdvDlgOpen = TRUE;
  1026. FocusIDAdv = GetDlgCtrlID((HWND)wParam);
  1027. SetStatusText(hwnd,FocusIDAdv,FALSE);
  1028. if(InitShWind) {
  1029. SetFocus((HWND)wParam); /* Give focus to wparam item */
  1030. SendMessage((HWND)wParam,EM_SETSEL,0,MAKELONG(0,0x7FFF));
  1031. return(FALSE);
  1032. } else {
  1033. return(FALSE); /* Do not set focus until init show */
  1034. }
  1035. break;
  1036. case WM_PAINT:
  1037. PaintStatus(hwnd);
  1038. return(FALSE);
  1039. break;
  1040. case WM_COMMAND:
  1041. SetStatusText(hwnd,FocusIDAdv,TRUE);
  1042. FocusIDAdvMenu = 0;
  1043. DoDlgCommand(hwnd, wParam, lParam);
  1044. break;
  1045. case WM_SYSCOLORCHANGE:
  1046. InvalidateStatusBar(hwnd);
  1047. break;
  1048. case WM_MENUSELECT:
  1049. tmpFOCID = FocusIDAdvMenu;
  1050. if((HIWORD(wParam) == 0xFFFF) && (lParam == (LPARAM)NULL)) { // was menu closed?
  1051. SetStatusText(hwnd,FocusIDAdv,TRUE);
  1052. tmpFOCID = FocusIDAdvMenu = 0;
  1053. } else if(lParam == 0) { /* ignore these */
  1054. } else if(HIWORD(wParam) & MF_POPUP) {
  1055. if((HMENU)lParam == hSysMenuAdv)
  1056. FocusIDAdvMenu = M_SYSMENUADV;
  1057. } else {
  1058. if(LOWORD(wParam) != 0) /* separators have wparam of 0 */
  1059. FocusIDAdvMenu = LOWORD(wParam);
  1060. if(FocusIDAdvMenu == SC_CLOSE)
  1061. FocusIDAdvMenu = SC_CLOSEADV;
  1062. }
  1063. if(tmpFOCID != FocusIDAdvMenu)
  1064. SetStatusText(hwnd,FocusIDAdvMenu,TRUE);
  1065. break;
  1066. case WM_SIZE:
  1067. GetClientRect(hwnd, &rc);
  1068. rc.top = rc.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  1069. if(rc.top < StatRecSizeAdv.top) {
  1070. /* Window SHRANK, need to invalidate current status rect */
  1071. InvalidateRect(hwnd, (CONST RECT *)&rc,FALSE);
  1072. } else {
  1073. /* Window GREW, need to invalidate prev status rect */
  1074. InvalidateRect(hwnd, (CONST RECT *)&StatRecSizeAdv,TRUE);
  1075. }
  1076. switch (wParam) {
  1077. case SIZEFULLSCREEN:
  1078. case SIZENORMAL:
  1079. AdvWndSize = wParam;
  1080. SetMainWndSize(SBUADV);
  1081. /* NOTE FALL THROUGH */
  1082. default:
  1083. return(FALSE);
  1084. break;
  1085. }
  1086. break;
  1087. case WM_VSCROLL:
  1088. if(AdvScrollRange)
  1089. MainScroll(hwnd, (int)(LOWORD(wParam)), (int)(HIWORD(wParam)), 0, 0);
  1090. return(TRUE);
  1091. break;
  1092. case WM_PRIVCLOSECANCEL:
  1093. CompleteKey = FALSE;
  1094. EditHotKey = FALSE;
  1095. NewHotKey = FALSE;
  1096. UpdatePifScreenAdv(); /* DISCARD any changes in advanced */
  1097. /* NOTE FALL THROUGH */
  1098. case WM_PRIVCLOSEOK:
  1099. bAdvDlgOpen = FALSE;
  1100. ChngFlg = UpdatePifStruct();
  1101. if(ChngFlg)
  1102. FileChanged = ChngFlg;
  1103. hwndAdvPifDlg = (HWND)NULL;
  1104. hSysMenuAdv = (HMENU)NULL;
  1105. /*
  1106. * WHAT IS THIS RANDOM SetFocus DOING HERE??? Well the advanced
  1107. * window is WS_OVERLAPPED, and Windows CAN get all confused
  1108. * about where the Focus should go on Destroy with this style.
  1109. * The style probably should be changed to WS_POPUP, but that
  1110. * is a change that may cause other problems.
  1111. */
  1112. SetFocus(hMainwnd);
  1113. DragAcceptFiles(hwnd,FALSE);
  1114. DestroyWindow(hwnd);
  1115. ReEnableAdvButton();
  1116. AdvScrollRange = 0;
  1117. ModeAdvanced = FALSE;
  1118. return(TRUE);
  1119. break;
  1120. case WM_SYSCOMMAND:
  1121. switch (wParam) {
  1122. case SC_CLOSE:
  1123. SendMessage(hwnd,WM_PRIVCLOSECANCEL,0,0L);
  1124. return(TRUE);
  1125. default:
  1126. return(FALSE);
  1127. }
  1128. break;
  1129. case WM_PRIVGETSIZE: /* return correct size for client area */
  1130. *(long FAR *)lParam = GetAdvDlgSize(hwnd);
  1131. break;
  1132. case WM_GETMINMAXINFO:
  1133. GetClientRect(hwnd, &StatRecSizeAdv);
  1134. StatRecSizeAdv.top = StatRecSizeAdv.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  1135. size = GetAdvDlgSize(hwnd);
  1136. width = LOWORD(size) +
  1137. (2 * GetSystemMetrics(SM_CXFRAME)) +
  1138. GetSystemMetrics(SM_CXVSCROLL) +
  1139. GetSystemMetrics(SM_CXBORDER);
  1140. height = HIWORD(size) +
  1141. GetSystemMetrics(SM_CYCAPTION) +
  1142. (2 * GetSystemMetrics(SM_CYFRAME));
  1143. ppnt3 = ppnt4 = (LPPOINT)lParam;
  1144. ppnt3 += 3;
  1145. ppnt4 += 4;
  1146. if(height > (ppnt4->y - (4 * SysCharHeight)))
  1147. height = ppnt4->y - (4 * SysCharHeight);
  1148. ppnt3->y = height;
  1149. ppnt3->x = width;
  1150. return(TRUE);
  1151. break;
  1152. case WM_DROPFILES:
  1153. DoOpenPifFile((HDROP)wParam);
  1154. break;
  1155. default:
  1156. return(FALSE);
  1157. }
  1158. return(TRUE);
  1159. }
  1160. BOOL CALLBACK PifWndProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
  1161. {
  1162. RECT rc2;
  1163. RECT rc3;
  1164. RECT rc4;
  1165. switch (message) {
  1166. case WM_INITDIALOG:
  1167. hwndFocusMain = (HWND)wParam;
  1168. FocusIDMain = GetDlgCtrlID((HWND)wParam);
  1169. SetStatusText(hMainwnd,FocusIDMain,TRUE);
  1170. if(InitShWind) {
  1171. SetFocus((HWND)wParam); /* Give focus to wparam item */
  1172. SendMessage((HWND)wParam,EM_SETSEL,0,MAKELONG(0,0x7FFF));
  1173. return(FALSE);
  1174. } else {
  1175. return(FALSE); /* Do not set focus until init show */
  1176. }
  1177. break;
  1178. case WM_COMMAND:
  1179. DoDlgCommand(hwnd, wParam, lParam);
  1180. break;
  1181. case WM_PRIVGETSIZE: /* return correct size for parent window client area */
  1182. GetWindowRect(hwnd,(LPRECT)&rc3);
  1183. if(CurrMode386) {
  1184. GetWindowRect(GetDlgItem(hwnd,IDI_BACK),(LPRECT)&rc4);
  1185. GetWindowRect(GetDlgItem(hwnd,IDI_EXIT),(LPRECT)&rc2);
  1186. } else {
  1187. GetWindowRect(GetDlgItem(hwnd,IDI_EPATH),(LPRECT)&rc4);
  1188. GetWindowRect(GetDlgItem(hwnd,IDI_ALTPRTSC),(LPRECT)&rc2);
  1189. }
  1190. *(long FAR *)lParam = MAKELONG((rc4.right - rc3.left) +
  1191. SysCharWidth,
  1192. (rc2.top-rc3.top) +
  1193. (rc2.bottom - rc2.top) +
  1194. ((rc2.bottom - rc2.top)/3) +
  1195. (StatusPntData.dyStatus + StatusPntData.dyBorderx2));
  1196. if(!wParam) {
  1197. SetWindowPos(hwnd,
  1198. (HWND)NULL,
  1199. 0,
  1200. 0,
  1201. 0,
  1202. 0,
  1203. SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
  1204. }
  1205. break;
  1206. case WM_DROPFILES:
  1207. DoOpenPifFile((HDROP)wParam);
  1208. break;
  1209. default:
  1210. return(FALSE);
  1211. }
  1212. return(TRUE);
  1213. }
  1214. SwitchNT(HWND hwnd)
  1215. {
  1216. BOOL ChngFlg;
  1217. hwndFocusMain = hwndFocusAdv = hwndFocusNT = hwndFocus = (HWND)NULL;
  1218. if(ModeAdvanced) {
  1219. Disable386Advanced(hwndAdvPifDlg, hwndNTPifDlg);
  1220. }
  1221. else {
  1222. ChngFlg = UpdatePifStruct();
  1223. if(ChngFlg)
  1224. FileChanged = ChngFlg;
  1225. if(!bNTDlgOpen) {
  1226. EnableWindow(GetDlgItem(hwnd,IDI_NT),FALSE);
  1227. NTScrollRange = 0;
  1228. /*
  1229. NTClose = TRUE;
  1230. */
  1231. hwndNTPifDlg = CreateDialog(hPifInstance,
  1232. MAKEINTRESOURCE(ID_PIFNTTEMPLT),
  1233. hMainwnd ,
  1234. lpfnNTPifWnd);
  1235. }
  1236. if(hwndNTPifDlg == (HWND)NULL) {
  1237. hwndNTPifDlg = (HWND)NULL;
  1238. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1239. Disable386Advanced(hwndAdvPifDlg, hwndNTPifDlg);
  1240. } else {
  1241. hSysMenuNT = GetSystemMenu(hwndNTPifDlg,FALSE);
  1242. DragAcceptFiles(hwndNTPifDlg,TRUE);
  1243. ModeAdvanced = TRUE;
  1244. SetMainTitle();
  1245. UpdatePifScreen();
  1246. hwndFocusMain = GetDlgItem(hwndPifDlg,IDI_ENAME);
  1247. FocusIDMain = IDI_ENAME;
  1248. SetMainWndSize(SBUSZNT);
  1249. SetStatusText(hMainwnd,FocusIDMain,TRUE);
  1250. }
  1251. }
  1252. if(hwndNTPifDlg) {
  1253. ShowWindow(hwndNTPifDlg, SW_SHOWNORMAL);
  1254. SendDlgItemMessage(hwndNTPifDlg,IDI_AUTOEXEC,EM_SETSEL,0,MAKELONG(0,0x7FFF));
  1255. }
  1256. return(TRUE);
  1257. }
  1258. SwitchAdvance386(HWND hwnd)
  1259. {
  1260. BOOL ChngFlg;
  1261. hwndFocusMain = hwndFocusAdv = hwndFocusNT = hwndFocus = (HWND)NULL;
  1262. if(ModeAdvanced) {
  1263. Disable386Advanced(hwndAdvPifDlg, hwndNTPifDlg);
  1264. } else {
  1265. ChngFlg = UpdatePifStruct();
  1266. if(ChngFlg)
  1267. FileChanged = ChngFlg;
  1268. if(!bAdvDlgOpen)
  1269. EnableWindow(GetDlgItem(hwnd,IDI_ADVANCED),FALSE);
  1270. AdvScrollRange = 0;
  1271. AdvClose = TRUE;
  1272. hwndAdvPifDlg = CreateDialog(hPifInstance,
  1273. MAKEINTRESOURCE(ID_PIF386ADVTEMPLT),
  1274. hMainwnd ,
  1275. lpfnAdvPifWnd);
  1276. if(hwndAdvPifDlg == (HWND)NULL) {
  1277. hwndAdvPifDlg = (HWND)NULL;
  1278. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1279. Disable386Advanced(hwndAdvPifDlg, hwndNTPifDlg);
  1280. } else {
  1281. hSysMenuAdv = GetSystemMenu(hwndAdvPifDlg,FALSE);
  1282. DragAcceptFiles(hwndAdvPifDlg,TRUE);
  1283. ModeAdvanced = TRUE;
  1284. SetMainTitle();
  1285. UpdatePifScreen();
  1286. hwndFocusMain = GetDlgItem(hwndPifDlg,IDI_ENAME);
  1287. FocusIDMain = IDI_ENAME;
  1288. SetMainWndSize(SBUSZADV);
  1289. SetStatusText(hMainwnd,FocusIDMain,TRUE);
  1290. }
  1291. }
  1292. if(hwndAdvPifDlg) {
  1293. ShowWindow(hwndAdvPifDlg, SW_SHOWNORMAL);
  1294. SendDlgItemMessage(hwndAdvPifDlg,IDI_BPRI,EM_SETSEL,0,MAKELONG(0,0x7FFF));
  1295. }
  1296. return(TRUE);
  1297. }
  1298. BOOL EnableMode286(HWND hwnd,BOOL showflg)
  1299. {
  1300. HMENU hMenu;
  1301. HWND hWndSv;
  1302. if(!Pif286ext30) {
  1303. if(!(Pif286ext30 = AllocInit286Ext30())) {
  1304. Warning(NOMODE286,MB_ICONEXCLAMATION | MB_OK);
  1305. return(FALSE);
  1306. }
  1307. }
  1308. /*
  1309. * if(!Pif286ext31) {
  1310. * if(!(Pif286ext31 = AllocInit286Ext31())) {
  1311. * Warning(NOMODE286,MB_ICONEXCLAMATION | MB_OK);
  1312. * return(FALSE);
  1313. * }
  1314. * }
  1315. */
  1316. hwndFocusMain = hwndFocusAdv = hwndFocusNT = hwndFocus = (HWND)NULL;
  1317. if(hwndAdvPifDlg)
  1318. SendMessage(hwndAdvPifDlg,WM_PRIVCLOSEOK,0,0L);
  1319. if(hwndNTPifDlg)
  1320. SendMessage(hwndNTPifDlg,WM_PRIVCLOSEOK,0,0L);
  1321. if(hwndPifDlg) {
  1322. hWndSv = hwndPifDlg;
  1323. hwndPifDlg = (HWND)NULL;
  1324. DragAcceptFiles(hWndSv,FALSE);
  1325. DestroyWindow(hWndSv);
  1326. }
  1327. CurrMode386 = FALSE;
  1328. if(Pif386ext && !(Pif286ext30->PfW286Flags &
  1329. (fALTTABdis286 | fALTESCdis286 | fCTRLESCdis286 | fALTPRTSCdis286 | fPRTSCdis286))) {
  1330. if(Pif386ext->PfW386Flags & fALTTABdis)
  1331. Pif286ext30->PfW286Flags |= fALTTABdis286;
  1332. if(Pif386ext->PfW386Flags & fALTESCdis)
  1333. Pif286ext30->PfW286Flags |= fALTESCdis286;
  1334. if(Pif386ext->PfW386Flags & fCTRLESCdis)
  1335. Pif286ext30->PfW286Flags |= fCTRLESCdis286;
  1336. if(Pif386ext->PfW386Flags & fALTPRTSCdis)
  1337. Pif286ext30->PfW286Flags |= fALTPRTSCdis286;
  1338. if(Pif386ext->PfW386Flags & fPRTSCdis)
  1339. Pif286ext30->PfW286Flags |= fPRTSCdis286;
  1340. }
  1341. hwndPifDlg = CreateDialog(hPifInstance,
  1342. MAKEINTRESOURCE(ID_PIF286TEMPLATE),
  1343. hwnd,
  1344. lpfnPifWnd);
  1345. if(hwndPifDlg == (HWND)NULL) {
  1346. hwndPifDlg = (HWND)NULL;
  1347. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1348. return(FALSE);
  1349. } else {
  1350. DragAcceptFiles(hwndPifDlg,TRUE);
  1351. CheckMenuItem((hMenu = GetMenu(hwnd)),M_286,MF_BYCOMMAND + MF_CHECKED);
  1352. CheckMenuItem(hMenu,M_386,MF_BYCOMMAND + MF_UNCHECKED);
  1353. SetMainWndSize(SBUSZMAINADVNT);
  1354. SendDlgItemMessage(hwndPifDlg, IDI_ENAME, EM_LIMITTEXT, PIFSTARTLOCSIZE-1, 0L);
  1355. SendDlgItemMessage(hwndPifDlg, IDI_EPARM, EM_LIMITTEXT, PIFPARAMSSIZE-1, 0L);
  1356. SendDlgItemMessage(hwndPifDlg, IDI_EPATH, EM_LIMITTEXT, PIFDEFPATHSIZE-1, 0L);
  1357. SendDlgItemMessage(hwndPifDlg, IDI_ETITLE, EM_LIMITTEXT, PIFNAMESIZE, 0L);
  1358. UpdatePifScreen();
  1359. if(showflg) {
  1360. ShowWindow(hwndPifDlg, SW_SHOWNORMAL);
  1361. if(hwndAdvPifDlg)
  1362. ShowWindow(hwndAdvPifDlg, SW_SHOWNORMAL);
  1363. if(hwndNTPifDlg)
  1364. ShowWindow(hwndNTPifDlg, SW_SHOWNORMAL);
  1365. }
  1366. return(TRUE);
  1367. }
  1368. }
  1369. EnableMode386(HWND hwnd,BOOL showflg)
  1370. {
  1371. HMENU hMenu;
  1372. HWND hWndSv;
  1373. unsigned char buf[20];
  1374. unsigned char buf2[100];
  1375. unsigned char buf3[100];
  1376. unsigned char buf4[100];
  1377. if(!Pif386ext) {
  1378. if(!(Pif386ext = AllocInit386Ext())) {
  1379. Warning(NOMODE386,MB_ICONEXCLAMATION | MB_OK);
  1380. return(FALSE);
  1381. }
  1382. }
  1383. if(!PifNText) {
  1384. if(!(PifNText = AllocInitNTExt())) {
  1385. Warning(NOMODENT,MB_ICONEXCLAMATION | MB_OK);
  1386. return(FALSE);
  1387. }
  1388. }
  1389. hwndFocusMain = hwndFocusAdv = hwndFocusNT = hwndFocus = (HWND)NULL;
  1390. if(hwndAdvPifDlg)
  1391. SendMessage(hwndAdvPifDlg,WM_PRIVCLOSEOK,0,0L);
  1392. if(hwndNTPifDlg)
  1393. SendMessage(hwndNTPifDlg,WM_PRIVCLOSEOK,0,0L);
  1394. if(hwndPifDlg) {
  1395. hWndSv = hwndPifDlg;
  1396. hwndPifDlg = (HWND)NULL;
  1397. DragAcceptFiles(hWndSv,FALSE);
  1398. DestroyWindow(hWndSv);
  1399. }
  1400. CurrMode386 = TRUE;
  1401. ModeAdvanced = FALSE;
  1402. if(Pif286ext30 && !(Pif386ext->PfW386Flags &
  1403. (fALTTABdis | fALTESCdis | fCTRLESCdis | fALTPRTSCdis | fPRTSCdis))) {
  1404. if(Pif286ext30->PfW286Flags & fALTTABdis286)
  1405. Pif386ext->PfW386Flags |= fALTTABdis;
  1406. if(Pif286ext30->PfW286Flags & fALTESCdis286)
  1407. Pif386ext->PfW386Flags |= fALTESCdis;
  1408. if(Pif286ext30->PfW286Flags & fCTRLESCdis286)
  1409. Pif386ext->PfW386Flags |= fCTRLESCdis;
  1410. if(Pif286ext30->PfW286Flags & fALTPRTSCdis286)
  1411. Pif386ext->PfW386Flags |= fALTPRTSCdis;
  1412. if(Pif286ext30->PfW286Flags & fPRTSCdis286)
  1413. Pif386ext->PfW386Flags |= fPRTSCdis;
  1414. }
  1415. hwndPifDlg = CreateDialog(hPifInstance,
  1416. MAKEINTRESOURCE(ID_PIF386TEMPLATE),
  1417. hwnd ,
  1418. lpfnPifWnd);
  1419. if(hwndPifDlg == (HWND)NULL) {
  1420. hwndPifDlg = (HWND)NULL;
  1421. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1422. return(FALSE);
  1423. } else {
  1424. DragAcceptFiles(hwndPifDlg,TRUE);
  1425. CheckMenuItem((hMenu = GetMenu(hwnd)),M_386,MF_BYCOMMAND + MF_CHECKED);
  1426. CheckMenuItem(hMenu,M_286,MF_BYCOMMAND + MF_UNCHECKED);
  1427. if(LoadString(hPifInstance, WININISECT, (LPSTR)buf, sizeof(buf)) &&
  1428. LoadString(hPifInstance, WININIADV, (LPSTR)buf2, sizeof(buf2)) &&
  1429. LoadString(hPifInstance, WININION, (LPSTR)buf3, sizeof(buf3))) {
  1430. GetProfileString((LPSTR)buf,(LPSTR)buf2,(LPSTR)"",(LPSTR)buf4,sizeof(buf4));
  1431. if(!lstrcmp(AnsiUpper((LPSTR)buf4),AnsiUpper((LPSTR)buf3)))
  1432. ModeAdvanced = TRUE;
  1433. }
  1434. if(ModeAdvanced) {
  1435. EnableWindow(GetDlgItem(hwndPifDlg,IDI_ADVANCED),FALSE);
  1436. AdvScrollRange = 0;
  1437. AdvClose = TRUE;
  1438. hwndAdvPifDlg = CreateDialog(hPifInstance,
  1439. MAKEINTRESOURCE(ID_PIF386ADVTEMPLT),
  1440. hwnd ,
  1441. lpfnAdvPifWnd);
  1442. if(hwndAdvPifDlg == (HWND)NULL) {
  1443. hwndAdvPifDlg = (HWND)NULL;
  1444. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1445. ReEnableAdvButton();
  1446. return(FALSE);
  1447. }
  1448. hSysMenuAdv = GetSystemMenu(hwndAdvPifDlg,FALSE);
  1449. DragAcceptFiles(hwndAdvPifDlg,TRUE);
  1450. EnableWindow(GetDlgItem(hwndPifDlg,IDI_NT),FALSE);
  1451. NTScrollRange = 0;
  1452. /*
  1453. NTClose = TRUE;
  1454. */
  1455. hwndNTPifDlg = CreateDialog(hPifInstance,
  1456. MAKEINTRESOURCE(ID_PIFNTTEMPLT),
  1457. hwnd ,
  1458. lpfnNTPifWnd);
  1459. if(hwndNTPifDlg == (HWND)NULL) {
  1460. hwndNTPifDlg = (HWND)NULL;
  1461. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1462. ReEnableAdvButton();
  1463. return(FALSE);
  1464. }
  1465. hSysMenuNT = GetSystemMenu(hwndNTPifDlg,FALSE);
  1466. DragAcceptFiles(hwndNTPifDlg,TRUE);
  1467. SetMainTitle();
  1468. } else {
  1469. ReEnableAdvButton();
  1470. }
  1471. SetMainWndSize(SBUSZMAINADVNT);
  1472. SendDlgItemMessage(hwndPifDlg, IDI_ENAME, EM_LIMITTEXT, PIFSTARTLOCSIZE-1, 0L);
  1473. SendDlgItemMessage(hwndPifDlg, IDI_EPARM, EM_LIMITTEXT, PIFPARAMSSIZE-1, 0L);
  1474. SendDlgItemMessage(hwndPifDlg, IDI_EPATH, EM_LIMITTEXT, PIFDEFPATHSIZE-1, 0L);
  1475. SendDlgItemMessage(hwndPifDlg, IDI_ETITLE, EM_LIMITTEXT, PIFNAMESIZE, 0L);
  1476. UpdatePifScreen();
  1477. if(showflg) {
  1478. ShowWindow(hwndPifDlg, SW_SHOWNORMAL);
  1479. if(hwndAdvPifDlg)
  1480. ShowWindow(hwndAdvPifDlg, SW_SHOWNORMAL);
  1481. if(hwndNTPifDlg)
  1482. ShowWindow(hwndNTPifDlg, SW_SHOWNORMAL);
  1483. }
  1484. return(TRUE);
  1485. }
  1486. }
  1487. DoPifCommand(HWND hwnd,WPARAM wParam,LONG lParam)
  1488. {
  1489. int i, cmd;
  1490. unsigned char *pch;
  1491. unsigned char *pchBuf;
  1492. HWND hwnd2;
  1493. BOOL ChngFlg;
  1494. cmd = LOWORD(wParam);
  1495. switch (cmd) {
  1496. case M_NEW:
  1497. if (MaybeSaveFile()) {
  1498. InitPifStruct();
  1499. UpdatePifScreen();
  1500. UpdatePifStruct();
  1501. FileChanged = FALSE;
  1502. ofReopen.szPathName[0] = 0;
  1503. CurPifFile[0] = 0;
  1504. PifFile->id = 0; /* compute check sum */
  1505. pch = (PUCHAR)PifFile->name;
  1506. i = PIFSIZE;
  1507. while (i--)
  1508. PifFile->id += *pch++;
  1509. SendMessage(hwndPifDlg,WM_NEXTDLGCTL,
  1510. (WPARAM)(hwnd2 = GetDlgItem(hwndPifDlg,IDI_ENAME)),1L);
  1511. SetFocus(hwnd2);
  1512. SetMainTitle();
  1513. }
  1514. break;
  1515. case M_OPEN:
  1516. DoOpenPifFile((HDROP)NULL);
  1517. break;
  1518. case M_SAVE:
  1519. if (CurPifFile[0]) {
  1520. pchBuf = CurPifFile;
  1521. goto Save;
  1522. }
  1523. case M_SAVEAS:
  1524. SaveAs:
  1525. if(pchBuf = PutUpDB(DTSAVE)) {
  1526. Save:
  1527. HourGlass(TRUE);
  1528. i = SavePifFile(pchBuf, cmd);
  1529. if (pchBuf != CurPifFile) {
  1530. LocalFree((HANDLE)pchBuf);
  1531. }
  1532. HourGlass(FALSE);
  1533. if (i == SAVERETRY)
  1534. goto SaveAs;
  1535. }
  1536. SetMainTitle();
  1537. break;
  1538. case M_INDXHELP:
  1539. if(CurrMode386) {
  1540. if(ModeAdvanced) {
  1541. if(hwnd == hwndAdvPifDlg) {
  1542. DoHelp(IDXID_386AHELP,IDXID_386AHELP);
  1543. }
  1544. else {
  1545. DoHelp(IDXID_NTHELP,IDXID_NTHELP);
  1546. }
  1547. } else {
  1548. DoHelp(IDXID_386HELP,IDXID_386HELP);
  1549. }
  1550. } else {
  1551. DoHelp(IDXID_286HELP,IDXID_286HELP);
  1552. }
  1553. break;
  1554. case M_HELPHELP:
  1555. case M_286HELP:
  1556. case M_386HELP:
  1557. case M_386AHELP:
  1558. case M_NTHELP:
  1559. case M_SHELP:
  1560. DoHelp(cmd,0);
  1561. break;
  1562. case M_AHELP:
  1563. DoHelp(0,0);
  1564. break;
  1565. case M_ABOUT:
  1566. PutUpDB(DTABOUT);
  1567. break;
  1568. case M_286:
  1569. if(CurrMode386) {
  1570. if(SysMode386) {
  1571. if(Warning(IS286,MB_ICONASTERISK | MB_OKCANCEL) == IDCANCEL) {
  1572. break;
  1573. }
  1574. }
  1575. ChngFlg = UpdatePifStruct();
  1576. if(ChngFlg)
  1577. FileChanged = ChngFlg;
  1578. if(!DoFieldsWork(FALSE))
  1579. break;
  1580. HourGlass(TRUE);
  1581. if(!EnableMode286(hwnd,TRUE))
  1582. SendMessage(hwnd,WM_CLOSE,0,0);
  1583. HourGlass(FALSE);
  1584. }
  1585. break;
  1586. case M_386:
  1587. if(!CurrMode386) {
  1588. if(!SysMode386) {
  1589. if(Warning(IS386,MB_ICONASTERISK | MB_OKCANCEL) == IDCANCEL) {
  1590. break;
  1591. }
  1592. }
  1593. ChngFlg = UpdatePifStruct();
  1594. if(ChngFlg)
  1595. FileChanged = ChngFlg;
  1596. if(!DoFieldsWork(FALSE))
  1597. break;
  1598. HourGlass(TRUE);
  1599. if(!EnableMode386(hwnd,TRUE))
  1600. SendMessage(hwnd,WM_CLOSE,0,0);
  1601. HourGlass(FALSE);
  1602. }
  1603. break;
  1604. case M_EXIT:
  1605. PostMessage(hwnd, WM_CLOSE, 0, 0L);
  1606. break;
  1607. }
  1608. return(TRUE);
  1609. }
  1610. long FAR PASCAL PifMainWndProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
  1611. {
  1612. LPPOINT ppnt3;
  1613. LPPOINT ppnt4;
  1614. int width;
  1615. int height;
  1616. int tmpFOCID;
  1617. long size;
  1618. RECT rc;
  1619. HWND Hparsav;
  1620. switch (message) {
  1621. case WM_SETFOCUS:
  1622. if(hwndFocusMain) {
  1623. /*
  1624. * How can hwndFocusMain != 0 but hwndPifDlg == 0, I hear you
  1625. * ask. Well it's due to a message race. Windows has sent the
  1626. * WM_INITDIALOG to hwndPifDlg which sets hwndFocusMain, but
  1627. * the CreateDialog call has not actually returned yet so
  1628. * hwndPifDlg is still 0.
  1629. *
  1630. */
  1631. if(hwndPifDlg)
  1632. SendMessage(hwndPifDlg,WM_NEXTDLGCTL,(WPARAM)hwndFocusMain,1L);
  1633. SetFocus(hwndFocusMain);
  1634. }
  1635. return(TRUE);
  1636. case WM_PAINT:
  1637. PaintStatus(hwnd);
  1638. goto DoDef;
  1639. break;
  1640. case WM_MENUSELECT:
  1641. tmpFOCID = FocusIDMainMenu;
  1642. if((HIWORD(wParam) == 0xFFFF) && (lParam == (LPARAM)NULL)) { // was menu closed?
  1643. SetStatusText(hwnd,FocusIDMain,TRUE);
  1644. tmpFOCID = FocusIDMainMenu = 0;
  1645. } else if(lParam == 0) { /* ignore these */
  1646. } else if(HIWORD(wParam) & MF_POPUP) {
  1647. if((HMENU)lParam == hSysMenuMain)
  1648. FocusIDMainMenu = M_SYSMENUMAIN;
  1649. else if((HMENU)lParam == hFileMenu)
  1650. FocusIDMainMenu = M_FILEMENU;
  1651. else if((HMENU)lParam == hModeMenu)
  1652. FocusIDMainMenu = M_MODEMENU;
  1653. else if((HMENU)lParam == hHelpMenu)
  1654. FocusIDMainMenu = M_HELPMENU;
  1655. } else {
  1656. if(LOWORD(wParam) != 0) /* separators have wparam of 0 */
  1657. FocusIDMainMenu = LOWORD(wParam);
  1658. }
  1659. if(tmpFOCID != FocusIDMainMenu)
  1660. SetStatusText(hwnd,FocusIDMainMenu,TRUE);
  1661. goto DoDef;
  1662. break;
  1663. case WM_QUERYENDSESSION:
  1664. if(DoingMsg) {
  1665. Hparsav = hParentWnd;
  1666. hParentWnd = 0;
  1667. Warning(errNOEND,MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
  1668. hParentWnd = Hparsav;
  1669. return(FALSE);
  1670. }
  1671. case WM_CLOSE:
  1672. if (MaybeSaveFile()) {
  1673. if (message == WM_CLOSE) {
  1674. if(hwndHelpDlgParent) {
  1675. WinHelp(hwndHelpDlgParent,(LPSTR)PIFHELPFILENAME,HELP_QUIT,(DWORD)NULL);
  1676. hwndHelpDlgParent = (HWND)NULL;
  1677. }
  1678. DragAcceptFiles(hwnd,FALSE);
  1679. DestroyWindow(hwnd);
  1680. }
  1681. return(TRUE);
  1682. }
  1683. return(FALSE);
  1684. break;
  1685. case WM_COMMAND:
  1686. SetStatusText(hwnd,FocusIDMain,TRUE);
  1687. tmpFOCID = FocusIDMainMenu = 0;
  1688. DoPifCommand(hwnd,wParam,lParam);
  1689. break;
  1690. case WM_VSCROLL:
  1691. if(MainScrollRange)
  1692. MainScroll(hwnd, (int)(LOWORD(wParam)), (int)(HIWORD(wParam)), 0, 0);
  1693. break;
  1694. case WM_SYSCOLORCHANGE:
  1695. InvalidateStatusBar(hwnd);
  1696. break;
  1697. case WM_SIZE:
  1698. GetClientRect(hwnd, &rc);
  1699. rc.top = rc.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  1700. if(rc.top < StatRecSizeMain.top) {
  1701. /* Window SHRANK, need to invalidate current status rect */
  1702. InvalidateRect(hwnd, (CONST RECT *)&rc,FALSE);
  1703. } else {
  1704. /* Window GREW, need to invalidate prev status rect */
  1705. InvalidateRect(hwnd, (CONST RECT *)&StatRecSizeMain,TRUE);
  1706. }
  1707. switch (wParam) {
  1708. case SIZEFULLSCREEN:
  1709. case SIZENORMAL:
  1710. MainWndSize = wParam;
  1711. SetMainWndSize(SBUMAIN);
  1712. break;
  1713. default:
  1714. break;
  1715. }
  1716. break;
  1717. case WM_GETMINMAXINFO:
  1718. if(!hwndPifDlg)
  1719. goto DoDef;
  1720. GetClientRect(hwnd, &StatRecSizeMain);
  1721. StatRecSizeMain.top = StatRecSizeMain.bottom - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  1722. SendMessage(hwndPifDlg,WM_PRIVGETSIZE,1,(LONG)(long FAR *)&size);
  1723. width = LOWORD(size) +
  1724. (2 * GetSystemMetrics(SM_CXFRAME)) +
  1725. GetSystemMetrics(SM_CXVSCROLL) +
  1726. GetSystemMetrics(SM_CXBORDER);
  1727. height = HIWORD(size) +
  1728. GetSystemMetrics(SM_CYCAPTION) +
  1729. GetSystemMetrics(SM_CYMENU) +
  1730. (2 * GetSystemMetrics(SM_CYFRAME));
  1731. ppnt3 = ppnt4 = (LPPOINT)lParam;
  1732. ppnt3 += 3;
  1733. ppnt4 += 4;
  1734. if(height > (ppnt4->y - (4 * SysCharHeight)))
  1735. height = ppnt4->y - (4 * SysCharHeight);
  1736. ppnt3->y = height;
  1737. ppnt3->x = width;
  1738. break;
  1739. case WM_DESTROY:
  1740. if(HotKyFnt) {
  1741. DeleteObject((HGDIOBJ)HotKyFnt);
  1742. HotKyFnt = (HFONT)NULL;
  1743. }
  1744. if(StatusPntData.hFontStatus) {
  1745. DeleteObject(StatusPntData.hFontStatus);
  1746. StatusPntData.hFontStatus = (HGDIOBJ)NULL;
  1747. }
  1748. PostQuitMessage(0);
  1749. break;
  1750. case WM_DROPFILES:
  1751. DoOpenPifFile((HDROP)wParam);
  1752. break;
  1753. /* this must be just before the default section */
  1754. case WM_SYSCOMMAND:
  1755. DoDef:
  1756. default:
  1757. return(DefWindowProc(hwnd, message, wParam, lParam));
  1758. }
  1759. return(TRUE);
  1760. }
  1761. AdjustFocusCtrl(HWND hwnd)
  1762. {
  1763. RECT rc;
  1764. RECT rc2;
  1765. POINT cTLpt;
  1766. POINT cLRpt;
  1767. int i;
  1768. int tmpFOCID;
  1769. HWND tmpFocWnd;
  1770. if(hwnd == hwndAdvPifDlg) {
  1771. if(!(tmpFocWnd = hwndFocusAdv))
  1772. return(TRUE);
  1773. } else if(hwnd == hwndNTPifDlg) {
  1774. if(!(tmpFocWnd = hwndFocusNT))
  1775. return(TRUE);
  1776. } else {
  1777. if(!(tmpFocWnd = hwndFocusMain))
  1778. return(TRUE);
  1779. }
  1780. for(i = 0; i < 20; i++) {
  1781. if((hwnd == hwndAdvPifDlg) || (hwnd == hwndNTPifDlg)) {
  1782. GetWindowRect(tmpFocWnd,(LPRECT)&rc2);
  1783. GetWindowRect(hwnd,(LPRECT)&rc);
  1784. rc.bottom -= GetSystemMetrics(SM_CYFRAME) + (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  1785. rc.top += GetSystemMetrics(SM_CYFRAME) +
  1786. GetSystemMetrics(SM_CYCAPTION);
  1787. } else {
  1788. GetClientRect(hMainwnd,(LPRECT)&rc);
  1789. cTLpt.x = rc.left;
  1790. cTLpt.y = rc.top;
  1791. cLRpt.x = rc.right;
  1792. cLRpt.y = rc.bottom;
  1793. ClientToScreen(hMainwnd,(LPPOINT)&cTLpt);
  1794. ClientToScreen(hMainwnd,(LPPOINT)&cLRpt);
  1795. rc.left = cTLpt.x;
  1796. rc.top = cTLpt.y;
  1797. rc.right = cLRpt.x;
  1798. rc.bottom = cLRpt.y - (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  1799. GetWindowRect(tmpFocWnd,(LPRECT)&rc2);
  1800. }
  1801. if((rc2.top >= rc.top) && (rc2.bottom <= rc.bottom)) {
  1802. if(hwnd == hwndAdvPifDlg) {
  1803. if(tmpFocWnd == hwndFocusAdv)
  1804. return(TRUE);
  1805. hwndFocus = hwndFocusAdv = tmpFocWnd;
  1806. tmpFOCID = FocusIDAdv;
  1807. FocusID = FocusIDAdv = GetDlgCtrlID(hwndFocusAdv);
  1808. if(tmpFOCID != FocusIDAdv)
  1809. SetStatusText(hwndAdvPifDlg,FocusIDAdv,TRUE);
  1810. } else if(hwnd == hwndNTPifDlg) {
  1811. if(tmpFocWnd == hwndFocusNT)
  1812. return(TRUE);
  1813. hwndFocus = hwndFocusNT = tmpFocWnd;
  1814. tmpFOCID = FocusIDNT;
  1815. FocusID = FocusIDNT = GetDlgCtrlID(hwndFocusNT);
  1816. if(tmpFOCID != FocusIDNT)
  1817. SetStatusText(hwndNTPifDlg,FocusIDNT,TRUE);
  1818. } else {
  1819. if(tmpFocWnd == hwndFocusMain)
  1820. return(TRUE);
  1821. hwndFocus = hwndFocusMain = tmpFocWnd;
  1822. tmpFOCID = FocusIDMain;
  1823. FocusID = FocusIDMain = GetDlgCtrlID(hwndFocusMain);
  1824. if(tmpFOCID != FocusIDMain)
  1825. SetStatusText(hMainwnd,FocusIDMain,TRUE);
  1826. }
  1827. SendMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)tmpFocWnd,1L);
  1828. SetFocus(tmpFocWnd);
  1829. return(TRUE);
  1830. } else if (rc2.top < rc.top) {
  1831. tmpFocWnd = GetNextDlgTabItem(hwnd,tmpFocWnd,0);
  1832. } else {
  1833. tmpFocWnd = GetNextDlgTabItem(hwnd,tmpFocWnd,1);
  1834. }
  1835. }
  1836. if(hwnd == hwndAdvPifDlg) {
  1837. if(tmpFocWnd == hwndFocusAdv)
  1838. return(TRUE);
  1839. hwndFocus = hwndFocusAdv = tmpFocWnd;
  1840. tmpFOCID = FocusIDAdv;
  1841. FocusID = FocusIDAdv = GetDlgCtrlID(hwndFocusAdv);
  1842. if(tmpFOCID != FocusIDAdv)
  1843. SetStatusText(hwndAdvPifDlg,FocusIDAdv,TRUE);
  1844. } else if(hwnd == hwndNTPifDlg) {
  1845. if(tmpFocWnd == hwndFocusNT)
  1846. return(TRUE);
  1847. hwndFocus = hwndFocusNT = tmpFocWnd;
  1848. tmpFOCID = FocusIDNT;
  1849. FocusID = FocusIDNT = GetDlgCtrlID(hwndFocusNT);
  1850. if(tmpFOCID != FocusIDNT)
  1851. SetStatusText(hwndNTPifDlg,FocusIDNT,TRUE);
  1852. } else {
  1853. if(tmpFocWnd == hwndFocusMain)
  1854. return(TRUE);
  1855. hwndFocus = hwndFocusMain = tmpFocWnd;
  1856. tmpFOCID = FocusIDMain;
  1857. FocusID = FocusIDMain = GetDlgCtrlID(hwndFocusMain);
  1858. if(tmpFOCID != FocusIDMain)
  1859. SetStatusText(hMainwnd,FocusIDMain,TRUE);
  1860. }
  1861. SendMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)tmpFocWnd,1L);
  1862. SetFocus(tmpFocWnd);
  1863. return(TRUE);
  1864. }
  1865. MainScrollTrack(HWND hwnd,int cmd,int mindistance)
  1866. {
  1867. int *ScrollLineSz;
  1868. if(hwnd == hwndAdvPifDlg) {
  1869. ScrollLineSz = &AdvScrollLineSz;
  1870. } else if(hwnd == hwndNTPifDlg) {
  1871. ScrollLineSz = &NTScrollLineSz;
  1872. } else {
  1873. ScrollLineSz = &MainScrollLineSz;
  1874. }
  1875. if(mindistance <= *ScrollLineSz) {
  1876. MainScroll(hwnd,cmd,0,0,0);
  1877. } else {
  1878. MainScroll(hwnd,cmd,0,
  1879. (mindistance + (2* *ScrollLineSz) - 1) / *ScrollLineSz,
  1880. 0);
  1881. }
  1882. return(TRUE);
  1883. }
  1884. MainScroll(HWND hwnd, int cmd, int pos, int multiln, int callflag)
  1885. {
  1886. int oldScrollPos;
  1887. int newScrollPos;
  1888. int *ScrollRange;
  1889. int *ScrollLineSz;
  1890. int *WndLines;
  1891. int *MaxNeg;
  1892. RECT rc2;
  1893. if(hwnd == hwndAdvPifDlg) {
  1894. ScrollRange = &AdvScrollRange;
  1895. ScrollLineSz = &AdvScrollLineSz;
  1896. WndLines = &AdvWndLines;
  1897. MaxNeg = &MaxAdvNeg;
  1898. } else if(hwnd == hwndNTPifDlg) {
  1899. ScrollRange = &NTScrollRange;
  1900. ScrollLineSz = &NTScrollLineSz;
  1901. WndLines = &NTWndLines;
  1902. MaxNeg = &MaxNTNeg;
  1903. } else {
  1904. ScrollRange = &MainScrollRange;
  1905. ScrollLineSz = &MainScrollLineSz;
  1906. WndLines = &MainWndLines;
  1907. MaxNeg = &MaxMainNeg;
  1908. }
  1909. newScrollPos = oldScrollPos = GetScrollPos(hwnd,SB_VERT);
  1910. switch (cmd) {
  1911. case SB_LINEUP:
  1912. if (oldScrollPos)
  1913. if(multiln)
  1914. newScrollPos -= min(oldScrollPos,multiln);
  1915. else
  1916. newScrollPos--;
  1917. break;
  1918. case SB_LINEDOWN:
  1919. if (oldScrollPos < *ScrollRange)
  1920. if(multiln)
  1921. newScrollPos += min((*ScrollRange -
  1922. oldScrollPos),multiln);
  1923. else
  1924. newScrollPos++;
  1925. break;
  1926. case SB_PAGEUP:
  1927. newScrollPos -= *WndLines;
  1928. if ( newScrollPos < 0)
  1929. newScrollPos = 0;
  1930. break;
  1931. case SB_PAGEDOWN:
  1932. newScrollPos += *WndLines;
  1933. if (newScrollPos > *ScrollRange)
  1934. newScrollPos = *ScrollRange;
  1935. break;
  1936. case SB_THUMBPOSITION:
  1937. SetScrollPos(hwnd, SB_VERT, pos, TRUE);
  1938. return(TRUE);
  1939. case SB_THUMBTRACK:
  1940. newScrollPos = pos;
  1941. break;
  1942. case SB_TOP:
  1943. if (!callflag && GetKeyState(VK_CONTROL) >= 0)
  1944. return(TRUE); /* top of data must be Ctrl+Home */
  1945. newScrollPos = 0;
  1946. break;
  1947. case SB_BOTTOM:
  1948. if (!callflag && GetKeyState(VK_CONTROL) >= 0)
  1949. return(TRUE); /* end of data must be Ctrl+End */
  1950. newScrollPos = *ScrollRange;
  1951. break;
  1952. }
  1953. if (newScrollPos != oldScrollPos) {
  1954. if (cmd != SB_THUMBTRACK)
  1955. SetScrollPos(hwnd, SB_VERT, newScrollPos, TRUE);
  1956. newScrollPos = min((newScrollPos * *ScrollLineSz),*MaxNeg);
  1957. oldScrollPos = min((oldScrollPos * *ScrollLineSz),*MaxNeg);
  1958. GetClientRect(hwnd,(LPRECT)&rc2);
  1959. if((hwnd == hwndAdvPifDlg) || (hwnd == hwndNTPifDlg)) {
  1960. ScrollWindow(hwnd,
  1961. 0,
  1962. oldScrollPos-newScrollPos,
  1963. (CONST RECT *)NULL,
  1964. (CONST RECT *)NULL);
  1965. UpdateWindow(hwnd);
  1966. AdjustFocusCtrl(hwnd);
  1967. } else {
  1968. SetWindowPos(hwndPifDlg,
  1969. (HWND)NULL,
  1970. 0,
  1971. -newScrollPos,
  1972. rc2.right - rc2.left,
  1973. rc2.bottom - rc2.top + newScrollPos -
  1974. (StatusPntData.dyStatus + StatusPntData.dyBorderx2),
  1975. SWP_NOZORDER | SWP_NOACTIVATE);
  1976. UpdateWindow(hwndPifDlg);
  1977. AdjustFocusCtrl(hwndPifDlg);
  1978. }
  1979. InvalidateStatusBar(hwnd);
  1980. }
  1981. return(TRUE);
  1982. }
  1983. DoHkeyCaret(HWND hwnd)
  1984. {
  1985. HDC hdc;
  1986. HFONT hfont;
  1987. SIZE size;
  1988. if(!(hdc = GetDC(hwnd))) {
  1989. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  1990. return(FALSE);
  1991. }
  1992. if(HotKyFnt)
  1993. hfont = (HFONT)SelectObject(hdc,(HGDIOBJ)HotKyFnt);
  1994. GetTextExtentPoint(hdc,(LPSTR)CurrHotKeyTxt,CurrHotKeyTxtLen, &size);
  1995. SetCaretPos(size.cx+4,1);
  1996. if(HotKyFnt && hfont)
  1997. SelectObject(hdc,(HGDIOBJ)hfont);
  1998. ReleaseDC(hwnd,hdc);
  1999. return(TRUE);
  2000. }
  2001. /*
  2002. *
  2003. * This is the Windows Proc for the private Hot Key Control in
  2004. * the WIN386 dialog box
  2005. *
  2006. */
  2007. long FAR PASCAL PifHotKyWndProc(HWND hwnd, UINT message, WPARAM wParam, LONG lParam)
  2008. {
  2009. PAINTSTRUCT ps;
  2010. HFONT hfont;
  2011. DWORD txtcolor;
  2012. switch (message) {
  2013. case WM_SETFOCUS:
  2014. if(HotKyFntHgt)
  2015. CreateCaret(hwnd,NULL,0,HotKyFntHgt);
  2016. else
  2017. CreateCaret(hwnd,NULL,0,SysCharHeight);
  2018. DoHkeyCaret(hwnd);
  2019. ShowCaret(hwnd);
  2020. break;
  2021. case WM_KILLFOCUS:
  2022. /* ChangeHotKey(); */
  2023. DestroyCaret();
  2024. break;
  2025. case WM_SYSKEYDOWN:
  2026. case WM_KEYDOWN:
  2027. switch (wParam) {
  2028. case VK_BACK:
  2029. if(GetKeyState(VK_SHIFT) & 0x8000) {
  2030. InMemHotKeyScan = 0;
  2031. InMemHotKeyShVal = 0;
  2032. InMemHotKeyShMsk = 0;
  2033. NewHotKey = TRUE;
  2034. UndoAdvClose();
  2035. CompleteKey = FALSE;
  2036. EditHotKey = FALSE;
  2037. if(!LoadString(hPifInstance,
  2038. NONE,
  2039. (LPSTR)CurrHotKeyTxt,
  2040. sizeof(CurrHotKeyTxt))) {
  2041. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2042. }
  2043. } else {
  2044. CompleteKey = FALSE;
  2045. EditHotKey = TRUE;
  2046. NewHotKey = TRUE;
  2047. CurrHotKeyTxt[0] = '\0';
  2048. }
  2049. SetHotKeyLen();
  2050. InvalidateRect(hwnd,(CONST RECT *)NULL,TRUE);
  2051. DoHkeyCaret(hwnd);
  2052. break;
  2053. case VK_RETURN:
  2054. if(!(GetKeyState(VK_SHIFT) & 0x8000) &&
  2055. !(GetKeyState(VK_MENU) & 0x8000) &&
  2056. !(GetKeyState(VK_CONTROL) & 0x8000)) {
  2057. PostMessage(hwndAdvPifDlg,WM_COMMAND,IDOK,0L);
  2058. } else {
  2059. CompleteKey = FALSE;
  2060. EditHotKey = FALSE;
  2061. NewHotKey = FALSE;
  2062. SetHotKeyTextFromInMem();
  2063. DoHkeyCaret(hwnd);
  2064. return(DefWindowProc(hwnd, message, wParam, lParam));
  2065. }
  2066. break;
  2067. case VK_TAB:
  2068. if(GetKeyState(VK_MENU) & 0x8000) {
  2069. CompleteKey = FALSE;
  2070. EditHotKey = FALSE;
  2071. NewHotKey = FALSE;
  2072. SetHotKeyTextFromInMem();
  2073. DoHkeyCaret(hwnd);
  2074. } else {
  2075. ChangeHotKey();
  2076. DoHkeyCaret(hwnd);
  2077. }
  2078. return(DefWindowProc(hwnd, message, wParam, lParam));
  2079. break;
  2080. case VK_CONTROL: /* Add modifier */
  2081. case VK_MENU:
  2082. if(!EditHotKey) {
  2083. StartHotKey:
  2084. CompleteKey = FALSE;
  2085. EditHotKey = TRUE;
  2086. CurrHotKeyTxt[0] = '\0';
  2087. SetHotKeyLen();
  2088. }
  2089. SetHotKey:
  2090. SetHotKeyState(wParam,lParam);
  2091. InvalidateRect(hwnd,(CONST RECT *)NULL,TRUE);
  2092. DoHkeyCaret(hwnd);
  2093. UndoAdvClose();
  2094. break;
  2095. case VK_SHIFT:
  2096. if(EditHotKey && !CompleteKey && (CurrHotKeyTxtLen != 0))
  2097. goto SetHotKey;
  2098. break;
  2099. case VK_ESCAPE:
  2100. if((GetKeyState(VK_MENU) & 0x8000) ||
  2101. (GetKeyState(VK_CONTROL) & 0x8000)) {
  2102. CompleteKey = FALSE;
  2103. EditHotKey = FALSE;
  2104. NewHotKey = FALSE;
  2105. SetHotKeyTextFromInMem();
  2106. DoHkeyCaret(hwnd);
  2107. return(DefWindowProc(hwnd, message, wParam, lParam));
  2108. } else {
  2109. if(GetKeyState(VK_SHIFT) & 0x8000)
  2110. MessageBeep(0);
  2111. else {
  2112. CompleteKey = FALSE;
  2113. EditHotKey = FALSE;
  2114. NewHotKey = FALSE;
  2115. PostMessage(hwndAdvPifDlg,WM_COMMAND,IDCANCEL,0L);
  2116. }
  2117. }
  2118. break;
  2119. case VK_SPACE:
  2120. case VK_MULTIPLY:
  2121. CompleteKey = FALSE;
  2122. EditHotKey = FALSE;
  2123. NewHotKey = FALSE;
  2124. SetHotKeyTextFromInMem();
  2125. DoHkeyCaret(hwnd);
  2126. return(DefWindowProc(hwnd, message, wParam, lParam));
  2127. break;
  2128. default: /* Set Key */
  2129. if(!EditHotKey || CompleteKey)
  2130. goto StartHotKey;
  2131. goto SetHotKey;
  2132. break;
  2133. }
  2134. break;
  2135. case WM_SYSCHAR:
  2136. case WM_CHAR:
  2137. case WM_SYSKEYUP:
  2138. case WM_KEYUP:
  2139. switch (wParam) {
  2140. case VK_SPACE:
  2141. case VK_MULTIPLY:
  2142. case VK_RETURN:
  2143. case VK_ESCAPE:
  2144. case VK_TAB:
  2145. return(DefWindowProc(hwnd, message, wParam, lParam));
  2146. break;
  2147. default:
  2148. break;
  2149. }
  2150. break;
  2151. case WM_LBUTTONDOWN:
  2152. SetFocus(hwnd);
  2153. break;
  2154. case WM_CREATE:
  2155. hwndPrivControl = hwnd;
  2156. SetHotKeyTextFromPIF();
  2157. break;
  2158. case WM_PAINT:
  2159. if(!BeginPaint(hwnd, (LPPAINTSTRUCT)&ps)) {
  2160. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2161. break;
  2162. }
  2163. if(HotKyFnt)
  2164. hfont = (HFONT)SelectObject(ps.hdc,(HGDIOBJ)HotKyFnt);
  2165. txtcolor = GetSysColor(COLOR_WINDOWTEXT);
  2166. SetTextColor(ps.hdc,txtcolor);
  2167. txtcolor = GetSysColor(COLOR_WINDOW);
  2168. SetBkColor(ps.hdc,txtcolor);
  2169. TextOut(ps.hdc, 4, 1, (LPSTR)CurrHotKeyTxt, sizeof(CurrHotKeyTxt));
  2170. if(HotKyFnt && hfont)
  2171. SelectObject(ps.hdc,(HGDIOBJ)hfont);
  2172. EndPaint(hwnd, (CONST PAINTSTRUCT *)&ps);
  2173. break;
  2174. case WM_DESTROY:
  2175. hwndPrivControl = (HWND)NULL;
  2176. default:
  2177. return(DefWindowProc(hwnd, message, wParam, lParam));
  2178. }
  2179. return(TRUE);
  2180. }
  2181. SetHotKeyState(WPARAM keyid,LONG lParam)
  2182. {
  2183. unsigned char *cptr;
  2184. BOOL FirstEl = FALSE;
  2185. cptr = CurrHotKeyTxt;
  2186. if(lParam & 0x01000000L)
  2187. TmpHotKeyVal = 1;
  2188. else
  2189. TmpHotKeyVal = 0;
  2190. if(GetKeyState(VK_MENU) & 0x8000) {
  2191. cptr += GetKeyNameText(ALTLPARAM,(LPSTR)cptr,
  2192. sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt));
  2193. FirstEl = TRUE;
  2194. TmpHotKeyShVal |= 0x0008;
  2195. } else {
  2196. TmpHotKeyShVal &= ~0x0008;
  2197. }
  2198. if(GetKeyState(VK_CONTROL) & 0x8000) {
  2199. if(FirstEl) {
  2200. *cptr++ = KeySepChr;
  2201. } else {
  2202. FirstEl = TRUE;
  2203. }
  2204. cptr += GetKeyNameText(CTRLLPARAM,(LPSTR)cptr,
  2205. sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt));
  2206. TmpHotKeyShVal |= 0x0004;
  2207. } else {
  2208. TmpHotKeyShVal &= ~0x0004;
  2209. }
  2210. if(GetKeyState(VK_SHIFT) & 0x8000) {
  2211. if(FirstEl) {
  2212. *cptr++ = KeySepChr;
  2213. } else {
  2214. FirstEl = TRUE;
  2215. }
  2216. cptr += GetKeyNameText(SHIFTLPARAM,(LPSTR)cptr,
  2217. sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt));
  2218. TmpHotKeyShVal |= 0x0003;
  2219. } else {
  2220. TmpHotKeyShVal &= ~0x0003;
  2221. }
  2222. if((keyid != VK_MENU) && (keyid != VK_SHIFT) && (keyid != VK_CONTROL)) {
  2223. if(FirstEl) {
  2224. *cptr++ = KeySepChr;
  2225. } else {
  2226. FirstEl = TRUE;
  2227. }
  2228. if((GetKeyNameText(lParam,(LPSTR)cptr,
  2229. sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt)))
  2230. && (TmpHotKeyShVal & 0x000C)) {
  2231. TmpHotKeyScan = HIWORD(lParam) & 0x00FF;
  2232. CompleteKey = TRUE;
  2233. }
  2234. }
  2235. SetHotKeyLen();
  2236. return(TRUE);
  2237. }
  2238. ChangeHotKey()
  2239. {
  2240. if(!ChangeHkey) {
  2241. ChangeHkey = TRUE;
  2242. if(EditHotKey) {
  2243. if(CompleteKey) {
  2244. InMemHotKeyScan = TmpHotKeyScan;
  2245. InMemHotKeyShVal = TmpHotKeyShVal;
  2246. InMemHotKeyShMsk = TmpHotKeyShMsk;
  2247. InMemHotKeyVal = TmpHotKeyVal;
  2248. NewHotKey = TRUE;
  2249. } else if (CurrHotKeyTxtLen == 0) {
  2250. SetHotKeyTextFromPIF();
  2251. NewHotKey = FALSE;
  2252. } else {
  2253. Warning(BADHK,MB_ICONEXCLAMATION | MB_OK);
  2254. SetHotKeyTextFromPIF();
  2255. NewHotKey = FALSE;
  2256. }
  2257. EditHotKey = FALSE;
  2258. CompleteKey = FALSE;
  2259. }
  2260. ChangeHkey = FALSE;
  2261. }
  2262. return(TRUE);
  2263. }
  2264. BOOL UpdateHotKeyStruc(void)
  2265. {
  2266. ChangeHotKey();
  2267. if(((UINT)Pif386ext->PfHotKeyScan != InMemHotKeyScan) ||
  2268. ((UINT)Pif386ext->PfHotKeyShVal != InMemHotKeyShVal) ||
  2269. ((UINT)Pif386ext->PfHotKeyShMsk != InMemHotKeyShMsk) ||
  2270. (Pif386ext->PfHotKeyVal != InMemHotKeyVal)) {
  2271. Pif386ext->PfHotKeyScan = InMemHotKeyScan;
  2272. Pif386ext->PfHotKeyShVal = InMemHotKeyShVal;
  2273. Pif386ext->PfHotKeyShMsk = InMemHotKeyShMsk;
  2274. Pif386ext->PfHotKeyVal = InMemHotKeyVal;
  2275. return(TRUE);
  2276. } else {
  2277. return(FALSE);
  2278. }
  2279. }
  2280. SetHotKeyTextFromInMem(void)
  2281. {
  2282. unsigned char *cptr;
  2283. BOOL FirstEl = FALSE;
  2284. cptr = CurrHotKeyTxt;
  2285. if((InMemHotKeyScan == 0) &&
  2286. (InMemHotKeyShVal == 0) &&
  2287. (InMemHotKeyShMsk == 0)) {
  2288. if(!LoadString(hPifInstance, NONE, (LPSTR)CurrHotKeyTxt, sizeof(CurrHotKeyTxt))) {
  2289. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2290. }
  2291. } else {
  2292. if(InMemHotKeyShVal & 0x0008) {
  2293. cptr += GetKeyNameText(ALTLPARAM,(LPSTR)cptr
  2294. ,sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt));
  2295. FirstEl = TRUE;
  2296. }
  2297. if(InMemHotKeyShVal & 0x0004) {
  2298. if(FirstEl) {
  2299. *cptr++ = KeySepChr;
  2300. } else {
  2301. FirstEl = TRUE;
  2302. }
  2303. cptr += GetKeyNameText(CTRLLPARAM,(LPSTR)cptr
  2304. ,sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt));
  2305. }
  2306. if(InMemHotKeyShVal & 0x0003) {
  2307. if(FirstEl) {
  2308. *cptr++ = KeySepChr;
  2309. } else {
  2310. FirstEl = TRUE;
  2311. }
  2312. cptr += GetKeyNameText(SHIFTLPARAM,(LPSTR)cptr
  2313. ,sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt));
  2314. }
  2315. if(FirstEl) {
  2316. *cptr++ = KeySepChr;
  2317. } else {
  2318. FirstEl = TRUE;
  2319. }
  2320. if(GetKeyNameText(InMemHotKeyVal ? ((DWORD)InMemHotKeyScan << 16L | 0x01000000L) : ((DWORD)InMemHotKeyScan << 16L),
  2321. (LPSTR)cptr,
  2322. sizeof(CurrHotKeyTxt)-(cptr-CurrHotKeyTxt)) == 0 ||
  2323. (!(InMemHotKeyShVal & 0x000C)) ||
  2324. (InMemHotKeyShMsk != 0x000F)) {
  2325. if(CurrMode386 && hwndAdvPifDlg)
  2326. Warning(BADHK,MB_ICONEXCLAMATION | MB_OK);
  2327. InMemHotKeyScan = 0;
  2328. InMemHotKeyShVal = 0;
  2329. InMemHotKeyShMsk = 0;
  2330. InMemHotKeyVal = 0;
  2331. if(!LoadString(hPifInstance, NONE, (LPSTR)CurrHotKeyTxt, sizeof(CurrHotKeyTxt))) {
  2332. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2333. }
  2334. }
  2335. }
  2336. SetHotKeyLen();
  2337. if(CurrMode386 && hwndAdvPifDlg)
  2338. InvalidateRect(GetDlgItem(hwndAdvPifDlg, IDI_HOTKEY),
  2339. (CONST RECT *)NULL,
  2340. TRUE);
  2341. return(TRUE);
  2342. }
  2343. SetHotKeyTextFromPIF()
  2344. {
  2345. if(!Pif386ext)
  2346. return(FALSE);
  2347. InMemHotKeyScan = Pif386ext->PfHotKeyScan;
  2348. InMemHotKeyShVal = Pif386ext->PfHotKeyShVal;
  2349. InMemHotKeyShMsk = Pif386ext->PfHotKeyShMsk;
  2350. InMemHotKeyVal = Pif386ext->PfHotKeyVal;
  2351. SetHotKeyTextFromInMem();
  2352. return(TRUE);
  2353. }
  2354. SetHotKeyLen()
  2355. {
  2356. int i;
  2357. BOOL dospc;
  2358. for(dospc = FALSE, i = 0; i < sizeof(CurrHotKeyTxt); i++) {
  2359. if(dospc) {
  2360. CurrHotKeyTxt[i] = ' ';
  2361. } else {
  2362. if(!CurrHotKeyTxt[i]){
  2363. CurrHotKeyTxt[i] = ' ';
  2364. CurrHotKeyTxtLen = i;
  2365. dospc = TRUE;
  2366. }
  2367. }
  2368. }
  2369. return(TRUE);
  2370. }
  2371. Disable386Advanced(HWND hAdvwnd, HWND hNTwnd)
  2372. {
  2373. if(hAdvwnd) {
  2374. if(CurrMode386) {
  2375. if(UpdatePif386Struc())
  2376. FileChanged = TRUE;
  2377. if(UpdatePifNTStruc())
  2378. FileChanged = TRUE;
  2379. }
  2380. if(!DoFieldsWorkAdv(FALSE))
  2381. return(FALSE);
  2382. if(!DoFieldsWorkNT(FALSE))
  2383. return(FALSE);
  2384. SendMessage(hNTwnd,WM_PRIVCLOSEOK,0,0L);
  2385. }
  2386. ModeAdvanced = FALSE;
  2387. ReEnableAdvButton();
  2388. return(TRUE);
  2389. }
  2390. /*
  2391. * routine added so that pifedit can hack in normal menu functionality.
  2392. * Want Alt+Mnemonic to work like normal windows, even though pifedit is
  2393. * really a dialog box. Look for Alt+Mnemonic before letting message go
  2394. * to the dialog manager.
  2395. * 08-Jun-1987. davidhab.
  2396. */
  2397. BOOL PifMenuMnemonic(LPMSG lpmsg)
  2398. {
  2399. unsigned char chMenu;
  2400. HWND hwAct;
  2401. if (lpmsg->message == WM_SYSCHAR && GetActiveWindow() == hMainwnd) {
  2402. chMenu = (unsigned char)AnsiUpper((LPSTR)(DWORD)(unsigned char)lpmsg->wParam);
  2403. if ((chMenu == MenuMnemonic1) || (chMenu == MenuMnemonic2) ||
  2404. (chMenu == MenuMnemonic3)) {
  2405. DefWindowProc(hwndPifDlg, lpmsg->message, lpmsg->wParam, lpmsg->lParam);
  2406. return(TRUE);
  2407. }
  2408. /*
  2409. *
  2410. * The following allows keyboard access to the main window scroll bar
  2411. *
  2412. */
  2413. } else if ((lpmsg->message == WM_KEYDOWN) &&
  2414. (((hwAct = GetActiveWindow()) == hMainwnd) ||
  2415. (hwndAdvPifDlg && (hwAct == hwndAdvPifDlg)))) {
  2416. switch (lpmsg->wParam) {
  2417. case VK_HOME:
  2418. PostMessage(hwAct, WM_VSCROLL, SB_TOP, 0L);
  2419. break;
  2420. case VK_END:
  2421. PostMessage(hwAct, WM_VSCROLL, SB_BOTTOM, 0L);
  2422. break;
  2423. case VK_NEXT:
  2424. PostMessage(hwAct, WM_VSCROLL, SB_PAGEDOWN, 0L);
  2425. break;
  2426. case VK_PRIOR:
  2427. PostMessage(hwAct, WM_VSCROLL, SB_PAGEUP, 0L);
  2428. break;
  2429. default:
  2430. break;
  2431. }
  2432. return(FALSE);
  2433. }
  2434. return(FALSE);
  2435. }
  2436. FilterPrivateMsg(HWND hwnd, unsigned message, WPARAM wParam, LONG lParam)
  2437. {
  2438. switch (message) {
  2439. case WM_KEYDOWN:
  2440. case WM_CHAR:
  2441. case WM_KEYUP:
  2442. case WM_SYSKEYDOWN:
  2443. case WM_SYSCHAR:
  2444. case WM_SYSKEYUP:
  2445. switch (wParam) {
  2446. case VK_TAB:
  2447. return(TRUE);
  2448. case VK_SPACE:
  2449. case VK_RETURN:
  2450. case VK_ESCAPE:
  2451. case VK_MULTIPLY:
  2452. if(GetKeyState(VK_MENU) & 0x8000)
  2453. return(TRUE);
  2454. else
  2455. return(FALSE);
  2456. default:
  2457. return(FALSE);
  2458. }
  2459. break;
  2460. default:
  2461. return(TRUE);
  2462. }
  2463. }
  2464. BOOL InitPifStuff(HINSTANCE hPrevInstance)
  2465. {
  2466. unsigned char buf[20];
  2467. PWNDCLASS pClass;
  2468. HDC hIC;
  2469. HFONT hfont;
  2470. TEXTMETRIC Metrics;
  2471. HANDLE mhand;
  2472. HDC hdcScreen;
  2473. char szHelv[] = "MS Sans Serif"; // don't use Helv, mapping problems
  2474. TEXTMETRIC tm;
  2475. int dxText;
  2476. if (lpfnRegisterPenApp = (LPFNREGISTERPENAPP)GetProcAddress((HMODULE)(GetSystemMetrics(SM_PENWINDOWS)), "RegisterPenApp")) {
  2477. (*lpfnRegisterPenApp)((WORD)1, TRUE); /* be Pen-Enhanced */
  2478. }
  2479. if (!hPrevInstance) {
  2480. StatusPntData.dyBorder = GetSystemMetrics(SM_CYBORDER);
  2481. StatusPntData.dyBorderx2 = StatusPntData.dyBorder * 2;
  2482. StatusPntData.dyBorderx3 = StatusPntData.dyBorder * 3;
  2483. if(!(hdcScreen = GetDC(NULL)))
  2484. goto NoMem;
  2485. StatusPntData.Fntheight = MulDiv(-10, GetDeviceCaps(hdcScreen, LOGPIXELSY), 72);
  2486. dxText = LOWORD(GetTextExtent(hdcScreen, "M", 1));
  2487. if(!(StatusPntData.hFontStatus = (HGDIOBJ)CreateFont(StatusPntData.Fntheight, 0, 0, 0, 400, 0, 0, 0,
  2488. ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  2489. DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, (LPCTSTR)szHelv)))
  2490. goto NoMem;
  2491. mhand = SelectObject(hdcScreen, StatusPntData.hFontStatus);
  2492. GetTextMetrics(hdcScreen, &tm);
  2493. SelectObject(hdcScreen, mhand);
  2494. StatusPntData.dyStatus = tm.tmHeight + tm.tmExternalLeading + 7 * StatusPntData.dyBorder;
  2495. ReleaseDC(NULL, hdcScreen);
  2496. } else {
  2497. if(!GetInstanceData(hPrevInstance,(NPSTR)&StatusPntData,sizeof(StatusPntData))) {
  2498. StatusPntData.hFontStatus = (HGDIOBJ)NULL;
  2499. goto NoMem;
  2500. }
  2501. if(!(StatusPntData.hFontStatus = (HGDIOBJ)CreateFont(StatusPntData.Fntheight, 0, 0, 0, 400, 0, 0, 0,
  2502. ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  2503. DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, szHelv)))
  2504. goto NoMem;
  2505. }
  2506. if(!(lpfnPifWnd = MakeProcInstance(PifWndProc, hPifInstance))) {
  2507. NoMem:
  2508. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2509. return(FALSE);
  2510. }
  2511. if(!(lpfnAdvPifWnd = MakeProcInstance(PifAdvWndProc, hPifInstance)))
  2512. goto NoMem;
  2513. if(!(lpfnNTPifWnd = MakeProcInstance(PifNTWndProc, hPifInstance)))
  2514. goto NoMem;
  2515. if(!LoadString(hPifInstance, errTitle, (LPSTR)rgchTitle, sizeof(rgchTitle)))
  2516. goto NoMem;
  2517. if(!(hAccel = LoadAccelerators(hPifInstance, (LPSTR)"pifaccels")))
  2518. goto NoMem;
  2519. if(!LoadString(hPifInstance, MENUMNEMONIC1, (LPSTR)buf, sizeof(buf)))
  2520. goto NoMem;
  2521. MenuMnemonic1 = buf[0];
  2522. if(!LoadString(hPifInstance, MENUMNEMONIC2, (LPSTR)buf, sizeof(buf)))
  2523. goto NoMem;
  2524. MenuMnemonic2 = buf[0];
  2525. if(!LoadString(hPifInstance, MENUMNEMONIC3, (LPSTR)buf, sizeof(buf)))
  2526. goto NoMem;
  2527. MenuMnemonic3 = buf[0];
  2528. if(!LoadString(hPifInstance, KEYSEPCHAR, (LPSTR)buf, sizeof(buf)))
  2529. goto NoMem;
  2530. KeySepChr = buf[0];
  2531. if(!(hArrowCurs = LoadCursor((HANDLE)NULL,(LPSTR)IDC_ARROW)))
  2532. goto NoMem;
  2533. if(!(hWaitCurs = LoadCursor((HANDLE)NULL,(LPSTR)IDC_WAIT)))
  2534. goto NoMem;
  2535. bMouse = GetSystemMetrics(SM_MOUSEPRESENT);
  2536. hIC = CreateIC((LPSTR)"DISPLAY", (LPSTR)NULL, (LPSTR)NULL, (LPDEVMODE)NULL);
  2537. if (!hIC)
  2538. return(FALSE);
  2539. /* Setup the fonts */
  2540. GetTextMetrics(hIC, (LPTEXTMETRIC)(&Metrics)); /* find out what kind of font it really is */
  2541. SysCharHeight = Metrics.tmHeight; /* the height */
  2542. SysCharWidth = Metrics.tmAveCharWidth; /* the average width */
  2543. SysFixedFont = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
  2544. SelectObject(hIC,(HGDIOBJ)SysFixedFont);
  2545. GetTextMetrics(hIC, (LPTEXTMETRIC)(&Metrics));
  2546. SysFixedHeight = Metrics.tmHeight;
  2547. SysFixedWidth = Metrics.tmAveCharWidth;
  2548. if(Metrics.tmPitchAndFamily & 1) {
  2549. SysFixedFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
  2550. SelectObject(hIC,(HGDIOBJ)SysFixedFont);
  2551. GetTextMetrics(hIC, (LPTEXTMETRIC)(&Metrics)); /* find out what kind of font it really is */
  2552. SysFixedHeight = Metrics.tmHeight; /* the height */
  2553. SysFixedWidth = Metrics.tmAveCharWidth; /* the average width */
  2554. }
  2555. HotKyFnt = CreateFont(8, /* lfHeight */
  2556. 0, /* lfWidth */
  2557. 0, /* lfEscapement */
  2558. 0, /* lfOrientation*/
  2559. FW_BOLD, /* lfWeight */
  2560. FALSE, /* lfItalic */
  2561. FALSE, /* lfUnderline */
  2562. FALSE, /* lfStrikeout */
  2563. ANSI_CHARSET, /* lfCharset */
  2564. OUT_DEFAULT_PRECIS, /* lfOutPrec */
  2565. OUT_DEFAULT_PRECIS, /* lfClipPrec */
  2566. DEFAULT_QUALITY, /* lfQuality */
  2567. VARIABLE_PITCH | FF_SWISS, /* lfPitchAndFam*/
  2568. (LPSTR)"MS Sans Serif"); /* lfFacename */
  2569. if(HotKyFnt) {
  2570. if((hfont = (HFONT)SelectObject(hIC,(HGDIOBJ)HotKyFnt))) {
  2571. if(GetTextMetrics(hIC, (LPTEXTMETRIC)(&Metrics))) {
  2572. HotKyFntHgt = Metrics.tmHeight;
  2573. }
  2574. SelectObject(hIC,(HGDIOBJ)hfont);
  2575. }
  2576. }
  2577. DeleteDC(hIC);
  2578. /* only register classes if first instance. 23-Oct-1987. davidhab. */
  2579. if (!hPrevInstance) {
  2580. if(!(pClass = (PWNDCLASS)LocalAlloc(LPTR, sizeof(WNDCLASS))))
  2581. goto NoMem;
  2582. pClass->hCursor = LoadCursor(NULL, IDC_ARROW);
  2583. pClass->hIcon = LoadIcon(hPifInstance, MAKEINTRESOURCE(ID_PIFICON));
  2584. pClass->lpszMenuName = MAKEINTRESOURCE(ID_PIFMENU);
  2585. pClass->hInstance = hPifInstance;
  2586. pClass->lpszClassName = (LPSTR)"Pif";
  2587. pClass->hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  2588. pClass->lpfnWndProc = PifMainWndProc;
  2589. pClass->style = CS_BYTEALIGNCLIENT;
  2590. if (!RegisterClass((CONST WNDCLASS *)pClass))
  2591. return(FALSE);
  2592. LocalFree((HANDLE)pClass);
  2593. if(!(pClass = (PWNDCLASS)LocalAlloc(LPTR, sizeof(WNDCLASS))))
  2594. goto NoMem;
  2595. pClass->hCursor = LoadCursor(NULL, IDC_ARROW);
  2596. pClass->hIcon = (HICON)NULL;
  2597. pClass->hInstance = hPifInstance;
  2598. pClass->lpszClassName = (LPSTR)"PifHKy";
  2599. pClass->hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  2600. pClass->lpfnWndProc = PifHotKyWndProc;
  2601. pClass->style = 0;
  2602. if (!RegisterClass((CONST WNDCLASS *)pClass))
  2603. return(FALSE);
  2604. LocalFree((HANDLE)pClass);
  2605. }
  2606. return(TRUE);
  2607. }
  2608. int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCommandLine, int cmdShow)
  2609. {
  2610. MSG msg;
  2611. BYTE *p;
  2612. PSTR pchFileName;
  2613. HWND hWndTmp;
  2614. HWND hWndTmp2;
  2615. HMENU hMenu;
  2616. int i;
  2617. unsigned char buf[160];
  2618. POINT cTLpt;
  2619. POINT cLRpt;
  2620. RECT rc1;
  2621. RECT rc2;
  2622. int tmpFOCID;
  2623. PifFile = (PIFNEWSTRUCT *)PifBuf;
  2624. if(!LoadString(hPifInstance, EINSMEMORY, (LPSTR)rgchInsMem, sizeof(rgchInsMem))) {
  2625. return(FALSE);
  2626. }
  2627. if(!LoadString(hPifInstance, NTSYSTEMROOT, (LPSTR)NTSys32Root, PIFDEFPATHSIZE-1)) {
  2628. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2629. return(FALSE);
  2630. }
  2631. if(!LoadString(hPifInstance, NTSYSTEM32, (LPSTR)buf, PIFDEFPATHSIZE-1)) {
  2632. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2633. return(FALSE);
  2634. }
  2635. lstrcat(NTSys32Root, buf);
  2636. hPifInstance = hInstance;
  2637. if(!InitPifStuff(hPrevInstance)) {
  2638. if (lpfnRegisterPenApp)
  2639. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2640. return(FALSE);
  2641. }
  2642. if(!(i = LoadString(hPifInstance, PIFCAPTION, (LPSTR)buf, sizeof(buf)))) {
  2643. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2644. if (lpfnRegisterPenApp)
  2645. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2646. return(FALSE);
  2647. }
  2648. if(!LoadString(hPifInstance, NOTITLE, (LPSTR)(buf+i), (sizeof(buf)-i))) {
  2649. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2650. if (lpfnRegisterPenApp)
  2651. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2652. return(FALSE);
  2653. }
  2654. hParentWnd = hMainwnd = CreateWindow((LPSTR)"Pif",
  2655. (LPSTR)buf,
  2656. WS_OVERLAPPED | WS_THICKFRAME | WS_CAPTION |
  2657. WS_SYSMENU | WS_MINIMIZEBOX | WS_VSCROLL |
  2658. WS_MAXIMIZEBOX,
  2659. SysCharWidth * 2,
  2660. SysCharHeight * 3,
  2661. 0,
  2662. 0,
  2663. (HWND)NULL,
  2664. (HMENU)NULL,
  2665. hPifInstance,
  2666. (LPSTR)NULL);
  2667. if(!hMainwnd) {
  2668. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2669. if (lpfnRegisterPenApp)
  2670. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2671. return(FALSE);
  2672. }
  2673. hSysMenuMain = GetSystemMenu(hMainwnd,FALSE);
  2674. hMenu = GetMenu(hMainwnd);
  2675. hFileMenu = GetSubMenu(hMenu,0);
  2676. hModeMenu = GetSubMenu(hMenu,1);
  2677. hHelpMenu = GetSubMenu(hMenu,2);
  2678. CurrMode386 = SysMode386 = SetInitialMode();
  2679. if(!InitPifStruct()){
  2680. if (lpfnRegisterPenApp)
  2681. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2682. return(FALSE);
  2683. }
  2684. if(CurrMode386) {
  2685. if(!EnableMode386(hMainwnd,FALSE)) {
  2686. if (lpfnRegisterPenApp)
  2687. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2688. return(FALSE);
  2689. }
  2690. } else {
  2691. if(!EnableMode286(hMainwnd,FALSE)) {
  2692. if (lpfnRegisterPenApp)
  2693. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2694. return(FALSE);
  2695. }
  2696. }
  2697. if(hMainwnd) {
  2698. DragAcceptFiles(hMainwnd,TRUE);
  2699. }
  2700. if(hwndPifDlg) {
  2701. DragAcceptFiles(hwndPifDlg,TRUE);
  2702. }
  2703. if(hwndAdvPifDlg) {
  2704. DragAcceptFiles(hwndAdvPifDlg,TRUE);
  2705. }
  2706. if(hwndNTPifDlg) {
  2707. DragAcceptFiles(hwndNTPifDlg,TRUE);
  2708. }
  2709. if (*lpszCommandLine) {
  2710. if (pchFileName = (PSTR)LocalAlloc(LPTR, MAX_PATH)) {
  2711. if (lstrlen(lpszCommandLine) > (MAX_PATH - 5))
  2712. *(lpszCommandLine + (MAX_PATH - 5)) = 0;
  2713. CpyCmdStr((LPSTR)pchFileName, lpszCommandLine);
  2714. CmdArgAddCorrectExtension(pchFileName);
  2715. LoadPifFile(pchFileName);
  2716. LocalFree((HANDLE)pchFileName);
  2717. SetMainTitle();
  2718. } else {
  2719. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2720. if (lpfnRegisterPenApp)
  2721. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2722. return(FALSE);
  2723. }
  2724. }
  2725. UpdatePifScreen();
  2726. UpdatePifStruct();
  2727. PifFile->id = 0; /* compute check sum */
  2728. p = (BYTE *)&PifFile->name[ 0 ];
  2729. i = PIFSIZE;
  2730. while (i--)
  2731. PifFile->id += *p++;
  2732. InitShWind = TRUE;
  2733. ShowWindow(hwndPifDlg, SW_SHOWNORMAL);
  2734. if(hwndAdvPifDlg)
  2735. ShowWindow(hwndAdvPifDlg, cmdShow);
  2736. if(hwndNTPifDlg)
  2737. ShowWindow(hwndNTPifDlg, cmdShow);
  2738. ShowWindow(hMainwnd, cmdShow);
  2739. /*
  2740. * The following HACK gets around a wierd problem where we end up with no
  2741. * ICON when started minimized. It is believed that this is due to the
  2742. * wierd stuff we do based on the InitShWind flag in WM_INITDIALOG.
  2743. */
  2744. if((cmdShow == SW_SHOWMINNOACTIVE) || (cmdShow == SW_SHOWMINIMIZED))
  2745. InvalidateRect(hMainwnd, (CONST RECT *)NULL, TRUE);
  2746. while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  2747. if (!TranslateAccelerator(hMainwnd, hAccel, (LPMSG)&msg)) {
  2748. if(hwndPrivControl == msg.hwnd) {
  2749. if(!FilterPrivateMsg(msg.hwnd,msg.message,msg.wParam,msg.lParam)) {
  2750. TranslateMessage((CONST MSG *)&msg);
  2751. DispatchMessage((CONST MSG *)&msg);
  2752. goto CheckFocus;
  2753. }
  2754. }
  2755. if(PifMenuMnemonic((LPMSG)&msg))
  2756. goto CheckFocus;
  2757. if (!hwndPifDlg || !IsDialogMessage(hwndPifDlg, (LPMSG)&msg)) {
  2758. if(hwndAdvPifDlg && IsDialogMessage(hwndAdvPifDlg, (LPMSG)&msg))
  2759. goto CheckFocus;
  2760. if(hwndNTPifDlg && IsDialogMessage(hwndNTPifDlg, (LPMSG)&msg))
  2761. goto CheckFocus;
  2762. TranslateMessage((CONST MSG *)&msg);
  2763. DispatchMessage((CONST MSG *)&msg);
  2764. } else { /* Dialog message for hwndPifDlg or hwndAdvPifDlg */
  2765. CheckFocus:
  2766. if (hWndTmp = GetFocus()) {
  2767. if((((hWndTmp2 = GetParent(hWndTmp)) == hwndPifDlg) ||
  2768. (hWndTmp2 == hwndAdvPifDlg) || (hWndTmp2 == hwndNTPifDlg))
  2769. && (hWndTmp != hwndFocus)) {
  2770. if((hWndTmp2 == hwndAdvPifDlg)
  2771. || (hWndTmp2 == hwndNTPifDlg))
  2772. hParentWnd = hWndTmp2;
  2773. else
  2774. hParentWnd = hMainwnd;
  2775. hwndFocus = hWndTmp;
  2776. FocusID = GetDlgCtrlID(hWndTmp);
  2777. if(hWndTmp2 == hwndPifDlg) {
  2778. hwndFocusMain = hwndFocus;
  2779. tmpFOCID = FocusIDMain;
  2780. FocusIDMain = FocusID;
  2781. if(tmpFOCID != FocusIDMain)
  2782. SetStatusText(hMainwnd,FocusIDMain,TRUE);
  2783. } else if(hWndTmp2 == hwndAdvPifDlg) {
  2784. hwndFocusAdv = hwndFocus;
  2785. tmpFOCID = FocusIDAdv;
  2786. FocusIDAdv = FocusID;
  2787. if(tmpFOCID != FocusIDAdv)
  2788. SetStatusText(hwndAdvPifDlg,FocusIDAdv,TRUE);
  2789. } else {
  2790. hwndFocusNT = hwndFocus;
  2791. tmpFOCID = FocusIDNT;
  2792. FocusIDNT = FocusID;
  2793. if(tmpFOCID != FocusIDNT)
  2794. SetStatusText(hwndNTPifDlg,FocusIDNT,TRUE);
  2795. }
  2796. /*
  2797. * Check to make sure this control is visible.
  2798. * If it isn't, scroll the window to make it
  2799. * visible.
  2800. *
  2801. */
  2802. if((hWndTmp2 == hwndPifDlg) && MainScrollRange) {
  2803. GetClientRect(hMainwnd,(LPRECT)&rc1);
  2804. rc1.bottom -= (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  2805. cTLpt.x = rc1.left;
  2806. cTLpt.y = rc1.top;
  2807. cLRpt.x = rc1.right;
  2808. cLRpt.y = rc1.bottom;
  2809. ClientToScreen(hMainwnd,(LPPOINT)&cTLpt);
  2810. ClientToScreen(hMainwnd,(LPPOINT)&cLRpt);
  2811. GetWindowRect(hwndFocus,(LPRECT)&rc2);
  2812. if(rc2.top < cTLpt.y) {
  2813. MainScrollTrack(hMainwnd,SB_LINEUP,
  2814. cTLpt.y - rc2.top);
  2815. } else if(rc2.bottom > cLRpt.y) {
  2816. MainScrollTrack(hMainwnd,SB_LINEDOWN,
  2817. rc2.bottom - cLRpt.y);
  2818. }
  2819. } else if ((hWndTmp2 == hwndAdvPifDlg) && AdvScrollRange) {
  2820. GetClientRect(hwndAdvPifDlg,(LPRECT)&rc1);
  2821. rc1.bottom -= (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  2822. cTLpt.x = rc1.left;
  2823. cTLpt.y = rc1.top;
  2824. cLRpt.x = rc1.right;
  2825. cLRpt.y = rc1.bottom;
  2826. ClientToScreen(hwndAdvPifDlg,(LPPOINT)&cTLpt);
  2827. ClientToScreen(hwndAdvPifDlg,(LPPOINT)&cLRpt);
  2828. GetWindowRect(hwndFocus,(LPRECT)&rc2);
  2829. if(rc2.top < cTLpt.y) {
  2830. MainScrollTrack(hwndAdvPifDlg,SB_LINEUP,
  2831. cTLpt.y - rc2.top);
  2832. } else if(rc2.bottom > cLRpt.y) {
  2833. MainScrollTrack(hwndAdvPifDlg,SB_LINEDOWN,
  2834. rc2.bottom - cLRpt.y);
  2835. }
  2836. } else if((hWndTmp2 == hwndNTPifDlg) && NTScrollRange) {
  2837. GetClientRect(hwndNTPifDlg,(LPRECT)&rc1);
  2838. rc1.bottom -= (StatusPntData.dyStatus + StatusPntData.dyBorderx2);
  2839. cTLpt.x = rc1.left;
  2840. cTLpt.y = rc1.top;
  2841. cLRpt.x = rc1.right;
  2842. cLRpt.y = rc1.bottom;
  2843. ClientToScreen(hwndNTPifDlg,(LPPOINT)&cTLpt);
  2844. ClientToScreen(hwndNTPifDlg,(LPPOINT)&cLRpt);
  2845. GetWindowRect(hwndFocus,(LPRECT)&rc2);
  2846. if(rc2.top < cTLpt.y) {
  2847. MainScrollTrack(hwndNTPifDlg,SB_LINEUP,
  2848. cTLpt.y - rc2.top);
  2849. } else if(rc2.bottom > cLRpt.y) {
  2850. MainScrollTrack(hwndNTPifDlg,SB_LINEDOWN,
  2851. rc2.bottom - cLRpt.y);
  2852. }
  2853. }
  2854. }
  2855. }
  2856. }
  2857. }
  2858. }
  2859. if (lpfnRegisterPenApp)
  2860. (*lpfnRegisterPenApp)((WORD)1, FALSE); /* deregister */
  2861. return(0);
  2862. }
  2863. unsigned char *PutUpDB(int idb)
  2864. {
  2865. OPENFILENAME OpnStruc;
  2866. BOOL MsgFlagSav;
  2867. unsigned char *pResultBuf = NULL;
  2868. char filespec[160];
  2869. char specbuf[80];
  2870. int i,j;
  2871. char extspec[] = "PIF";
  2872. char chbuf[100];
  2873. HICON hIcon;
  2874. if(!(i = LoadString(hPifInstance, errFlTypePIF, (LPSTR)filespec, sizeof(specbuf)))) {
  2875. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2876. return((unsigned char *)NULL);
  2877. }
  2878. if(!(j = LoadString(hPifInstance,errFlTypeAll , (LPSTR)specbuf, sizeof(specbuf)))) {
  2879. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2880. return((unsigned char *)NULL);
  2881. }
  2882. i++; /* point to char after NUL at end of errFlTypePIF */
  2883. lstrcpy((LPSTR)&filespec[i],(LPSTR)"*.PIF");
  2884. i += 6; /* point to char after NUL at end of *.PIF */
  2885. lstrcpy((LPSTR)&filespec[i],(LPSTR)specbuf);
  2886. i += j + 1; /* point to char after NUL at end of errFlTypeAll */
  2887. lstrcpy((LPSTR)&filespec[i],(LPSTR)"*.*");
  2888. i += 4; /* point to char after NUL at end of *.* */
  2889. filespec[i] = '\0'; /* double nul terminate */
  2890. if((idb == DTOPEN) || (idb == DTSAVE)) {
  2891. if(!(pResultBuf = (unsigned char *)LocalAlloc(LPTR, 132))) {
  2892. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2893. return((unsigned char *)NULL);
  2894. }
  2895. lstrcpy((LPSTR)pResultBuf, (LPSTR)CurPifFile);
  2896. OpnStruc.lStructSize = (unsigned long)(sizeof(OpnStruc));
  2897. OpnStruc.hwndOwner = hMainwnd;
  2898. OpnStruc.hInstance = 0;
  2899. OpnStruc.lpstrFilter = (LPSTR)filespec;
  2900. OpnStruc.lpstrCustomFilter = (LPSTR)NULL;
  2901. OpnStruc.nMaxCustFilter = (DWORD)NULL;
  2902. OpnStruc.nFilterIndex = 1;
  2903. OpnStruc.lpstrFile = (LPSTR)pResultBuf;
  2904. OpnStruc.nMaxFile = 132;
  2905. /*
  2906. * We should use the next cookie to set our title BUT we still
  2907. * have to deal with file names we get from command line
  2908. * argument and drag drop.
  2909. */
  2910. OpnStruc.lpstrFileTitle = (LPSTR)NULL;
  2911. OpnStruc.nMaxFileTitle = 0;
  2912. OpnStruc.lpstrInitialDir = (LPSTR)NULL;
  2913. OpnStruc.lpstrTitle = (LPSTR)NULL;
  2914. OpnStruc.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  2915. OpnStruc.nFileOffset = 0;
  2916. OpnStruc.nFileExtension = 0;
  2917. OpnStruc.lpstrDefExt = (LPSTR)extspec;
  2918. OpnStruc.lCustData = 0;
  2919. OpnStruc.lpfnHook = (LPOFNHOOKPROC)NULL;
  2920. OpnStruc.lpTemplateName = (LPSTR)NULL;
  2921. } else if(idb == DTABOUT) {
  2922. if(!LoadString(hPifInstance, errTitle, (LPSTR)chbuf, sizeof(chbuf))) {
  2923. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  2924. return(pResultBuf);
  2925. }
  2926. hIcon = LoadIcon(hPifInstance, MAKEINTRESOURCE(ID_PIFICON));
  2927. }
  2928. /*
  2929. * These dialogs always come up via menu selections in the main window
  2930. * menu. The parent is therefore always hMainwnd
  2931. */
  2932. switch(idb) {
  2933. case DTOPEN:
  2934. MsgFlagSav = DoingMsg;
  2935. DoingMsg = TRUE;
  2936. if(MsgFlagSav != DoingMsg)
  2937. InvalidateAllStatus();
  2938. if(!(GetOpenFileName((LPOPENFILENAME)&OpnStruc))){
  2939. if(pResultBuf)
  2940. LocalFree((HANDLE)pResultBuf);
  2941. pResultBuf = (unsigned char *)NULL;
  2942. } else {
  2943. tmpfileoffset = OpnStruc.nFileOffset;
  2944. tmpextoffset = OpnStruc.nFileExtension;
  2945. }
  2946. if(MsgFlagSav != DoingMsg) {
  2947. DoingMsg = MsgFlagSav;
  2948. InvalidateAllStatus();
  2949. } else {
  2950. DoingMsg = MsgFlagSav;
  2951. }
  2952. break;
  2953. case DTSAVE:
  2954. MsgFlagSav = DoingMsg;
  2955. DoingMsg = TRUE;
  2956. if(MsgFlagSav != DoingMsg)
  2957. InvalidateAllStatus();
  2958. if(!(GetSaveFileName((LPOPENFILENAME)&OpnStruc))){
  2959. if(pResultBuf)
  2960. LocalFree((HANDLE)pResultBuf);
  2961. pResultBuf = (unsigned char *)NULL;
  2962. } else {
  2963. tmpfileoffset = OpnStruc.nFileOffset;
  2964. tmpextoffset = OpnStruc.nFileExtension;
  2965. }
  2966. if(MsgFlagSav != DoingMsg) {
  2967. DoingMsg = MsgFlagSav;
  2968. InvalidateAllStatus();
  2969. } else {
  2970. DoingMsg = MsgFlagSav;
  2971. }
  2972. break;
  2973. case DTABOUT:
  2974. MsgFlagSav = DoingMsg;
  2975. DoingMsg = TRUE;
  2976. if(MsgFlagSav != DoingMsg)
  2977. InvalidateAllStatus();
  2978. ShellAbout(hMainwnd, (LPSTR)chbuf, (LPSTR)NULL, hIcon);
  2979. pResultBuf = (unsigned char *)NULL;
  2980. if(MsgFlagSav != DoingMsg) {
  2981. DoingMsg = MsgFlagSav;
  2982. InvalidateAllStatus();
  2983. } else {
  2984. DoingMsg = MsgFlagSav;
  2985. }
  2986. break;
  2987. }
  2988. return(pResultBuf);
  2989. }
  2990. /* ** return TRUE iff 0 terminated string contains a '*' or '\' */
  2991. BOOL FSearchSpec(unsigned char *sz)
  2992. {
  2993. for (; *sz;sz=AnsiNext(sz)) {
  2994. if (*sz == '*' || *sz == '?')
  2995. return TRUE;
  2996. }
  2997. return FALSE;
  2998. }
  2999. CheckOkEnable(HWND hwnd, unsigned message)
  3000. {
  3001. if (message == EN_CHANGE)
  3002. EnableWindow(GetDlgItem(hwnd, IDOK),
  3003. (BOOL)(SendMessage(GetDlgItem(hwnd, ID_EDIT),
  3004. WM_GETTEXTLENGTH, 0, 0L)));
  3005. return(TRUE);
  3006. }
  3007. /* ** Given filename or partial filename or search spec or partial
  3008. search spec, add appropriate extension. */
  3009. CmdArgAddCorrectExtension(unsigned char *szEdit)
  3010. {
  3011. register unsigned char *pchLast;
  3012. register unsigned char *pchT;
  3013. int ichExt;
  3014. BOOL fDone = FALSE;
  3015. int cchEdit;
  3016. pchT = pchLast = (unsigned char *)AnsiPrev((LPSTR)szEdit, (LPSTR)(szEdit + (cchEdit = lstrlen((LPSTR)szEdit))));
  3017. if ((*pchLast == '.' && *(AnsiPrev((LPSTR)szEdit, (LPSTR)pchLast)) == '.') && cchEdit == 2)
  3018. ichExt = 0;
  3019. else if (*pchLast == '\\' || *pchLast == ':')
  3020. ichExt = 1;
  3021. else {
  3022. ichExt = 2;
  3023. for (; pchT > szEdit; pchT = (unsigned char *)AnsiPrev((LPSTR)szEdit, (LPSTR)pchT)) {
  3024. /* If we're not searching and we encounter a period, don't add
  3025. any extension. If we are searching, period is assumed to be
  3026. part of directory name, so go ahead and add extension. However,
  3027. if we are searching and find a search spec, do not add any
  3028. extension. */
  3029. if (*pchT == '.') {
  3030. return(TRUE);
  3031. }
  3032. /* Quit when we get to beginning of last node. */
  3033. if (*pchT == '\\')
  3034. break;
  3035. }
  3036. }
  3037. lstrcpy((LPSTR)(pchLast+1), (LPSTR)(szExtSave+ichExt));
  3038. return(TRUE);
  3039. }
  3040. DoHelp(unsigned int hindx,unsigned int IDIndx)
  3041. {
  3042. BOOL retval;
  3043. unsigned int *aliasptr;
  3044. int i;
  3045. if(hindx == 0)
  3046. hindx = (unsigned int)FocusID;
  3047. if(IDIndx == 0) {
  3048. if(CurrMode386) {
  3049. if(ModeAdvanced) {
  3050. IDIndx = IDXID_386AHELP;
  3051. } else {
  3052. IDIndx = IDXID_386HELP;
  3053. }
  3054. } else {
  3055. IDIndx = IDXID_286HELP;
  3056. }
  3057. }
  3058. if(hindx == M_HELPHELP) {
  3059. retval = WinHelp(hMainwnd,(LPSTR)NULL,HELP_HELPONHELP,(DWORD)0);
  3060. } else if(hindx == M_SHELP) {
  3061. retval = WinHelp(hMainwnd,(LPSTR)PIFHELPFILENAME,HELP_PARTIALKEY,(DWORD)(LPSTR)"");
  3062. } else if((hindx == IDXID_386AHELP) || (hindx == IDXID_386HELP) ||
  3063. (hindx == IDXID_286HELP)) {
  3064. WinHelp(hMainwnd,(LPSTR)PIFHELPFILENAME,HELP_CONTEXT,(DWORD)IDIndx);
  3065. retval = WinHelp(hMainwnd,(LPSTR)PIFHELPFILENAME,HELP_SETINDEX,(DWORD)IDIndx);
  3066. } else {
  3067. if(IDIndx == IDXID_286HELP) {
  3068. for(i = 1, aliasptr = Aliases286;
  3069. i <= NUM286ALIASES;
  3070. i++, aliasptr += 2) {
  3071. if(*aliasptr == hindx) {
  3072. aliasptr++;
  3073. hindx = *aliasptr;
  3074. break;
  3075. }
  3076. }
  3077. }
  3078. retval = WinHelp(hMainwnd,(LPSTR)PIFHELPFILENAME,HELP_CONTEXT,(DWORD)hindx);
  3079. WinHelp(hMainwnd,(LPSTR)PIFHELPFILENAME,HELP_SETINDEX,(DWORD)IDIndx);
  3080. }
  3081. if(retval) {
  3082. hwndHelpDlgParent = hMainwnd;
  3083. } else {
  3084. Warning(EINSMEMORY,MB_ICONEXCLAMATION | MB_OK);
  3085. return(FALSE);
  3086. }
  3087. return(TRUE);
  3088. }
  3089. int SetWndScroll(int sizeflg, HWND hMwnd, int WindHeight, int WindWidth,
  3090. int *WndSize, int *ScrollRange, int *ScrollLineSz,
  3091. int *WndLines, int *MaxNeg)
  3092. {
  3093. int i;
  3094. int range;
  3095. int rangeFS;
  3096. int MaxrangeNRML;
  3097. int WndCapSz;
  3098. int newheight;
  3099. int newwidth;
  3100. int oldscrollpos;
  3101. int oldscrollOffset;
  3102. int newscrollOffset;
  3103. int oldscrollRange;
  3104. RECT rc1;
  3105. RECT rc2;
  3106. if(hMwnd == hMainwnd) {
  3107. WndCapSz = GetSystemMetrics(SM_CYCAPTION) +
  3108. GetSystemMetrics(SM_CYMENU);
  3109. } else {
  3110. WndCapSz = GetSystemMetrics(SM_CYCAPTION);
  3111. }
  3112. WndCapSz += (i = (2 * GetSystemMetrics(SM_CYFRAME)));
  3113. rangeFS = GetSystemMetrics(SM_CYSCREEN) + i;
  3114. MaxrangeNRML = rangeFS - (2 * SysCharHeight);
  3115. if(*WndSize != SIZEFULLSCREEN) {
  3116. range = MaxrangeNRML;
  3117. } else {
  3118. range = rangeFS;
  3119. }
  3120. WindHeight += WndCapSz;
  3121. if(sizeflg) {
  3122. if(WindHeight > range)
  3123. newheight = range;
  3124. else
  3125. newheight = WindHeight;
  3126. newwidth = WindWidth + (2 * GetSystemMetrics(SM_CXFRAME));
  3127. } else {
  3128. GetWindowRect(hMwnd,(LPRECT)&rc1);
  3129. newheight = rc1.bottom - rc1.top;
  3130. newwidth = rc1.right - rc1.left;
  3131. }
  3132. if(*WndSize == SIZEFULLSCREEN) {
  3133. newwidth = GetSystemMetrics(SM_CXSCREEN) +
  3134. (2 * GetSystemMetrics(SM_CXFRAME));
  3135. newheight = rangeFS;
  3136. }
  3137. newscrollOffset = 0;
  3138. /* Don't bother with SB stuff till window is visible */
  3139. if(IsWindowVisible(hMwnd)) {
  3140. oldscrollOffset = oldscrollpos = 0;
  3141. if((oldscrollRange = *ScrollRange)) {
  3142. oldscrollpos = GetScrollPos(hMwnd,SB_VERT);
  3143. newscrollOffset = oldscrollOffset =
  3144. min((oldscrollpos * *ScrollLineSz),*MaxNeg);
  3145. }
  3146. if(WindHeight > newheight) {
  3147. GetWindowRect(GetDlgItem(hwndPifDlg,IDI_ENAME),(LPRECT)&rc1);
  3148. GetWindowRect(GetDlgItem(hwndPifDlg,IDI_ETITLE),(LPRECT)&rc2);
  3149. *ScrollLineSz = rc2.top - rc1.top;
  3150. *MaxNeg = WindHeight - newheight;
  3151. *WndLines = range = (*MaxNeg + *ScrollLineSz - 1)/ *ScrollLineSz;
  3152. if(range != *ScrollRange) {
  3153. SetScrollRange(hMwnd, SB_VERT, 0, range, FALSE);
  3154. if(!oldscrollpos) {
  3155. SetScrollPos(hMwnd, SB_VERT, 0, TRUE);
  3156. } else if (oldscrollpos > range) {
  3157. SetScrollPos(hMwnd, SB_VERT, range, TRUE);
  3158. newscrollOffset = min((range * *ScrollLineSz),*MaxNeg);
  3159. } else {
  3160. SetScrollPos(hMwnd, SB_VERT, oldscrollpos, TRUE);
  3161. newscrollOffset = min((oldscrollpos * *ScrollLineSz),*MaxNeg);
  3162. }
  3163. *ScrollRange = range;
  3164. } else {
  3165. newscrollOffset = min((oldscrollpos * *ScrollLineSz),*MaxNeg);
  3166. }
  3167. if(oldscrollpos && (newscrollOffset != oldscrollOffset)) {
  3168. if((hMwnd == hwndAdvPifDlg) || (hMwnd == hwndNTPifDlg)) {
  3169. ScrollWindow(hMwnd,
  3170. 0,
  3171. oldscrollOffset-newscrollOffset,
  3172. (CONST RECT *)NULL,
  3173. (CONST RECT *)NULL);
  3174. UpdateWindow(hMwnd);
  3175. AdjustFocusCtrl(hMwnd);
  3176. } else {
  3177. SetWindowPos(hwndPifDlg,
  3178. (HWND)NULL,
  3179. 0,
  3180. -newscrollOffset,
  3181. newwidth,
  3182. newheight + newscrollOffset -
  3183. (StatusPntData.dyStatus + StatusPntData.dyBorderx2),
  3184. SWP_NOZORDER | SWP_NOACTIVATE);
  3185. UpdateWindow(hwndPifDlg);
  3186. AdjustFocusCtrl(hwndPifDlg);
  3187. }
  3188. InvalidateStatusBar(hMwnd);
  3189. }
  3190. } else {
  3191. if(*ScrollRange && oldscrollpos) {
  3192. MainScroll(hMwnd, SB_TOP, 0, 0, 1);
  3193. }
  3194. SetScrollRange(hMwnd, SB_VERT, 0, 0, FALSE);
  3195. *ScrollRange = 0;
  3196. }
  3197. }
  3198. if(sizeflg) {
  3199. SetWindowPos(hMwnd,
  3200. (HWND)NULL,
  3201. (int)NULL,
  3202. (int)NULL,
  3203. newwidth,
  3204. newheight,
  3205. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  3206. }
  3207. return(newscrollOffset);
  3208. }
  3209. SetMainWndSize(int sizeflg)
  3210. {
  3211. long SizeLong;
  3212. int MainWindHeight;
  3213. int MainWindWidth;
  3214. int AdvWindHeight;
  3215. int AdvWindWidth;
  3216. int NTWindHeight;
  3217. int NTWindWidth;
  3218. int PassFlg;
  3219. int ScrlOff;
  3220. RECT rc;
  3221. if(SizingFlag)
  3222. return(TRUE);
  3223. SizingFlag++;
  3224. switch(sizeflg) {
  3225. case SBUMAIN:
  3226. case SBUADV:
  3227. case SBUNT:
  3228. PassFlg = 0; /* Flag just SB update to do */
  3229. break;
  3230. default:
  3231. PassFlg = 1; /* Flag SB and SIZE update to do */
  3232. break;
  3233. }
  3234. switch(sizeflg) {
  3235. case SBUMAIN:
  3236. case SBUMAINADVNT:
  3237. case SBUSZMAIN:
  3238. case SBUSZMAINADVNT:
  3239. SendMessage(hwndPifDlg,WM_PRIVGETSIZE,0,(LONG)(long FAR *)&SizeLong);
  3240. MainWindHeight = HIWORD(SizeLong);
  3241. MainWindWidth = LOWORD(SizeLong);
  3242. ScrlOff = SetWndScroll(PassFlg,hMainwnd,MainWindHeight,
  3243. MainWindWidth,&MainWndSize,&MainScrollRange,
  3244. &MainScrollLineSz,&MainWndLines,&MaxMainNeg);
  3245. /*
  3246. * Clip the dialog so that it doesn't overlap the status bar
  3247. */
  3248. GetClientRect(hMainwnd,(LPRECT)&rc);
  3249. SetWindowPos(hwndPifDlg,
  3250. (HWND)NULL,
  3251. 0,
  3252. 0,
  3253. rc.right - rc.left,
  3254. rc.bottom - rc.top + ScrlOff -
  3255. (StatusPntData.dyStatus + StatusPntData.dyBorderx2),
  3256. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  3257. break;
  3258. default:
  3259. break;
  3260. }
  3261. if(hwndAdvPifDlg) {
  3262. switch(sizeflg) {
  3263. case SBUSZMAINADVNT:
  3264. case SBUMAINADVNT:
  3265. case SBUSZADV:
  3266. case SBUADV:
  3267. SendMessage(hwndAdvPifDlg,WM_PRIVGETSIZE,0,
  3268. (LONG)(long FAR *)&SizeLong);
  3269. AdvWindHeight = HIWORD(SizeLong);
  3270. AdvWindWidth = LOWORD(SizeLong);
  3271. ScrlOff = SetWndScroll(PassFlg,hwndAdvPifDlg,AdvWindHeight,
  3272. AdvWindWidth,&AdvWndSize,&AdvScrollRange,
  3273. &AdvScrollLineSz,&AdvWndLines,
  3274. &MaxAdvNeg);
  3275. break;
  3276. default:
  3277. break;
  3278. }
  3279. }
  3280. if(hwndNTPifDlg) {
  3281. switch(sizeflg) {
  3282. case SBUSZMAINADVNT:
  3283. case SBUMAINADVNT:
  3284. case SBUSZNT:
  3285. case SBUNT:
  3286. SendMessage(hwndNTPifDlg,WM_PRIVGETSIZE,0,
  3287. (LONG)(long FAR *)&SizeLong);
  3288. NTWindHeight = HIWORD(SizeLong);
  3289. NTWindWidth = LOWORD(SizeLong);
  3290. ScrlOff = SetWndScroll(PassFlg,hwndNTPifDlg,NTWindHeight,
  3291. NTWindWidth,&NTWndSize,&NTScrollRange,
  3292. &NTScrollLineSz,&NTWndLines,
  3293. &MaxNTNeg);
  3294. break;
  3295. default:
  3296. break;
  3297. }
  3298. }
  3299. SizingFlag = 0;
  3300. return(TRUE);
  3301. }
  3302. /*
  3303. * CpyCmdStr( LPSTR szDst, LPSTR szSrc )
  3304. *
  3305. * Copies szSrc to szDst and correctly deals with double quotes
  3306. */
  3307. void CpyCmdStr( LPSTR szDst, LPSTR szSrc ) {
  3308. do {
  3309. switch( *szSrc ) {
  3310. case '"':
  3311. /* eat double quotes */
  3312. break;
  3313. #if 0
  3314. //
  3315. // This 'case' makes it difficult to put a '^' in a filename.
  3316. // (due to cmd processing, it needs to appear 4 times in the line)!
  3317. //
  3318. // With out this case, it is impossible to put a '"' in the middle
  3319. // of a filename, but " is illegal in a filename on _ALL_ NT
  3320. // filesystems, and is not supported by any command line utility
  3321. // in that context.
  3322. //
  3323. case '^':
  3324. /* use '^' to mean 'quote next char' */
  3325. szSrc++;
  3326. /* FALL THROUGH to default */
  3327. #endif
  3328. default:
  3329. *szDst++ = *szSrc;
  3330. break;
  3331. }
  3332. }while( *szSrc++ );
  3333. }