home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gsview13 / src / gvwmisc.c < prev    next >
C/C++ Source or Header  |  1995-12-09  |  5KB  |  185 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. /* gvwmisc.c */
  19. /* Miscellaneous Windows GSview routines */
  20.  
  21. #include "gvwin.h"
  22.  
  23. /* SetDlgItemText is a Windows API */
  24.  
  25. void
  26. post_close(void)
  27. {
  28.     PostMessage(hwndimg, WM_CLOSE, (WPARAM)0, (LPARAM)0);
  29. }
  30.  
  31. void
  32. get_help(void)
  33. {
  34.     SendMessage(hwndimg, help_message, 0, 0L);
  35. }
  36.  
  37. /* display message */
  38. int message_box(char *str, int icon)
  39. {
  40.     return MessageBox(hwndimg, str, szAppName, icon | MB_OK);
  41. }
  42.  
  43. /* change menu item checkmark */
  44. void
  45. check_menu_item(int menuid, int itemid, BOOL checked)
  46. {
  47.     menuid = menuid;    /* shut up warning */
  48.         CheckMenuItem(hmenu, itemid, MF_BYCOMMAND | (checked ? MF_CHECKED : MF_UNCHECKED));
  49. }
  50.  
  51. /* get text of menu item */
  52. int
  53. get_menu_string(int menuid, int itemid, char *str, int len)
  54. {
  55.     menuid = menuid;    /* shut up warning */
  56.     return GetMenuString(hmenu, itemid, str, len, MF_BYCOMMAND);
  57. }
  58.  
  59. int
  60. load_string(int id, char *str, int len)
  61. {
  62.     return LoadString(phInstance, id, str, len);
  63. }
  64.  
  65. void
  66. play_sound(int num)
  67. {
  68.     if (strlen(sound[num].file)==0)
  69.         return;
  70.     if (!is_win31 || (strcmp(sound[num].file,BEEP)==0)) {
  71.         MessageBeep(-1);
  72.         return;
  73.     }
  74.     if (is_win31) {
  75.         if (lpfnSndPlaySound != (FPSPS)NULL) 
  76.                lpfnSndPlaySound(sound[num].file, SND_SYNC);
  77.         else
  78.             MessageBeep(-1);
  79.         return;
  80.     }
  81. }
  82.  
  83.  
  84. /* display or remove 'wait' message */
  85. void
  86. info_wait(BOOL wait)
  87. {
  88. HWND hwnd;
  89. POINT pt;
  90.     waiting = wait;
  91.     InvalidateRect(hwndimg, (LPRECT)&info_rect, FALSE);
  92.     UpdateWindow(hwndimg);
  93.  
  94.     if (waiting) {
  95.             GetCursorPos(&pt);
  96.         hwnd = WindowFromPoint(pt);
  97.         if ((hwnd == hwndimg) || IsChild(hwndimg,hwnd))
  98.         SetCursor(hcWait);
  99.     }
  100.     else {
  101.         /* revert to generic text */
  102.         load_string(IDS_WAIT, szWait, sizeof(szWait));
  103.         /* set cursor to that of active window */
  104.         hwnd = GetFocus();
  105.         if ( (hwndimgchild && IsWindow(hwndimgchild))
  106.           && ((hwnd == hwndimg) || (hwnd == hwndimgchild)) ) {
  107.         if (in_child_client_area()) {
  108.             SetCursor(GetClassCursor(hwndimgchild));
  109.             return;
  110.         }
  111.         }
  112.         SetCursor(GetClassCursor(hwnd));
  113.     }
  114. }
  115.  
  116. /* change directory and drive */
  117. int
  118. _chdir(char *dirname)
  119. {
  120. #ifdef __WIN32__
  121.     SetCurrentDirectory(dirname);
  122. #else
  123.     if (isalpha(dirname[0]) && (dirname[1]==':'))
  124.         (void) setdisk(toupper(dirname[0])-'A');
  125.     if (!((strlen(dirname)==2) && isalpha(dirname[0]) && (dirname[1]==':')))
  126.         chdir(dirname);
  127. #endif
  128.     return 0;
  129. }
  130.  
  131. char * 
  132. _getcwd(char *dirname, int size)
  133. {
  134. #ifdef __WIN32__
  135.     GetCurrentDirectory(size, dirname);
  136.     return dirname;
  137. #else
  138.     return getcwd(dirname, size);
  139. #endif
  140. }
  141.  
  142.  
  143. void
  144. send_prolog(FILE *f, int resource)
  145. {  
  146. HGLOBAL hglobal;
  147. LPSTR prolog;
  148.     hglobal = LoadResource(phInstance, 
  149.         FindResource(phInstance, MAKEINTRESOURCE(resource), RT_RCDATA));
  150.     if ( (prolog = (LPSTR)LockResource(hglobal)) != (LPSTR)NULL) {
  151.         while (*prolog) {
  152.         if (debug_file != (FILE *)NULL)
  153.                 fputc(*prolog, debug_file);
  154.             fputc(*prolog++, f);
  155.         }
  156.         FreeResource(hglobal);
  157.     }
  158. }
  159.  
  160. void
  161. profile_create_section(PROFILE *prf, char *section, int id)
  162. {  
  163. HGLOBAL hglobal;
  164. LPSTR entry, value;
  165. char name[MAXSTR];
  166. char val[256];
  167.     hglobal = LoadResource(phInstance, 
  168.         FindResource(phInstance, MAKEINTRESOURCE(id), RT_RCDATA));
  169.     if ( (entry = (LPSTR)LockResource(hglobal)) == (LPSTR)NULL)
  170.         return;
  171.     while (lstrlen(entry)!=0) {
  172.         for ( value = entry; 
  173.           (*value!='\0') && (*value!=',') && (*value!='='); 
  174.           value++)
  175.         /* nothing */;
  176.         _fstrncpy(name, entry, (int)(value-entry));
  177.         name[(int)(value-entry)] = '\0';
  178.         value++;
  179.         _fstrncpy(val, value, sizeof(val));
  180.         profile_write_string(prf, section, name, val);
  181.         entry = value + lstrlen(value) + 1;
  182.     }
  183.     FreeResource(hglobal);
  184. }
  185.