46 static bool class_already_registered =
false;
47 if (!class_already_registered)
50 memset(&wc, 0,
sizeof(wc));
52 wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
53 wc.lpfnWndProc = (WNDPROC)Win32Window::WindowProc;
56 wc.hInstance = GetModuleHandle(
NULL);
57 wc.hIcon = LoadIcon(
NULL, IDI_WINLOGO);
58 wc.hCursor = LoadCursor(
NULL, IDC_ARROW);
59 wc.hbrBackground =
NULL;
60 wc.lpszMenuName =
NULL;
63 if (!RegisterClass(&wc))
64 MessageBox(
NULL, L
"Class registration failed.", L
"Visualization Library Error", MB_OK);
66 class_already_registered =
true;
68 return class_already_registered;
73 void win32PrintError(LPTSTR lpszFunction)
77 DWORD dw = GetLastError();
80 FORMAT_MESSAGE_ALLOCATE_BUFFER |
81 FORMAT_MESSAGE_FROM_SYSTEM,
84 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
89 L
"%s failed with error %d: %s",
90 lpszFunction, dw, lpMsgBuf);
92 MessageBox(
NULL, szBuf, L
"Visualization Library Error", MB_OK);
99 std::map< HWND, Win32Window* > Win32Window::mWinMap;
101 LONG WINAPI Win32Window::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
105 return (LONG)DefWindowProc(hWnd, uMsg, wParam, lParam);
112 LONG val = (LONG)DefWindowProc(hWnd, uMsg, wParam, lParam);
128 POINTS pt = MAKEPOINTS(lParam);
133 case WM_LBUTTONDBLCLK:
135 case WM_MBUTTONDBLCLK:
137 case WM_RBUTTONDBLCLK:
142 SetCapture(win->
hwnd());
144 if (uMsg == WM_LBUTTONDBLCLK || uMsg == WM_LBUTTONDOWN)
146 else if (uMsg == WM_MBUTTONDBLCLK || uMsg == WM_MBUTTONDOWN)
148 else if (uMsg == WM_RBUTTONDBLCLK || uMsg == WM_RBUTTONDOWN)
150 POINTS pt = MAKEPOINTS(lParam);
166 if (uMsg == WM_LBUTTONUP)
168 else if (uMsg == WM_MBUTTONUP)
170 else if (uMsg == WM_RBUTTONUP)
172 POINTS pt = MAKEPOINTS(lParam);
195 Win32Window::mWinMap.erase(hWnd);
203 unsigned short unicode_out = 0;
212 unsigned short unicode_out = 0;
221 HDROP hDrop = (HDROP)wParam;
222 int count = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0);
223 const int char_count = 1024;
224 std::vector<String> files;
225 for(
int i=0; i<count; ++i)
227 wchar_t file_path[char_count];
228 memset(file_path, 0, char_count);
229 DragQueryFile(hDrop,i,file_path,char_count);
230 files.push_back(file_path);
245 return (LONG)DefWindowProc(hWnd, uMsg, wParam, lParam);
250 Win32Window::Win32Window()
257 mStyle = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
258 mExStyle = WS_EX_APPWINDOW | WS_EX_ACCEPTFILES;
262 Win32Window::~Win32Window()
264 destroyWin32GLWindow();
269 destroyWin32GLWindow();
274 unsigned style = mStyle & ~(WS_CHILD|WS_OVERLAPPEDWINDOW);;
275 style |= parent?WS_CHILD:WS_OVERLAPPEDWINDOW;
277 mHWND = CreateWindowEx(
280 L
"Visualization Library Win32",
285 if (initWin32GLContext(share_context, title, fmt, x, y, width, height))
287 mWinMap[mHWND] =
this;
296 std::map< HWND, Win32Window* >::const_iterator it = mWinMap.find(hWnd);
297 if (it != mWinMap.end())
303 void Win32Window::destroyWin32GLWindow()
309 bool destroy_win = mWinMap.find(mHWND) != mWinMap.end();
314 DestroyWindow(mHWND);
319 if ( wglDeleteContext(mHGLRC) == FALSE )
321 MessageBox(
NULL, L
"OpenGL context creation failed.\n" 322 L
"The handle either doesn't specify a valid context or the context is being used by another thread.", L
"Visualization Library Error", MB_OK);
337 std::map< HWND, Win32Window* > wins = Win32Window::winMap();
338 for( std::map< HWND, Win32Window* >::iterator it = wins.begin();
352 if ( PeekMessage(&msg,
NULL, 0, 0, PM_REMOVE) )
354 if (msg.message != WM_QUIT)
356 TranslateMessage(&msg);
357 DispatchMessage(&msg);
366 while(!Win32Window::winMap().empty())
368 MSG msg = {0,0,0,0,0,0,0};
370 if (msg.message == WM_QUIT)
371 return (
int)msg.wParam;
384 case VK_CLEAR: key_out =
Key_Clear;
break;
385 case VK_CONTROL: key_out =
Key_Ctrl;
break;
388 case VK_MENU: key_out =
Key_Alt;
break;
391 case VK_SHIFT: key_out =
Key_Shift;
break;
396 case VK_HOME: key_out =
Key_Home;
break;
397 case VK_END: key_out =
Key_End;
break;
398 case VK_PRINT: key_out =
Key_Print;
break;
399 case VK_PAUSE: key_out =
Key_Pause;
break;
402 case VK_LEFT: key_out =
Key_Left;
break;
403 case VK_RIGHT: key_out =
Key_Right;
break;
404 case VK_UP: key_out =
Key_Up;
break;
405 case VK_DOWN: key_out =
Key_Down;
break;
406 case VK_F1: key_out =
Key_F1;
break;
407 case VK_F2: key_out =
Key_F2;
break;
408 case VK_F3: key_out =
Key_F3;
break;
409 case VK_F4: key_out =
Key_F4;
break;
410 case VK_F5: key_out =
Key_F5;
break;
411 case VK_F6: key_out =
Key_F6;
break;
412 case VK_F7: key_out =
Key_F7;
break;
413 case VK_F8: key_out =
Key_F8;
break;
414 case VK_F9: key_out =
Key_F9;
break;
415 case VK_F10: key_out =
Key_F10;
break;
416 case VK_F11: key_out =
Key_F11;
break;
417 case VK_F12: key_out =
Key_F12;
break;
425 case L
'0': key_out =
Key_0;
break;
426 case L
'1': key_out =
Key_1;
break;
427 case L
'2': key_out =
Key_2;
break;
428 case L
'3': key_out =
Key_3;
break;
429 case L
'4': key_out =
Key_4;
break;
430 case L
'5': key_out =
Key_5;
break;
431 case L
'6': key_out =
Key_6;
break;
432 case L
'7': key_out =
Key_7;
break;
433 case L
'8': key_out =
Key_8;
break;
434 case L
'9': key_out =
Key_9;
break;
436 case L
'A': key_out =
Key_A;
break;
437 case L
'B': key_out =
Key_B;
break;
438 case L
'C': key_out =
Key_C;
break;
439 case L
'D': key_out =
Key_D;
break;
440 case L
'E': key_out =
Key_E;
break;
441 case L
'F': key_out =
Key_F;
break;
442 case L
'G': key_out =
Key_G;
break;
443 case L
'H': key_out =
Key_H;
break;
444 case L
'I': key_out =
Key_I;
break;
445 case L
'J': key_out =
Key_J;
break;
446 case L
'K': key_out =
Key_K;
break;
447 case L
'L': key_out =
Key_L;
break;
448 case L
'M': key_out =
Key_M;
break;
449 case L
'N': key_out =
Key_N;
break;
450 case L
'O': key_out =
Key_O;
break;
451 case L
'P': key_out =
Key_P;
break;
452 case L
'Q': key_out =
Key_Q;
break;
453 case L
'R': key_out =
Key_R;
break;
454 case L
'S': key_out =
Key_S;
break;
455 case L
'T': key_out =
Key_T;
break;
456 case L
'U': key_out =
Key_U;
break;
457 case L
'V': key_out =
Key_V;
break;
458 case L
'W': key_out =
Key_W;
break;
459 case L
'X': key_out =
Key_X;
break;
460 case L
'Y': key_out =
Key_Y;
break;
461 case L
'Z': key_out =
Key_Z;
break;
466 memset( mskeys, 0,
sizeof(BYTE)*256 );
467 WCHAR unicode[4] = { 0, 0 };
468 if ( ToUnicode( (UINT)wParam, (UINT)((lParam >> 16) & 0xFF), mskeys, unicode, 4, 0 ) == 1 )
470 unicode_out = unicode[0];
475 case L
'0': key_out =
Key_0;
break;
476 case L
'1': key_out =
Key_1;
break;
477 case L
'2': key_out =
Key_2;
break;
478 case L
'3': key_out =
Key_3;
break;
479 case L
'4': key_out =
Key_4;
break;
480 case L
'5': key_out =
Key_5;
break;
481 case L
'6': key_out =
Key_6;
break;
482 case L
'7': key_out =
Key_7;
break;
483 case L
'8': key_out =
Key_8;
break;
484 case L
'9': key_out =
Key_9;
break;
486 case L
'A': key_out =
Key_A;
break;
487 case L
'B': key_out =
Key_B;
break;
488 case L
'C': key_out =
Key_C;
break;
489 case L
'D': key_out =
Key_D;
break;
490 case L
'E': key_out =
Key_E;
break;
491 case L
'F': key_out =
Key_F;
break;
492 case L
'G': key_out =
Key_G;
break;
493 case L
'H': key_out =
Key_H;
break;
494 case L
'I': key_out =
Key_I;
break;
495 case L
'J': key_out =
Key_J;
break;
496 case L
'K': key_out =
Key_K;
break;
497 case L
'L': key_out =
Key_L;
break;
498 case L
'M': key_out =
Key_M;
break;
499 case L
'N': key_out =
Key_N;
break;
500 case L
'O': key_out =
Key_O;
break;
501 case L
'P': key_out =
Key_P;
break;
502 case L
'Q': key_out =
Key_Q;
break;
503 case L
'R': key_out =
Key_R;
break;
504 case L
'S': key_out =
Key_S;
break;
505 case L
'T': key_out =
Key_T;
break;
506 case L
'U': key_out =
Key_U;
break;
507 case L
'V': key_out =
Key_V;
break;
508 case L
'W': key_out =
Key_W;
break;
509 case L
'X': key_out =
Key_X;
break;
510 case L
'Y': key_out =
Key_Y;
break;
511 case L
'Z': key_out =
Key_Z;
break;
513 case L
'a': key_out =
Key_A;
break;
514 case L
'b': key_out =
Key_B;
break;
515 case L
'c': key_out =
Key_C;
break;
516 case L
'd': key_out =
Key_D;
break;
517 case L
'e': key_out =
Key_E;
break;
518 case L
'f': key_out =
Key_F;
break;
519 case L
'g': key_out =
Key_G;
break;
520 case L
'h': key_out =
Key_H;
break;
521 case L
'i': key_out =
Key_I;
break;
522 case L
'j': key_out =
Key_J;
break;
523 case L
'k': key_out =
Key_K;
break;
524 case L
'l': key_out =
Key_L;
break;
525 case L
'm': key_out =
Key_M;
break;
526 case L
'n': key_out =
Key_N;
break;
527 case L
'o': key_out =
Key_O;
break;
528 case L
'p': key_out =
Key_P;
break;
529 case L
'q': key_out =
Key_Q;
break;
530 case L
'r': key_out =
Key_R;
break;
531 case L
's': key_out =
Key_S;
break;
532 case L
't': key_out =
Key_T;
break;
533 case L
'u': key_out =
Key_U;
break;
534 case L
'v': key_out =
Key_V;
break;
535 case L
'w': key_out =
Key_W;
break;
536 case L
'x': key_out =
Key_X;
break;
537 case L
'y': key_out =
Key_Y;
break;
538 case L
'z': key_out =
Key_Z;
break;
542 case 9: key_out =
Key_Tab;
break;
548 case L
'#': key_out =
Key_Hash;
break;
555 case L
'+': key_out =
Key_Plus;
break;
562 case L
'<': key_out =
Key_Less;
break;
566 case L
'@': key_out =
Key_At;
break;
VLWIN32_EXPORT void peekMessage(MSG &msg)
void dispatchKeyReleaseEvent(unsigned short unicode_ch, EKey key)
Dispatches the UIEventListener::keyReleaseEvent() notification to the subscribed UIEventListener obje...
The Win32Window class is a Win32Context that can be used as a top or child window.
void setWidth(int width)
The width of a render target.
void dispatchMouseDownEvent(EMouseButton button, int x, int y)
Dispatches the UIEventListener::mouseDownEvent() notification to the subscribed UIEventListener objec...
void update()
If the OpenGLContext is a widget this function requests a redraw and generates an updateEvent()...
Framebuffer * framebuffer()
The default render target (always returns leftFramebuffer()).
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
void destroyWin32GLWindow()
Destroys the window and the OpenGL rendering context.
void dispatchKeyPressEvent(unsigned short unicode_ch, EKey key)
Dispatches the UIEventListener::keyPressEvent() notification to the subscribed UIEventListener object...
void dispatchResizeEvent(int w, int h)
Dispatches the UIEventListener::resizeEvent() notification to the subscribed UIEventListener objects...
Visualization Library main namespace.
VLEGL_EXPORT void peekMessage(MSG &msg)
bool continuousUpdate() const
If the OpenGL context is a widget this function returns whether its area is continuously updated at e...
void dispatchUpdateEvent()
Dispatches the UIEventListener::updateEvent() notification to the subscribed UIEventListener objects...
The OpenGLContextFormat class encapsulates the settings of an OpenGL rendering context.
VLWIN32_EXPORT int messageLoop()
VLWIN32_EXPORT void dispatchUpdate()
void dispatchMouseWheelEvent(int n)
Dispatches the UIEventListener::mouseWheelEvent() notification to the subscribed UIEventListener obje...
VLEGL_EXPORT void translateKeyEvent(WPARAM wParam, LPARAM lParam, unsigned short &unicode_out, vl::EKey &key_out)
void dispatchDestroyEvent()
Dispatches the UIEventListener::destroyEvent() notification to the subscribed UIEventListener(s), calls destroyAllOpenGLResources() and eraseAllEventListeners() This event must be issued just before the actual GL context is destroyed.
void dispatchFileDroppedEvent(const std::vector< String > &files)
Dispatches the UIEventListener::fileDroppedEvent() notification to the subscribed UIEventListener obj...
VLWIN32_EXPORT void translateKeyEvent(WPARAM wParam, LPARAM lParam, unsigned short &unicode_out, vl::EKey &key_out)
void dispatchMouseMoveEvent(int x, int y)
Dispatches the UIEventListener::mouseMoveEvent() notification to the subscribed UIEventListener objec...
void setHeight(int height)
The height of a render target.
The Win32 bindings namespace.
const wchar_t * gWin32WindowClassName
void dispatchMouseUpEvent(EMouseButton button, int x, int y)
Dispatches the UIEventListener::mouseUpEvent() notification to the subscribed UIEventListener objects...
VLEGL_EXPORT void dispatchUpdate()