コード例 #1
0
//
//   FUNCTION: InitInstance(HINSTANCE, int)
//   PURPOSE: Saves instance handle and creates main window
//   COMMENTS:
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//-----------------------------------------------------------------------------
BOOL WindowWinCPRTViewer::InitInstance(HINSTANCE hInstance, int nCmdShow, int windowWidth, int windowHeight)
{
   m_hInst = hInstance; // Store instance handle in our global variable

   LPCSTR lpTitle = m_AppTitle;

   if( (0==windowWidth) || (0==windowHeight) )
   {
       // zero sized windows means - you choose the size. :)
       CPUTOSServices* pServices = CPUTOSServices::GetOSServices();
       pServices->GetDesktopDimensions(windowWidth, windowHeight);
       
       // default window size will be 1/3 of the screen size
       windowWidth/=3;
       windowHeight/=3;
   }

   m_hWnd = CreateWindow("CPRTChildWindowClass", lpTitle, //APPTITLE, APPTITLE, //szWindowClass, szTitle, 
       WS_CHILDWINDOW | WS_VISIBLE,
       CW_USEDEFAULT, 
       CW_USEDEFAULT, 
       100, 
       100,
       parentHWnd, 
       NULL, 
       (HINSTANCE)GetWindowLongPtr(parentHWnd, GWLP_HINSTANCE), 
       NULL);

   if (!m_hWnd)
   {
      return FALSE;
   }

   ShowWindow(m_hWnd, nCmdShow);
   UpdateWindow(m_hWnd);

   CPUTOSServices* pServices = CPUTOSServices::GetOSServices();
   pServices->SethWnd(m_hWnd);

   return TRUE;
}
コード例 #2
0
// InitInstance
// Saves the windows instance handle, creates, and displays the main program
// window
//-----------------------------------------------------------------------------
BOOL CPUTWindowWin::InitInstance(int nCmdShow, int windowWidth, int windowHeight, int windowX, int windowY)
{
    // assure we have a valid hInstance
    ASSERT(NULL!=mhInst, _L(""));

   // zero sized windows means - you choose the size. :)
   if( (0==windowWidth) || (0==windowHeight) )
   {
       CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
       pServices->GetDesktopDimensions(&windowWidth, &windowHeight);

       // default window size 1280x720
       // but if screen is smaller than 1280x720, then pick 1/3 the screen size 
       // so that it doesn't appear off the edges
       if(1280>windowWidth)
       {
           windowWidth = (2*windowWidth)/3;
           windowHeight = (2*windowHeight)/3;
       }
       else
       {
        
        windowWidth=1280;
        windowHeight=720;
       }
   }

   // set up size structure
   RECT rc = { 0, 0, windowWidth, windowHeight };
   AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );

   // if x = -1, then let windows decide where to put it
   if(-1==windowX)
   {
       windowX = CW_USEDEFAULT;
   }

   // create the window
   mhWnd = CreateWindow(mAppTitle.c_str(), mAppTitle.c_str(),
       WS_OVERLAPPEDWINDOW,
       windowX, //CW_USEDEFAULT,
       windowY, //CW_USEDEFAULT,
       rc.right - rc.left,
       rc.bottom - rc.top,
       NULL,
       NULL,
       mhInst,
       NULL);

   if (!mhWnd)
   {
      return FALSE;
   }

   ShowWindow(mhWnd, nCmdShow);
   UpdateWindow(mhWnd);

   // initialize the OS services with the hWND so you can make
   // reference to this object
   CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
   pServices->SethWnd(mhWnd);

   return TRUE;
}