• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Screen res change for a launched application

I was wondering how to launch another executable in a specific screen resolution (if possible).  For example: currently running in 1024X768 32-bit color and I want to launch a full screen application in 800X600 32-bit color (otherwise I get a black border and it's smaller).  I know how to do this for the current application using DirectX, but I want to do it for a launched application from the current application.
0
jbirk
Asked:
jbirk
  • 3
  • 2
1 Solution
 
AlexVirochovskyCommented:
You can simple change resolution
and launch Apps:
To get current resolution:

int cx = GetSystemMetrics(SM_CXSCREEN),
cy = GetSystemMetrics(SM_CYSCREEN));

To change resolution:
  DEVMODE dm; dm.dmPelsWidth=cx; dm.dmPelsHeight=cy;
  dm.dmSize = sizeof(dm);
  dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
  ChangeDisplaySettings(&dm, 0);
Alex
0
 
jbirkAuthor Commented:
Cool, that worked!
I looked up ChangeDisplaySettings and saw that I need to only add in one parameter for changing the bit depth as well.  But I couldn't find how to determine the users current bit depth like you showed for the SystemMetrics.  I want to return the system to normal after the application runs.  What command finds the current bit depth?
Also, what are the issues, if any, for changing the bit depth?  I know it was a problem with win 3.1, but does it work with win95,win98, and winNT ok?

Thanks very much for your help.
(can you tell I'm new to windows programming?)
-Josh
0
 
AlexVirochovskyCommented:
1.  how to determine the users current bit depth ?
int GetBitsPerPixel(void)
{
int bRet = 0;
// skip registry key opening sequence for clarity
  const INT nSIZE = 4096; //maximum(real 8)
  const char *lpszPathName="Display\\Settings";
  const char *pszValueName="BitsPerPixel";

  HKEY hKey,hBaseKey=HKEY_CURRENT_CONFIG;
  DWORD dwType;//
  DWORD dwData=nSIZE;
  char* bData = (char *)::calloc(nSIZE, sizeof(char));
//open key
 LONG retValue = ::RegOpenKeyEx(hBaseKey, lpszPathName,
   NULL,KEY_ALL_ACCESS,&hKey);
 if (retValue == ERROR_SUCCESS)//must be!
   {
     retValue = ::RegQueryValueEx(hKey,pszValueName,
        NULL,&dwType,(LPBYTE)bData,&dwData);
     if (retValue == ERROR_SUCCESS)
       bRet = atoi(bData);
     ::RegCloseKey(hKey); //close key
   }
  if (bData)
    free (bData);
  return bRet;
}
2. How test enables BitsPerPixel ?

int iModeNum = 0;
DEVMODE dm;
        while(EnumDisplaySettings(NULL, iModeNum,&dm))
       {
            iModeNum++;
            if (32 == dm.dmBitsPerPel)
               break;//ok!
        }
3. How chang the bit depth? 
//may 4,8,16,24,32                          dm.dmBitsPerPel = dm.dmBitsPerPel = GetBitsPerPixel();

dm.dmPelsWidth=cx; dm.dmPelsHeight=cy;
                          dm.dmSize=sizeof(dm);
                          dm.dmFields=DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
                          ChangeDisplaySettings(&dm, 0);
Alex
0
 
jbirkAuthor Commented:
Thanks, that helps a lot!
I just had one last quick question.  I'm not very familiar with Windows NT, and I was wondering if the registry queries GetBitsPerPixel() will work ok.

Thanks again,
Josh
0
 
AlexVirochovskyCommented:
>>I'm not very familiar with Windows NT
O, I am too! But i hope(by Windows Doc),
it will work in NT. Only one thing
may be: test WHERE is Display\Settings!
I 've tested in in Windows 95.
Thanks for grade A. Alex
 
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now