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.
LVL 8
jbirkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.