home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 December (Special) / DOSV2002_12.iso / utility / tcl230ja95.lzh / source.lzh / exe / propsheet.c < prev    next >
C/C++ Source or Header  |  2001-02-10  |  7KB  |  283 lines

  1. /*-------------------------------------------
  2.   propsheet.c
  3.   show "properties for TClock"
  4.   Kazubon 1997-2001
  5. ---------------------------------------------*/
  6.  
  7. #include "tclock.h"
  8.  
  9. #define MAX_PAGE  9
  10.  
  11. int CALLBACK PropSheetProc(HWND hDlg, UINT uMsg, LPARAM  lParam);
  12. LRESULT CALLBACK SubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  13. void SetMyDialgPos(HWND hwnd);
  14.  
  15. // dialog procedures of each page
  16. BOOL CALLBACK PageColorProc(HWND, UINT, WPARAM, LPARAM);
  17. BOOL CALLBACK PageFormatProc(HWND, UINT, WPARAM, LPARAM);
  18. BOOL CALLBACK PageAlarmProc(HWND, UINT, WPARAM, LPARAM);
  19. BOOL CALLBACK PageMouseProc(HWND, UINT, WPARAM, LPARAM);
  20. BOOL CALLBACK PageSkinProc(HWND, UINT, WPARAM, LPARAM);
  21. BOOL CALLBACK PageTaskbarProc(HWND, UINT, WPARAM, LPARAM);
  22. BOOL CALLBACK PageSNTPProc(HWND, UINT, WPARAM, LPARAM);
  23. BOOL CALLBACK PageMiscProc(HWND, UINT, WPARAM, LPARAM);
  24. BOOL CALLBACK PageAboutProc(HWND, UINT, WPARAM, LPARAM);
  25.  
  26. void SetPropSheetPos(HWND hwnd);
  27.  
  28. static WNDPROC oldWndProc; // to save default window procedure
  29. static int startpage = 0;  // page to open first
  30.  
  31. BOOL g_bApplyClock = FALSE;
  32. BOOL g_bApplyTaskbar = FALSE;
  33. BOOL g_bApplyLangDLL = FALSE;
  34.  
  35. // menu.c
  36. extern HMENU g_hMenu;
  37.  
  38. /*-------------------------------------------
  39.   show property sheet
  40. ---------------------------------------------*/
  41. void MyPropertySheet(void)
  42. {
  43.     PROPSHEETPAGE psp[MAX_PAGE];
  44.     PROPSHEETHEADER psh;
  45.     DLGPROC PageProc[MAX_PAGE] = { PageColorProc, PageFormatProc,
  46.         PageAlarmProc, PageMouseProc, PageSkinProc, PageTaskbarProc,
  47.         PageSNTPProc, PageMiscProc, PageAboutProc };
  48.     int i;
  49.     
  50.     // already opened
  51.     if(g_hwndSheet && IsWindow(g_hwndSheet))
  52.     {
  53.         SetForegroundWindow98(g_hwndSheet); return;
  54.     }
  55.     
  56.     // set data of each page
  57.     for(i = 0; i < MAX_PAGE; i++)
  58.     {
  59.         memset(&psp[i], 0, sizeof(PROPSHEETPAGE));
  60.         psp[i].dwSize = sizeof(PROPSHEETPAGE);
  61.         psp[i].dwFlags = PSP_HASHELP;
  62.         psp[i].hInstance = GetLangModule();
  63.         psp[i].pszTemplate = MAKEINTRESOURCE(IDD_PAGECOLOR + i);
  64.         psp[i].pfnDlgProc = PageProc[i];
  65.     }
  66.     
  67.     // set data of property sheet
  68.     memset(&psh, 0, sizeof(PROPSHEETHEADER));
  69.     psh.dwSize = sizeof(PROPSHEETHEADER);
  70.     psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE |
  71.         PSH_MODELESS | PSH_USECALLBACK | PSH_HASHELP;
  72.     psh.hInstance = g_hInst;
  73.     psh.pszIcon = MAKEINTRESOURCE(IDI_ICON1);
  74.     psh.pszCaption = MyString(IDS_PROPERTY);
  75.     psh.nPages = MAX_PAGE;
  76.     psh.nStartPage = startpage;
  77.     psh.ppsp = psp;
  78.     psh.pfnCallback = PropSheetProc;
  79.     
  80.     g_bApplyClock = FALSE;
  81.     g_bApplyTaskbar = FALSE;
  82.     g_bApplyLangDLL = FALSE;
  83.     
  84.     // show it !
  85.     g_hwndSheet = (HWND)PropertySheet(&psh);
  86.     SetForegroundWindow98(g_hwndSheet);
  87. }
  88.  
  89. /*-------------------------------------------
  90.   callback procedure of property sheet
  91. ---------------------------------------------*/
  92. int CALLBACK PropSheetProc(HWND hDlg, UINT uMsg, LPARAM  lParam)
  93. {
  94.     LONG style;
  95.     
  96.     if(uMsg == PSCB_INITIALIZED)
  97.     {
  98.         // hide ? button
  99.         style = GetWindowLong(hDlg, GWL_EXSTYLE);
  100.         style ^= WS_EX_CONTEXTHELP;
  101.         SetWindowLong(hDlg, GWL_EXSTYLE, style);
  102.         
  103.         // subclass the window
  104.         oldWndProc = (WNDPROC)SetWindowLong(hDlg, GWL_WNDPROC,
  105.             (LONG)SubclassProc);
  106.         
  107.         SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)g_hIconTClock);
  108.     }
  109.     return 0;
  110. }
  111.  
  112. /*--------------------------------------------------------
  113.    window procedure of subclassed property sheet
  114. ---------------------------------------------------------*/
  115. LRESULT CALLBACK SubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  116. {
  117.     LRESULT l;
  118.     
  119.     switch(message)
  120.     {
  121.         case WM_SHOWWINDOW: // adjust the window position
  122.             SetMyDialgPos(hwnd);
  123.             return 0;
  124.     }
  125.     
  126.     // default
  127.     l = CallWindowProc(oldWndProc, hwnd, message, wParam, lParam);
  128.     
  129.     switch(message)
  130.     {
  131.         case WM_COMMAND:
  132.         {
  133.             WORD id;
  134.             id = LOWORD(wParam);
  135.             // close the window by "OK" or "Cancel"
  136.             if(id == IDOK || id == IDCANCEL)
  137.             {
  138.                 // MyHelp(hwnd, -1);
  139.                 startpage = SendMessage(
  140.                     (HWND)SendMessage(hwnd, PSM_GETTABCONTROL, 0, 0),
  141.                     TCM_GETCURSEL, 0, 0);
  142.                 if(startpage < 0) startpage = 0;
  143.                 DestroyWindow(hwnd);
  144.                 g_hwndSheet = NULL;
  145.             }
  146.             // apply settings
  147.             if(id == IDOK || id == 0x3021)
  148.             {
  149.                 if(g_bApplyClock)
  150.                 {
  151.                     PostMessage(g_hwndClock, CLOCKM_REFRESHCLOCK, 0, 0);
  152.                     g_bApplyClock = FALSE;
  153.                 }
  154.                 if(g_bApplyTaskbar)
  155.                 {
  156.                     PostMessage(g_hwndClock, CLOCKM_REFRESHTASKBAR, 0, 0);
  157.                     g_bApplyTaskbar = FALSE;
  158.                 }
  159.             }
  160.             if(id == IDOK || id == IDCANCEL)
  161.             {
  162.                 // reload language dll
  163.                 if(g_bApplyLangDLL)
  164.                 {
  165.                     char fname[MAX_PATH];
  166.                     HINSTANCE hInst;
  167.                     hInst = LoadLanguageDLL(fname);
  168.                     if(hInst != NULL)
  169.                     {
  170.                         if(g_hDlgTimer && IsWindow(g_hDlgTimer))
  171.                             PostMessage(g_hDlgTimer, WM_CLOSE, 0, 0);
  172.                         if(g_hMenu) DestroyMenu(g_hMenu);
  173.                         g_hMenu = NULL;
  174.                         if(g_hInstResource) FreeLibrary(g_hInstResource);
  175.                         g_hInstResource = hInst;
  176.                         strcpy(g_langdllname, fname);
  177.                     }
  178.                 }
  179.             }
  180.             break;
  181.         }
  182.         // close by "x" button
  183.         case WM_SYSCOMMAND:
  184.         {
  185.             if((wParam & 0xfff0) == SC_CLOSE)
  186.                 PostMessage(hwnd, WM_COMMAND, IDCANCEL, 0);
  187.             break;
  188.         }
  189.     }
  190.     return l;
  191. }
  192.  
  193. /*------------------------------------------------
  194.    adjust the window position
  195. --------------------------------------------------*/
  196. void SetMyDialgPos(HWND hwnd)
  197. {
  198.     HWND hwndTray;
  199.     RECT rc, rcTray;
  200.     int wscreen, hscreen, wProp, hProp;
  201.     int x, y;
  202.  
  203.     GetWindowRect(hwnd, &rc);
  204.     wProp = rc.right - rc.left;
  205.     hProp = rc.bottom - rc.top;
  206.     
  207.     wscreen = GetSystemMetrics(SM_CXSCREEN);
  208.     hscreen = GetSystemMetrics(SM_CYSCREEN);
  209.     
  210.     hwndTray = FindWindow("Shell_TrayWnd", NULL);
  211.     if(hwndTray == NULL) return;
  212.     GetWindowRect(hwndTray, &rcTray);
  213.     if(rcTray.right - rcTray.left > 
  214.         rcTray.bottom - rcTray.top)
  215.     {
  216.         x = wscreen - wProp - 32;
  217.         if(rcTray.top < hscreen / 2)
  218.             y = rcTray.bottom + 2;
  219.         else
  220.             y = rcTray.top - hProp - 32;
  221.         if(y < 0) y = 0;
  222.     }
  223.     else
  224.     {
  225.         y = hscreen - hProp - 2;
  226.         if(rcTray.left < wscreen / 2)
  227.             x = rcTray.right + 2;
  228.         else
  229.             x = rcTray.left - wProp - 2;
  230.         if(x < 0) x = 0;
  231.     }
  232.  
  233.     MoveWindow(hwnd, x, y, wProp, hProp, FALSE);
  234. }
  235.  
  236. /*------------------------------------------------
  237.    select file
  238. --------------------------------------------------*/
  239. BOOL SelectMyFile(HWND hDlg, const char *filter, DWORD nFilterIndex,
  240.     const char *deffile, char *retfile)
  241. {
  242.     OPENFILENAME ofn;
  243.     char fname[MAX_PATH], ftitle[MAX_PATH], initdir[MAX_PATH];
  244.     BOOL r;
  245.     
  246.     memset(&ofn, '\0', sizeof(OPENFILENAME));
  247.     
  248.     strcpy(initdir, g_mydir);
  249.     if(deffile[0])
  250.     {
  251.         WIN32_FIND_DATA fd;
  252.         HANDLE hfind;
  253.         hfind = FindFirstFile(deffile, &fd);
  254.         if(hfind != INVALID_HANDLE_VALUE)
  255.         {
  256.             FindClose(hfind);
  257.             strcpy(initdir, deffile);
  258.             del_title(initdir);
  259.         }
  260.     }
  261.     
  262.     fname[0] = 0;
  263.     ofn.lStructSize = sizeof(OPENFILENAME);
  264.     ofn.hwndOwner = hDlg;
  265.     ofn.hInstance = g_hInst;
  266.     ofn.lpstrFilter = filter;
  267.     ofn.nFilterIndex = nFilterIndex;
  268.     ofn.lpstrFile= fname;
  269.     ofn.nMaxFile = MAX_PATH;
  270.     ofn.lpstrFileTitle = ftitle;
  271.     ofn.nMaxFileTitle = MAX_PATH;
  272.     ofn.lpstrInitialDir = initdir;
  273.     ofn.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_FILEMUSTEXIST;
  274.     
  275.     r = GetOpenFileName(&ofn);
  276.     if(!r) return r;
  277.     
  278.     strcpy(retfile, ofn.lpstrFile);
  279.     
  280.     return r;
  281. }
  282.  
  283.