home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gsview13 / src / gvpmisc.c < prev    next >
C/C++ Source or Header  |  1995-12-09  |  5KB  |  221 lines

  1. /* Copyright (C) 1993, 1994, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gvpmisc.c */
  19. /* Miscellaneous PM GSview routines */
  20.  
  21. #include "gvpm.h"
  22.  
  23. BOOL
  24. SetDlgItemText(HWND hwnd, int id, char *str)
  25. {
  26.     WinSetWindowText(WinWindowFromID(hwnd, id), str);
  27.     return TRUE;
  28. }
  29.  
  30. void
  31. post_close(void)
  32. {
  33.     WinPostMsg(hwnd_bmp, WM_CLOSE, MPFROMLONG(0), MPFROMLONG(0));
  34. }
  35.  
  36. void
  37. get_help()
  38. {
  39.     WinPostMsg(hwnd_frame, WM_HELP,
  40.     MPFROMLONG(0), MPFROM2SHORT(CMDSRC_OTHER, FALSE));
  41. }
  42.  
  43. /* display message */
  44. int
  45. message_box(char *str, int icon)
  46. {
  47.       return WinMessageBox(HWND_DESKTOP, hwnd_frame ? hwnd_frame : HWND_DESKTOP, 
  48.         str, szAppName, 0, icon | MB_MOVEABLE | MB_OK);
  49. }
  50.  
  51. /* change menu item checkmark */
  52. void
  53. check_menu_item(int menuid, int itemid, BOOL checked)
  54. {
  55. HWND hwndMenu;
  56. MENUITEM mi;
  57.     hwndMenu = WinWindowFromID(hwnd_frame, FID_MENU);
  58.     WinSendMsg(hwndMenu, MM_QUERYITEM, 
  59.         MPFROM2SHORT(menuid, TRUE), MPFROMP(&mi));
  60.     WinSendMsg(mi.hwndSubMenu, MM_SETITEMATTR, MPFROMLONG(itemid),
  61.         MPFROM2SHORT(MIA_CHECKED, checked ? MIA_CHECKED : 0));
  62. }
  63.  
  64. /* get text of menu item */
  65. int
  66. get_menu_string(int menuid, int itemid, char *str, int len)
  67. {
  68. HWND hwndMenu;
  69. MENUITEM mi;
  70.     hwndMenu = WinWindowFromID(hwnd_frame, FID_MENU);
  71.     WinSendMsg(hwndMenu, MM_QUERYITEM, 
  72.         MPFROM2SHORT(menuid, TRUE), MPFROMP(&mi));
  73.     return (int)WinSendMsg(mi.hwndSubMenu, MM_QUERYITEMTEXT, 
  74.         MPFROM2SHORT(itemid, len), MPFROMP(str));
  75. }
  76.  
  77. int
  78. load_string(int id, char *str, int len)
  79. {
  80.     return WinLoadString(hab, 0, id, len, str);
  81. }
  82.  
  83.  
  84. void
  85. play_system_sound(char *id)
  86. {
  87. HINI hini;
  88. char buf[MAXSTR];
  89. char *p;
  90.     if ( (hini = PrfOpenProfile(hab, szMMini)) == NULLHANDLE )
  91.         return;
  92.     PrfQueryProfileString(hini, "MMPM2_AlarmSounds", id, "##", buf, sizeof(buf));
  93.     PrfCloseProfile(hini);
  94.         p = strchr(buf,'#');
  95.         if (p != (char *)NULL) {
  96.         *p = '\0';
  97.         (*pfnMciPlayFile)(hwnd_frame, buf, 0, 0, 0);
  98.     }
  99.     return;
  100. }
  101.  
  102. void
  103. play_sound(int num)
  104. {
  105. ULONG rc;
  106.     if (strlen(sound[num].file)==0)
  107.         return;
  108.     if (!(pfnMciPlayFile) || (strcmp(sound[num].file,BEEP)==0)) {
  109.         DosBeep(200,200);
  110.         return;
  111.     }
  112.     if (isdigit(*sound[num].file))
  113.         play_system_sound(sound[num].file);
  114.     else {
  115.         char buf[MAXSTR];
  116.         buf[0] = '\042';
  117.         strcpy(buf+1, sound[num].file);
  118.         strcat(buf, "\042");
  119.         if ((*pfnMciPlayFile)(hwnd_frame, buf, 0, 0, 0))
  120.             DosBeep(200,200);
  121.     }
  122. }
  123.  
  124.  
  125.  
  126. void
  127. info_wait(BOOL flag)
  128. {
  129. POINTL pt, pt_save;
  130. RECTL rect;
  131.     waiting = flag;
  132.     if (hwnd_status) {
  133.         WinInvalidateRect(hwnd_status, (PRECTL)NULL, TRUE);
  134.           WinUpdateWindow(hwnd_status);
  135.     }
  136.     if (!waiting)
  137.         load_string(IDS_WAIT, szWait, sizeof(szWait));  /* revert to generic text */
  138.     /* find out if cursor over hwnd_bmp */
  139.     if (!WinQueryPointerPos(HWND_DESKTOP, &pt))
  140.         return;
  141.     if (hwnd_bmp == WinWindowFromPoint(HWND_DESKTOP, &pt, TRUE))
  142.         WinSendMsg(hwnd_bmp, WM_MOUSEMOVE, MPFROM2SHORT(pt.x, pt.y), (MPARAM)0);
  143. }
  144.  
  145.  
  146. int 
  147. _chdir(char *dirname)
  148. {
  149. #ifdef __BORLANDC__
  150.     if (isalpha(dirname[0]) && (dirname[1]==':'))
  151.         (void) setdisk(toupper(dirname[0])-'A');
  152.     if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':')))
  153.         chdir(dirname);
  154.     return TRUE;
  155. #else
  156.     if (isalpha(dirname[0]) && (dirname[1]==':'))
  157.         (void) _chdrive(dirname[0]);
  158.     return _chdir2(dirname);
  159. #endif
  160. }
  161.  
  162. char * 
  163. _getcwd(char *dirname, int size)
  164. {
  165. #ifdef __BORLANDC__
  166.     return getcwd(dirname, size);
  167. #else
  168.     return _getcwd2(dirname, size);
  169. #endif
  170. }
  171.  
  172.  
  173. void
  174. send_prolog(FILE *f, int resource)
  175. {  
  176. char *prolog, *p;
  177. APIRET rc;
  178.     rc = DosGetResource(0, RT_RCDATA, resource, (PPVOID)&prolog);
  179.     if (!rc && (prolog != (char *)NULL) ) {
  180.         p = prolog;
  181.         while (*p) {
  182.             while (*p) {
  183.             if (debug_file != (FILE *)NULL)
  184.                     fputc(*p, debug_file);
  185.                 fputc(*p++, f);
  186.         }
  187.         p++;    /* skip end of string null */
  188.         }
  189.         DosFreeResource(prolog);
  190.     }
  191. }
  192.  
  193. char tempbuf[8192];
  194.  
  195. void
  196. profile_create_section(PROFILE *prf, char *section, int id)
  197. {
  198. char *rcdata, *entry, *value;
  199. char name[MAXSTR];
  200.     if (!DosGetResource(0, RT_RCDATA, id, (PPVOID)&rcdata)) {
  201.     if (rcdata == (char *)NULL) {
  202.         profile_close(prf);
  203.         return;
  204.     }
  205.     entry = rcdata;
  206.     while (strlen(entry)!=0) {
  207.         for ( value = entry; 
  208.           (*value!='\0') && (*value!=',') && (*value!='='); 
  209.           value++)
  210.         /* nothing */;
  211.         strncpy(name, entry, value-entry);
  212.         name[value-entry] = '\0';
  213.         value++;
  214.         profile_write_string(prf, section, name, value);
  215.         entry = value + strlen(value) + 1;
  216.     }
  217.    }
  218.    DosFreeResource(rcdata);
  219. }
  220.  
  221.