38 #include <visp3/core/vpConfig.h>
40 #include <visp3/gui/vpWin32API.h>
42 #if ( defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) )
44 #define MAX_SEM_COUNT 2147483647
46 #ifndef DOXYGEN_SHOULD_SKIP_THIS
48 #include <visp3/gui/vpWin32Window.h>
52 # define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
56 # define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
62 __thread vpWin32Window *
window;
64 __declspec(thread) vpWin32Window *
window;
67 bool vpWin32Window::registered =
false;
71 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
76 if (!window->isInitialized())
78 window->initialized =
true;
79 vpReleaseSemaphore(window->semaInit,1,NULL);
86 InvalidateRect(window->getHWnd(), NULL, TRUE);
87 UpdateWindow(window->getHWnd());
90 case vpWM_DISPLAY_ROI:
94 rect.left = LOWORD(wParam);
95 rect.right = HIWORD(wParam);
97 rect.top = LOWORD(lParam);
98 rect.bottom = HIWORD(lParam);
100 InvalidateRect(window->getHWnd(), &rect, TRUE);
101 UpdateWindow(window->getHWnd());
107 window->clickX = GET_X_LPARAM(lParam);
108 window->clickY = GET_Y_LPARAM(lParam);
111 vpReleaseSemaphore(window->semaClick,1,NULL);
117 window->clickX = GET_X_LPARAM(lParam);
118 window->clickY = GET_Y_LPARAM(lParam);
121 vpReleaseSemaphore(window->semaClick,1,NULL);
127 window->clickX = GET_X_LPARAM(lParam);
128 window->clickY = GET_Y_LPARAM(lParam);
131 vpReleaseSemaphore(window->semaClick,1,NULL);
137 window->clickXUp = GET_X_LPARAM(lParam);
138 window->clickYUp = GET_Y_LPARAM(lParam);
141 vpReleaseSemaphore(window->semaClickUp,1,NULL);
147 window->clickXUp = GET_X_LPARAM(lParam);
148 window->clickYUp = GET_Y_LPARAM(lParam);
151 vpReleaseSemaphore(window->semaClickUp,1,NULL);
157 window->clickXUp = GET_X_LPARAM(lParam);
158 window->clickYUp = GET_Y_LPARAM(lParam);
161 vpReleaseSemaphore(window->semaClickUp,1,NULL);
166 window->coordX = GET_X_LPARAM(lParam);
167 window->coordY = GET_Y_LPARAM(lParam);
168 vpReleaseSemaphore(window->semaMove,1,NULL);
177 GetKeyNameText((LONG)lParam, window->lpString, 10);
179 vpReleaseSemaphore(window->semaKey,1,NULL);
194 window->renderer->render();
197 case vpWM_CLOSEDISPLAY:
207 return DefWindowProc(hWnd, message, wParam, lParam);
215 vpWin32Window::vpWin32Window(vpWin32Renderer * rend): initialized(false)
222 semaInit = CreateSemaphore(NULL,0,1,NULL);
223 semaClick = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
224 semaClickUp = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
225 semaKey = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
226 semaMove = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
232 vpWin32Window::~vpWin32Window()
235 CloseHandle(semaInit);
236 CloseHandle(semaClick);
237 CloseHandle(semaClickUp);
238 CloseHandle(semaKey);
239 CloseHandle(semaMove);
253 void vpWin32Window::initWindow(
const char* title,
int posx,
int posy,
unsigned int w,
unsigned int h)
256 DWORD style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
257 const char g_szClassName[] =
"ViSPWindowClass";
261 rect.right=
static_cast<int>(w);
263 rect.bottom=
static_cast<int>(h);
268 wcex.cbSize =
sizeof(WNDCLASSEX);
270 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE ;
271 wcex.lpfnWndProc = (WNDPROC)WndProc;
274 wcex.hInstance = hInst;
275 wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
276 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
277 wcex.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
278 wcex.lpszMenuName = NULL;
279 wcex.lpszClassName = g_szClassName;
280 wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
282 RegisterClassEx(&wcex);
284 AdjustWindowRectEx(&rect, style,
false, style);
288 hWnd = CreateWindowEx(WS_EX_APPWINDOW, g_szClassName, title, style,
289 posx, posy, rect.right-rect.left, rect.bottom-rect.top, NULL, NULL, hInst, NULL);
292 DWORD err= GetLastError();
293 std::cout <<
"err CreateWindowEx=" << err << std::endl;
295 "Can't create the window!");
297 SetWindowPos(hWnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE);
303 renderer->init(hWnd, w, h);
306 ShowWindow(hWnd, SW_SHOWDEFAULT);
315 BOOL val = GetMessage(&msg, NULL, 0, 0);
317 std::cout <<
"GetMessage error:" << GetLastError() << std::endl;
322 if (!TranslateAccelerator(msg.hwnd, NULL, &msg))
324 TranslateMessage(&msg);
325 DispatchMessage(&msg);
332 #elif !defined(VISP_BUILD_SHARED_LIBS)
334 void dummy_vpWin32Window() {};
vpWin32Window window
The window.
Error that can be emited by the vpDisplay class and its derivates.