//----------------------------------------------------------------------------- // PreInit //----------------------------------------------------------------------------- bool CIHVTestApp::PreInit( void ) { CreateInterfaceFn factory = GetFactory(); ConnectTier1Libraries( &factory, 1 ); // Add paths... if ( !SetupSearchPaths( NULL, false, true ) ) { Error( "Failed to setup search paths\n" ); return false; } const char *pArgVal; if ( CommandLine()->CheckParm( "-bench" ) ) { g_BenchMode = true; } if( !g_BenchMode && !CommandLine()->CheckParm( "-i" ) ) { // Set some default parameters for running as a unittest g_BenchMode = true; g_WindowMode = IsPC() ? true : false; } if( g_BenchMode ) { if ( CommandLine()->CheckParm( "-i", &pArgVal ) ) { g_BenchRuns[0].pModelName[0] = pArgVal; } } if( CommandLine()->CheckParm( "-softwaretl" ) ) { g_SoftwareTL = true; } // Explicitly in window/fullscreen mode? if ( CommandLine()->CheckParm( "-window") ) { g_WindowMode = true; } else if ( CommandLine()->CheckParm( "-fullscreen" ) ) { g_WindowMode = false; } /* figure out g_Renderwidth and g_RenderHeight */ g_RenderWidth = -1; g_RenderHeight = -1; if( CommandLine()->CheckParm( "-width", &pArgVal ) ) { g_RenderWidth = atoi( pArgVal ); } if( CommandLine()->CheckParm( "-height", &pArgVal ) ) { g_RenderHeight = atoi( pArgVal ); } if( g_RenderWidth == -1 && g_RenderHeight == -1 ) { g_RenderWidth = 640; g_RenderHeight = 480; } else if( g_RenderWidth != -1 && g_RenderHeight == -1 ) { switch( g_RenderWidth ) { case 320: g_RenderHeight = 240; break; case 512: g_RenderHeight = 384; break; case 640: g_RenderHeight = 480; break; case 800: g_RenderHeight = 600; break; case 1024: g_RenderHeight = 768; break; case 1280: g_RenderHeight = 1024; break; case 1600: g_RenderHeight = 1200; break; default: DisplayError( "Can't figure out window dimensions!!" ); exit( -1 ); break; } } if( g_RenderWidth == -1 || g_RenderHeight == -1 ) { DisplayError( "Can't figure out window dimensions!!" ); exit( -1 ); } int windowWidth, windowHeight; CalcWindowSize( g_RenderWidth, g_RenderHeight, &windowWidth, &windowHeight ); if( !CreateAppWindow( "ihvtest1", windowWidth, windowHeight ) ) { return false; } return true; }
// this routine calculates the size and position of the window relative // to it's anchor point, and moves the window accordingly. The region is also // created and set here. void CBalloonHelp::PositionWindow() { CSize sizeWnd = CalcWindowSize(); CPoint ptTail[3]; CPoint ptTopLeft(0,0); CPoint ptBottomRight(sizeWnd.cx, sizeWnd.cy); // force recalculation of desktop m_screenRect.SetRectEmpty(); switch (GetBalloonQuadrant()) { case BQ_TOPLEFT: ptTopLeft.y = nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4 + nTIP_TAIL; ptTail[0].y = nTIP_TAIL+1; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = 1; break; case BQ_TOPRIGHT: ptTopLeft.y = nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4*3; ptTail[0].y = nTIP_TAIL+1; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4*3 + nTIP_TAIL; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = 1; break; case BQ_BOTTOMLEFT: ptBottomRight.y = sizeWnd.cy-nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4 + nTIP_TAIL; ptTail[0].y = sizeWnd.cy-nTIP_TAIL-2; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = sizeWnd.cy-2; break; case BQ_BOTTOMRIGHT: ptBottomRight.y = sizeWnd.cy-nTIP_TAIL; ptTail[0].x = (sizeWnd.cx-nTIP_TAIL)/4*3; ptTail[0].y = sizeWnd.cy-nTIP_TAIL-2; ptTail[2].x = (sizeWnd.cx-nTIP_TAIL)/4*3 + nTIP_TAIL; ptTail[2].y = ptTail[0].y; ptTail[1].x = ptTail[2].x; ptTail[1].y = sizeWnd.cy-2; break; default: ASSERT(FALSE); } // adjust for very narrow balloons if ( ptTail[0].x < nTIP_MARGIN ) ptTail[0].x = nTIP_MARGIN; if ( ptTail[0].x > sizeWnd.cx - nTIP_MARGIN ) ptTail[0].x = sizeWnd.cx - nTIP_MARGIN; if ( ptTail[1].x < nTIP_MARGIN ) ptTail[1].x = nTIP_MARGIN; if ( ptTail[1].x > sizeWnd.cx - nTIP_MARGIN ) ptTail[1].x = sizeWnd.cx - nTIP_MARGIN; if ( ptTail[2].x < nTIP_MARGIN ) ptTail[2].x = nTIP_MARGIN; if ( ptTail[2].x > sizeWnd.cx - nTIP_MARGIN ) ptTail[2].x = sizeWnd.cx - nTIP_MARGIN; // get window position CPoint ptAnchor = GetAnchorPoint(); CPoint ptOffs(ptAnchor.x - ptTail[1].x, ptAnchor.y - ptTail[1].y); // adjust position so all is visible CRect rectScreen; GetAnchorScreenBounds(rectScreen); int nAdjustX = 0; int nAdjustY = 0; if ( ptOffs.x < rectScreen.left ) nAdjustX = rectScreen.left-ptOffs.x; else if ( ptOffs.x + sizeWnd.cx >= rectScreen.right ) nAdjustX = rectScreen.right - (ptOffs.x + sizeWnd.cx); if ( ptOffs.y + nTIP_TAIL < rectScreen.top ) nAdjustY = rectScreen.top - (ptOffs.y + nTIP_TAIL); else if ( ptOffs.y + sizeWnd.cy - nTIP_TAIL >= rectScreen.bottom ) nAdjustY = rectScreen.bottom - (ptOffs.y + sizeWnd.cy - nTIP_TAIL); // reposition tail // uncomment two commented lines below to move entire tail // instead of just anchor point //ptTail[0].x -= nAdjustX; ptTail[1].x -= nAdjustX; //ptTail[2].x -= nAdjustX; ptOffs.x += nAdjustX; ptOffs.y += nAdjustY; // place window MoveWindow(ptOffs.x, ptOffs.y, sizeWnd.cx, sizeWnd.cy, TRUE); // apply region CRgn region; CRgn regionRound; CRgn regionComplete; region.CreatePolygonRgn(&ptTail[0], 3, ALTERNATE); regionRound.CreateRoundRectRgn(ptTopLeft.x,ptTopLeft.y,ptBottomRight.x,ptBottomRight.y,nTIP_MARGIN*3,nTIP_MARGIN*3); regionComplete.CreateRectRgn(0,0,1,1); regionComplete.CombineRgn(®ion, ®ionRound, RGN_OR); if ( NULL == m_rgnComplete.m_hObject ) m_rgnComplete.CreateRectRgn(0,0,1,1); if ( !m_rgnComplete.EqualRgn(®ionComplete) ) { m_rgnComplete.CopyRgn(®ionComplete); SetWindowRgn((HRGN)regionComplete.Detach(), TRUE); // There is a bug with layered windows and NC changes in Win2k // As a workaround, redraw the entire window if the NC area changed. // Changing the anchor point is the ONLY thing that will change the // position of the client area relative to the window during normal // operation. RedrawWindow(NULL, NULL, RDW_UPDATENOW| RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } }