Пример #1
0
void OverlayFunctions::CreateWindowOverlay()
{
	Overlay.Window = CreateWindowEx(WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TRANSPARENT, Overlay.Name, Overlay.Name, WS_POPUP, 1, 1, Overlay.Width, Overlay.Height, 0, 0, hInstance, 0);
	SetLayeredWindowAttributes(Overlay.Window, RGB(0, 0, 0), 255, LWA_COLORKEY | LWA_ALPHA);
	ShowWindow(Overlay.Window, SW_SHOW);
	DwmExtendFrameIntoClientArea(Overlay.Window, &Overlay.Margin);
}
void CFramelessWindow::setResizeable(bool resizeable)
{
    bool visible = isVisible();
    m_bResizeable = resizeable;
    if (m_bResizeable){
        setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);
//        setWindowFlag(Qt::WindowMaximizeButtonHint);

        //此行代码可以带回Aero效果,同时也带回了标题栏和边框,在nativeEvent()会再次去掉标题栏
        //
        //this line will get titlebar/thick frame/Aero back, which is exactly what we want
        //we will get rid of titlebar and thick frame again in nativeEvent() later
        HWND hwnd = (HWND)this->winId();
        DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
        ::SetWindowLong(hwnd, GWL_STYLE, style | WS_MAXIMIZEBOX | WS_THICKFRAME | WS_CAPTION);
    }else{
        setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
//        setWindowFlag(Qt::WindowMaximizeButtonHint,false);

        HWND hwnd = (HWND)this->winId();
        DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
        ::SetWindowLong(hwnd, GWL_STYLE, style & ~WS_MAXIMIZEBOX & ~WS_CAPTION);
    }

    //保留一个像素的边框宽度,否则系统不会绘制边框阴影
    //
    //we better left 1 piexl width of border untouch, so OS can draw nice shadow around it
    const MARGINS shadow = { 1, 1, 1, 1 };
    DwmExtendFrameIntoClientArea(HWND(winId()), &shadow);

    setVisible(visible);
}
Пример #3
0
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_PAINT:
		DwmExtendFrameIntoClientArea(hWnd, &margin);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	case WM_HOTKEY:
		if (wParam >= 0 && wParam <= 24)
			ToggleDisplaySection(wParam);
		else if (wParam >= 100 && wParam <= 109)
			SetCountdown(wParam - 100);
		else if (wParam == 110)
			ResetDistance();
		else if (wParam == 201)
			ToggleInvert();
		else if (wParam == 202)
			ToggleFontOutline();
		else if (wParam == 203)
			ToggleSpeedLimitOnly();
		break;
	}

	return DefWindowProc (hWnd, message, wParam, lParam);
}
void BorderlessWindow::on_pShadowBtn_clicked()
{
	_isShadow = !_isShadow;
	static const MARGINS shadow_state[2] = { { 0, 0, 0, 0 }, { 1, 1, 1, 1 } };
	DwmExtendFrameIntoClientArea((HWND)this->winId(), &shadow_state[_isShadow]);
	// redraw frame
    SetWindowPos((HWND)winId(), nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
}
Пример #5
0
static void SetAero(HWND hWnd)
{
	if(g_Aero)
	{
		MARGINS margin = { -1 };
		DwmExtendFrameIntoClientArea(hWnd, &margin);
	}
}
Пример #6
0
void BorderlessWindow::toggleShadow()
{
    if (borderless)
    {
        aeroShadow = !aeroShadow;
        const MARGINS c_shadowOn = {1, 1, 1, 1};
        const MARGINS c_shadowOff = {0, 0, 0, 0};
        DwmExtendFrameIntoClientArea(hWnd, (aeroShadow) ? (&c_shadowOn) : (&c_shadowOff));
    }
}
Пример #7
0
void SetAeroGlass(HWND handle, bool enable_on_maximized) {
  if (!IsAeroGlassEnabled()) {
    return;
  }
  MARGINS margin = { -1, -1, -1, -1 };
  DwmExtendFrameIntoClientArea(handle, &margin);
  if (enable_on_maximized) {
    DWM_BLURBEHIND blurBehind;
    blurBehind.dwFlags = DWM_BB_ENABLE | DWM_BB_TRANSITIONONMAXIMIZED;
    blurBehind.fEnable = true;
    blurBehind.fTransitionOnMaximized = true;
    DwmEnableBlurBehindWindow(handle, &blurBehind);
  }
}
Пример #8
0
BOOL CSettings::OnInitDialog()
{
    BOOL bResult = CPropertySheet::OnInitDialog();
    MARGINS margs;
    margs.cxLeftWidth = 0;
    margs.cyTopHeight = 0;
    margs.cxRightWidth = 0;
    margs.cyBottomHeight = BOTTOMMARG;

    if (m_aeroControls.AeroDialogsEnabled())
    {
        DwmExtendFrameIntoClientArea(m_hWnd, &margs);
        m_aeroControls.SubclassOkCancelHelp(this);
        m_aeroControls.SubclassControl(this, ID_APPLY_NOW);
    }
    return bResult;
}
Пример #9
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_PAINT:
	{
					 DwmExtendFrameIntoClientArea(hWnd, &margin);
	}break;

	case WM_DESTROY:
	{
					   PostQuitMessage(0);
					   return 0;
	} break;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}
Пример #10
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_PAINT:
			renderOverlay();
			break;
		case WM_CREATE:
			DwmExtendFrameIntoClientArea(hWnd, &margins);
			break;
		case WM_DESTROY:

			PostQuitMessage(0);
			return 0;
	}

	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Пример #11
0
LRESULT CALLBACK WinProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
	const MARGINS objMargens = { 0, 0, Global::getInstance()->objMyWindow.intLargura, Global::getInstance()->objMyWindow.intAltura };

	switch (Message) {
		case WM_CREATE:
			DwmExtendFrameIntoClientArea(hWnd, &objMargens);
			break;

		case WM_DESTROY:
			PostQuitMessage(1);
			return 0;

		default:
			return DefWindowProc(hWnd, Message, wParam, lParam);
			break;
	}

	return 0;
}
Пример #12
0
HRESULT EnableBlurBehind(HWND hwnd)
{
    HRESULT hr = S_OK;

    // Create and populate the blur-behind structure.
    DWM_BLURBEHIND bb = {0};

    // Specify blur-behind and blur region.
    bb.dwFlags = DWM_BB_ENABLE;
    bb.fEnable = true;
    bb.hRgnBlur = NULL;

    // Enable blur-behind.
    hr = DwmEnableBlurBehindWindow(hwnd, &bb);
	MARGINS margins = {-1};

    hr = DwmExtendFrameIntoClientArea(hwnd,&margins);
    return hr;
}
Пример #13
0
BOOL CMergeWizard::OnInitDialog()
{
    BOOL bResult = CResizableSheetEx::OnInitDialog();
    CAppUtils::MarkWindowAsUnpinnable(m_hWnd);

    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    SVN svn;
    url = svn.GetURLFromPath(wcPath);
    sUUID = svn.GetUUIDFromPath(wcPath);

    MARGINS margs;
    margs.cxLeftWidth = 0;
    margs.cyTopHeight = 0;
    margs.cxRightWidth = 0;
    margs.cyBottomHeight = BOTTOMMARG;

    if ((DWORD)CRegDWORD(L"Software\\TortoiseSVN\\EnableDWMFrame", TRUE))
    {
        HIGHCONTRAST hc = { sizeof(HIGHCONTRAST) };
        SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRAST), &hc, FALSE);
        BOOL bEnabled = FALSE;
        if (((hc.dwFlags & HCF_HIGHCONTRASTON) == 0) && SUCCEEDED(DwmIsCompositionEnabled(&bEnabled)) && bEnabled)
        {
            DwmExtendFrameIntoClientArea(m_hWnd, &margs);
            ShowGrip(false);
        }
        m_aeroControls.SubclassOkCancelHelp(this);
        m_aeroControls.SubclassControl(this, ID_WIZFINISH);
        m_aeroControls.SubclassControl(this, ID_WIZBACK);
        m_aeroControls.SubclassControl(this, ID_WIZNEXT);
    }

    if ((m_pParentWnd == NULL) && (GetExplorerHWND()))
        CenterWindow(CWnd::FromHandle(GetExplorerHWND()));
    EnableSaveRestore(L"MergeWizard");

    return bResult;
}
Пример #14
0
void BrowserFrameWin::UpdateDWMFrame()
{
    // Nothing to do yet, or we're not showing a DWM frame.
    if(!GetWidget()->client_view() || !browser_frame_->ShouldUseNativeFrame())
    {
        return;
    }

    MARGINS margins = { 0 };
    if(browser_view_->IsBrowserTypeNormal())
    {
        // In fullscreen mode, we don't extend glass into the client area at all,
        // because the GDI-drawn text in the web content composited over it will
        // become semi-transparent over any glass area.
        if(!IsMaximized() && !IsFullscreen())
        {
            margins.cxLeftWidth = kClientEdgeThickness + 1;
            margins.cxRightWidth = kClientEdgeThickness + 1;
            margins.cyBottomHeight = kClientEdgeThickness + 1;
            margins.cyTopHeight = kClientEdgeThickness + 1;
        }
        // In maximized mode, we only have a titlebar strip of glass, no side/bottom
        // borders.
        if(!browser_view_->IsFullscreen())
        {
            gfx::Rect tabstrip_bounds(
                browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip()));
            margins.cyTopHeight = tabstrip_bounds.bottom() + kDWMFrameTopOffset;
        }
    }
    else
    {
        // For popup and app windows we want to use the default margins.
    }
    DwmExtendFrameIntoClientArea(GetNativeView(), &margins);
}
Пример #15
0
void Window::removeBorder() {
	static const MARGINS frame = { -1, -1, -1, -1 };
	DwmExtendFrameIntoClientArea(_hwnd, &frame);
}
Пример #16
0
bool MainWindowEx::winEvent(MSG *msg, long *result)
{
    bool fCallDWP = true;
    BOOL fDwmEnabled = FALSE;
    LRESULT lRet = 0;
    HRESULT hr = S_OK;
    HWND hWnd       = msg->hwnd;
    UINT message    = msg->message;
    WPARAM wParam   = msg->wParam;
    LPARAM lParam   = msg->lParam;

    // Winproc worker for custom frame issues.
    hr = DwmIsCompositionEnabled(&fDwmEnabled);
    if (!SUCCEEDED(hr) || !fDwmEnabled)
    {
        qDebug() << "DWM not enabled";
        return false;
    }
    fCallDWP = !DwmDefWindowProc(hWnd, message, wParam, lParam, &lRet);

    switch(message)
    {
        // 鼠标在窗口边缘时,缩放可用
        case WM_NCHITTEST:
        {
            return hitTestNCA(msg, result);
        }

        // Handle window activation.
        case WM_ACTIVATE:
        {
            // Extend the frame into the client area.
            MARGINS margins = { -1, -1, -1, -1 };
            hr = DwmExtendFrameIntoClientArea(hWnd, &margins);

            if (!SUCCEEDED(hr))
            {
                // Handle error.
                qDebug() << "Extend frame to Client Area error";
            }

            fCallDWP = true;
            lRet = 0;
        };
        break;

        // 缩放
        case WM_NCCALCSIZE:
        {
            if(wParam == TRUE)
            {
                // Calculate new NCCALCSIZE_PARAMS based on custom NCA inset.
                NCCALCSIZE_PARAMS *pncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);

                pncsp->rgrc[0].left   = pncsp->rgrc[0].left   - 1;
                pncsp->rgrc[0].top    = pncsp->rgrc[0].top    - 1;
                pncsp->rgrc[0].right  = pncsp->rgrc[0].right  + 1;
                pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom + 1;

                QRect rect;
                rect.setLeft(pncsp->rgrc[0].left);
                rect.setTop(pncsp->rgrc[0].top);
                rect.setRight(pncsp->rgrc[0].right);
                rect.setBottom(pncsp->rgrc[0].bottom);
                emit sizeChanged();

                lRet = 0;
                // No need to pass the message on to the DefWindowProc.
                fCallDWP = false;
            }
        };
        break;

        case WM_NCMOUSELEAVE:
        {
//    if( uRow ==0 || uRow == 2 || uCol == 0 || uCol == 2)
//        emit hoverLeave();
//    else
//        emit hoverEnter();
            if(!this->geometry().contains(QCursor::pos()))
            {
//                QTimer::singleShot(400, this, SIGNAL(hoverLeave()));
                emit hoverLeave();
            }
        };
        break;

        case WM_NCMOUSEMOVE:
        {
            emit hoverEnter();
        };
        break;
        //最大化/最小化
        case WM_GETMINMAXINFO:
        {
            MINMAXINFO *mmi = (MINMAXINFO*)lParam;
            QRect rect = QApplication::desktop()->availableGeometry();
//            mmi->ptMaxSize.x = rect.width();
//            mmi->ptMaxSize.y = rect.height();
            mmi->ptMaxPosition.x = 0;
            mmi->ptMaxPosition.y = 0;
            mmi->ptMinTrackSize.x = 400;
            mmi->ptMinTrackSize.y = 260;
            mmi->ptMaxTrackSize.x = rect.width();
            mmi->ptMaxTrackSize.y = rect.height();

            lRet = 0;
            fCallDWP = false;
        };
        break;
    }

    if (!fCallDWP)
        *result = lRet;

    return !fCallDWP;
}
//======================================================================
HWND CWindow::Initialize(HWND hTargetWindow, INT& riWidth, INT& riHeight, const std::wstring& szClassName, const TpfnDrawEvent pfnDrawEvent)
{
	//Create overlay window for target window

	if ((!hTargetWindow) || (!pfnDrawEvent))
		return NULL;

	//Get target window information
	if (!GetWindowRect(hTargetWindow, &this->m_rWndPosData))
		return NULL;

	this->m_szClassName = szClassName;

	//Setup data
	WNDCLASSEX wndClassData;
	memset(&wndClassData, 0x00, sizeof(wndClassData));
	wndClassData.cbSize = sizeof(WNDCLASSEX);
	wndClassData.style = CS_VREDRAW | CS_HREDRAW;
	wndClassData.lpfnWndProc = &WindowProc;
	wndClassData.hInstance = (HINSTANCE)GetCurrentProcess();
	wndClassData.lpszClassName = this->m_szClassName.c_str();
	
	//Register class
	this->m_aClass = RegisterClassEx(&wndClassData);
	if (!this->m_aClass)
		return NULL;

	//Create window
	this->m_hWindow = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED, this->m_szClassName.c_str(), this->m_szClassName.c_str(), WS_POPUP, this->m_rWndPosData.left, this->m_rWndPosData.top, this->m_rWndPosData.right - this->m_rWndPosData.left, this->m_rWndPosData.bottom - this->m_rWndPosData.top, NULL, NULL, 0, 0);
	if (!this->m_hWindow) {
		UnregisterClass(this->m_szClassName.c_str(), (HINSTANCE)GetCurrentProcess());
		this->m_aClass = NULL;
		return NULL;
	}

	//Set transparency color key of window
	if (!SetLayeredWindowAttributes(this->m_hWindow, RGB(0, 0, 0), 0, LWA_COLORKEY)) {
		DestroyWindow(this->m_hWindow);
		UnregisterClass(this->m_szClassName.c_str(), (HINSTANCE)GetCurrentProcess());
		this->m_aClass = NULL;
		return NULL;
	}

	//Extend window frame into client area
	MARGINS mMargin = {0, 0, this->m_rWndPosData.right - this->m_rWndPosData.left, this->m_rWndPosData.bottom - this->m_rWndPosData.top};
    if (FAILED(DwmExtendFrameIntoClientArea(this->m_hWindow, &mMargin))) {
		DestroyWindow(this->m_hWindow);
		UnregisterClass(this->m_szClassName.c_str(), (HINSTANCE)GetCurrentProcess());
		this->m_aClass = NULL;
		return NULL;
	}

	//Set resolution
	riWidth = this->m_rWndPosData.right - this->m_rWndPosData.left;
	riHeight = this->m_rWndPosData.bottom - this->m_rWndPosData.top;

	//Save target window handle
	this->m_hTarget = hTargetWindow;

	//Save event function pointer
	this->m_pDrawEvent = pfnDrawEvent;

	//Set instance pointer
	pWindowThisInstance = this;

	return this->m_hWindow;
}
Пример #18
0
void BorderlessWindow::set_shadow(bool enabled) const {
	if (composition_enabled()) {
		static const MARGINS shadow_state[2] = {{0,0,0,0},{1,1,1,1}};
		DwmExtendFrameIntoClientArea(hwnd.get(), &shadow_state[enabled]);
	}
}
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId;
    int wmEvent;
    
    switch (message) 
    {
        case WM_COMMAND:
            wmId    = LOWORD(wParam); 
            wmEvent = HIWORD(wParam); 
            // Parse the menu selections:
            switch (wmId)
            {
                case IDM_ABOUT:
                    DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                    break;
                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;

        case WM_ERASEBKGND:
            return 1;

        case WM_PAINT:
            // Let's open some theme data, and using BufferedPainting draw different fonts on glass background
            {
                RECT rcClient;
                GetClientRect(hWnd, &rcClient);

                MARGINS marGlassInset = {-1, -1, -1, -1}; // -1 means the whole window
                DwmExtendFrameIntoClientArea(hWnd, &marGlassInset);

                PAINTSTRUCT ps;
                HDC    hdc    = BeginPaint(hWnd, &ps);
                // ControlPanelStyle is declared in AeroStyle.xml
                HTHEME hTheme = OpenThemeData(NULL, L"ControlPanelStyle"); 

                if (hTheme)
                {
                    HDC hdcPaint = NULL;

                    BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
                    params.dwFlags        = BPPF_ERASE;

                    HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, &params, &hdcPaint);
                    if (hdcPaint)
                    {
                        // Let's start with the simplest GDI default font
                        DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                        DttOpts.dwFlags = DTT_COMPOSITED;
                        DrawText(hdcPaint, L"This is some GDI text in the default font", -1, &rcClient, 0);

                        // Let's look at the same text in the default theme
                        rcClient.top += RECT_INCREMENT;
                        DrawThemeTextEx(hTheme, hdcPaint, 0, 0, L"This is some text in the default font", -1, 0, &rcClient, &DttOpts);

                        // Let's add some text color to add to theming attributes and draw again
                        rcClient.top    += RECT_INCREMENT;
                        DttOpts.dwFlags |= DTT_TEXTCOLOR;
                        DttOpts.crText   = RGB(255, 255, 255);
                        // CPANEL_TASKLINK is declared in VSStyle.h
                        DrawThemeTextEx(hTheme, hdcPaint, CPANEL_TASKLINK, 0, L"This is some text in a themed font", -1, 0, &rcClient, &DttOpts);

                        // Draw text on glass in a selected font
                        DttOpts.dwFlags &= ~DTT_TEXTCOLOR;
                        LOGFONT lgFont;
                        HFONT hFontOld = NULL;
                        if (SUCCEEDED(GetThemeSysFont(hTheme, TMT_CAPTIONFONT, &lgFont)))
                        {
                            HFONT hFont = CreateFontIndirect(&lgFont);
                            hFontOld    = (HFONT) SelectObject(hdcPaint, hFont);
                        }

                        rcClient.top += RECT_INCREMENT;
                        DrawText(hdcPaint, L"This is some GDI text in the selected font", -1, &rcClient, 0);

                        // The same selected font in themed text
                        rcClient.top += RECT_INCREMENT;
                        DrawThemeTextEx(hTheme, hdcPaint, 0, 0, L"This is some text in the selected font", -1, 0, &rcClient, &DttOpts);

                        SelectObject(hdcPaint, hFontOld);
                        rcClient.top += RECT_INCREMENT;
                        DrawText(hdcPaint, L"This is some GDI text in the default font", -1, &rcClient, 0);

                        // Let's add glow to our text attributes
                        DttOpts.dwFlags |= DTT_GLOWSIZE;
                        DttOpts.iGlowSize = 12; // Default value
                        // CompositedWindow::Window is declared in AeroStyle.xml
                        HTHEME hThemeWindow = OpenThemeData(NULL, L"CompositedWindow::Window");
                        if (hThemeWindow != NULL)
                        {
                            GetThemeInt(hThemeWindow, 0, 0, TMT_TEXTGLOWSIZE, &DttOpts.iGlowSize);
                            CloseThemeData(hThemeWindow);
                        }

                        rcClient.top += RECT_INCREMENT;
                        DrawThemeTextEx(hTheme, hdcPaint, 0, 0, L"This is some text with glow in the default font", -1, 0, &rcClient, &DttOpts);

                        // Now some color(theme) and glow
                        DttOpts.dwFlags |= DTT_TEXTCOLOR;
                        DttOpts.crText   = RGB(255, 255, 255);

                        rcClient.top += RECT_INCREMENT;
                        // CPANEL_TASKLINK is declared in VSStyle.h
                        DrawThemeTextEx(hTheme, hdcPaint, CPANEL_TASKLINK, 0, L"This is some text with glow in a themed font", -1, 0, &rcClient, &DttOpts);

                        DttOpts.dwFlags &= ~DTT_TEXTCOLOR;

                        // Find a particular font and draw using this
                        if (SUCCEEDED(GetThemeSysFont(hTheme, TMT_CAPTIONFONT, &lgFont)))
                        {
                            HFONT hFont = CreateFontIndirect(&lgFont);
                            hFontOld    = (HFONT) SelectObject(hdcPaint, hFont);
                        }
                        
                        rcClient.top += RECT_INCREMENT;
                        DrawText(hdcPaint, L"This is some GDI text in the selected font", -1, &rcClient, 0);
                        
                        rcClient.top += RECT_INCREMENT;
                        DrawThemeTextEx(hTheme, hdcPaint, 0, 0, L"This is some text with glow in the selected font", -1, 0, &rcClient, &DttOpts);
                        
                        if (hFontOld)
                        {                        
                            SelectObject(hdcPaint, hFontOld);
                        }
                        EndBufferedPaint(hBufferedPaint, TRUE);
                    }
                    CloseThemeData(hTheme);
                }
                EndPaint(hWnd, &ps);
            }
            break;
        
        case WM_DESTROY:
            PostQuitMessage(0);
            BufferedPaintUnInit();
            break;
        
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Пример #20
0
// +-----------+
// | WinMain() |
// +-----------+---------+
// | Program entry point |
// +---------------------+
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
{
  HWND       hWnd  = NULL;
  MSG        uMsg;     
  WNDCLASSEX wc    = {sizeof(WNDCLASSEX),              // cbSize
                      NULL,                            // style
                      WindowProc,                      // lpfnWndProc
                      NULL,                            // cbClsExtra
                      NULL,                            // cbWndExtra
                      hInstance,                       // hInstance
                      LoadIcon(NULL, IDI_APPLICATION), // hIcon
                      LoadCursor(NULL, IDC_ARROW),     // hCursor
                      NULL,                            // hbrBackground
                      NULL,                            // lpszMenuName
                      g_wcpAppName,                    // lpszClassName
                      LoadIcon(NULL, IDI_APPLICATION)};// hIconSm

  RegisterClassEx(&wc);
  hWnd = CreateWindowEx(WS_EX_COMPOSITED,             // dwExStyle
                        g_wcpAppName,                 // lpClassName
                        g_wcpAppName,                 // lpWindowName
                        WS_POPUP | WS_SIZEBOX,        // dwStyle
                        CW_USEDEFAULT, CW_USEDEFAULT, // x, y
                        g_iWidth, g_iHeight,          // nWidth, nHeight
                        NULL,                         // hWndParent
                        NULL,                         // hMenu
                        hInstance,                    // hInstance
                        NULL);                        // lpParam

  // Extend glass to cover whole window
  DwmExtendFrameIntoClientArea(hWnd, &g_mgDWMMargins);

  // Initialise Direct3D
  if(SUCCEEDED(D3DStartup(hWnd)))
  {
    if(SUCCEEDED(CreateCube()))
    {
      // Show the window
      ShowWindow(hWnd, SW_SHOWDEFAULT);
      UpdateWindow(hWnd);
				
      // Enter main loop
      while(TRUE)
      {
        // Check for a message
        if(PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE))
        {
          // Check if the message is WM_QUIT
          if(uMsg.message == WM_QUIT)
          {
            // Break out of main loop
            break;
          }

          // Pump the message
          TranslateMessage(&uMsg);
          DispatchMessage(&uMsg);
        }

        // Render a frame
        Render();
      }
    }
  }

  // Shutdown Direct3D
  D3DShutdown();

  // Exit application
  return 0;
}