TAB.C
Upload User: sales84
Upload Date: 2007-01-11
Package Size: 864k
Code Size: 20k
Development Platform:

Visual C++

  1. #include <userdlg.h>    // 基本Windows编程接口的头文件
  2. #include <commctrl.h>   // 公共控件头文件
  3. #include <prsht.h> // 包含属性表控件的函数和常量说明的头文件
  4. //#include <stdio.h>
  5. //#include <string.h>
  6. #include "sharewareluncher.h"
  7. #include "Tab.h"
  8. #include "resource.h"
  9. #define EVERYDAY 1
  10. #define SUPER 2
  11. #define E_SUPER 3
  12. int nTimerNum;
  13. void TimeToString(void);
  14. void SortList1(void);
  15. void TtoS(int a,int b,int c);
  16. void RegAlarm(void);
  17. void DoTimerChange(HWND);
  18. extern HINSTANCE hInst;
  19. extern HWND      hMainWnd;
  20. extern BOOL bDlgRuned;
  21. PROPSHEETPAGE * ps;
  22. BOOL bSheet=FALSE;
  23. int nBarPos[]={212,270,-1};
  24. extern TIMERINFO ti[10];
  25. TIMERINFO titemp;
  26. LPSTR szflag[4]={"临时","每日提示","高级","高级"};
  27. //TIMEFLAG tiflag;
  28. HWND hListWnd,hBarWnd,hHUDWnd,hMUDWnd;
  29. char szerr[1100];
  30. int nOldSel=-2;
  31. BOOL bInScroll=FALSE,bInSel=FALSE;
  32. BOOL bTextChanged=FALSE,bHourChanged=FALSE,bMinChanged=FALSE;
  33. extern int nAlarmEveryHour;
  34. BOOL btRuning=FALSE,bNoShowDel=FALSE;
  35. HWND hSheetWnd,hTimelistWnd;
  36. TAB psp[2];
  37. TABFLAG psh;
  38. int CreatePropertySheet(HWND hwndOwner)
  39. {
  40.     //PROPSHEETPAGE psp[2];
  41.     //PROPSHEETHEADER psh;
  42.     bSheet=TRUE;
  43.     psp[0].dwSize = sizeof (PROPSHEETPAGE);
  44.     psp[0].dwFlags = PSP_USETITLE;
  45.     psp[0].hInstance = hInst;
  46.     psp[0].pszTemplate = MAKEINTRESOURCE(IDD_TIME);
  47.     psp[0].pszIcon = NULL;
  48.     psp[0].pfnDlgProc = (DLGPROC)MakeTime;
  49.     psp[0].pszTitle = "闹钟设置";
  50.     psp[0].lParam = 0;
  51.     psp[1].dwSize = sizeof (PROPSHEETPAGE);
  52.     psp[1].dwFlags = PSP_USETITLE | PSP_USEHICON;
  53.     psp[1].hInstance = hInst;
  54.     psp[1].pszTemplate = MAKEINTRESOURCE(IDD_LIST);
  55.     psp[1].hIcon = NULL;
  56.     psp[1].pfnDlgProc = (DLGPROC)ListWndProc;
  57.     psp[1].pszTitle = "程序设置";
  58.     psp[1].lParam = 0;
  59.     psh.dwSize = sizeof (PROPSHEETHEADER);
  60.     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_HASHELP;
  61.     psh.hwndParent = hwndOwner;
  62.     psh.hInstance = hInst;
  63.     psh.pszIcon = MAKEINTRESOURCE(IDI_APPICON);
  64.     psh.pszCaption = (LPSTR) "设置";
  65.     psh.nPages = sizeof (psp) / sizeof (PROPSHEETPAGE);
  66.     psh.ppsp = (LPCPROPSHEETPAGE) &psp;
  67.     //PropertySheet(&psh);
  68.     return (PropertySheet((LPCPROPSHEETHEADER)&psh));//hSheetWnd;
  69. }
  70. #pragma argsused
  71. LONG APIENTRY MakeTime(HWND hWnd,UINT message, WPARAM  wParam,LPARAM  lParam)
  72. {
  73.    int i,j;
  74.    hTimelistWnd=hWnd;
  75.    switch (message)
  76. {
  77. case WM_INITDIALOG:
  78.          hSheetWnd=GetParent(hWnd);
  79.          bSheet=TRUE;
  80.          btRuning=TRUE;
  81.          GetTimerInfo(nTimerNum);
  82.          TimeToString();
  83.          hListWnd=GetDlgItem(hWnd,IDC_LISTTIME);
  84. for (i=0; i < nTimerNum; i++)
  85. {
  86.        SendMessage(hListWnd,LB_ADDSTRING,0,(LPARAM)(ti[i].szTimerString));
  87.             SendMessage(hListWnd, LB_SETITEMDATA, SendMessage(hListWnd,LB_FINDSTRING,-1,(LPARAM)(ti[i].szTimerString)), (LPARAM) i);
  88. }
  89.          if(nTimerNum>0)
  90.          {
  91.           SendMessage(hListWnd,LB_SETCURSEL,0,0);
  92.             SendMessage(hWnd,WM_COMMAND,MAKELONG(IDC_LISTTIME,LBN_SELCHANGE),(LPARAM)hListWnd);
  93.          }
  94. if (hListWnd == NULL)
  95. MessageBox (NULL, "加载定时器信息时出错!", "出错", MB_OK );
  96.          SetFocus(hListWnd);
  97.          hBarWnd=GetDlgItem(hWnd,IDC_TIMEBAR);
  98.          SendMessage(hBarWnd,SB_SETPARTS,3,(LPARAM)nBarPos);
  99.          SendMessage(hBarWnd,SB_SETTEXT,(1 | 0),(LPARAM)"状态");
  100.          //SendMessage(hBarWnd,SB_SETTEXT,(2 | 0),(LPARAM)"01/23/1998");
  101.          hHUDWnd=GetDlgItem(hWnd,IDC_HOURUPDOWN);
  102.          SendMessage(hHUDWnd,UDM_SETRANGE,0,MAKELONG(23,0));
  103.          hMUDWnd=GetDlgItem(hWnd,IDC_MINUPDOWN);
  104.          SendMessage(hMUDWnd,UDM_SETRANGE,0,MAKELONG(59,0));
  105.          if(nAlarmEveryHour==1)
  106.           CheckDlgButton(hWnd,IDC_ONEHOUR,BST_CHECKED);
  107.          ps = (PROPSHEETPAGE *)lParam;
  108. return (TRUE);
  109.       case WM_VSCROLL:
  110.        bInScroll=TRUE;
  111.          i=SendMessage(hListWnd,LB_GETCURSEL,0,0);
  112.        if(i==LB_ERR)
  113.          {
  114.           nOldSel=-2;
  115.           bInScroll=FALSE;
  116.             break;
  117.          }
  118.          j=SendMessage(hListWnd, LB_GETITEMDATA, i, (LPARAM) 0);
  119.        TtoS(GetDlgItemInt(hWnd,IDC_SETHOUR,NULL,FALSE),GetDlgItemInt(hWnd,IDC_SETMIN,NULL,FALSE),j);
  120.          {
  121.           int x;
  122.             BOOL bf=FALSE;
  123.             for(x=0;x<nTimerNum;x++)
  124.             {
  125.                if(x!=j)
  126.              if(strcmp(ti[j].szTimerString,ti[x].szTimerString)==0)
  127.                   {
  128.                    bf=TRUE;
  129.                    break;
  130.                   }
  131.             }
  132.             if(bf)
  133.             {
  134.                bInScroll=FALSE;
  135.                ti[j]=titemp;
  136.                break;
  137.             }
  138.           SendMessage(hListWnd,LB_DELETESTRING,i,0L);
  139.           SendMessage(hListWnd,LB_ADDSTRING,0,(LPARAM)(ti[j].szTimerString));
  140.             x=SendMessage(hListWnd,LB_FINDSTRING,-1,(LPARAM)(ti[j].szTimerString));
  141.           SendMessage(hListWnd,LB_SETITEMDATA, x, (LPARAM) j);
  142.           SendMessage(hListWnd,LB_SETCURSEL,x,0);
  143.             nOldSel=x;
  144.          }
  145.          //SortList1();
  146.          //SendMessage(hBarWnd,SB_SETTEXT,(0 | 0),(LPARAM)" ");
  147.          //SendMessage(hBarWnd,SB_SETTEXT,(2 | 0),(LPARAM)" ");
  148.          bInScroll=FALSE;
  149.          break;
  150. case WM_COMMAND:
  151. switch ( LOWORD( wParam ))
  152. {
  153.             case IDOK:
  154.                if(nTimerNum>=10)
  155.                {
  156.                 nTimerNum=10;
  157.                 break;
  158.                }
  159.                for(i=0;i<nTimerNum;i++)
  160.                {
  161.                 if(strcmp(ti[i].szTimerString,"新定时器")==0)
  162.                    return FALSE;
  163.                }
  164.              wsprintf(ti[nTimerNum].szTimerString,"新定时器");
  165.                SendMessage(hListWnd,LB_ADDSTRING,0,(LPARAM)(ti[nTimerNum].szTimerString));
  166.              SendMessage(hListWnd, LB_SETITEMDATA, nTimerNum, (LPARAM) nTimerNum);
  167.                SendMessage(hListWnd, LB_SETCURSEL, nTimerNum,0);
  168.                SendMessage(hWnd,WM_COMMAND,MAKELONG(IDC_LISTTIME,LBN_SELCHANGE),(LPARAM)hListWnd);
  169.                CheckDlgButton(hWnd,IDC_EVERYDAY,BST_UNCHECKED);
  170.                //SetDlgItemInt(hWnd,IDC_SETHOUR,0,FALSE);
  171.                //SetDlgItemInt(hWnd,IDC_SETMIN,0,FALSE);
  172.                nTimerNum++;
  173.                break;
  174.             case IDHELP://"cancel" pushed
  175.                i=SendMessage(hListWnd,LB_GETCURSEL,0,0);
  176.                if(i==LB_ERR)
  177.                {
  178.                 nOldSel=-2;
  179.                 break;
  180.                }
  181.                j=SendMessage(hListWnd, LB_GETITEMDATA, i, (LPARAM) 0);
  182.                SendMessage(hListWnd,LB_DELETESTRING,i,0L);
  183.                nTimerNum--;
  184.                SortList1();
  185.                ListDel1(j);
  186.                //if(nTimerNum>0)
  187.     //{
  188. // SendMessage(hListWnd,LB_SETCURSEL,0,0L);
  189.    // SendMessage(hTimelistWnd,WM_COMMAND,MAKELONG(IDC_LISTTIME,LBN_SELCHANGE),(LPARAM)hListWnd);
  190.    //}
  191.                //else
  192.                {
  193.                 SendMessage(hBarWnd,SB_SETTEXT,(0 | 0),(LPARAM)" ");
  194.                SendMessage(hBarWnd,SB_SETTEXT,(2 | 0),(LPARAM)" ");
  195.                   SetDlgItemText(hWnd,IDC_ALARMINFO,"");
  196.                 CheckDlgButton(hWnd,IDC_EVERYDAY,BST_UNCHECKED);
  197.                 SetDlgItemInt(hWnd,IDC_SETHOUR,0,FALSE);
  198.                 SetDlgItemInt(hWnd,IDC_SETMIN,0,FALSE);
  199.                }
  200.                break;
  201.             case IDCANCEL:
  202.                //Errmsg("Will write later");
  203.                break;
  204.             case IDC_EVERYDAY:
  205.                i=SendMessage(hListWnd,LB_GETCURSEL,0,0);
  206.                if(i==LB_ERR)
  207.                {
  208.                 nOldSel=-2;
  209.                 break;
  210.                }
  211.                j=SendMessage(hListWnd, LB_GETITEMDATA, i, (LPARAM) 0);
  212.              switch(IsDlgButtonChecked(hWnd,IDC_EVERYDAY))
  213.                {
  214.                 case BST_CHECKED:
  215.                    if(ti[j].nflag==SUPER)
  216.                       ti[j].nflag=E_SUPER;
  217.                      else
  218.                       ti[j].nflag=EVERYDAY;
  219.                      break;
  220.                   case BST_UNCHECKED:
  221.                    if(ti[j].nflag==E_SUPER)
  222.                       ti[j].nflag=SUPER;
  223.                      else if(ti[j].nflag==EVERYDAY)
  224.                       ti[j].nflag=0;
  225.                      break;
  226.                }
  227.                break;
  228.             case IDC_ONEHOUR:
  229.              switch(IsDlgButtonChecked(hWnd,IDC_ONEHOUR))
  230.                {
  231.                 case BST_CHECKED:
  232.                    nAlarmEveryHour=1;
  233.                      break;
  234.                   case BST_UNCHECKED:
  235.                    nAlarmEveryHour=0;
  236.                      break;
  237.                }
  238.                RegAlarm();
  239.              break;
  240.          }
  241.          switch(HIWORD(wParam))
  242.          {
  243.             case EN_KILLFOCUS:
  244.                //i=SendMessage((HWND)lParam,LB_GETCURSEL,0,0);
  245.                if(!bTextChanged)
  246.                 break;
  247.                if(nOldSel==-2)
  248.                   break;
  249.                j=SendMessage(hListWnd, LB_GETITEMDATA, nOldSel, (LPARAM) 0);
  250.                GetDlgItemText(hWnd,IDC_ALARMINFO,ti[j].szInfo,500);
  251.                bTextChanged=FALSE;
  252.              break;
  253.             case EN_CHANGE:
  254.              switch((int)LOWORD(wParam))
  255.                {
  256.                 case IDC_ALARMINFO:
  257.                    bTextChanged=TRUE;
  258.                      break;
  259.                   case IDC_SETHOUR:
  260.                      bHourChanged=TRUE;
  261.                      break;
  262.                   case IDC_SETMIN:
  263.                    bMinChanged=TRUE;
  264.                      break;
  265.                }
  266.                break;
  267.             case EN_UPDATE:
  268.              switch((int)LOWORD(wParam))
  269.                {
  270.                 case IDC_SETHOUR:
  271.                      if(bInScroll || bInSel)
  272.                       break;
  273.                      DoTimerChange(hWnd);
  274.                      break;
  275.                   case IDC_SETMIN:
  276.                    if(bInScroll || bInSel)
  277.                       break;
  278.                      DoTimerChange(hWnd);
  279.                      break;
  280.                }
  281.                break;
  282.             case LBN_SELCHANGE:
  283.                if(bInScroll)
  284.                 break;
  285.                bInSel=TRUE;
  286.                i=SendMessage((HWND)lParam,LB_GETCURSEL,0,0);
  287.                if(i==LB_ERR)
  288.                {
  289.                 SendMessage(hBarWnd,SB_SETTEXT,(0 | 0),(LPARAM)" ");
  290.                 SendMessage(hBarWnd,SB_SETTEXT,(2 | 0),(LPARAM)" ");
  291.                   nOldSel=-2;
  292.                   break;
  293.                }
  294.                if(nOldSel==-2)
  295.                 nOldSel=i;
  296.                else if(bTextChanged)
  297.                {
  298.                 j=SendMessage((HWND)lParam, LB_GETITEMDATA, nOldSel, (LPARAM) 0);
  299.                 GetDlgItemText(hWnd,IDC_ALARMINFO,ti[j].szInfo,500);
  300.                   bTextChanged=FALSE;
  301.                }
  302.                j=SendMessage((HWND)lParam, LB_GETITEMDATA, i, (LPARAM) 0);
  303.                SendMessage(hBarWnd,SB_SETTEXT,(0 | 0),(LPARAM)(szflag[ti[j].nflag]));
  304.                SetDlgItemInt(hWnd,IDC_SETHOUR,ti[j].wHour,FALSE);
  305.                SetDlgItemInt(hWnd,IDC_SETMIN,ti[j].wMinute,FALSE);
  306.                SetDlgItemText(hWnd,IDC_ALARMINFO,ti[j].szInfo);
  307.                if(ti[j].nflag==EVERYDAY || ti[j].nflag==E_SUPER)
  308.                 CheckDlgButton(hWnd,IDC_EVERYDAY,BST_CHECKED);
  309.                else
  310.                 CheckDlgButton(hWnd,IDC_EVERYDAY,BST_UNCHECKED);
  311.                nOldSel=i;
  312.                bInSel=FALSE;
  313.                break;
  314.          }
  315. break;
  316. case WM_CLOSE:
  317.        SortList1();
  318.          WriteTimerInfo();
  319.          btRuning=FALSE;
  320.          bSheet=FALSE;
  321. EndDialog(hWnd,TRUE);
  322. return TRUE;
  323.       case WM_NOTIFY:
  324.      switch (((NMHDR FAR *) lParam)->code)
  325.      {
  326. case PSN_SETACTIVE:
  327.                btRuning=TRUE;
  328.                break;
  329. case PSN_APPLY:
  330.                if(nOldSel==-2)
  331.                {
  332.                 bSheet=FALSE;
  333.                 break;
  334.                }
  335.                //GetDlgItemText(hWnd,IDC_ALARMINFO,ti[nOldSel].szInfo,500);
  336.                switch(IsDlgButtonChecked(hWnd,IDC_ONEHOUR))
  337.                {
  338.                 case BST_CHECKED:
  339.                    nAlarmEveryHour=1;
  340.                      break;
  341.                   case BST_UNCHECKED:
  342.                    nAlarmEveryHour=0;
  343.                      break;
  344.                }
  345.                RegAlarm();
  346.                SortList1();
  347.                WriteTimerInfo();
  348.                btRuning=FALSE;
  349.                bSheet=FALSE;
  350.              SetWindowLong(hMainWnd, GWL_STYLE, GetWindowLong(hMainWnd,GWL_STYLE));
  351. ShowWindow(hMainWnd, SW_SHOW);
  352.                SetWindowLong(hWnd,DWL_MSGRESULT, FALSE);
  353.                return TRUE;
  354. case PSN_KILLACTIVE:
  355.              //btRuning=FALSE;
  356.                SetWindowLong(hWnd,DWL_MSGRESULT, FALSE);
  357. return (TRUE);
  358. case PSN_RESET:
  359.              btRuning=FALSE;
  360.                bSheet=FALSE;
  361.              break;
  362. case PSN_HELP:
  363. break;
  364.      }
  365. default:
  366. return FALSE;
  367. }
  368. return FALSE;
  369. }
  370. void TimeToString(void)
  371. {
  372. int i;
  373.    for(i=0;i<nTimerNum;i++)
  374.    {
  375.       if(ti[i].wHour<10)
  376.     wsprintf(ti[i].szTimerString,"0%d:",ti[i].wHour);
  377.       else
  378.        wsprintf(ti[i].szTimerString,"%d:",ti[i].wHour);
  379.       if(ti[i].wMinute<10)
  380.     wsprintf(ti[i].szTimerString,"%s0%d",ti[i].szTimerString,ti[i].wMinute);
  381.       else
  382.        wsprintf(ti[i].szTimerString,"%s%d",ti[i].szTimerString,ti[i].wMinute);
  383.    }
  384. }
  385. void SortList1(void)
  386. {
  387.    int i,j,pi[10];
  388.    TIMERINFO tiTemp,tiSort;
  389. for(i=0;i<nTimerNum;i++)
  390.    {
  391.       pi[i]=SendMessage(hListWnd,LB_GETITEMDATA,i,0L);
  392.    }
  393.    for(i=0;i<nTimerNum;i++)
  394.    {
  395.       if(pi[i]!=i)
  396.       {
  397.       tiSort=ti[pi[i]];
  398.        tiTemp=ti[i];
  399.        ti[i]=tiSort;
  400.       ti[pi[i]]=tiTemp;
  401.          for(j=0;j<nTimerNum;j++)
  402.          {
  403.         if(pi[j]==i)
  404.              pi[j]=pi[i];
  405.          }
  406.       }
  407.    }
  408. }
  409. void GetTimerInfo(int n)
  410. {
  411. int i;
  412.    char sztemp[500];
  413.    HKEY  hKey1;//, hKey2;
  414.    DWORD  dwDisposition;
  415.    LONG   lRetCode;    DWORD dwDate,dwDateSize=sizeof(DWORD);
  416.    DWORD dwtemp;
  417.    lRetCode=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\phonix\sharewareluncher",0, NULL, REG_OPTION_NON_VOLATILE,
  418.                            KEY_ALL_ACCESS,NULL,&hKey1,&dwDisposition);
  419.    if (lRetCode != ERROR_SUCCESS)
  420.    {
  421.       Errmsg("Error in creating keyn");//,"Error",MB_OK);
  422.       return;//break;
  423.    }
  424.    for(i=0;i<n;i++)
  425.    {
  426.     wsprintf(sztemp,"TimerHour%d",i);
  427.       lRetCode=RegQueryValueEx(hKey1,sztemp,NULL,&dwtemp,(LPBYTE)(&dwDate),&dwDateSize);
  428.       if (lRetCode != ERROR_SUCCESS)
  429. ti[i].wHour=0;
  430.       else
  431.        ti[i].wHour=(WORD)dwDate;
  432.       wsprintf(sztemp,"TimerMinute%d",i);
  433.       lRetCode=RegQueryValueEx(hKey1,sztemp,NULL,&dwtemp,(LPBYTE)(&dwDate),&dwDateSize);
  434.       if (lRetCode != ERROR_SUCCESS)
  435. ti[i].wMinute=0;
  436.       else
  437.        ti[i].wMinute=(WORD)dwDate;
  438.       wsprintf(sztemp,"TimerChar%d",i);
  439.       dwDisposition=500;
  440.       lRetCode=RegQueryValueEx(hKey1,sztemp,NULL,&dwtemp,(LPBYTE)(ti[i].szInfo),&dwDisposition);
  441.       if (lRetCode != ERROR_SUCCESS)
  442.       {
  443.        wsprintf(ti[i].szInfo,"");
  444.       }
  445.       wsprintf(sztemp,"Timerflag%d",i);
  446.       lRetCode=RegQueryValueEx(hKey1,sztemp,NULL,&dwtemp,(LPBYTE)(&dwDate),&dwDateSize);
  447.       if (lRetCode != ERROR_SUCCESS)
  448. ti[i].nflag=0;
  449.       else
  450.        ti[i].nflag=(WORD)dwDate;
  451.    }
  452. }
  453. #pragma argsused
  454. void ListDel1(int x)
  455. {
  456. int i;
  457.    //char sztemp[20];
  458.    HKEY  hKey1;//, hKey2;
  459.    DWORD  dwDisposition;
  460.    //LONG   lRetCode;    DWORD dwFlag=(DWORD)nTimerNum,dwDateSize=sizeof(DWORD);    //char cmd[150]="SOFTWARE\phonix\sharewareluncher\";    char sz[150];
  461.    RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\phonix\sharewareluncher",0, NULL, REG_OPTION_NON_VOLATILE,                            KEY_ALL_ACCESS,NULL,&hKey1,&dwDisposition);
  462. RegSetValueEx ( hKey1,"tiNum",NULL,REG_DWORD,(LPBYTE)(&dwFlag),dwDateSize);
  463.    if(bNoShowDel)
  464.    {
  465.     for(i=x;i<nTimerNum;i++)
  466.     {
  467.     ti[i]=ti[i+1];
  468.     }
  469.       bNoShowDel=FALSE;
  470.    }
  471.    ti[nTimerNum].wHour=0;
  472.    ti[nTimerNum].wMinute=0;
  473.    wsprintf(ti[nTimerNum].szInfo,"");
  474.    wsprintf(ti[nTimerNum].szTimerString,"");
  475.    ti[nTimerNum].nflag=0;
  476.    wsprintf(sz,"TimerHour%d",nTimerNum);
  477.    RegDeleteValue(hKey1,sz);
  478.    wsprintf(sz,"TimerMinute%d",nTimerNum);
  479.    RegDeleteValue(hKey1,sz);
  480.    wsprintf(sz,"TimerChar%d",nTimerNum);
  481.    RegDeleteValue(hKey1,sz);
  482.    wsprintf(sz,"Timerflag%d",nTimerNum);
  483.    RegDeleteValue(hKey1,sz);
  484. }
  485. void TtoS(int a,int b,int c)
  486. {
  487. titemp=ti[c];
  488. if(a<10)
  489.     wsprintf(ti[c].szTimerString,"0%d:",a);
  490.    else
  491.     wsprintf(ti[c].szTimerString,"%d:",a);
  492.    if(b<10)
  493.     wsprintf(ti[c].szTimerString,"%s0%d",ti[c].szTimerString,b);
  494.    else
  495.     wsprintf(ti[c].szTimerString,"%s%d",ti[c].szTimerString,b);
  496.    ti[c].wHour=(WORD)a;
  497.    ti[c].wMinute=(WORD)b;
  498. }
  499. void WriteTimerInfo(void)
  500. {
  501. int i;
  502. char sztemp[20];
  503.    HKEY  hKey1;//, hKey2;
  504.    DWORD  dwDisposition;
  505.    LONG   lRetCode;    DWORD dwFlag=(DWORD)nTimerNum,dwDateSize=sizeof(DWORD);
  506.    lRetCode=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\phonix\sharewareluncher",0, NULL, REG_OPTION_NON_VOLATILE,                            KEY_ALL_ACCESS,NULL,&hKey1,&dwDisposition);
  507.    if (lRetCode != ERROR_SUCCESS)
  508.    {
  509.       Errmsg("Error in creating keyn");//,"Error",MB_OK);
  510.       return;//break;
  511.    }
  512. lRetCode = RegSetValueEx ( hKey1,"tiNum",NULL,REG_DWORD,(LPBYTE)(&dwFlag),dwDateSize);
  513.       // if we failed, note it, and leave
  514.    if (lRetCode != ERROR_SUCCESS)
  515. {
  516.       Errmsg("Error in getting Section1 valuen");//,"Reg Error",MB_OK);
  517.       return;
  518.    }
  519.    for(i=0;i<nTimerNum;i++)
  520.    {
  521. wsprintf(sztemp,"TimerHour%d",i);
  522.       dwFlag=ti[i].wHour;
  523.       RegSetValueEx ( hKey1,sztemp,NULL,REG_DWORD,(LPBYTE)(&dwFlag),dwDateSize);
  524.       wsprintf(sztemp,"TimerMinute%d",i);
  525.       dwFlag=ti[i].wMinute;
  526.       RegSetValueEx ( hKey1,sztemp,NULL,REG_DWORD,(LPBYTE)(&dwFlag),dwDateSize);
  527.       wsprintf(sztemp,"TimerChar%d",i);
  528.       RegSetValueEx ( hKey1,sztemp,NULL,REG_SZ,(LPBYTE)(ti[i].szInfo),dwDateSize);
  529.       wsprintf(sztemp,"Timerflag%d",i);
  530.       dwFlag=ti[i].nflag;
  531.       RegSetValueEx ( hKey1,sztemp,NULL,REG_DWORD,(LPBYTE)(&dwFlag),dwDateSize);
  532.    }
  533. }
  534. void RegAlarm(void)
  535. {
  536. HKEY  hKey1;//, hKey2;
  537.    DWORD  dwDisposition;
  538.    LONG   lRetCode;    DWORD dwFlag=(DWORD)nAlarmEveryHour,dwDateSize=sizeof(DWORD);
  539.    lRetCode=RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\phonix\sharewareluncher",0, NULL, REG_OPTION_NON_VOLATILE,                            KEY_ALL_ACCESS,NULL,&hKey1,&dwDisposition);
  540.    if (lRetCode != ERROR_SUCCESS)
  541.    {
  542.       Errmsg("Error in creating keyn");//,"Error",MB_OK);
  543.       return;//break;
  544.    }
  545. lRetCode = RegSetValueEx ( hKey1,"AlarmEveryHour",NULL,REG_DWORD,(LPBYTE)(&dwFlag),dwDateSize);
  546.       // if we failed, note it, and leave
  547.    if (lRetCode != ERROR_SUCCESS)
  548.    Errmsg("Error in getting Section1 valuen");//,"Reg Error",MB_OK);
  549. }
  550. void DoTimerChange(HWND hWnd)
  551. {
  552.    int i,j,a,b;
  553. i=SendMessage(hListWnd,LB_GETCURSEL,0,0);
  554.    if(i==LB_ERR)
  555.    {
  556.       nOldSel=-2;
  557.       return;
  558.    }
  559.    j=SendMessage(hListWnd, LB_GETITEMDATA, i, (LPARAM) 0);
  560.    a=GetDlgItemInt(hWnd,IDC_SETHOUR,NULL,FALSE);
  561.    if(a<0 || a>23)
  562.     a=0;
  563.    b=GetDlgItemInt(hWnd,IDC_SETMIN,NULL,FALSE);
  564.    if(b<0 || b>59)
  565.     b=0;
  566.    TtoS(a,b,j);
  567.    {
  568.     int x;
  569.       BOOL bf=FALSE;
  570.       for(x=0;x<nTimerNum;x++)
  571.       {
  572.        if(x!=j)
  573.           if(strcmp(ti[j].szTimerString,ti[x].szTimerString)==0)
  574.           {
  575.           bf=TRUE;
  576.              break;
  577.           }
  578.       }
  579.       if(bf)
  580.       {
  581.        ti[j]=titemp;
  582.          return;
  583.       }
  584.       SendMessage(hListWnd,LB_DELETESTRING,i,0L);
  585.       SendMessage(hListWnd,LB_ADDSTRING,0,(LPARAM)(ti[j].szTimerString));
  586.       x=SendMessage(hListWnd,LB_FINDSTRING,-1,(LPARAM)(ti[j].szTimerString));
  587.       SendMessage(hListWnd,LB_SETITEMDATA, x, (LPARAM) j);
  588.       SendMessage(hListWnd,LB_SETCURSEL,x,0);
  589.       nOldSel=x;
  590.    }
  591. }