1 /*
2 * ppui/osinterface/win32/WaitWindow_WIN32.cpp
3 *
4 * Copyright 2009 Peter Barth
5 *
6 * This file is part of Milkytracker.
7 *
8 * Milkytracker is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Milkytracker is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Milkytracker. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #include "WaitWindow_WIN32.h"
24 #include "DisplayDeviceBase.h"
25
26 extern HINSTANCE g_hinst; /* My instance handle */
27
28 WaitWindow* WaitWindow::instance = NULL;
29
30 TCHAR WaitWindow::szClassName[] = _T("MILKYTRACKERWAITWNDCLASS");
31
WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)32 LRESULT CALLBACK WaitWindow::WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
33 {
34 switch (msg)
35 {
36 case WM_PAINT:
37 WaitWindow::getInstance()->render();
38 break;
39 }
40
41 return DefWindowProc(hWnd, msg, wParam, lParam);
42 }
43
init()44 void WaitWindow::init()
45 {
46 m_BitmapInfo.biSize = sizeof(BITMAPINFOHEADER);
47 m_BitmapInfo.biWidth = getWidth();
48 m_BitmapInfo.biHeight = -getHeight();
49 m_BitmapInfo.biPlanes = 1;
50 m_BitmapInfo.biBitCount = 24;
51 m_BitmapInfo.biCompression = BI_RGB;
52 m_BitmapInfo.biSizeImage = 0;
53 m_BitmapInfo.biXPelsPerMeter = 0;
54 m_BitmapInfo.biYPelsPerMeter = 0;
55 m_BitmapInfo.biClrUsed = 0;
56 m_BitmapInfo.biClrImportant = 0;
57
58 HDC hScreenDC = ::GetWindowDC(NULL);
59
60 m_hBitmap = ::CreateDIBSection(hScreenDC, (LPBITMAPINFO)&m_BitmapInfo, DIB_RGB_COLORS,(LPVOID *)&m_pBits, NULL, 0);
61
62 ::ReleaseDC(NULL, hScreenDC);
63
64 m_hDC = NULL;
65 }
66
DrawPixel24(void * buffer,pp_int32 x,pp_int32 y,pp_int32 pitch,const PPColor & color)67 void DrawPixel24(void* buffer, pp_int32 x, pp_int32 y, pp_int32 pitch, const PPColor& color)
68 {
69 unsigned char* buff = (unsigned char*)buffer;
70 buff[y*pitch+x*3] = (unsigned char)color.b;
71 buff[y*pitch+x*3+1] = (unsigned char)color.g;
72 buff[y*pitch+x*3+2] = (unsigned char)color.r;
73 }
74
render()75 void WaitWindow::render()
76 {
77 ::DrawWaitBar(getWidth(), getHeight(),
78 160, 16,
79 0xFFFFFF, (color.r << 16) + (color.g << 8) + (color.b),
80 m_pBits, getWidth()*3, &DrawPixel24);
81
82 m_hDC = ::GetDC(hWnd);
83
84 blit(hWnd, m_hDC, 0, 0, getWidth(), getHeight());
85
86 ::ReleaseDC(hWnd, m_hDC);
87
88 m_hDC = NULL;
89 }
90
blit(HWND hWnd,HDC pDC,pp_int32 x,pp_int32 y,pp_int32 width,pp_int32 height)91 void WaitWindow::blit(HWND hWnd, HDC pDC, pp_int32 x, pp_int32 y, pp_int32 width, pp_int32 height)
92 {
93 RECT r;
94
95 ::GetClientRect(hWnd,&r);
96
97 HDC hBitmapDC = ::CreateCompatibleDC(NULL);
98
99 HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hBitmapDC, m_hBitmap);
100
101 ::BitBlt(pDC, x, y, width, height, hBitmapDC, x, y, SRCCOPY);
102
103 ::SelectObject(hBitmapDC, hOldBitmap);
104
105 ::DeleteDC(hBitmapDC);
106 }
107
WaitWindow()108 WaitWindow::WaitWindow()
109 {
110 WNDCLASS wc;
111
112 wc.hCursor = NULL;
113 wc.hIcon = (HICON)::LoadIcon(NULL, IDI_APPLICATION);
114 wc.lpszMenuName = NULL;
115 wc.lpszClassName = szClassName;
116 wc.hbrBackground = 0;
117 wc.hInstance = g_hinst;
118 wc.style = 0;
119 wc.lpfnWndProc = WndProc;
120 wc.cbClsExtra = 0;
121 wc.cbWndExtra = 0;
122
123 ::RegisterClass(&wc);
124
125 hWnd = ::CreateWindow(szClassName,
126 _T("Working..."),
127 0/*|WS_MAXIMIZEBOX|WS_MINIMIZEBOX*/,CW_USEDEFAULT,CW_USEDEFAULT,
128 getWidth()+::GetSystemMetrics(SM_CXEDGE)*2+2,
129 getHeight()+::GetSystemMetrics(SM_CYCAPTION)+2+::GetSystemMetrics(SM_CYEDGE)*2,
130 NULL,
131 NULL,
132 g_hinst,
133 0);
134
135 init();
136 }
137
getInstance()138 WaitWindow* WaitWindow::getInstance()
139 {
140 if (instance == NULL)
141 instance = new WaitWindow();
142
143 return instance;
144 }
145
~WaitWindow()146 WaitWindow::~WaitWindow()
147 {
148 ::SendMessage(hWnd, WM_CLOSE, 0, 0);
149 }
150
show()151 void WaitWindow::show()
152 {
153 ::ShowWindow(hWnd, SW_SHOW);
154 }
155
hide()156 void WaitWindow::hide()
157 {
158 ::ShowWindow(hWnd, SW_HIDE);
159 }
160
move(pp_int32 x,pp_int32 y)161 void WaitWindow::move(pp_int32 x, pp_int32 y)
162 {
163 ::SetWindowPos(hWnd, HWND_TOPMOST, x, y, 0, 0, SWP_NOSIZE);
164 }
165