42 #define MAX_SEM_COUNT 2147483647
43 #include <visp/vpConfig.h>
45 #include <visp/vpWin32API.h>
47 #if ( defined(WIN32) )
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
51 #include <visp/vpWin32Window.h>
55 # define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
59 # define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
64 _declspec(thread) vpWin32Window * window;
66 bool vpWin32Window::registered = false;
70 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
75 if (!window->isInitialized())
77 window->initialized =
true;
78 vpReleaseSemaphore(window->semaInit,1,NULL);
86 InvalidateRect(window->getHWnd(), NULL, TRUE);
87 UpdateWindow(window->getHWnd());
90 case vpWM_DISPLAY_ROI:
93 typedef struct _half_rect_t{
94 unsigned short left_top;
95 unsigned short right_bottom;
101 hr1 = *((half_rect_t*)(&wParam));
102 hr2 = *((half_rect_t*)(&lParam));
104 rect.left = hr1.left_top;
105 rect.right = hr1.right_bottom;
107 rect.top = hr2.left_top;
108 rect.bottom = hr2.right_bottom;
110 InvalidateRect(window->getHWnd(), &rect, TRUE);
111 UpdateWindow(window->getHWnd());
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->clickX = GET_X_LPARAM(lParam);
138 window->clickY = GET_Y_LPARAM(lParam);
141 vpReleaseSemaphore(window->semaClick,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);
167 window->clickXUp = GET_X_LPARAM(lParam);
168 window->clickYUp = GET_Y_LPARAM(lParam);
171 vpReleaseSemaphore(window->semaClickUp,1,NULL);
176 window->coordX = GET_X_LPARAM(lParam);
177 window->coordY = GET_Y_LPARAM(lParam);
178 vpReleaseSemaphore(window->semaMove,1,NULL);
187 GetKeyNameText(lParam, window->lpString, 10);
189 vpReleaseSemaphore(window->semaKey,1,NULL);
204 window->renderer->render();
207 case vpWM_CLOSEDISPLAY:
217 return DefWindowProc(hWnd, message, wParam, lParam);
225 vpWin32Window::vpWin32Window(vpWin32Renderer * rend): initialized(false)
232 semaInit = CreateSemaphore(NULL,0,1,NULL);
233 semaClick = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
234 semaClickUp = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
235 semaKey = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
236 semaMove = CreateSemaphore(NULL,0,MAX_SEM_COUNT,NULL);
243 vpWin32Window::~vpWin32Window()
246 CloseHandle(semaInit);
247 CloseHandle(semaClick);
248 CloseHandle(semaClickUp);
249 CloseHandle(semaKey);
250 CloseHandle(semaMove);
264 void vpWin32Window::initWindow(
const char* title,
int posx,
int posy,
unsigned int w,
unsigned int h)
267 DWORD style = WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX |WS_MAXIMIZEBOX;
268 const char g_szClassName[] =
"ViSPWindowClass";
272 rect.right=
static_cast<int>(w);
274 rect.bottom=
static_cast<int>(h);
276 AdjustWindowRectEx(&rect, style,
false, 0);
285 wcex.cbSize =
sizeof(WNDCLASSEX);
287 wcex.style = CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE ;
288 wcex.lpfnWndProc = (WNDPROC)WndProc;
291 wcex.hInstance = hInst;
292 wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
293 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
294 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
295 wcex.lpszMenuName = NULL;
296 wcex.lpszClassName = g_szClassName;
297 wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
299 RegisterClassEx(&wcex);
302 hWnd = CreateWindowEx(WS_EX_APPWINDOW,g_szClassName, title, style,
303 posx, posy, static_cast<int>(w), static_cast<int>(h), NULL, NULL, hInst, NULL);
306 DWORD err= GetLastError();
307 std::cout <<
"err=" << err << std::endl;
309 "Can't create the window!");
316 renderer->init(hWnd, w, h);
319 ShowWindow(hWnd, SW_SHOWDEFAULT);
327 BOOL val = GetMessage(&msg, NULL, 0, 0);
329 std::cout <<
"GetMessage error:" << GetLastError() << std::endl;
334 if (!TranslateAccelerator(msg.hwnd, NULL, &msg))
336 TranslateMessage(&msg);
337 DispatchMessage(&msg);
Error that can be emited by the vpDisplay class and its derivates.