| 1 | 
 | 
|---|
| 2 | /***********************************************************************
 | 
|---|
| 3 | 
 | 
|---|
| 4 |   $Id: seticon.c 1544 2010-09-30 13:00:59Z gyoung $
 | 
|---|
| 5 | 
 | 
|---|
| 6 |   Edit ICON EA
 | 
|---|
| 7 | 
 | 
|---|
| 8 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| 9 |   Copyright (c) 2006, 2008 Steven H.Levine
 | 
|---|
| 10 | 
 | 
|---|
| 11 |   17 Jul 06 SHL Use Runtime_Error
 | 
|---|
| 12 |   22 Mar 06 GKY Use QWL_USER
 | 
|---|
| 13 |   20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
 | 
|---|
| 14 | 
 | 
|---|
| 15 | ***********************************************************************/
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include <stdlib.h>
 | 
|---|
| 18 | #include <string.h>
 | 
|---|
| 19 | #include <share.h>
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #define INCL_WIN
 | 
|---|
| 22 | #define INCL_LONGLONG                   // dircnrs.h
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc.
 | 
|---|
| 25 | #include "fm3dlg.h"
 | 
|---|
| 26 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
| 27 | #include "seticon.h"
 | 
|---|
| 28 | #include "fm3dll.h"
 | 
|---|
| 29 | #include "notebook.h"                   // Data declaration(s)
 | 
|---|
| 30 | #include "wrappers.h"                   // xfsopen
 | 
|---|
| 31 | #include "fortify.h"
 | 
|---|
| 32 | 
 | 
|---|
| 33 | #pragma data_seg(DATA2)
 | 
|---|
| 34 | 
 | 
|---|
| 35 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
| 36 | 
 | 
|---|
| 37 | MRESULT EXPENTRY SetIconDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 | 
|---|
| 38 | {
 | 
|---|
| 39 |   switch (msg) {
 | 
|---|
| 40 |   case WM_INITDLG:
 | 
|---|
| 41 |     WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mp2);
 | 
|---|
| 42 |     WinCheckButton(hwnd, SETICON_SPTR_ARROW, TRUE);
 | 
|---|
| 43 |     break;
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   case WM_CONTROL:
 | 
|---|
| 46 |     return 0;
 | 
|---|
| 47 | 
 | 
|---|
| 48 |   case WM_COMMAND:
 | 
|---|
| 49 |     switch (SHORT1FROMMP(mp1)) {
 | 
|---|
| 50 |     case DID_OK:
 | 
|---|
| 51 |       {
 | 
|---|
| 52 |         CHAR *filename = WinQueryWindowPtr(hwnd, QWL_USER), *buff = NULL;
 | 
|---|
| 53 |         ICONINFO icf;
 | 
|---|
| 54 |         ULONG icid = SPTR_ARROW;
 | 
|---|
| 55 |         INT x;
 | 
|---|
| 56 |         HWND hwndDeskTop;
 | 
|---|
| 57 |         FILE *fp;
 | 
|---|
| 58 |         CHAR *moderb = "rb";
 | 
|---|
| 59 | 
 | 
|---|
| 60 |         hwndDeskTop = WinQueryDesktopWindow(WinQueryAnchorBlock(hwnd),
 | 
|---|
| 61 |                                             NULLHANDLE);
 | 
|---|
| 62 |         memset(&icf, 0, sizeof(ICONINFO));
 | 
|---|
| 63 |         icf.cb = sizeof(ICONINFO);
 | 
|---|
| 64 |         icf.fFormat = ICON_DATA;
 | 
|---|
| 65 |         if (filename && *filename) {
 | 
|---|
| 66 |           fp = xfsopen(filename, moderb, SH_DENYNO, pszSrcFile, __LINE__, FALSE);
 | 
|---|
| 67 |           if (!fp)
 | 
|---|
| 68 |             break;
 | 
|---|
| 69 |           else {
 | 
|---|
| 70 |             fseek(fp, 0, SEEK_END);
 | 
|---|
| 71 |             icf.cbIconData = ftell(fp);
 | 
|---|
| 72 |             fseek(fp, 0, SEEK_SET);
 | 
|---|
| 73 |             buff = xmalloc(icf.cbIconData, pszSrcFile, __LINE__);
 | 
|---|
| 74 |             if (!buff) {
 | 
|---|
| 75 |               fclose(fp);
 | 
|---|
| 76 |               break;
 | 
|---|
| 77 |             }
 | 
|---|
| 78 |             fread(buff, icf.cbIconData, 1, fp);
 | 
|---|
| 79 |             icf.pIconData = (PVOID) buff;
 | 
|---|
| 80 |             fclose(fp);
 | 
|---|
| 81 |           }
 | 
|---|
| 82 |         }
 | 
|---|
| 83 |         for (x = 1; x < 15; x++) {
 | 
|---|
| 84 |           if (WinQueryButtonCheckstate(hwnd, SETICON_FRAME + x)) {
 | 
|---|
| 85 |             icid = (ULONG) x;
 | 
|---|
| 86 |             break;
 | 
|---|
| 87 |           }
 | 
|---|
| 88 |         }
 | 
|---|
| 89 |         for (x = 18; x < 23; x++) {
 | 
|---|
| 90 |           if (WinQueryButtonCheckstate(hwnd, SETICON_FRAME + x)) {
 | 
|---|
| 91 |             icid = (ULONG) x;
 | 
|---|
| 92 |             break;
 | 
|---|
| 93 |           }
 | 
|---|
| 94 |         }
 | 
|---|
| 95 |         if (!WinSetSysPointerData(hwndDeskTop, icid,
 | 
|---|
| 96 |                                   (PICONINFO) ((filename && *filename) ?
 | 
|---|
| 97 |                                                &icf : NULL))) {
 | 
|---|
| 98 |           Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, "WinSetSysPointerData");
 | 
|---|
| 99 |         }
 | 
|---|
| 100 |         free(buff);
 | 
|---|
| 101 |       }
 | 
|---|
| 102 |       WinDismissDlg(hwnd, 1);
 | 
|---|
| 103 |       break;
 | 
|---|
| 104 | 
 | 
|---|
| 105 |     case IDM_HELP:
 | 
|---|
| 106 |       if (hwndHelp)
 | 
|---|
| 107 |         WinSendMsg(hwndHelp,
 | 
|---|
| 108 |                    HM_DISPLAY_HELP,
 | 
|---|
| 109 |                    MPFROM2SHORT(HELP_SETICON, 0), MPFROMSHORT(HM_RESOURCEID));
 | 
|---|
| 110 |       break;
 | 
|---|
| 111 | 
 | 
|---|
| 112 |     case DID_CANCEL:
 | 
|---|
| 113 |       WinDismissDlg(hwnd, 0);
 | 
|---|
| 114 |       break;
 | 
|---|
| 115 |     }
 | 
|---|
| 116 |     return 0;
 | 
|---|
| 117 |   }
 | 
|---|
| 118 |   return WinDefDlgProc(hwnd, msg, mp1, mp2);
 | 
|---|
| 119 | }
 | 
|---|
| 120 | 
 | 
|---|
| 121 | #pragma alloc_text(MENU,SetIconDlgProc)
 | 
|---|