home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / osm2_102.zip / setup.c < prev    next >
C/C++ Source or Header  |  1999-02-01  |  5KB  |  206 lines

  1. /*
  2.  * setup.c - setup dialog
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include "osmulti2.h"
  12. #include "osmulres.h"
  13.  
  14. /*
  15.  * Data to Setup Here
  16.  */
  17.  
  18. extern  int     posRatio ;      /* track.c      */
  19. extern  BOOL    useMsg   ;      /* balloon.c    */
  20. extern  BOOL    useSnd   ;      /* balloon.c    */
  21.  
  22. /*
  23.  * dialogAtMouse - place dialog near mouse position
  24.  */
  25.  
  26. void    dialogAtMouse(HWND hwndDialog)
  27. {
  28.     POINTL  pt ;
  29.     SWP     posDlg ;
  30.     SWP     posScr ;
  31.  
  32.     WinQueryPointerPos(HWND_DESKTOP, &pt)    ;
  33.     WinQueryWindowPos(HWND_DESKTOP, &posScr) ;
  34.     WinQueryWindowPos(hwndDialog,   &posDlg) ;
  35.  
  36.     posDlg.x = pt.x - (posDlg.cx / 10)    ;
  37.     posDlg.y = pt.y - (posDlg.cy * 4 / 5) ;
  38.  
  39.     if (posDlg.x < 0) {
  40.         posDlg.x = 0 ;
  41.     }
  42.     if (posDlg.y < 0) {
  43.         posDlg.y = 0 ;
  44.     }
  45.     if ((posDlg.x + posDlg.cx) > posScr.cx) {
  46.         posDlg.x = posScr.cx - posDlg.cx ;
  47.     }
  48.     if ((posDlg.y + posDlg.cy) > posScr.cy) {
  49.         posDlg.y = posScr.cy - posDlg.cy ;
  50.     }
  51.     WinSetWindowPos(hwndDialog, NULLHANDLE,
  52.                     posDlg.x, posDlg.y, 0, 0, SWP_MOVE) ;
  53. }
  54.  
  55. /*
  56.  * sliderIni - initialize Slider
  57.  *
  58.  *      set tick marks on slider
  59.  */
  60.  
  61. static  void    sliderIni(HWND hwndDlg)
  62. {
  63.     HWND    hwnd = WinWindowFromID(hwndDlg, IDD_SPOS) ;
  64.     int     i ;
  65.     
  66.     for (i = 0 ; i <= 100 ; i++) {
  67.         if ((i % 10) == 0) {
  68.             WinSendMsg(hwnd, SLM_SETTICKSIZE, MPFROM2SHORT(i, 5), NULL) ;
  69.         } else if ((i % 5) == 0) {
  70.         WinSendMsg(hwnd, SLM_SETTICKSIZE, MPFROM2SHORT(i, 2), NULL) ;
  71.     }
  72.     }
  73. }
  74.  
  75. /*
  76.  * sliderSet/Get - position Slider
  77.  */
  78.  
  79. static  void    sliderSet(HWND hwndDlg, int pos)
  80. {
  81.     HWND    hwndPos = WinWindowFromID(hwndDlg, IDD_SPOS) ;
  82.     HWND    hwndNum = WinWindowFromID(hwndDlg, IDD_SNUM) ;
  83.     UCHAR   buff[16] ;
  84.  
  85.     sprintf(buff, "%d%%", pos) ;
  86.     WinSetWindowText(hwndNum, buff) ;
  87.  
  88.     WinSendMsg(hwndPos, SLM_SETSLIDERINFO,
  89.         MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), 
  90.     MPFROMLONG(pos)) ;
  91. }
  92.  
  93. static  int     sliderGet(HWND hwndDlg)
  94. {
  95.     HWND    hwndPos = WinWindowFromID(hwndDlg, IDD_SPOS) ;
  96.     int     pos ;
  97.     
  98.     pos = (int) WinSendMsg(hwndPos, SLM_QUERYSLIDERINFO, 
  99.         MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), NULL) ;
  100.     return pos ;    
  101. }
  102.  
  103. static  void    sliderUpd(HWND hwndDlg)
  104. {
  105.     HWND    hwndPos = WinWindowFromID(hwndDlg, IDD_SPOS) ;
  106.     HWND    hwndNum = WinWindowFromID(hwndDlg, IDD_SNUM) ;
  107.     UCHAR   buff[16] ;
  108.     int     pos ;
  109.     
  110.     pos = (int) WinSendMsg(hwndPos, SLM_QUERYSLIDERINFO, 
  111.         MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), NULL) ;
  112.  
  113.     sprintf(buff, "%d%%", pos) ;
  114.     WinSetWindowText(hwndNum, buff) ;
  115. }
  116.  
  117. /*
  118.  * setData - set option data to dialog
  119.  */
  120.  
  121. static  void    setData(HWND hwndDlg)
  122. {
  123.     HWND    hwndMsg = WinWindowFromID(hwndDlg, IDD_SMSG) ;
  124.     HWND    hwndSnd = WinWindowFromID(hwndDlg, IDD_SSND) ;
  125.     
  126.     WinSendMsg(hwndMsg, BM_SETCHECK, MPFROMSHORT(useMsg), NULL) ;
  127.     WinSendMsg(hwndSnd, BM_SETCHECK, MPFROMSHORT(useSnd), NULL) ;
  128.     WinEnableWindow(hwndSnd, FALSE) ;       /* not use yet */
  129.     sliderSet(hwndDlg, posRatio) ;
  130. }
  131.  
  132. /*
  133.  * getData - get option data from dialog
  134.  */
  135.  
  136. static  void    getData(HWND hwndDlg)
  137. {
  138.     HWND    hwndMsg = WinWindowFromID(hwndDlg, IDD_SMSG) ;
  139.     HWND    hwndSnd = WinWindowFromID(hwndDlg, IDD_SSND) ;
  140.  
  141.     posRatio = sliderGet(hwndDlg) ;
  142.     useMsg = (BOOL) WinSendMsg(hwndMsg, BM_QUERYCHECK, NULL, NULL) ;
  143.     useSnd = (BOOL) WinSendMsg(hwndSnd, BM_QUERYCHECK, NULL, NULL) ;
  144. }
  145.  
  146. /*
  147.  * procSetup - dialog procedure for setup dialog
  148.  */
  149.  
  150. static MRESULT EXPENTRY procSetup(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  151. {
  152.     switch (msg) {
  153.  
  154.     case WM_INITDLG :
  155.         dialogAtMouse(hwnd) ;
  156.     sliderIni(hwnd) ;
  157.     setData(hwnd) ;
  158.         return (MRESULT) 0 ;
  159.  
  160.     case WM_COMMAND :
  161.         switch (SHORT1FROMMP(mp1)) {
  162.     case DID_OK :
  163.         getData(hwnd) ;
  164.         profileSave(WinQueryAnchorBlock(hwnd)) ;
  165.         WinDismissDlg(hwnd, DID_OK) ;
  166.         return (MRESULT) 0 ;
  167.         case DID_CANCEL :
  168.         WinDismissDlg(hwnd, DID_CANCEL) ;
  169.         return (MRESULT) 0 ;    
  170.         default :
  171.         return (MRESULT) 0 ;
  172.     }
  173.  
  174.     case WM_CONTROL :
  175.         if (SHORT1FROMMP(mp1) == IDD_SPOS) {
  176.         if (SHORT2FROMMP(mp1) == SLN_CHANGE) {
  177.             sliderUpd(hwnd) ;
  178.         } else if (SHORT2FROMMP(mp1) == SLN_SLIDERTRACK) {
  179.                 sliderUpd(hwnd) ;
  180.             }
  181.         }
  182.     return (MRESULT) 0 ;
  183.     }
  184.     return WinDefDlgProc(hwnd, msg, mp1, mp2) ;
  185. }
  186.  
  187. /*
  188.  * setupDialog - entry of setup dialog
  189.  */
  190.  
  191. void    setupDialog(void)
  192. {
  193.     ULONG   idSetup ;
  194.  
  195.     switch (ProgramLang) {
  196.         case NLS_JA : idSetup = IDD_SETUP  ; break ;
  197.     case NLS_EN : idSetup = IDD_SETUPE ; break ;
  198.     default     : idSetup = IDD_SETUPE ; break ;
  199.     }
  200.     
  201.     WinDlgBox(HWND_DESKTOP, NULLHANDLE, 
  202.                 procSetup, NULLHANDLE, idSetup, NULL) ;
  203.  
  204.     trackFocus(WinQueryAnchorBlock(HWND_DESKTOP)) ;     /* update multi */
  205. }
  206.