Solved

Toggle Hardware Acceleration

Posted on 1999-01-08
23
319 Views
Last Modified: 2013-12-03
Under display settings, the settings tab, then click on advanced. The performance tab displays a hardware acceleration slider, is there a way to set this value progmatically?
0
Comment
Question by:TheMedia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
  • 2
  • +2
23 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1418340
Of couse, it is one of REGISTRY keys. But i not found it.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418341
If you are talking about Win95 control panel->system->Performance->Display->Hardware accel (I've not found anything alike in the display properties or NT),
then, if you agree,  for 500 pts+gradeA I'll try to find answer for you.
0
 

Author Comment

by:TheMedia
ID: 1418342
I can give you 350 points + grade A.. still interested?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Expert Comment

by:Lucidity
ID: 1418343
Ok, I set up a new question, same thing for 400 points. I had to use a different account but it seems to work. let me know.
0
 

Expert Comment

by:Lucidity
ID: 1418344
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418345
Ok, give me 1-2 days
0
 

Author Comment

by:TheMedia
ID: 1418346
ok, I'll be waiting
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418347
The same is pasted to http://www.experts-exchange.com/Q.10116315

It was much harder than I thought before. I'll happy if you increase points again (it'll be a tiny compensation for my wasted time). In any case, I expect grade A.


Here is a first part of the answer - how to obtain current setting. The second part of the answer (how to set value) you may discover basing on the first part. In any case, I'll paste second part tomorrow.

Here is the exact way the Win98 doing the job.


At first, Accel value may be in range 0...3

Lets define 3 parameters:

1) P_SAFEMODE
-------------
   INIFILE = WIN.INI
   SECTION = Windows
   KEY     = SafeMode

   REGKEY  = 0
   REGVALUE= 0

   MIN     = 0
   MAX     = 2
   DEFAULT = 0

2) P_ADVANCED
-------------
   INIFILE = SYSTEM.INI
   SECTION = Display
   KEY     = Mmio

   REGKEY  = Display\Settings
   REGVALUE= Advanced

   MIN     = 0
   MAX     = 1
   DEFAULT = 1

3) P_SWCURSOR
-------------
   INIFILE = SYSTEM.INI
   SECTION = Display
   KEY     = SwCursor

   REGKEY  = Display\Settings
   REGVALUE= SwCursor

   MIN     = 0
   MAX     = 1
   DEFAULT = 0



How to get current Acceleration setting
---------------------------------------

   int safeMode=getParam(P_SAFEMODE);
   bool isAdvanced=getParam(P_ADVANCED);
   bool isSwCursor=getParam(P_SWCURSOR);

   int curAccel;
   if(safeMode==0) {
      if(!isAdvanced) curAccel=1;
      else if(!isSwCursor) curAccel=3;
      else curAccel=2;
   }
   else
      curAccel=2-safeMode;

   // That's all!

int getParam(PARAM)
{
   int r=GetPrivateProfileInt(SECTION,KEY,-1,INIFILE);
   if(r!=-1) goto check;
   r=DEFAULT;
   if(!REGKEY) goto check;

   // If error occurs in registry functions then GOTO CHECK;

   HKEY key;
   RegOpenKey(HKEY_CURRENT_CONFIG,REGKEY,&key);

   DWORD rv,sz;
   RegQueryValueEx(key,REGVALUE,0,&type,&rv,&sz)

   // Check type==REG_DWORD & size==4 here
   // If type==REG_SZ then convert string to number
   if(all OK) r=rv;

check:
   if(r<MIN) r=MIN;
   else if(r>MAX) r=MAX;
   return r;
}

0
 
LVL 2

Expert Comment

by:lucidity
ID: 1418348
I'll only up the points if you supply a fullr functioning sample dialog program, and try to keep it simple and straight forward.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418349
The same is pasted to http://www.experts-exchange.com/Q.10116315 

Ok, 115+400 + grade A will be enough for me.

Here is the second part of the answer - how to set hardware acceleration setting.

             Accel value
               0    1    2    3     Default (3)
             ----------------------------------
safeMode       2    1    0    0         0
isAdvanced     0    0    1    1         1
isSwCursor     1    1    1    0         0



How to set Acceleration setting
---------------------------------------
void setAccel(DWORD v) {
   int safeMode=0;
   bool isAdvanced=1;
   bool isSwCursor=1;

   if(v>2) isSwCursor=0;
   else {
      safeMode=2-val;
      if(val<2) isAdvanced=0;
   }

   setParam(P_SAFEMODE,safeMode);
   setParam(P_ADVANCED,isAdvanced);
   setParam(P_SWCURSOR,isSwCursor);
}

void setParam(PARAM,DWORD v)
{
   char buf[16];
   if(v==DEFAULT) {
      WritePrivateProfileString(SECTION,KEY,0,0,INIFILE);
      if(REGKEY) {
         // If error occurs in registry functions then return
         HKEY key;
         RegOpenKey(HKEY_CURRENT_CONFIG,REGKEY,&key);
         RegDeleteValue(key,REGVALUE);
         RegCloseKey(...)
      }
   }
   else {
      wsprintf(buf,"%u",v);                        
      WritePrivateProfileString(SECTION,KEY,buf,INIFILE);
      if(REGKEY) {
         // If error occurs in registry functions then return
         HKEY key;
         RegOpenKey(HKEY_CURRENT_CONFIG,REGKEY,&key);
         RegSetValueEx(key,REGVALUE,0,REG_SZ,buf,strlen(buf)+1);
         RegCloseKey(...)
      }
   }
   // Restart Windows
}

0
 

Author Comment

by:TheMedia
ID: 1418350
RESTART???? windows doesn't have to reboot when IT does it, is there a non restart way?

and I'm using VC6 that doesn't like PARAM? what is param defined as???

don't freak, just waiting for some more info
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418351
At first, I cannot write your program instead of you!

My code here is the ALGORITHM, not the C code.
Could you make some efforts to read and understand my whole answer? Or, it seems, that you think that 500 FREE points is too much for this?

Next, all in my answer is the EXACT way the WIN98 doing.
As to restart windows  (you say it works without restart) - I'll check it.

   setParam(P_ADVANCED,isAdvanced);

   void setParam(PARAM, value)
   {
   }

It's mean, that inside the setParam you must use "System.ini" as INIFILE, "Advanced" as REGVALUE, "Mmio" as KEY, atc. Is it very hard to understand?
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 110 total points
ID: 1418352
Lets try again...

1) My Windows 98 shows "New setting will be applied after rebooting. Restart ?" dialog after any changing of slider in Advanced/Performance dialog. And I'm sure your one must do the same.
In any case, in your Q you did not mention about possibility to change this value without rebooting. But I found exact answer to your question (by the way, I spent several hours you):
>Under display settings, the settings tab, then click on
>advanced. The performance tab displays a hardware acceleration
>slider, is there a way to set this value progmatically?

2) How do know that your display changes acceleration mode without rebooting? Is there any visual effects? If you talking just about slider position, then my solution works fine in this case without rebooting.

3) If you don't understand my answer, then I write for you 'true' C code (function to set Hardware acceleration value). If so, let me know.

0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418353
Now I'm 100% sure that dialog box that changes acceleration post PSM_REBOOTSYSTEM message to the property sheet.

Here is a working C code you want.
You may compile it as console app and run from command line.
Eg,
  a.exe 0   (no acceleartion)
  a.exe 3   (full acceleration)

After each run RE-open display properties dialog and check slider position.

//C code
#include <windows.h>
#include <stdlib.h>

struct _pStructT {
 LPCSTR inifile;
 LPCSTR section;
 LPCSTR key;
 LPCSTR regkey;
 LPCSTR regvalue;
 DWORD min;
 DWORD max;
 DWORD def;
};
typedef struct _pStructT pStructT;

pStructT pSafeMode={"Win.ini","Windows","SafeMode",0,0,0,2,0};
pStructT pAdvanced={"System.ini","Display","Mmio",
   "Display\\Settings","Advanced",0,1,1};
pStructT pSwCursor={"System.ini","Display","SwCursor",
   "Display\\Settings","SwCursor",0,1,0};

void setParam(pStructT* p,DWORD v)
{
   if(v==p->def) {
      WritePrivateProfileString(p->section,p->key,0,p->inifile);
      if(p->regkey) {
         HKEY key;
         LONG r=RegOpenKey(HKEY_CURRENT_CONFIG,p->regkey,&key);
         if(r!=ERROR_SUCCESS) return;
         RegDeleteValue(key,p->regvalue);
         RegCloseKey(key);
      }
   }
   else {
      char buf[16];
      wsprintf(buf,"%u",v);
      WritePrivateProfileString(p->section,p->key,buf,p->inifile);
      if(p->regkey) {
         HKEY key;
         LONG r=RegCreateKey(HKEY_CURRENT_CONFIG,p->regkey,&key);
         if(r!=ERROR_SUCCESS) return;
         RegSetValueEx(key,p->regvalue,0,REG_SZ,buf,strlen(buf)+1);
         RegCloseKey(key);
      }
   }
}

void setAccel(DWORD v)
{
   DWORD safeMode=0;
   DWORD isAdvanced=1;
   DWORD isSwCursor=1;

   if(v>2) isSwCursor=0;
   else {
      safeMode=2-v;
      if(v<2) isAdvanced=0;
   }

   setParam(&pSafeMode,safeMode);
   setParam(&pAdvanced,isAdvanced);
   setParam(&pSwCursor,isSwCursor);
}

void main(int argc,char* argv[])
{
   DWORD v;
   if(argc<2) return;
   v=atoi(argv[1]);
   if(v>3) v=3;
   setAccel(v);
}


0
 
LVL 2

Expert Comment

by:lucidity
ID: 1418354
OK, just relax. I only wanted to make sure that its the best solution, thats all. I was under the impression that it didn't need to be rebooted, I was incorrect. Second, my compiler didn't know what a PARAm was. I don't have time to check all these things right away or I would have done it myself. I appreciate all your help, really, I see no need to rush, the points are here and not going anywhere. At work I will run your test program, if it works I will award you your points.

sound fair...? See you tomorrow.

PS, when it comes to windows code there is an ALGORITHM and actual functioning code. nes pas? I should have made it more clear, but thats a lot of points to NOT get code.

Thanks
0
 

Author Comment

by:TheMedia
ID: 1418355
how did you find that, before I ran that program I never had that entry in the registry!?! I looked in that exact spot and it wasn't there, I even watched it pop in as I ran the program.. weird. anyway, thanks
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418356
>how did you find that,
Professional secrets...

You may be sure my C code has no errors.

Thank you.
0
 

Author Comment

by:TheMedia
ID: 1418357
could you also add in a function to spit out the current value?
thanks
Jason
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418358
//C code
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

struct _pStructT {
 LPCSTR inifile;
 LPCSTR section;
 LPCSTR key;
 LPCSTR regkey;
 LPCSTR regvalue;
 DWORD min;
 DWORD max;
 DWORD def;
};
typedef struct _pStructT pStructT;

pStructT pSafeMode={"Win.ini","Windows","SafeMode",0,0,0,2,0};
pStructT pAdvanced={"System.ini","Display","Mmio",
   "Display\\Settings","Advanced",0,1,1};
pStructT pSwCursor={"System.ini","Display","SwCursor",
   "Display\\Settings","SwCursor",0,1,0};

void setParam(pStructT* p,DWORD v)
{
   if(v==p->def) {
      WritePrivateProfileString(p->section,p->key,0,p->inifile);
      if(p->regkey) {
         HKEY key;
         LONG r=RegOpenKey(HKEY_CURRENT_CONFIG,p->regkey,&key);
         if(r!=ERROR_SUCCESS) return;
         RegDeleteValue(key,p->regvalue);
         RegCloseKey(key);
      }
   }
   else {
      char buf[16];
      wsprintf(buf,"%u",v);
      WritePrivateProfileString(p->section,p->key,buf,p->inifile);
      if(p->regkey) {
         HKEY key;
         LONG r=RegCreateKey(HKEY_CURRENT_CONFIG,p->regkey,&key);
         if(r!=ERROR_SUCCESS) return;
         RegSetValueEx(key,p->regvalue,0,REG_SZ,buf,strlen(buf)+1);
         RegCloseKey(key);
      }
   }
}

int getParam(pStructT* p)
{
   DWORD r=GetPrivateProfileInt(p->section,p->key,(UINT)-1,p->inifile);
   if(r!=(DWORD)-1) goto check;
   r=p->def;

   if(p->regkey) {
      HKEY key;
      char buf[16];
      DWORD type,sz=sizeof(buf);
      LONG res=RegOpenKey(HKEY_CURRENT_CONFIG,p->regkey,&key);
      if(res!=ERROR_SUCCESS) goto check;
      res=RegQueryValueEx(key,p->regvalue,0,&type,buf,&sz);
      RegCloseKey(key);
      if(res!=ERROR_SUCCESS) goto check;
      if(type==REG_SZ)
         r=(DWORD)atoi(buf);
      else
         r=*((LPDWORD) buf);
   }

check:
   if(r<p->min) r=p->min;
   else if(r>p->max) r=p->max;
   return r;
}

DWORD getAccel(void)
{
   DWORD safeMode=getParam(&pSafeMode);
   DWORD isAdvanced=getParam(&pAdvanced);
   DWORD isSwCursor=getParam(&pSwCursor);

   DWORD curAccel;
   if(safeMode==0) {
      if(!isAdvanced) curAccel=1;
      else if(!isSwCursor) curAccel=3;
      else curAccel=2;
   }
   else
      curAccel=2-safeMode;
   return curAccel;
}


void setAccel(DWORD v)
{
   DWORD safeMode=0;
   DWORD isAdvanced=1;
   DWORD isSwCursor=1;

   if(v>2) isSwCursor=0;
   else {
      safeMode=2-v;
      if(v<2) isAdvanced=0;
   }

   setParam(&pSafeMode,safeMode);
   setParam(&pAdvanced,isAdvanced);
   setParam(&pSwCursor,isSwCursor);
}

void main(int argc,char* argv[])
{
   DWORD v;
   printf("Current acceleration: %u\n",getAccel());
   if(argc<2) return;
   v=atoi(argv[1]);
   if(v>3) v=3;
   setAccel(v);
   printf("Acceleration changed to: %u\n",getAccel());
}

0
 

Author Comment

by:TheMedia
ID: 1418359
cool, if I could give you an A+ I would ;).
0
 

Author Comment

by:TheMedia
ID: 1418360
I have 1200 points if you can help me out with this one....

hey, just as something on the side I have something I've been working on that I can't quite get to work the way I want. Right now I'm trying to adapt the FileMon from sysinternals so that if a file is being access my program finds out BEFORE the file is opened and either prompt for a password or replace the filename with a predefined file, like if you try to open stayout.html it will be replaced with ahah.html which says access is restricted in HTML.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418361
What exact doesn't work as you want?
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1418362
You can write me directly to nick@rtzi.ru
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question