home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------
- ü@STARTBTN.C
- ü@ü@âXâ^ü[âgâ{â^âôé╠ëⁿæó
- ü@ü@Copyright (C) KAZUBON 1997
- ---------------------------------------------*/
-
- #include "tcdll.h"
-
- extern HANDLE hmod;
-
- /*------------------------------------------------
- ü@Globals
- --------------------------------------------------*/
- WNDPROC oldWndProcStart = NULL, oldWndProcTask = NULL;
- HWND hwndStart = NULL, hwndTask = NULL, hwndTray = NULL;
- HBITMAP hbmpstartold = NULL;
- int wStart = -1, hStart = -1;
-
- static void SetStartButtonBmp(void);
- static void SetTaskWinPos(void);
-
- /*------------------------------------------------
- ü@âXâ^ü[âgâ{â^âôé╠âTâuâNâëâXâvâìâVü[âWââ
- --------------------------------------------------*/
- LRESULT CALLBACK WndProcStart(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_SYSCOLORCHANGE: // âVâXâeâÇé╠É▌ÆΦò╧ìX
- case WM_WININICHANGE:
- if(IsWindowVisible(hwnd))
- PostMessage(hwnd, WM_USER+10, 0, 0L);
- return 0;
- case (WM_USER + 10): // ì─Åëè·ë╗
- SetStartButtonBmp();
- return 0;
- case WM_WINDOWPOSCHANGING: // âTâCâYé≡ò╧ìXé│é╣é╚éó
- {
- LPWINDOWPOS pwp;
- pwp = (LPWINDOWPOS)lParam;
- if(!(pwp->flags & SWP_NOSIZE))
- {
- if(wStart > 0) pwp->cx = wStart;
- if(hStart > 0) pwp->cy = hStart;
- }
- if(!IsWindowVisible(hwnd))
- {
- RECT rc; POINT pt;
- GetWindowRect(hwndTray, &rc);
- pt.x = rc.left; pt.y = rc.top;
- ScreenToClient(GetParent(hwndTray), &pt);
- pwp->x = pt.x; pwp->y = pt.y;
- pwp->cx = rc.right - rc.left;
- pwp->cy = rc.bottom - rc.top;
- }
- break;
- }
- }
- return CallWindowProc(oldWndProcStart, hwnd, message, wParam, lParam);
- }
-
- /*--------------------------------------------------
- ü@MSTaskSwWClassé╠âTâuâNâëâXâvâìâVü[âWââ
- ----------------------------------------------------*/
- LRESULT CALLBACK WndProcTask(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- {
- case WM_WINDOWPOSCHANGING: // ê╩ÆuüEâTâCâYé╠ɺî└
- {
- LPWINDOWPOS pwp;
- RECT rcBar, rcTray;
-
- pwp = (LPWINDOWPOS)lParam;
- if((pwp->flags & SWP_NOMOVE) ||
- wStart < 0 || hStart < 0) break;
-
- GetClientRect(GetParent(hwndStart), &rcBar); // â^âXâNâoü[
- GetWindowRect(hwndTray, &rcTray); // TrayNotifyWnd
-
- // â^âXâNâoü[é¬ëíÆué½é╠é╞é½
- if(rcBar.right > rcBar.bottom)
- {
- pwp->x = 2 + wStart; // ëEê╩Æu
- pwp->cx = rcTray.left - 2 - wStart - 2; // ëíò¥
- if(wStart > 0)
- {
- pwp->x += 2; pwp->cx -= 2;
- }
- }
- else // ÅcÆué½é╠é╞é½
- {
- if(rcTray.top < pwp->y)
- {
- pwp->cy = rcBar.bottom - 2 - hStart - 2; // ìéé│
- }
- else
- {
- pwp->cy = rcTray.top - 2 - hStart - 2; // ìéé│
- }
- pwp->y = 2 + hStart; // Åπê╩Æu
- if(hStart > 0)
- {
- pwp->y += 1; pwp->cy -= 2;
- }
- }
- break;
- }
- }
- return CallWindowProc(oldWndProcTask, hwnd, message, wParam, lParam);
- }
-
- /*--------------------------------------------------
- ü@âXâ^ü[âgâ{â^âôé╠Åëè·ë╗
- ----------------------------------------------------*/
- void SetStartButton(HWND hwndClock)
- {
- BOOL b, bHide;
- HANDLE hwnd;
- char classname[80];
-
- EndStartButton();
-
- if(!GetMyRegLong("StartButton", &b)) b = FALSE;
- if(!GetMyRegLong("StartButtonHide", &bHide)) bHide = FALSE;
- if(!b && !bHide) return;
-
- // "button"é╞"MSTaskSwWClass"é╠âEâBâôâhâEânâôâhâïé≡ô╛éΘ
- hwndStart = hwndTask = NULL;
- hwndTray = GetParent(hwndClock); // TrayNotifyWnd
- hwnd = GetParent(hwndTray); // Shell_TrayWnd
- if(hwnd == NULL) return;
- hwnd = GetWindow(hwnd, GW_CHILD);
- while(hwnd)
- {
- GetClassName(hwnd, classname, 80);
- if(_stricmp(classname, "button") == 0)
- hwndStart = hwnd;
- else if(_stricmp(classname, "MSTaskSwWClass") == 0)
- hwndTask = hwnd;
- else if(_stricmp(classname, "ReBarWindow32") == 0)
- hwndTask = hwnd;
- hwnd = GetWindow(hwnd, GW_HWNDNEXT);
- }
- if(hwndStart == NULL || hwndTask == NULL)
- {
- hwndStart = hwndTask = NULL; return;
- }
-
- // âTâuâNâëâXë╗
- oldWndProcStart = (WNDPROC)GetWindowLong(hwndStart, GWL_WNDPROC);
- SetWindowLong(hwndStart, GWL_WNDPROC, (LONG)WndProcStart);
- oldWndProcTask = (WNDPROC)GetWindowLong(hwndTask, GWL_WNDPROC);
- SetWindowLong(hwndTask, GWL_WNDPROC, (LONG)WndProcTask);
-
- if(bHide) // â{â^âôé≡ëBé╖
- {
- RECT rc; POINT pt;
- ShowWindow(hwndStart, SW_HIDE);
- wStart = 0; hStart = 0;
- GetWindowRect(hwndTray, &rc);
- pt.x = rc.left; pt.y = rc.top;
- ScreenToClient(GetParent(hwndTray), &pt);
- SetWindowPos(hwndStart, NULL, pt.x, pt.y,
- rc.right - rc.left, rc.bottom - rc.top,
- SWP_NOZORDER|SWP_NOACTIVATE);
- }
- else
- {
- // â{â^âôùpârâbâgâ}âbâvé╠É▌ÆΦ
- SetStartButtonBmp();
- }
- // MSTaskSwWClassé╠ê╩ÆuüEâTâCâYé╠É▌ÆΦ
- SetTaskWinPos();
- }
-
- /*--------------------------------------------------
- ü@âXâ^ü[âgâ{â^âôé≡î│é╔û▀é╖
- ----------------------------------------------------*/
- void EndStartButton(void)
- {
- HBITMAP hbmpold;
-
- if(hwndStart && IsWindow(hwndStart))
- {
- if(hbmpstartold != NULL)
- {
- hbmpold = (HBITMAP)SendMessage(hwndStart, BM_SETIMAGE,
- 0, (LPARAM)hbmpstartold);
- DeleteObject(hbmpold); hbmpstartold = NULL;
- }
- if(oldWndProcStart)
- SetWindowLong(hwndStart, GWL_WNDPROC, (LONG)oldWndProcStart);
- oldWndProcStart = NULL;
- SetWindowPos(hwndStart, NULL, 0, 0, 0, 0,
- SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
- ShowWindow(hwndStart, SW_SHOW);
- }
- hwndStart = NULL;
-
- if(hwndTask && IsWindow(hwndTask) && oldWndProcTask)
- SetWindowLong(hwndTask, GWL_WNDPROC, (LONG)oldWndProcTask);
- oldWndProcTask = NULL; hwndStart = NULL;
- }
-
- /*--------------------------------------------------
- ü@âXâ^ü[âgâ{â^âôé╠ârâbâgâ}âbâvé╞âTâCâYé╠É▌ÆΦ
- ----------------------------------------------------*/
- void SetStartButtonBmp(void)
- {
- char s[1024], caption[1024];
- HBITMAP hbmp, hbmpicon, hbmpold;
- HICON hicon;
- HDC hdc, hdcMem;
- HFONT hfont;
- BITMAP bmp;
- int whbmp, hhbmp, cxicon, cyicon;
- BOOL b;
-
- if(hwndStart == NULL) return;
-
- hbmpicon = NULL; hicon = NULL;
- cxicon = GetSystemMetrics(SM_CXSMICON);
- cyicon = GetSystemMetrics(SM_CYSMICON);
-
- // âtâ@âCâïé⌐éτâAâCâRâôùpârâbâgâ}âbâvé╠ô╟é▌ì₧é▌
- if(GetMyRegStr("StartButtonIcon", s) && s[0])
- {
- char fname[MAX_PATH], head[2];
- HFILE hf;
-
- parse(fname, s, 0);
- hf = _lopen(fname, OF_READ);
- if(hf != HFILE_ERROR)
- {
- _lread(hf, head, 2);
- _lclose(hf);
- if(head[0] == 'B' && head[1] == 'M') //ârâbâgâ}âbâvé╠ÅΩìç
- hbmpicon = ReadBitmap(hwndStart, fname, TRUE);
- else if(head[0] == 'M' && head[1] == 'Z') //Ä└ìsâtâ@âCâïé╠ÅΩìç
- {
- char num[10]; int n;
- HICON hiconl;
- parse(num, s, 1);
- if(num[0] == 0) n = 0; else n = atoi(num);
- if(ExtractIconEx(fname, n, &hiconl, &hicon, 1) < 2)
- hicon = NULL;
- else DestroyIcon(hiconl);
- }
- else // âAâCâRâôé╠ÅΩìç
- {
- hicon = (HICON)LoadImage(hmod, fname,
- IMAGE_ICON, cxicon, cyicon,
- LR_DEFAULTCOLOR|LR_LOADFROMFILE);
- }
- }
- }
-
- if(hbmpicon)
- {
- GetObject(hbmpicon, sizeof(BITMAP), (LPVOID)&bmp);
- cxicon = bmp.bmWidth; cyicon = bmp.bmHeight;
- }
-
- // âLâââvâVâçâôé╠ĵô╛
- if(!GetMyRegStr("StartButtonCaption", caption))
- caption[0] = 0;
-
- hdc = GetDC(hwndStart);
-
- // â{â^âôùpé╠âtâHâôâg = â^âCâgâïâoü[é╠âtâHâôâg + BOLD
- hfont = NULL;
- whbmp = cxicon; hhbmp = cyicon;
- if(caption[0])
- {
- NONCLIENTMETRICS ncm;
- SIZE sz;
- ncm.cbSize = sizeof(ncm);
- SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
- ncm.lfCaptionFont.lfWeight = FW_BOLD;
- hfont = CreateFontIndirect(&(ncm.lfCaptionFont));
- SelectObject(hdc, hfont);
-
- //âLâââvâVâçâôé╠ò¥é≡ô╛éΘ
- GetTextExtentPoint32(hdc, caption, strlen(caption), &sz);
- whbmp = sz.cx;
- if(hbmpicon || hicon) whbmp += cxicon + 2;
- hhbmp = sz.cy;
- if((hbmpicon || hicon) && cyicon > sz.cy)
- hhbmp = cyicon;
- //if(hhbmp < 16) hhbmp = 16;
- }
-
- // ârâbâgâ}âbâvé╠ì∞ɼ
- hdcMem = CreateCompatibleDC(hdc);
- hbmp = CreateCompatibleBitmap(hdc, whbmp, hhbmp);
- SelectObject(hdcMem, hbmp);
-
- { // öwîiÉFé┼ôhéΦé┬é╘é╡
- RECT rc; HBRUSH hbr;
- SetRect(&rc, 0, 0, whbmp, hhbmp);
- hbr = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
- FillRect(hdcMem, &rc, hbr);
- DeleteObject(hbr);
- }
-
- // ârâbâgâ}âbâvé╔âAâCâRâôé╠èGé≡ò`ëµ
- if(hbmpicon)
- {
- HDC hdcicon;
- hdcicon = CreateCompatibleDC(hdc);
- SelectObject(hdcicon, hbmpicon);
- BitBlt(hdcMem, 0, (hhbmp - cyicon)/2,
- cxicon, cyicon, hdcicon, 0, 0, SRCCOPY);
- DeleteDC(hdcicon);
- DeleteObject(hbmpicon);
- }
- if(hicon)
- {
- DrawIconEx(hdcMem, 0, (hhbmp - cyicon)/2,
- hicon, cxicon, cyicon, 0, NULL, DI_NORMAL);
- DestroyIcon(hicon);
- }
-
- // ârâbâgâ}âbâvé╔âLâââvâVâçâôé≡Åæé¡
- if(caption[0])
- {
- TEXTMETRIC tm;
- int x, y;
-
- GetTextMetrics(hdc, &tm);
- SelectObject(hdcMem, hfont);
- x = 0; if(hbmpicon || hicon) x = cxicon + 2;
- y = (hhbmp - tm.tmHeight) / 2;
- SetBkMode(hdcMem, TRANSPARENT);
- SetTextColor(hdcMem, GetSysColor(COLOR_BTNTEXT));
- TextOut(hdcMem, x, y, caption, strlen(caption));
- }
-
- DeleteDC(hdcMem);
- ReleaseDC(hwndStart, hdc);
- if(hfont) DeleteObject(hfont);
-
- // â{â^âôé╔ârâbâgâ}âbâvé≡É▌ÆΦ
- hbmpold = (HICON)SendMessage(hwndStart, BM_SETIMAGE, 0, (LPARAM)hbmp);
- // ê╚æOé╠ârâbâgâ}âbâvé≡ò█æ╢ / öjèⁿ
- if(hbmpstartold == NULL) hbmpstartold = hbmpold;
- else DeleteObject(hbmpold);
-
- // â{â^âôé╠âTâCâYé╠É▌ÆΦ Åπî└üF160x80
- wStart = whbmp + 8;
- if(wStart > 160) wStart = 160;
- hStart = GetSystemMetrics(SM_CYCAPTION) + 3;
- if(hhbmp + 6 > hStart) hStart = hhbmp + 6;
- if(hStart > 80) hStart = 80;
- SetWindowPos(hwndStart, NULL, 0, 0,
- wStart, hStart,
- SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
- }
-
- /*--------------------------------------------------
- ü@MSTaskSwWClassé╠ê╩ÆuüEâTâCâYé╠É▌ÆΦ
- ----------------------------------------------------*/
- void SetTaskWinPos(void)
- {
- RECT rcBar, rcTask, rcTray;
- POINT pt;
- int x, y, w, h;
-
- GetClientRect(GetParent(hwndStart), &rcBar); // Shell_TrayWnd
- GetWindowRect(hwndTray, &rcTray); // TrayNotifyWnd
- GetWindowRect(hwndTask, &rcTask); // MSTaskSwWClass
-
- // MSTaskSwWClassé╠ëEÅπê╩Æu
- pt.x = rcTask.left; pt.y = rcTask.top;
- ScreenToClient(GetParent(hwndStart), &pt);
-
- x = pt.x; y = pt.y;
- w = rcTask.right - rcTask.left;
- h = rcTask.bottom - rcTask.top;
-
- // â^âXâNâoü[é¬ëíÆué½é╠é╞é½
- if(rcBar.right > rcBar.bottom)
- {
- x = 2 + wStart;
- w = rcTray.left - 2 - wStart - 2;
- if(wStart > 0)
- {
- x += 2; w -= 2;
- }
- }
- else // ÅcÆué½é╠é╞é½
- {
- y = 2 + hStart;
- h = rcTray.top - 2 - hStart - 2;
- if(hStart > 0)
- {
- y += 1; h -= 2;
- }
- }
- SetWindowPos(hwndTask, NULL, x, y, w, h,
- SWP_NOZORDER|SWP_NOACTIVATE);
- }
-