home *** CD-ROM | disk | FTP | other *** search
/ Online Software 2: 1,000 Utilities / TK_OJ9711.iso / accessor / TCL170.LZH / DLLSRC.lzh / startbtn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-27  |  10.5 KB  |  404 lines

  1. /*-------------------------------------------
  2. ü@STARTBTN.C
  3. ü@ü@âXâ^ü[âgâ{â^âôé╠ëⁿæó
  4. ü@ü@Copyright (C) KAZUBON 1997
  5. ---------------------------------------------*/
  6.  
  7. #include "tcdll.h"
  8.  
  9. extern HANDLE hmod;
  10.  
  11. /*------------------------------------------------
  12. ü@Globals
  13. --------------------------------------------------*/
  14. WNDPROC oldWndProcStart = NULL, oldWndProcTask = NULL;
  15. HWND hwndStart = NULL, hwndTask = NULL, hwndTray = NULL;
  16. HBITMAP hbmpstartold = NULL;
  17. int wStart = -1, hStart = -1;
  18.  
  19. static void SetStartButtonBmp(void);
  20. static void SetTaskWinPos(void);
  21.  
  22. /*------------------------------------------------
  23. ü@âXâ^ü[âgâ{â^âôé╠âTâuâNâëâXâvâìâVü[âWââ
  24. --------------------------------------------------*/
  25. LRESULT CALLBACK WndProcStart(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  26. {
  27.     switch(message)
  28.     {
  29.         case WM_SYSCOLORCHANGE:  // âVâXâeâÇé╠É▌ÆΦò╧ìX
  30.         case WM_WININICHANGE:
  31.             if(IsWindowVisible(hwnd))
  32.                 PostMessage(hwnd, WM_USER+10, 0, 0L);
  33.             return 0;
  34.         case (WM_USER + 10):     // ì─Åëè·ë╗
  35.             SetStartButtonBmp();
  36.             return 0;
  37.         case WM_WINDOWPOSCHANGING:  // âTâCâYé≡ò╧ìXé│é╣é╚éó
  38.         {
  39.             LPWINDOWPOS pwp;
  40.             pwp = (LPWINDOWPOS)lParam;
  41.             if(!(pwp->flags & SWP_NOSIZE))
  42.             {
  43.                 if(wStart > 0) pwp->cx = wStart;
  44.                 if(hStart > 0) pwp->cy = hStart;
  45.             }
  46.             if(!IsWindowVisible(hwnd))
  47.             {
  48.                 RECT rc; POINT pt;
  49.                 GetWindowRect(hwndTray, &rc);
  50.                 pt.x = rc.left; pt.y = rc.top;
  51.                 ScreenToClient(GetParent(hwndTray), &pt);
  52.                 pwp->x = pt.x; pwp->y = pt.y;
  53.                 pwp->cx = rc.right - rc.left;
  54.                 pwp->cy = rc.bottom - rc.top;
  55.             }
  56.             break;
  57.         }
  58.     }
  59.     return CallWindowProc(oldWndProcStart, hwnd, message, wParam, lParam);
  60. }
  61.  
  62. /*--------------------------------------------------
  63. ü@MSTaskSwWClassé╠âTâuâNâëâXâvâìâVü[âWââ
  64. ----------------------------------------------------*/
  65. LRESULT CALLBACK WndProcTask(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  66. {
  67.     switch(message)
  68.     {
  69.         case WM_WINDOWPOSCHANGING: // ê╩ÆuüEâTâCâYé╠ɺî└
  70.         {
  71.             LPWINDOWPOS pwp;
  72.             RECT rcBar, rcTray;
  73.     
  74.             pwp = (LPWINDOWPOS)lParam;
  75.             if((pwp->flags & SWP_NOMOVE) ||
  76.                 wStart < 0 || hStart < 0) break;
  77.             
  78.             GetClientRect(GetParent(hwndStart), &rcBar); // â^âXâNâoü[
  79.             GetWindowRect(hwndTray, &rcTray); // TrayNotifyWnd
  80.             
  81.             // â^âXâNâoü[é¬ëíÆué½é╠é╞é½
  82.             if(rcBar.right > rcBar.bottom)
  83.             {
  84.                 pwp->x = 2 + wStart; // ëEê╩Æu
  85.                 pwp->cx = rcTray.left - 2 - wStart - 2; // ëíò¥
  86.                 if(wStart > 0)
  87.                 {
  88.                     pwp->x += 2; pwp->cx -= 2;
  89.                 }
  90.             }
  91.             else // ÅcÆué½é╠é╞é½
  92.             {
  93.                 if(rcTray.top < pwp->y)
  94.                 {
  95.                     pwp->cy = rcBar.bottom - 2 - hStart - 2; // ìéé│
  96.                 }
  97.                 else
  98.                 {
  99.                     pwp->cy = rcTray.top - 2 - hStart - 2; // ìéé│
  100.                 }
  101.                 pwp->y = 2 + hStart; // Åπê╩Æu
  102.                 if(hStart > 0)
  103.                 {
  104.                     pwp->y += 1; pwp->cy -= 2;
  105.                 }
  106.             }
  107.             break;
  108.         }
  109.     }
  110.     return CallWindowProc(oldWndProcTask, hwnd, message, wParam, lParam);
  111. }
  112.  
  113. /*--------------------------------------------------
  114. ü@âXâ^ü[âgâ{â^âôé╠Åëè·ë╗
  115. ----------------------------------------------------*/
  116. void SetStartButton(HWND hwndClock)
  117. {
  118.     BOOL b, bHide;
  119.     HANDLE hwnd;
  120.     char classname[80];
  121.     
  122.     EndStartButton();
  123.     
  124.     if(!GetMyRegLong("StartButton", &b)) b = FALSE;
  125.     if(!GetMyRegLong("StartButtonHide", &bHide)) bHide = FALSE;
  126.     if(!b && !bHide) return;
  127.     
  128.     // "button"é╞"MSTaskSwWClass"é╠âEâBâôâhâEânâôâhâïé≡ô╛éΘ
  129.     hwndStart = hwndTask = NULL;
  130.     hwndTray = GetParent(hwndClock); // TrayNotifyWnd
  131.     hwnd = GetParent(hwndTray);      // Shell_TrayWnd
  132.     if(hwnd == NULL) return;
  133.     hwnd = GetWindow(hwnd, GW_CHILD);
  134.     while(hwnd)
  135.     {
  136.         GetClassName(hwnd, classname, 80);
  137.         if(_stricmp(classname, "button") == 0)
  138.             hwndStart = hwnd;
  139.         else if(_stricmp(classname, "MSTaskSwWClass") == 0)
  140.             hwndTask = hwnd;
  141.         else if(_stricmp(classname, "ReBarWindow32") == 0)
  142.             hwndTask = hwnd;
  143.         hwnd = GetWindow(hwnd, GW_HWNDNEXT);
  144.     }
  145.     if(hwndStart == NULL || hwndTask == NULL)
  146.     {
  147.         hwndStart = hwndTask = NULL; return;
  148.     }
  149.     
  150.     // âTâuâNâëâXë╗
  151.     oldWndProcStart = (WNDPROC)GetWindowLong(hwndStart, GWL_WNDPROC);
  152.     SetWindowLong(hwndStart, GWL_WNDPROC, (LONG)WndProcStart);
  153.     oldWndProcTask = (WNDPROC)GetWindowLong(hwndTask, GWL_WNDPROC);
  154.     SetWindowLong(hwndTask, GWL_WNDPROC, (LONG)WndProcTask);
  155.     
  156.     if(bHide) // â{â^âôé≡ëBé╖
  157.     {
  158.         RECT rc; POINT pt;
  159.         ShowWindow(hwndStart, SW_HIDE);
  160.         wStart = 0; hStart = 0;
  161.         GetWindowRect(hwndTray, &rc);
  162.         pt.x = rc.left; pt.y = rc.top;
  163.         ScreenToClient(GetParent(hwndTray), &pt);
  164.         SetWindowPos(hwndStart, NULL, pt.x, pt.y,
  165.             rc.right - rc.left, rc.bottom - rc.top,
  166.             SWP_NOZORDER|SWP_NOACTIVATE);
  167.     }
  168.     else
  169.     {
  170.         // â{â^âôùpârâbâgâ}âbâvé╠É▌ÆΦ
  171.         SetStartButtonBmp();
  172.     }
  173.     // MSTaskSwWClassé╠ê╩ÆuüEâTâCâYé╠É▌ÆΦ
  174.     SetTaskWinPos();
  175. }
  176.  
  177. /*--------------------------------------------------
  178. ü@âXâ^ü[âgâ{â^âôé≡î│é╔û▀é╖
  179. ----------------------------------------------------*/
  180. void EndStartButton(void)
  181. {
  182.     HBITMAP hbmpold;
  183.     
  184.     if(hwndStart && IsWindow(hwndStart))
  185.     {
  186.         if(hbmpstartold != NULL)
  187.         {
  188.             hbmpold = (HBITMAP)SendMessage(hwndStart, BM_SETIMAGE,
  189.                 0, (LPARAM)hbmpstartold);
  190.             DeleteObject(hbmpold); hbmpstartold = NULL;
  191.         }
  192.         if(oldWndProcStart)
  193.             SetWindowLong(hwndStart, GWL_WNDPROC, (LONG)oldWndProcStart);
  194.         oldWndProcStart = NULL;
  195.         SetWindowPos(hwndStart, NULL, 0, 0, 0, 0,
  196.             SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
  197.         ShowWindow(hwndStart, SW_SHOW);
  198.     }
  199.     hwndStart = NULL;
  200.     
  201.     if(hwndTask && IsWindow(hwndTask) && oldWndProcTask)
  202.         SetWindowLong(hwndTask, GWL_WNDPROC, (LONG)oldWndProcTask);
  203.     oldWndProcTask = NULL; hwndStart = NULL;
  204. }
  205.  
  206. /*--------------------------------------------------
  207. ü@âXâ^ü[âgâ{â^âôé╠ârâbâgâ}âbâvé╞âTâCâYé╠É▌ÆΦ
  208. ----------------------------------------------------*/
  209. void SetStartButtonBmp(void)
  210. {
  211.     char s[1024], caption[1024];
  212.     HBITMAP hbmp, hbmpicon, hbmpold;
  213.     HICON hicon;
  214.     HDC hdc, hdcMem;
  215.     HFONT hfont;
  216.     BITMAP bmp;
  217.     int whbmp, hhbmp, cxicon, cyicon;
  218.     BOOL b;
  219.  
  220.     if(hwndStart == NULL) return;
  221.     
  222.     hbmpicon = NULL; hicon = NULL;
  223.     cxicon = GetSystemMetrics(SM_CXSMICON);
  224.     cyicon = GetSystemMetrics(SM_CYSMICON);
  225.     
  226.     // âtâ@âCâïé⌐éτâAâCâRâôùpârâbâgâ}âbâvé╠ô╟é▌ì₧é▌
  227.     if(GetMyRegStr("StartButtonIcon", s) && s[0])
  228.     {
  229.         char fname[MAX_PATH], head[2];
  230.         HFILE hf;
  231.         
  232.         parse(fname, s, 0);
  233.         hf = _lopen(fname, OF_READ);
  234.         if(hf != HFILE_ERROR)
  235.         {
  236.             _lread(hf, head, 2);
  237.             _lclose(hf);
  238.             if(head[0] == 'B' && head[1] == 'M') //ârâbâgâ}âbâvé╠ÅΩìç
  239.                 hbmpicon = ReadBitmap(hwndStart, fname, TRUE);
  240.             else if(head[0] == 'M' && head[1] == 'Z') //Ä└ìsâtâ@âCâïé╠ÅΩìç
  241.             {
  242.                 char num[10]; int n;
  243.                 HICON hiconl;
  244.                 parse(num, s, 1);
  245.                 if(num[0] == 0) n = 0; else n = atoi(num);
  246.                 if(ExtractIconEx(fname, n, &hiconl, &hicon, 1) < 2)
  247.                     hicon = NULL;
  248.                 else DestroyIcon(hiconl);
  249.             }
  250.             else // âAâCâRâôé╠ÅΩìç
  251.             {
  252.                 hicon = (HICON)LoadImage(hmod, fname,
  253.                     IMAGE_ICON, cxicon, cyicon,
  254.                     LR_DEFAULTCOLOR|LR_LOADFROMFILE);
  255.             }
  256.         }
  257.     }
  258.     
  259.     if(hbmpicon)
  260.     {
  261.         GetObject(hbmpicon, sizeof(BITMAP), (LPVOID)&bmp);
  262.         cxicon = bmp.bmWidth; cyicon = bmp.bmHeight;
  263.     }
  264.  
  265.     // âLâââvâVâçâôé╠ĵô╛
  266.     if(!GetMyRegStr("StartButtonCaption", caption))
  267.         caption[0] = 0;
  268.     
  269.     hdc = GetDC(hwndStart);
  270.     
  271.     // â{â^âôùpé╠âtâHâôâg = â^âCâgâïâoü[é╠âtâHâôâg + BOLD
  272.     hfont = NULL;
  273.     whbmp = cxicon; hhbmp = cyicon;
  274.     if(caption[0])
  275.     {
  276.         NONCLIENTMETRICS ncm;
  277.         SIZE sz;
  278.         ncm.cbSize = sizeof(ncm);
  279.         SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  280.         ncm.lfCaptionFont.lfWeight = FW_BOLD;
  281.         hfont =  CreateFontIndirect(&(ncm.lfCaptionFont));
  282.         SelectObject(hdc, hfont);
  283.         
  284.         //âLâââvâVâçâôé╠ò¥é≡ô╛éΘ
  285.         GetTextExtentPoint32(hdc, caption, strlen(caption), &sz);
  286.         whbmp = sz.cx;
  287.         if(hbmpicon || hicon) whbmp += cxicon + 2;
  288.         hhbmp = sz.cy;
  289.         if((hbmpicon || hicon) && cyicon > sz.cy)
  290.             hhbmp = cyicon;
  291.         //if(hhbmp < 16) hhbmp = 16;
  292.     }
  293.     
  294.     // ârâbâgâ}âbâvé╠ì∞ɼ
  295.     hdcMem = CreateCompatibleDC(hdc);
  296.     hbmp = CreateCompatibleBitmap(hdc, whbmp, hhbmp);
  297.     SelectObject(hdcMem, hbmp);
  298.     
  299.     { // öwîiÉFé┼ôhéΦé┬é╘é╡
  300.         RECT rc; HBRUSH hbr;
  301.         SetRect(&rc, 0, 0, whbmp, hhbmp);
  302.         hbr = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
  303.         FillRect(hdcMem, &rc, hbr);
  304.         DeleteObject(hbr);
  305.     }
  306.     
  307.     // ârâbâgâ}âbâvé╔âAâCâRâôé╠èGé≡ò`ëµ
  308.     if(hbmpicon)
  309.     {
  310.         HDC hdcicon;
  311.         hdcicon = CreateCompatibleDC(hdc);
  312.         SelectObject(hdcicon, hbmpicon);
  313.         BitBlt(hdcMem, 0, (hhbmp - cyicon)/2,
  314.             cxicon, cyicon, hdcicon, 0, 0, SRCCOPY);
  315.         DeleteDC(hdcicon);
  316.         DeleteObject(hbmpicon);
  317.     }
  318.     if(hicon)
  319.     {
  320.         DrawIconEx(hdcMem, 0, (hhbmp - cyicon)/2,
  321.             hicon, cxicon, cyicon, 0, NULL, DI_NORMAL);
  322.         DestroyIcon(hicon);
  323.     }
  324.     
  325.     // ârâbâgâ}âbâvé╔âLâââvâVâçâôé≡Åæé¡
  326.     if(caption[0])
  327.     {
  328.         TEXTMETRIC tm;
  329.         int x, y;
  330.  
  331.         GetTextMetrics(hdc, &tm);
  332.         SelectObject(hdcMem, hfont);
  333.         x = 0; if(hbmpicon || hicon) x = cxicon + 2;
  334.         y = (hhbmp - tm.tmHeight) / 2;
  335.         SetBkMode(hdcMem, TRANSPARENT);
  336.         SetTextColor(hdcMem, GetSysColor(COLOR_BTNTEXT));
  337.         TextOut(hdcMem, x, y, caption, strlen(caption));
  338.     }
  339.     
  340.     DeleteDC(hdcMem);
  341.     ReleaseDC(hwndStart, hdc);
  342.     if(hfont) DeleteObject(hfont);
  343.  
  344.     // â{â^âôé╔ârâbâgâ}âbâvé≡É▌ÆΦ
  345.     hbmpold = (HICON)SendMessage(hwndStart, BM_SETIMAGE, 0, (LPARAM)hbmp);
  346.     // ê╚æOé╠ârâbâgâ}âbâvé≡ò█æ╢ / öjèⁿ
  347.     if(hbmpstartold == NULL) hbmpstartold = hbmpold;
  348.     else DeleteObject(hbmpold);
  349.     
  350.     // â{â^âôé╠âTâCâYé╠É▌ÆΦ  Åπî└üF160x80
  351.     wStart = whbmp + 8;
  352.     if(wStart > 160) wStart = 160;
  353.     hStart = GetSystemMetrics(SM_CYCAPTION) + 3;
  354.     if(hhbmp + 6 > hStart) hStart = hhbmp + 6;
  355.     if(hStart > 80) hStart = 80;
  356.     SetWindowPos(hwndStart, NULL, 0, 0,
  357.         wStart, hStart,
  358.         SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  359. }
  360.  
  361. /*--------------------------------------------------
  362. ü@MSTaskSwWClassé╠ê╩ÆuüEâTâCâYé╠É▌ÆΦ
  363. ----------------------------------------------------*/
  364. void SetTaskWinPos(void)
  365. {
  366.     RECT rcBar, rcTask, rcTray;
  367.     POINT pt;
  368.     int x, y, w, h;
  369.  
  370.     GetClientRect(GetParent(hwndStart), &rcBar);  // Shell_TrayWnd
  371.     GetWindowRect(hwndTray, &rcTray); // TrayNotifyWnd
  372.     GetWindowRect(hwndTask, &rcTask);             // MSTaskSwWClass
  373.     
  374.     // MSTaskSwWClassé╠ëEÅπê╩Æu
  375.     pt.x = rcTask.left; pt.y = rcTask.top;
  376.     ScreenToClient(GetParent(hwndStart), &pt);
  377.     
  378.     x = pt.x; y = pt.y;
  379.     w = rcTask.right - rcTask.left;
  380.     h = rcTask.bottom - rcTask.top;
  381.     
  382.     // â^âXâNâoü[é¬ëíÆué½é╠é╞é½
  383.     if(rcBar.right > rcBar.bottom)
  384.     {
  385.         x = 2 + wStart;
  386.         w = rcTray.left - 2 - wStart - 2;
  387.         if(wStart > 0)
  388.         {
  389.             x += 2; w -= 2;
  390.         }
  391.     }
  392.     else // ÅcÆué½é╠é╞é½
  393.     {
  394.         y = 2 + hStart;
  395.         h = rcTray.top - 2 - hStart - 2;
  396.         if(hStart > 0)
  397.         {
  398.             y += 1; h -= 2;
  399.         }
  400.     }
  401.     SetWindowPos(hwndTask, NULL, x, y, w, h,
  402.         SWP_NOZORDER|SWP_NOACTIVATE);
  403. }
  404.