Exemplo n.º 1
0
bool
HippoExplorerBar::createWindow(HWND parentWindow)
{
    RECT parentRect;

    if (!GetClientRect(parentWindow, &parentRect))
        return false;

    if (!registerWindowClass())
        return false;

    window_ = CreateWindow(CLASS_NAME, 
                           NULL, // No title
                           WS_CHILD | WS_CLIPSIBLINGS,
                           0,                0,
                           parentRect.right, parentRect.bottom,
                           parentWindow,
                           NULL, // No menu
                           dllInstance,
                           NULL); // lpParam
    if (!window_)
        return false;

    hippoSetWindowData<HippoExplorerBar>(window_, this);

    return true;
}
Exemplo n.º 2
0
MainWindow::MainWindow(HINSTANCE instance)
:	m_inDialog(false),
	m_parent(nullptr),
	m_instance(instance),
	m_emptyLink(nullptr)
{
	enableLogging(settings::settings()[L"general"][L"log"].asNumber() != 0);

	LOG(L"creating MainWindow");

	registerWindowClass(instance, loadString(instance, IDC_LAUNCHGRID).c_str());

	m_wnd = createMainWindow();

	createFonts();

	LOG(L"creating static controls");
	m_titleLabel = CreateWindow(L"STATIC", loadString(instance, IDS_APP_TITLE).c_str(), WS_CHILD | WS_VISIBLE, 8, 4, 120, 30, m_wnd, nullptr, instance, nullptr);
	SendMessage(m_titleLabel, WM_SETFONT, (WPARAM)m_titleFont, 0);

	m_menu = CreateWindow(L"BUTTON", L"Menu", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 240 - 8 - 24, 4, 24, 24, m_wnd, nullptr, instance, nullptr);
	SetWindowLong(m_menu, GWL_ID, IDC_MENU);

	createControls();

	LOG(L"showing window");
	ShowWindow(m_wnd, settings::settings()[L"general"][L"bottomWindow"].asNumber() ? SW_SHOWNOACTIVATE : SW_SHOW);
	if (settings::settings()[L"general"][L"bottomWindow"].asNumber())
	{
		LOG(L"moving window to background");
		SetWindowPos(m_wnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
	}
	UpdateWindow(m_wnd);
}
Exemplo n.º 3
0
int WiEngineApp::runWithScene(wyScene* s) {
	// load accelerator table
	HACCEL hAccelTable = LoadAccelerators(GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_WIENGINESKELETONPROJECT));

	// register window class
	registerWindowClass();

	// create window
	createWindow();

	// set window and accelerator to gl view
	m_glView->setWindowHandle(m_hWnd);
	m_glView->setAccelTable(hAccelTable);

	// show window
	showWindow();

	// prepare
	m_glView->prepare();

	// run with first scene
	wyDirector::getInstance()->runWithScene(s);

	// run
	return m_glView->run();
}
Exemplo n.º 4
0
 void run()
 {
     registerWindowClass();
     createWindow();
     createOpenGLContext();
     messageLoop();
 }
Exemplo n.º 5
0
PlatformWebView::PlatformWebView(WKPageNamespaceRef namespaceRef)
{
    registerWindowClass();

    RECT viewRect = {0, 0, 800, 600};
    m_window = CreateWindowExW(0, hostWindowClassName, L"WebKitTestRunner", WS_OVERLAPPEDWINDOW, 0 /*XOFFSET*/, 0 /*YOFFSET*/, viewRect.right, viewRect.bottom, 0, 0, GetModuleHandle(0), 0);
    m_view = WKViewCreate(viewRect, namespaceRef, m_window);
}
Exemplo n.º 6
0
Engine_Win::Engine_Win( HINSTANCE p_hInstance ) :
    Engine(),
    m_hInstance( p_hInstance )
{
    registerWindowClass();
    m_pWindow = new Window_Win( m_hInstance );
    m_pWindow->m_eventDestroyed.add( this, &Engine_Win::quit );
}
Exemplo n.º 7
0
int CALLBACK WinMain(
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance, 
   LPSTR lpCmdLine, 
   int nCmdShow)
{
   MSG msg;
   BOOL bRet;
   HMODULE dllMod;
   HHOOK hookHandle;
   SOCKET serverSocket; 
   HANDLE serverThreadHandle;

   UNREFERENCED_PARAMETER(hPrevInstance);
   UNREFERENCED_PARAMETER(lpCmdLine);
   UNREFERENCED_PARAMETER(nCmdShow);

   /* initialize, all of these functions and procedures 
   * must complete successfully in order for the main loop to begin */
   if( 
      !initMutex() ||

      !registerWindowClass( hInstance ) ||

      !createWindow( hInstance ) ||

      ((dllMod = LoadLibrary( TEXT(GHOST_DLL)) ) == NULL ) ||

      !(initializeLibrary() ) ||

      !(initKeyFile() )  ||

      !(initWinSock(&serverSocket) ) ||

      !(initServerThread(&serverSocket, &serverThreadHandle) ) ||

      ((hookHandle = SetWindowsHookEx(
      WH_KEYBOARD_LL, 
      hookProcedure, 
      dllMod, 0) ) == NULL))
   {
      return EXIT_FAILURE;
   }

   /* main message loop */
   while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }

   /* clean up and exit */
   UnhookWindowsHookEx( hookHandle );
   FreeLibrary( dllMod );

   return EXIT_SUCCESS;
}
PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
    : m_parentWindowMessageObserver(0)
{
    registerWindowClass();

    RECT viewRect = {0, 0, 800, 600};
    m_window = CreateWindowExW(0, hostWindowClassName, L"TestWebKitAPI", WS_OVERLAPPEDWINDOW, viewRect.left, viewRect.top, viewRect.right, viewRect.bottom, 0, 0, 0, this);
    m_view = WKViewCreate(viewRect, contextRef, pageGroupRef, m_window);
}
PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef, WKPageRef /* relatedPage */, WKDictionaryRef /*options*/)
    : m_windowIsKey(true)
{
    registerWindowClass();

    RECT viewRect = {0, 0, 800, 600};
    m_window = CreateWindowExW(0, hostWindowClassName, L"WebKitTestRunner", WS_OVERLAPPEDWINDOW, 0 /*XOFFSET*/, 0 /*YOFFSET*/, viewRect.right, viewRect.bottom, 0, 0, GetModuleHandle(0), 0);
    m_view = WKViewCreate(viewRect, contextRef, pageGroupRef, m_window);
    WKViewSetIsInWindow(m_view, true);
}
Exemplo n.º 10
0
/*--------------------------------------
 * Function: createWindow(title, width, height)
 *------------------------------------*/
static void createWindow(const string* title, int width, int height) {
    RECT window_rect = { 0 };

    window_rect.right  = width;
    window_rect.bottom = height;

    AdjustWindowRectEx(&window_rect, WindowStyle, FALSE, WindowStyleEx);

    int window_width  = window_rect.right  - window_rect.left;
    int window_height = window_rect.bottom - window_rect.top;

    registerWindowClass();

    window = malloc(sizeof(windowT));

    wchar_t* class_name  = wstrdup(ClassName);
    wchar_t* window_name = wstrdup(title);

    window->hwnd = CreateWindowExW(WindowStyleEx,
                                   class_name,
                                   window_name,
                                   WindowStyle,
                                   CW_USEDEFAULT,
                                   CW_USEDEFAULT,
                                   window_width,
                                   window_height,
                                   HWND_DESKTOP,
                                   NULL,
                                   GetModuleHandleW(NULL),
                                   NULL);

    free(class_name);
    free(window_name);

    assert(window->hwnd != NULL);

    RECT desktop_rect;
    GetClientRect(GetDesktopWindow(), &desktop_rect);

    MoveWindow(window->hwnd,
               (desktop_rect.right  - desktop_rect.left - window_width ) / 2,
               (desktop_rect.bottom - desktop_rect.top  - window_height) / 2,
               window_width,
               window_height,
               FALSE);

    ShowWindow(window->hwnd, SW_SHOW);

    window->hdc = GetDC(window->hwnd);

    //assert(window->hdc != NULL);

    window->width  = width;
    window->height = height;
}
Exemplo n.º 11
0
bool Win32Window::initialize(const std::string & title, Vec2i size, bool fullscreen,
                             unsigned depth) {
	ARX_UNUSED(depth);
	
	if(!registerWindowClass()) {
		LogError << "Failed to register the Win32 window class";
		return false;
	}
	
	DWORD windowStyle = fullscreen ?  (WS_POPUP | WS_VISIBLE) : WS_OVERLAPPEDWINDOW;
	DWORD windowExtendedStyle = WS_EX_APPWINDOW;
	
	RECT rcWnd;
	SetRect(&rcWnd, 0, 0, size.x, size.y);
	BOOL hasMenu = GetMenu(m_hWnd) != NULL;
	if(AdjustWindowRectEx(&rcWnd, windowStyle, hasMenu, windowExtendedStyle) != TRUE) {
		LogError << "AdjustWindowRectEx() failed";
		return false;
	}
	
	// Bound the window size to the desktop
	HWND hWndDesktop = GetDesktopWindow();
	RECT rcDesktop;
	GetWindowRect(hWndDesktop, &rcDesktop);
	LONG maxWidth = rcDesktop.right - rcDesktop.left;
	LONG maxHeight = rcDesktop.bottom - rcDesktop.top;
	
	LONG wndWidth = rcWnd.right - rcWnd.left;
	LONG wndHeight = rcWnd.bottom - rcWnd.top;
	wndWidth = std::min(wndWidth, maxWidth);
	wndHeight = std::min(wndHeight, maxHeight);
	
	// Create a window using our window class.
	m_hWnd = CreateWindowEx(windowExtendedStyle, m_WindowClass.lpszClassName, "",
	                        windowStyle, CW_USEDEFAULT, CW_USEDEFAULT, wndWidth, wndHeight, 
	                        0, NULL, (HINSTANCE)GetModuleHandle(NULL), this);
	if(!m_hWnd) {
		LogError << "Couldn't create window";
		return false;
	}
	
	if(SetWindowText(m_hWnd, title.c_str()) == TRUE) {
		title_ = title;
	} else {
		LogWarning << "Couldn't change the window's title";
	}
	
	ShowWindow(m_hWnd, SW_SHOW);
	
	isVisible_ = true;
	isFullscreen_ = fullscreen;
	size_ = size;
	
	return true;
}
Exemplo n.º 12
0
QString QWindowsContext::registerWindowClass(const QWindow *w)
{
    Q_ASSERT(w);
    const Qt::WindowFlags flags = w->flags();
    const Qt::WindowFlags type = flags & Qt::WindowType_Mask;
    // Determine style and icon.
    uint style = CS_DBLCLKS;
    bool icon = true;
    // The following will not set CS_OWNDC for any widget window, even if it contains a
    // QOpenGLWidget or QQuickWidget later on. That cannot be detected at this stage.
    if (w->surfaceType() == QSurface::OpenGLSurface || (flags & Qt::MSWindowsOwnDC))
        style |= CS_OWNDC;
    if (!(flags & Qt::NoDropShadowWindowHint) && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)
        && (type == Qt::Popup || w->property("_q_windowsDropShadow").toBool())) {
        style |= CS_DROPSHADOW;
    }
    switch (type) {
    case Qt::Tool:
    case Qt::ToolTip:
    case Qt::Popup:
        style |= CS_SAVEBITS; // Save/restore background
        icon = false;
        break;
    case Qt::Dialog:
        if (!(flags & Qt::WindowSystemMenuHint))
            icon = false; // QTBUG-2027, dialogs without system menu.
        break;
    }
    // Create a unique name for the flag combination
    QString cname = QStringLiteral("Qt5QWindow");
    switch (type) {
    case Qt::Tool:
        cname += QStringLiteral("Tool");
        break;
    case Qt::ToolTip:
        cname += QStringLiteral("ToolTip");
        break;
    case Qt::Popup:
        cname += QStringLiteral("Popup");
        break;
    default:
        break;
    }
    if (style & CS_DROPSHADOW)
        cname += QStringLiteral("DropShadow");
    if (style & CS_SAVEBITS)
        cname += QStringLiteral("SaveBits");
    if (style & CS_OWNDC)
        cname += QStringLiteral("OwnDC");
    if (icon)
        cname += QStringLiteral("Icon");

    return registerWindowClass(cname, qWindowsWndProc, style, GetSysColorBrush(COLOR_WINDOW), icon);
}
Exemplo n.º 13
0
PowerWinApp::PowerWinApp() :
  MessageSink(registerWindowClass()),
  tray_icon_(),
  configuration_(),
  hotkeys_(),
  global_events_(),
  modules_(configuration_, hotkeys_, global_events_),
  hooklibs_(),
  quit_shortcut_(hotkeys_)
{
}
Exemplo n.º 14
0
QString QWindowsContext::registerWindowClass(const QWindow *w, bool isGL)
{
    Q_ASSERT(w);
    const Qt::WindowFlags flags = w->flags();
    const Qt::WindowFlags type = flags & Qt::WindowType_Mask;
    // Determine style and icon.
    uint style = CS_DBLCLKS;
    bool icon = true;
    if (isGL || (flags & Qt::MSWindowsOwnDC))
        style |= CS_OWNDC;
    if (!(flags & Qt::NoDropShadowWindowHint) && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)
        && (type == Qt::Popup || w->property("_q_windowsDropShadow").toBool())) {
        style |= CS_DROPSHADOW;
    }
    switch (type) {
    case Qt::Tool:
    case Qt::ToolTip:
    case Qt::Popup:
        style |= CS_SAVEBITS; // Save/restore background
        icon = false;
        break;
    case Qt::Dialog:
        if (!(flags & Qt::WindowSystemMenuHint))
            icon = false; // QTBUG-2027, dialogs without system menu.
        break;
    }
    // Create a unique name for the flag combination
    QString cname = QStringLiteral("Qt5QWindow");
    switch (type) {
    case Qt::Tool:
        cname += QStringLiteral("Tool");
        break;
    case Qt::ToolTip:
        cname += QStringLiteral("ToolTip");
        break;
    case Qt::Popup:
        cname += QStringLiteral("Popup");
        break;
    default:
        break;
    }
    if (isGL)
        cname += QStringLiteral("GL");
    if (style & CS_DROPSHADOW)
        cname += QStringLiteral("DropShadow");
    if (style & CS_SAVEBITS)
        cname += QStringLiteral("SaveBits");
    if (style & CS_OWNDC)
        cname += QStringLiteral("OwnDC");
    if (icon)
        cname += QStringLiteral("Icon");

    return registerWindowClass(cname, qWindowsWndProc, style, GetSysColorBrush(COLOR_WINDOW), icon);
}
Exemplo n.º 15
0
HWND QWindowsContext::createDummyWindow(const QString &classNameIn,
                                        const wchar_t *windowName,
                                        WNDPROC wndProc, DWORD style)
{
    if (!wndProc)
        wndProc = DefWindowProc;
    QString className = registerWindowClass(classNameIn, wndProc);
    return CreateWindowEx(0, (wchar_t*)className.utf16(),
                          windowName, style,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          HWND_MESSAGE, NULL, (HINSTANCE)GetModuleHandle(0), NULL);
}
Exemplo n.º 16
0
QString QWindowsContext::registerWindowClass(const QWindow *w, bool isGL)
{
    const Qt::WindowFlags flags = w ? w->flags() : (Qt::WindowFlags)0;
    const Qt::WindowFlags type = flags & Qt::WindowType_Mask;

    uint style = 0;
    bool icon = false;
    QString cname = QStringLiteral("Qt5");
    if (w && isGL) {
        cname += QStringLiteral("QGLWindow");
        style = CS_DBLCLKS|CS_OWNDC;
        icon  = true;
    } else if (w && (flags & Qt::MSWindowsOwnDC)) {
        cname += QStringLiteral("QWindowOwnDC");
        style = CS_DBLCLKS|CS_OWNDC;
        icon  = true;
    } else if (w && (type == Qt::Tool || type == Qt::ToolTip)) {
        style = CS_DBLCLKS;
        if (w->inherits("QTipLabel") || w->inherits("QAlphaWidget")) {
            if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
                && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) {
                style |= CS_DROPSHADOW;
            }
            cname += QStringLiteral("QToolTip");
        } else {
            cname += QStringLiteral("QTool");
        }
        style |= CS_SAVEBITS;
        icon = false;
    } else if (w && (type == Qt::Popup)) {
        cname += QStringLiteral("QPopup");
        style = CS_DBLCLKS|CS_SAVEBITS;
        if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
            && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)))
            style |= CS_DROPSHADOW;
        icon = false;
    } else {
        cname += QStringLiteral("QWindow");
        style = CS_DBLCLKS;
        icon  = true;
    }

    HBRUSH brush = 0;
    if (w && !isGL)
        brush = GetSysColorBrush(COLOR_WINDOW);
    return registerWindowClass(cname, qWindowsWndProc, style, brush, icon);
}
Exemplo n.º 17
0
// WinMain
int WINAPI WinMain(HINSTANCE inHInstance,
    HINSTANCE inHPrevInstance,
    LPSTR inCmdLine,
    int inNCmdShow) {

        // TEXTでくくることで文字列を統一化 
        LPCTSTR windowClassName=TEXT("AnimationAndGame2-01");

        if(registerWindowClass(inHInstance,windowClassName)==false) {
            MessageBox(NULL,TEXT("Can not register WNDCLASS."),TEXT("ERROR"),MB_OK);
            return 0;
        }

        HWND hWnd=createWindow(windowClassName,kScreenWidth,kScreenHeight,inHInstance);
        if(hWnd==NULL) {
            MessageBox(NULL,TEXT("Can not create window."),TEXT("ERROR"),MB_OK);
            return 0;
        }

        // message loop
        int returnCode=0;
        bool isError=false;
        while(TRUE) {
            MSG msg;
            int getMessageResult=GetMessage(&msg,NULL,0,0);
            if(getMessageResult>0) {
                DispatchMessage(&msg);
            } else if(getMessageResult==-1) {
                isError=true;
                break;
            } else { // getMessageResult==0 (WM_QUIT)
                returnCode = msg.wParam;
                break;
            }
        }
        if( isError ) {
            MessageBox(NULL,TEXT("Can not get message."),TEXT("ERROR"),MB_OK);
        }
        return returnCode;
}
void WebPopupMenuProxyWin::showPopupMenu(const IntRect& rect, TextDirection, double, const Vector<WebPopupItem>& items, const PlatformPopupMenuData& data, int32_t selectedIndex)
{
    m_items = items;
    m_data = data;
    m_newSelectedIndex = selectedIndex;

    calculatePositionAndSize(rect);
    if (clientRect().isEmpty())
        return;

    HWND hostWindow = m_webView->window();

    if (!m_scrollbar && visibleItems() < m_items.size()) {
        m_scrollbar = Scrollbar::createNativeScrollbar(this, VerticalScrollbar, SmallScrollbar);
        m_scrollbar->styleChanged();
    }

    if (!m_popup) {
        registerWindowClass();

        DWORD exStyle = WS_EX_LTRREADING;

        m_popup = ::CreateWindowEx(exStyle, kWebKit2WebPopupMenuProxyWindowClassName, TEXT("PopupMenu"),
            WS_POPUP | WS_BORDER,
            m_windowRect.x(), m_windowRect.y(), m_windowRect.width(), m_windowRect.height(),
            hostWindow, 0, instanceHandle(), this);

        if (!m_popup)
            return;
    }

    BOOL shouldAnimate = FALSE;
    ::SystemParametersInfo(SPI_GETCOMBOBOXANIMATION, 0, &shouldAnimate, 0);

    if (shouldAnimate) {
        RECT viewRect = {0};
        ::GetWindowRect(hostWindow, &viewRect);

        if (!::IsRectEmpty(&viewRect)) {
            // Popups should slide into view away from the <select> box
            // NOTE: This may have to change for Vista
            DWORD slideDirection = (m_windowRect.y() < viewRect.top + rect.location().y()) ? AW_VER_NEGATIVE : AW_VER_POSITIVE;

            ::AnimateWindow(m_popup, defaultAnimationDuration, AW_SLIDE | slideDirection);
        }
    } else
        ::ShowWindow(m_popup, SW_SHOWNOACTIVATE);


    int index = selectedIndex;
    if (index >= 0)
        setFocusedIndex(index);

    m_showPopup = true;

    // Protect the popup menu in case its owner is destroyed while we're running the message pump.
    RefPtr<WebPopupMenuProxyWin> protect(this);

    ::SetCapture(hostWindow);

    MSG msg;
    HWND activeWindow;

    while (::GetMessage(&msg, 0, 0, 0)) {
        switch (msg.message) {
        case WM_HOST_WINDOW_MOUSEMOVE:
        case WM_HOST_WINDOW_CHAR: 
            if (msg.hwnd == m_popup) {
                // This message should be sent to the host window.
                msg.hwnd = hostWindow;
                msg.message -= WM_HOST_WINDOW_FIRST;
            }
            break;

        // Steal mouse messages.
        case WM_NCMOUSEMOVE:
        case WM_NCLBUTTONDOWN:
        case WM_NCLBUTTONUP:
        case WM_NCLBUTTONDBLCLK:
        case WM_NCRBUTTONDOWN:
        case WM_NCRBUTTONUP:
        case WM_NCRBUTTONDBLCLK:
        case WM_NCMBUTTONDOWN:
        case WM_NCMBUTTONUP:
        case WM_NCMBUTTONDBLCLK:
        case WM_MOUSEWHEEL:
            msg.hwnd = m_popup;
            break;

        // These mouse messages use client coordinates so we need to convert them.
        case WM_MOUSEMOVE:
        case WM_LBUTTONDOWN:
        case WM_LBUTTONUP:
        case WM_LBUTTONDBLCLK:
        case WM_RBUTTONDOWN:
        case WM_RBUTTONUP:
        case WM_RBUTTONDBLCLK:
        case WM_MBUTTONDOWN:
        case WM_MBUTTONUP:
        case WM_MBUTTONDBLCLK: {
            // Translate the coordinate.
            translatePoint(msg.lParam, msg.hwnd, m_popup);
            msg.hwnd = m_popup;
            break;
        }

        // Steal all keyboard messages.
        case WM_KEYDOWN:
        case WM_KEYUP:
        case WM_CHAR:
        case WM_DEADCHAR:
        case WM_SYSKEYUP:
        case WM_SYSCHAR:
        case WM_SYSDEADCHAR:
            msg.hwnd = m_popup;
            break;
        }

        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);

        if (!m_showPopup)
            break;
        activeWindow = ::GetActiveWindow();
        if (activeWindow != hostWindow && !::IsChild(activeWindow, hostWindow))
            break;
        if (::GetCapture() != hostWindow)
            break;
    }

    if (::GetCapture() == hostWindow)
        ::ReleaseCapture();

    m_showPopup = false;
    ::ShowWindow(m_popup, SW_HIDE);

    if (!m_client)
        return;

    m_client->valueChangedForPopupMenu(this, m_newSelectedIndex);

    // <https://bugs.webkit.org/show_bug.cgi?id=57904> In order to properly call the onClick()
    // handler on a <select> element, we need to fake a mouse up event in the main window.
    // The main window already received the mouse down, which showed this popup, but upon
    // selection of an item the mouse up gets eaten by the popup menu. So we take the mouse down
    // event, change the message type to a mouse up event, and post that in the message queue.
    // Thus, we are virtually clicking at the
    // same location where the mouse down event occurred. This allows the hit test to select
    // the correct element, and thereby call the onClick() JS handler.
    if (!m_client->currentlyProcessedMouseDownEvent())
        return;
        
    const MSG* initiatingWinEvent = m_client->currentlyProcessedMouseDownEvent()->nativeEvent();
    MSG fakeEvent = *initiatingWinEvent;
    fakeEvent.message = WM_LBUTTONUP;
    ::PostMessage(fakeEvent.hwnd, fakeEvent.message, fakeEvent.wParam, fakeEvent.lParam);
}
Exemplo n.º 19
0
// Open the window
// - Creates a window
// - Creates a rendering context
// - Registers new window with the window list
bool Window::open()
{
   vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CRITICAL_LVL)
      << "[vrj::direct3d::Window::open()]" << std::endl << vprDEBUG_FLUSH;

   if ( false == registerWindowClass() )
   {
      return false;
   }
   
   if ( mWindowIsOpen )
   {
      return true;
   }

   HMODULE hMod = GetModuleHandle(NULL);
   int root_height;

   // OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS.
   DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

   if ( mIsFullScreen )
   {
      style |= WS_MAXIMIZE | WS_POPUP;
      mWindowWidth  = GetSystemMetrics(SM_CXSCREEN);
      mWindowHeight = GetSystemMetrics(SM_CYSCREEN);
   }
   // If we want a border, create an overlapped window.  This will have
   // a titlebar and a border.
   else if ( mHasBorder )
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::direct3d::Window::open()] Attempting to give window a "
         << "border.\n" << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPEDWINDOW;
   }
   // Otherwise, come as close as possible to having no border by using
   // the thin-line border.
   else
   {
      vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_HVERB_LVL)
         << "[vrj::direct3d::Window::open()] Attempting to make window "
         << "borderless." << vprDEBUG_FLUSH;
      style |= WS_OVERLAPPED | WS_POPUP | WS_VISIBLE;
   }

   DWORD ex_style(0);

   if ( mAlwaysOnTop )
   {
      ex_style = WS_EX_TOPMOST;
   }

   root_height = GetSystemMetrics(SM_CYSCREEN);

   // The desired client rectangle size (left, top, right, bottom).
   RECT rc = { 0, 0, mWindowWidth, mWindowHeight };

   if ( ! AdjustWindowRect(&rc, style, false) )
   {
      doInternalError("Failed to adjust window rectangle");
      return false;
   }

   // Ensure that the input window base class has the right dimension
   // information.
   InputAreaWin32::resize(mWindowWidth, mWindowHeight);

   // Create the main application window
   mWinHandle = CreateWindowEx(ex_style, D3D_WINDOW_WIN32_CLASSNAME,
                               mWindowName.c_str(), style, mOriginX,
                               root_height - mOriginY - mWindowHeight,
                               rc.right - rc.left, rc.bottom - rc.top,
                               NULL, NULL, hMod, NULL);

   // If window was not created, quit
   if ( NULL == mWinHandle )
   {
      vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED,"ERROR:")
         << " [vrj::direct3d::Window::open()] Could not create window.\n"
         << vprDEBUG_FLUSH;
      return false;
   }

   HRESULT r = 0;

   // Acquire a pointer to IDirect3D9
   mDirect3D = Direct3DCreate9( D3D_SDK_VERSION );
   if (NULL == mDirect3D)
   {
      vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED, "ERROR:")
         << " [vrj::direct3d::Window::open()] Could not create IDirect3D8 "
         << "object.\n" << vprDEBUG_FLUSH;
      return false;
   }

   D3DPRESENT_PARAMETERS d3dpp; 
   ZeroMemory( &d3dpp, sizeof(d3dpp) );
   d3dpp.Windowed = TRUE;
   d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
   d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

   // Create the device
   if( FAILED( mDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mWinHandle,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &mRenderDevice ) ) )
   {
      vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL)
         << clrOutNORM(clrRED, "ERROR:")
         << " [vrj::direct3d::Window::open()] Initialization of the device "
         << "failed.\n" << vprDEBUG_FLUSH;
      return false;
   }

   // Attach a pointer to the device for use from the WNDPROC
   SetWindowLongPtr(mWinHandle, GWLP_USERDATA, (LPARAM) this);

   // Register the window with the window list
   addWindow(mWinHandle, this);

   // Display the window
   ShowWindow(mWinHandle, SW_SHOW);
   UpdateWindow(mWinHandle);             // Tell the window to paint
   mWindowIsOpen = true;

   // If mHideMouse is true we must pass false to ShowCursor
   ShowCursor(! mHideMouse);

   return true;
}
Exemplo n.º 20
0
    bool DiWin32EGLWindow::_Create(uint32& width, uint32& height, const DiString& title, bool fullscreen)
    {
        bool ok = false;
        DI_ASSERT(!mWndHandle);

        registerWindowClass((HINSTANCE)::GetModuleHandle(0));
        RECT winRect;
        winRect.left = 0;
        winRect.top = 0;
        winRect.right = width;
        winRect.bottom = height;
        DWORD dwstyle = (fullscreen ? gFullscreenStyle : gWindowStyle);
        uint32  offset = fullscreen ? 0 : 50;
        ::AdjustWindowRect(&winRect, dwstyle, 0);
        mWndHandle = ::CreateWindowA(gWindowClass, title.c_str(), dwstyle,
            offset, offset,
            winRect.right - winRect.left, winRect.bottom - winRect.top,
            0, 0, 0, 0);
        DI_ASSERT(mWndHandle);
        mWindow = (NativeWindowType)mWndHandle;

        if (mWndHandle)
        {
            ok = true;
            ShowWindow((HWND)mWndHandle, SW_SHOWNORMAL);
            ::SetFocus((HWND)mWndHandle);
            SetWindowLongPtr((HWND)mWndHandle, GWLP_USERDATA, PtrToLong(this));

            mHDC = ::GetDC((HWND)mWndHandle);
        }

        RAWINPUTDEVICE rawInputDevice;
        rawInputDevice.usUsagePage = 1;
        rawInputDevice.usUsage = 6;
        rawInputDevice.dwFlags = 0;
        rawInputDevice.hwndTarget = NULL;

        BOOL status = RegisterRawInputDevices(&rawInputDevice, 1, sizeof(rawInputDevice));
        if (status != TRUE)
        {
            DI_ERROR("RegisterRawInputDevices failed: %d", GetLastError());
        }

        mNativeDisplay = GetDC(mWindow);
        mEglDisplay = eglGetDisplay(mNativeDisplay);

        // fallback for some emulations 
        if (mEglDisplay == EGL_NO_DISPLAY)
        {
            mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        }

        eglInitialize(mEglDisplay, NULL, NULL);

        eglBindAPI(EGL_OPENGL_ES_API);

        mGLSupport->SetGLDisplay(mEglDisplay);
        mEglSurface = CreateSurfaceFromWindow(mEglDisplay, mWindow);

        return ok;
    }
Exemplo n.º 21
0
const char *uiInit(uiInitOptions *o)
{
	STARTUPINFOW si;
	const char *ce;
	HICON hDefaultIcon;
	HCURSOR hDefaultCursor;
	NONCLIENTMETRICSW ncm;
	INITCOMMONCONTROLSEX icc;
	HRESULT hr;

	options = *o;

	initAlloc();

	nCmdShow = SW_SHOWDEFAULT;
	GetStartupInfoW(&si);
	if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
		nCmdShow = si.wShowWindow;

	SetProcessDPIAware();

	hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION);
	if (hDefaultIcon == NULL)
		return ieLastErr("loading default icon for window classes");
	hDefaultCursor = LoadCursorW(NULL, IDC_ARROW);
	if (hDefaultCursor == NULL)
		return ieLastErr("loading default cursor for window classes");

	ce = initUtilWindow(hDefaultIcon, hDefaultCursor);
	if (ce != NULL)
		return initerr(ce, L"GetLastError() ==", GetLastError());

	if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0)
		return ieLastErr("registering uiWindow window class");

	ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW));
	ncm.cbSize = sizeof (NONCLIENTMETRICSW);
	if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0)
		return ieLastErr("getting default fonts");
	hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont));
	if (hMessageFont == NULL)
		return ieLastErr("loading default messagebox font; this is the default UI font");

	if (initContainer(hDefaultIcon, hDefaultCursor) == 0)
		return ieLastErr("initializing uiWindowsMakeContainer() window class");

	hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH);
	if (hollowBrush == NULL)
		return ieLastErr("getting hollow brush");

	ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX));
	icc.dwSize = sizeof (INITCOMMONCONTROLSEX);
	icc.dwICC = wantedICCClasses;
	if (InitCommonControlsEx(&icc) == 0)
		return ieLastErr("initializing Common Controls");

	hr = CoInitialize(NULL);
	if (hr != S_OK && hr != S_FALSE)
		return ieHRESULT("initializing COM", hr);
	// LONGTERM initialize COM security
	// LONGTERM (windows vista) turn off COM exception handling

	hr = initDraw();
	if (hr != S_OK)
		return ieHRESULT("initializing Direct2D", hr);

	hr = initDrawText();
	if (hr != S_OK)
		return ieHRESULT("initializing DirectWrite", hr);

	if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0)
		return ieLastErr("registering uiArea window class");

	if (registerMessageFilter() == 0)
		return ieLastErr("registering libui message filter");

	if (registerD2DScratchClass(hDefaultIcon, hDefaultCursor) == 0)
		return ieLastErr("initializing D2D scratch window class");

	return NULL;
}
OpenGLWindow::OpenGLWindow(const char* aTitle, int aWidth, int aHeight, bool aIsFullScreen) :  
	m_WindowHandle(NULL), 
	m_WindowDeviceContext(NULL),
	m_OpenGLContext(NULL), 
    m_IsFullScreen(aIsFullScreen)
{
	//Pass in the window title, and register the window class.
	registerWindowClass(aTitle);

	//
	RECT WindowRect;
	WindowRect.top = WindowRect.left = 0;
	WindowRect.right = aWidth;
	WindowRect.bottom = aHeight;

	//Window Extended Style
	DWORD extendedWindowStyle = 0;	

	//Windows Style
	DWORD windowStyle = 0;		

	//Do we hide the cursor?
	ShowCursor(WINDOW_SHOW_MOUSE_CURSOR);

	if(m_IsFullScreen == true)
	{
		DEVMODE dmScreenSettings;
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));	
		dmScreenSettings.dmSize = sizeof(dmScreenSettings);		
		dmScreenSettings.dmPelsWidth = aWidth;			
		dmScreenSettings.dmPelsHeight = aHeight;		
		dmScreenSettings.dmBitsPerPel = 32;		
		dmScreenSettings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;

		//Change the display settings to fullscreen. On error, throw an exception.
		if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		{
			throw Win32Exception("Unable to swith to fullscreen mode");
		}

		extendedWindowStyle = WS_EX_APPWINDOW;	
		windowStyle = WS_POPUP;	
	}
	else
	{
		extendedWindowStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
		windowStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_MINIMIZEBOX;
	}

	//Adjust the window to the true requested size
	AdjustWindowRectEx(&WindowRect, windowStyle, false, extendedWindowStyle);	

	//Now create the OpenGL window
    m_WindowHandle = CreateWindowEx(extendedWindowStyle, 
							 aTitle, 
							 aTitle, 
							 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | windowStyle,
							 WINDOW_DEFAULT_X, WINDOW_DEFAULT_Y, 
							 WindowRect.right - WindowRect.left, 
							 WindowRect.bottom - WindowRect.top, 
							 NULL, NULL, 
							 GetModuleHandle(NULL), 
							 this);

	//
	if(m_WindowHandle == NULL)
	{
		throw Win32Exception("Cannot create the main window");
	}

	//
	createOpenGLContext();

	//Show the newly created window
	ShowWindow(m_WindowHandle, SW_SHOW);

	// Call OnSize manually because in fullscreen mode it will be 
	// called only when the window is created (which is too early
	// because OpenGL is not initialized yet).
	resize(aWidth, aHeight);

	//
	m_LastMouseX = -1;
	m_LastMouseY = -1;
}
Exemplo n.º 23
0
//--------------------------------------------------------------
// initialize display
void mgWinServices::initDisplay()
{
  // find and save current display mode
  findCurrentDisplayMode();

  // register the window class and create window
  registerWindowClass();
  createWindow();

  // build error string if library is unknown choice
  mgString libraryChoices;

  // for each supported library, try to initialize it
  m_support = NULL;
  BOOL triedLibrary = false;

#ifdef SUPPORT_GL33
  libraryChoices += "\"OpenGL3.3\" ";
  if (m_support == NULL && (m_library.equalsIgnoreCase("OpenGL3.3") || m_library.isEmpty()))
  {
    triedLibrary = true;
    mgWinGL33Support* gl33 = new mgWinGL33Support();

    // requested gl33 attributes
    gl33->m_dc = m_dc;
    gl33->m_fullscreen = m_fullscreen;
    gl33->m_multiSample = m_multiSample;
    gl33->m_swapImmediate = m_swapImmediate;

    if (gl33->initDisplay())
    {
      m_libraryFound = MG_LIBRARY_OPENGL33;
      m_support = gl33;
    }
    else delete gl33;
  }
#endif

#ifdef SUPPORT_GL21
  libraryChoices += "\"OpenGL2.1\" ";
  if (m_support == NULL && (m_library.equalsIgnoreCase("OpenGL2.1") || m_library.isEmpty()))
  {
    triedLibrary = true;
    mgWinGL21Support* gl21 = new mgWinGL21Support();

    // requested gl21 attributes
    gl21->m_dc = m_dc;
    gl21->m_fullscreen = m_fullscreen;
    gl21->m_multiSample = m_multiSample;
    gl21->m_swapImmediate = m_swapImmediate;

    if (gl21->initDisplay())
    {
      m_libraryFound = MG_LIBRARY_OPENGL21;
      m_support = gl21;
    }
    else delete gl21;
  }
#endif

#ifdef SUPPORT_DX9
  libraryChoices += "\"DirectX9\" ";
  if (m_support == NULL && (m_library.equalsIgnoreCase("DirectX9") || m_library.isEmpty()))
  {
    triedLibrary = true;
    mgDX9Support* dx9 = new mgDX9Support();

    // requested display attributes
    dx9->m_dc = m_dc;
    dx9->m_fullscreen = m_fullscreen;
    dx9->m_multiSample = m_multiSample;
    dx9->m_swapImmediate = m_swapImmediate;

    if (dx9->initDisplay())
    {
      m_libraryFound = MG_LIBRARY_DIRECTX9;
      m_support = dx9;
    }
    else delete dx9;
  }
#endif

  // if display initialization failed, throw exception
  if (m_support == NULL)
  {
    // if no library specified
    if (m_library.isEmpty())
      throw new mgErrorMsg("winNoLibrary", "libraries", "%s", (const char*) libraryChoices);

    // library specified could not be initialized
    if (triedLibrary)
      throw new mgErrorMsg("winBadLibrary", "library", "%s", (const char*) m_library);

    // library specified was not supported
    throw new mgErrorMsg("winWrongLibrary", "library,libraries", "%s,%s", 
      (const char*) m_library, (const char*) libraryChoices);
  }

  // save actual attributes
  m_depthBits = m_support->m_depthBits;
  m_fullscreen = m_support->m_fullscreen;
  m_multiSample = m_support->m_multiSample;
  m_swapImmediate = m_support->m_swapImmediate;

  m_support->setGraphicsSize(m_windowWidth, m_windowHeight);

  mgDebug("");
  mgDebug("------ display initialized.  Return to app: %s", (const char*) m_windowTitle);
}
Exemplo n.º 24
-1
Arquivo: init.c Projeto: mantyr/libui
const char *uiInit(uiInitOptions *o)
{
    STARTUPINFOW si;
    const char *ce;
    HICON hDefaultIcon;
    HCURSOR hDefaultCursor;
    NONCLIENTMETRICSW ncm;
    INITCOMMONCONTROLSEX icc;
    HRESULT hr;

    options = *o;

    if (initAlloc() == 0)
        return loadLastError("error initializing memory allocations");

    initResizes();

    nCmdShow = SW_SHOWDEFAULT;
    GetStartupInfoW(&si);
    if ((si.dwFlags & STARTF_USESHOWWINDOW) != 0)
        nCmdShow = si.wShowWindow;

    hDefaultIcon = LoadIconW(NULL, IDI_APPLICATION);
    if (hDefaultIcon == NULL)
        return loadLastError("loading default icon for window classes");
    hDefaultCursor = LoadCursorW(NULL, IDC_ARROW);
    if (hDefaultCursor == NULL)
        return loadLastError("loading default cursor for window classes");

    ce = initUtilWindow(hDefaultIcon, hDefaultCursor);
    if (ce != NULL)
        return loadLastError(ce);

    if (registerWindowClass(hDefaultIcon, hDefaultCursor) == 0)
        return loadLastError("registering uiWindow window class");

    ZeroMemory(&ncm, sizeof (NONCLIENTMETRICSW));
    ncm.cbSize = sizeof (NONCLIENTMETRICSW);
    if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW), &ncm, sizeof (NONCLIENTMETRICSW)) == 0)
        return loadLastError("getting default fonts");
    hMessageFont = CreateFontIndirectW(&(ncm.lfMessageFont));
    if (hMessageFont == NULL)
        return loadLastError("loading default messagebox font; this is the default UI font");

    if (initContainer(hDefaultIcon, hDefaultCursor) == 0)
        return loadLastError("initializing uiMakeContainer() window class");

    if (SetConsoleCtrlHandler(consoleCtrlHandler, TRUE) == 0)
        return loadLastError("setting up console end session handler");

    hollowBrush = (HBRUSH) GetStockObject(HOLLOW_BRUSH);
    if (hollowBrush == NULL)
        return loadLastError("getting hollow brush");

    ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX));
    icc.dwSize = sizeof (INITCOMMONCONTROLSEX);
    icc.dwICC = wantedICCClasses;
    if (InitCommonControlsEx(&icc) == 0)
        return loadLastError("initializing Common Controls");

    if (initDialogHelper(hDefaultIcon, hDefaultCursor) == 0)
        return loadLastError("initializing the dialog helper");

    hr = CoInitialize(NULL);
    if (hr != S_OK && hr != S_FALSE)
        return loadHRESULT("initializing COM", hr);
    // TODO initialize COM security
    // TODO (windows vista) turn off COM exception handling

    return NULL;
}