40 #include <visp3/core/vpConfig.h> 41 #include <visp3/gui/vpWin32API.h> 43 #if (defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9)) 45 #define MAX_SEM_COUNT 2147483647 47 #ifndef DOXYGEN_SHOULD_SKIP_THIS 49 #include <visp3/gui/vpWin32Window.h> 53 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) 57 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) 63 __thread vpWin32Window *
window;
65 __declspec(thread) vpWin32Window *
window;
68 bool vpWin32Window::registered =
false;
72 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
77 if (!window->isInitialized()) {
78 window->initialized =
true;
79 vpReleaseSemaphore(window->semaInit, 1, NULL);
85 InvalidateRect(window->getHWnd(), NULL, TRUE);
86 UpdateWindow(window->getHWnd());
89 case vpWM_DISPLAY_ROI: {
92 rect.left = LOWORD(wParam);
93 rect.right = HIWORD(wParam);
95 rect.top = LOWORD(lParam);
96 rect.bottom = HIWORD(lParam);
98 InvalidateRect(window->getHWnd(), &rect, TRUE);
99 UpdateWindow(window->getHWnd());
102 case WM_LBUTTONDOWN: {
103 window->clickX = GET_X_LPARAM(lParam);
104 window->clickY = GET_Y_LPARAM(lParam);
107 vpReleaseSemaphore(window->semaClick, 1, NULL);
110 case WM_MBUTTONDOWN: {
111 window->clickX = GET_X_LPARAM(lParam);
112 window->clickY = GET_Y_LPARAM(lParam);
115 vpReleaseSemaphore(window->semaClick, 1, NULL);
118 case WM_RBUTTONDOWN: {
119 window->clickX = GET_X_LPARAM(lParam);
120 window->clickY = GET_Y_LPARAM(lParam);
123 vpReleaseSemaphore(window->semaClick, 1, NULL);
127 window->clickXUp = GET_X_LPARAM(lParam);
128 window->clickYUp = GET_Y_LPARAM(lParam);
131 vpReleaseSemaphore(window->semaClickUp, 1, NULL);
135 window->clickXUp = GET_X_LPARAM(lParam);
136 window->clickYUp = GET_Y_LPARAM(lParam);
139 vpReleaseSemaphore(window->semaClickUp, 1, NULL);
143 window->clickXUp = GET_X_LPARAM(lParam);
144 window->clickYUp = GET_Y_LPARAM(lParam);
147 vpReleaseSemaphore(window->semaClickUp, 1, NULL);
150 window->coordX = GET_X_LPARAM(lParam);
151 window->coordY = GET_Y_LPARAM(lParam);
152 vpReleaseSemaphore(window->semaMove, 1, NULL);
160 GetKeyNameText((LONG)lParam, window->lpString,
163 vpReleaseSemaphore(window->semaKey, 1, NULL);
178 window->renderer->render();
181 case vpWM_CLOSEDISPLAY:
191 return DefWindowProc(hWnd, message, wParam, lParam);
199 vpWin32Window::vpWin32Window(vpWin32Renderer *rend) : initialized(false)
207 semaInit = CreateSemaphore(NULL, 0, 1, NULL);
208 semaClick = CreateSemaphore(NULL, 0, MAX_SEM_COUNT, NULL);
209 semaClickUp = CreateSemaphore(NULL, 0, MAX_SEM_COUNT, NULL);
210 semaKey = CreateSemaphore(NULL, 0, MAX_SEM_COUNT, NULL);
211 semaMove = CreateSemaphore(NULL, 0, MAX_SEM_COUNT, NULL);
217 vpWin32Window::~vpWin32Window()
220 CloseHandle(semaInit);
221 CloseHandle(semaClick);
222 CloseHandle(semaClickUp);
223 CloseHandle(semaKey);
224 CloseHandle(semaMove);
237 void vpWin32Window::initWindow(
const char *title,
int posx,
int posy,
unsigned int w,
unsigned int h)
240 DWORD style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
241 const char g_szClassName[] =
"ViSPWindowClass";
245 rect.right =
static_cast<int>(w);
247 rect.bottom =
static_cast<int>(h);
252 wcex.cbSize =
sizeof(WNDCLASSEX);
254 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE;
255 wcex.lpfnWndProc = (WNDPROC)WndProc;
258 wcex.hInstance = hInst;
259 wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
260 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
261 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
262 wcex.lpszMenuName = NULL;
263 wcex.lpszClassName = g_szClassName;
264 wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
266 RegisterClassEx(&wcex);
268 AdjustWindowRectEx(&rect, style,
false, style);
273 hWnd = CreateWindowEx(WS_EX_APPWINDOW, g_szClassName, title, style, posx, posy, rect.right - rect.left,
274 rect.bottom - rect.top, NULL, NULL, hInst, NULL);
276 DWORD err = GetLastError();
277 std::cout <<
"err CreateWindowEx=" << err << std::endl;
280 SetWindowPos(hWnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE);
286 renderer->init(hWnd, w, h);
289 ShowWindow(hWnd, SW_SHOWDEFAULT);
297 BOOL val = GetMessage(&msg, NULL, 0, 0);
299 std::cout <<
"GetMessage error:" << GetLastError() << std::endl;
301 }
else if (val == 0) {
304 if (!TranslateAccelerator(msg.hwnd, NULL, &msg)) {
305 TranslateMessage(&msg);
306 DispatchMessage(&msg);
313 #elif !defined(VISP_BUILD_SHARED_LIBS) 316 void dummy_vpWin32Window(){};
vpWin32Window window
The window.
Error that can be emited by the vpDisplay class and its derivates.