// アイテム用ウィンドウ private { import std.thread; import std.utf; import uxtheme; import basewindow; import entry; import skin; } struct ItemConfig { HWND hParentWnd; Entry entry; int x, y; int width; int position; // int width, height; Skin skin; Skin tab_skin; } // アイテム用ウィンドウ class ItemWindow : BaseWindow { private: ItemConfig config; Skin item, item_root; bool hover; char[] state; public: this(ItemConfig conf) { config = conf; item_root = config.skin; item = item_root; } extern(Windows) uint WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: OnCreate(hWnd, cast(LPCREATESTRUCT)lParam); break; case WM_MOUSEMOVE: return OnMouseMove(hWnd); case WM_MOUSELEAVE: return OnMouseLeave(hWnd); case WM_LBUTTONDOWN: return OnLeftButtonDown(hWnd); case WM_LBUTTONUP: return OnLeftButtonUp(hWnd); case WM_PAINT: OnPaint(hWnd); break; default: return BaseWindow.WindowProc(hWnd, uMsg, wParam, lParam); } return 0; } // ウィンドウ生成前処理 void PreCreateWindow(inout WNDCLASSEX wcex) { wcex.hbrBackground = cast(HBRUSH) GetStockObject(NULL_BRUSH); wcex.hCursor = LoadCursor(null, IDC_HAND); return; } // 初期化処理 void OnCreate(HWND hWnd, LPCREATESTRUCT lpcs) { ShowWindow(hWnd, SW_SHOW); } // 描画 void OnPaint(HWND hWnd) { PAINTSTRUCT paint; HDC hdrawdc = BeginPaint(hWnd, &paint); HDC hdc = CreateCompatibleDC(hdrawdc); RECT client_rect, virtual_rect; GetClientRect(hWnd, &client_rect); switch (config.position) { case 1: case 3: virtual_rect.top = 0; virtual_rect.left = 0; virtual_rect.right = client_rect.bottom; virtual_rect.bottom = client_rect.right; break; case 0: case 2: default: virtual_rect = client_rect; } // メモリDC用仮想Bmp HBITMAP hVirtualBmp = CreateCompatibleBitmap(hdrawdc, virtual_rect.right, virtual_rect.bottom); SelectObject(hdc, hVirtualBmp); // 応急処置... config.tab_skin.DrawBackground(hWnd, hdc, virtual_rect); item.DrawBackground(hWnd, hdc, virtual_rect); item.GetChild("text").DrawText(hdc, config.entry.Name, virtual_rect); if (config.entry.IconIndex != -1) { if (config.entry.IconFile.length > 0) { item.GetChild("icon").DrawIcon(hdc, config.entry.IconFile, config.entry.IconIndex); } else { item.GetChild("icon").DrawIcon(hdc, config.entry.ExecFile, config.entry.IconIndex); } } else { item.GetChild("icon").DrawIcon(hdc, config.entry.ExecFile); } // 転送 POINT* pt = new POINT[3]; switch (config.position) { case 1: pt[0].x = client_rect.right; pt[0].y = 0; pt[1].x = client_rect.right; pt[1].y = client_rect.bottom; pt[2].x = 0; pt[2].y = 0; break; // case 2:// 逆さまにしたときだけ変?要調査 // pt[0].x = client_rect.right -1; pt[0].y = client_rect.bottom -1; // pt[1].x = -1; pt[1].y = client_rect.bottom -1; // pt[2].x = client_rect.right -1; pt[2].y = -1; // break; case 3: pt[0].x = 0; pt[0].y = client_rect.bottom; pt[1].x = 0; pt[1].y = 0; pt[2].x = client_rect.right; pt[2].y = client_rect.bottom; break; case 0: case 2: default: pt[0].x = 0; pt[0].y = 0; pt[1].x = client_rect.right; pt[1].y = 0; pt[2].x = 0; pt[2].y = client_rect.bottom; } PlgBlt(hdrawdc, pt, hdc, 0, 0, virtual_rect.right, virtual_rect.bottom, NULL, 0, 0); // 一時オブジェクト破棄 DeleteObject(hVirtualBmp); DeleteDC(hdc); EndPaint(hWnd, &paint); } void OnSkinChanged(Skin new_skin) { item_root = new_skin; item = item_root; InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); } HRESULT OnMouseMove(HWND hWnd) { if (hover) return 0; RECT client; GetClientRect(hWnd, &client); item = item_root.GetChild("hover"); InvalidateRect(hWnd, &client, TRUE); UpdateWindow(hWnd); TRACKMOUSEEVENT mouse_event; mouse_event.cbSize = TRACKMOUSEEVENT.sizeof; mouse_event.dwFlags = TME_LEAVE; mouse_event.hwndTrack = hWnd; mouse_event.dwHoverTime = 0; TrackMouseEvent(&mouse_event); hover = true; return 0; } HRESULT OnMouseLeave(HWND hWnd) { if (!hover) return 0; RECT client; GetClientRect(hWnd, &client); item = item_root; InvalidateRect(hWnd, &client, TRUE); UpdateWindow(hWnd); hover = false; return 0; } HRESULT OnLeftButtonDown(HWND hWnd) { RECT client; GetClientRect(hWnd, &client); item = item_root.GetChild("pressed"); InvalidateRect(hWnd, &client, TRUE); UpdateWindow(hWnd); return 0; } HRESULT OnLeftButtonUp(HWND hWnd) { RECT client; GetClientRect(hWnd, &client); item = item_root.GetChild("hover"); InvalidateRect(hWnd, &client, TRUE); UpdateWindow(hWnd); // プログラムの実行 Entry item = config.entry; HINSTANCE hInst = ShellExecute(NULL, toUTF16z("open"), toUTF16z(item.ExecFile), toUTF16z(item.ExecParams), toUTF16z(item.ExecPath), SW_SHOW); if (cast(int)hInst < 32) { MessageBox(null, toUTF16z(std.string.toString(cast(int)hInst)), "", MB_OK); } return 0; } }