home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 June / VPR0106A.BIN / OLS / TCL228 / TCL228.lzh / EXESRC.lzh / propsheet.c < prev    next >
C/C++ Source or Header  |  1999-09-18  |  5KB  |  197 lines

  1. /*-------------------------------------------
  2.  PROPSHEET.C
  3.   設定用プロパティシートの表示
  4.   KAZUBON 1997-1998
  5. ---------------------------------------------*/
  6.  
  7. #include "tclock.h"
  8.  
  9. int CALLBACK PropSheetProc(HWND hDlg, UINT uMsg, LPARAM  lParam);
  10. LRESULT CALLBACK SubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  11. void SetMyDialgPos(HWND hwnd);
  12.  
  13. //各プロパティページ用ダイアログプロシージャ
  14. BOOL CALLBACK PageColorProc(HWND, UINT, WPARAM, LPARAM);
  15. BOOL CALLBACK PageFormatProc(HWND, UINT, WPARAM, LPARAM);
  16. BOOL CALLBACK PageAlarmProc(HWND, UINT, WPARAM, LPARAM);
  17. BOOL CALLBACK PageMouseProc(HWND, UINT, WPARAM, LPARAM);
  18. BOOL CALLBACK PageTaskbarProc(HWND, UINT, WPARAM, LPARAM);
  19. BOOL CALLBACK PageSNTPProc(HWND, UINT, WPARAM, LPARAM);
  20. BOOL CALLBACK PageMiscProc(HWND, UINT, WPARAM, LPARAM);
  21. BOOL CALLBACK PageAboutProc(HWND, UINT, WPARAM, LPARAM);
  22.  
  23. void SetPropSheetPos(HWND hwnd);
  24.  
  25. static WNDPROC oldWndProc; //以前のウィンドウプロシージャの保存
  26. static int startpage = 0;  //最初に表示するページ
  27.  
  28. /*-------------------------------------------
  29.  プロパティシートの表示
  30. ---------------------------------------------*/
  31. void MyPropertySheet(void)
  32. {
  33.     PROPSHEETPAGE psp[8];
  34.     PROPSHEETHEADER psh;
  35.     DLGPROC PageProc[8] = { PageColorProc, PageFormatProc,
  36.         PageAlarmProc, PageMouseProc, PageTaskbarProc, PageSNTPProc,
  37.         PageMiscProc, PageAboutProc };
  38.     int i;
  39.     
  40.     if(hwndSheet && IsWindow(hwndSheet))
  41.     {
  42.         SetForegroundWindow98(hwndSheet); return;
  43.     }
  44.     
  45.     //プロパティページの設定
  46.     for(i = 0; i < 8; i++)
  47.     {
  48.         memset(&psp[i], 0, sizeof(PROPSHEETPAGE));
  49.         psp[i].dwSize = sizeof(PROPSHEETPAGE);
  50.         psp[i].dwFlags = PSP_HASHELP;
  51.         psp[i].hInstance = hInst;
  52.         psp[i].pszTemplate = MAKEINTRESOURCE(IDD_PAGECOLOR + i);
  53.         psp[i].pfnDlgProc = PageProc[i];
  54.     }
  55.     
  56.     //プロパティシートの設定
  57.     memset(&psh, 0, sizeof(PROPSHEETHEADER));
  58.     psh.dwSize = sizeof(PROPSHEETHEADER);
  59.     //アイコン表示、ppspを使う、
  60.     //モードレス、コールバックを使う、ヘルプあり
  61.     psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE |
  62.         PSH_MODELESS | PSH_USECALLBACK | PSH_HASHELP;
  63.     psh.hInstance = hInst;
  64.     psh.pszIcon = MAKEINTRESOURCE(IDI_ICON1);
  65.     psh.pszCaption = MyString(IDS_PROPERTY);
  66.     psh.nPages = 8;
  67.     psh.nStartPage = startpage;
  68.     psh.ppsp = psp;
  69.     psh.pfnCallback = PropSheetProc;
  70.  
  71.     //プロパティシートの表示
  72.     //ウィンドウハンドルをグローバル変数に保存
  73.     hwndSheet = (HWND)PropertySheet(&psh);
  74.     SetForegroundWindow98(hwndSheet);
  75. }
  76.  
  77. /*-------------------------------------------
  78.  プロパティシート用コールバック
  79. ---------------------------------------------*/
  80. int CALLBACK PropSheetProc(HWND hDlg, UINT uMsg, LPARAM  lParam)
  81. {
  82.     LONG style;
  83.     
  84.     if(uMsg == PSCB_INITIALIZED)
  85.     {
  86.         //「?」ボタンを消す
  87.         style = GetWindowLong(hDlg, GWL_EXSTYLE);
  88.         style ^= WS_EX_CONTEXTHELP;
  89.         SetWindowLong(hDlg, GWL_EXSTYLE, style);
  90.         
  91.         //サブクラス化する
  92.         oldWndProc = (WNDPROC)SetWindowLong(hDlg, GWL_WNDPROC,
  93.             (LONG)SubclassProc);
  94.         
  95.         SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIconTClock);
  96.     }
  97.     return 0;
  98. }
  99.  
  100. /*--------------------------------------------------
  101.  プロパティシート用サブクラスウィンドウプロシージャ
  102. ----------------------------------------------------*/
  103. LRESULT CALLBACK SubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  104. {
  105.     LRESULT l;
  106.     
  107.     switch(message)
  108.     {
  109.         case WM_SHOWWINDOW: // ウィンドウを画面の中心に
  110.             SetMyDialgPos(hwnd);
  111.             return 0;
  112.     }
  113.     
  114.     //デフォルトの処理
  115.     l = CallWindowProc(oldWndProc, hwnd, message, wParam, lParam);
  116.     
  117.     switch(message)
  118.     {
  119.         case WM_COMMAND:
  120.         {
  121.             WORD id;
  122.             id = LOWORD(wParam);
  123.             //OK、キャンセルボタンで閉じる
  124.             if(id == IDOK || id == IDCANCEL)
  125.             {
  126.                 MyHelp(hwnd, -1);
  127.                 startpage = SendMessage(
  128.                     (HWND)SendMessage(hwnd, PSM_GETTABCONTROL, 0, 0),
  129.                     TCM_GETCURSEL, 0, 0);
  130.                 if(startpage < 0) startpage = 0;
  131.                 DestroyWindow(hwnd);
  132.                 hwndSheet = NULL;
  133.             }
  134.             //「OK」「更新」ボタンで時計を更新
  135.             if(id == IDOK || id == 0x3021)
  136.             {
  137.                 InitAlarm();
  138.                 InitWatchWallpaper();
  139.                 PostMessage(hwndClock, WM_USER+1, 0, 0);
  140.             }
  141.             break;
  142.         }
  143.         //「×」ボタンでキャンセル
  144.         case WM_SYSCOMMAND:
  145.         {
  146.             if((wParam & 0xfff0) == SC_CLOSE)
  147.                 PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0);
  148.             break;
  149.         }
  150.     }
  151.     return l;
  152. }
  153.  
  154. /*------------------------------------------------
  155.  ダイアログの表示位置調整
  156. --------------------------------------------------*/
  157. void SetMyDialgPos(HWND hwnd)
  158. {
  159.     HWND hwndTray;
  160.     RECT rc, rcTray;
  161.     int wscreen, hscreen, wProp, hProp;
  162.     int x, y;
  163.  
  164.     GetWindowRect(hwnd, &rc);
  165.     wProp = rc.right - rc.left;
  166.     hProp = rc.bottom - rc.top;
  167.     
  168.     wscreen = GetSystemMetrics(SM_CXSCREEN);
  169.     hscreen = GetSystemMetrics(SM_CYSCREEN);
  170.     
  171.     hwndTray = FindWindow("Shell_TrayWnd", NULL);
  172.     if(hwndTray == NULL) return;
  173.     GetWindowRect(hwndTray, &rcTray);
  174.     if(rcTray.right - rcTray.left > 
  175.         rcTray.bottom - rcTray.top)
  176.     {
  177.         x = wscreen - wProp - 32;
  178.         if(rcTray.top < hscreen / 2)
  179.             y = rcTray.bottom + 2;
  180.         else
  181.             y = rcTray.top - hProp - 32;
  182.         if(y < 0) y = 0;
  183.     }
  184.     else
  185.     {
  186.         y = hscreen - hProp - 2;
  187.         if(rcTray.left < wscreen / 2)
  188.             x = rcTray.right + 2;
  189.         else
  190.             x = rcTray.left - wProp - 2;
  191.         if(x < 0) x = 0;
  192.     }
  193.  
  194.     MoveWindow(hwnd, x, y, wProp, hProp, FALSE);
  195. }
  196.  
  197.