Solved

SystemParametersInfo

Posted on 1998-07-13
12
462 Views
Last Modified: 2008-03-17
I tried to set the screensaver timeout, but it returns 0 to me which means it failed.
dim x&, d&, r&
x& = 2400
r&=SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x&, 0, 0)

The GET one works though
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, d&, 0)
0
Comment
Question by:fury
  • 7
  • 5
12 Comments
 
LVL 39

Accepted Solution

by:
abel earned 50 total points
ID: 1465548
You should use the code as follows:
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDCHANGE|SPIF_UPDATEINIFILE)

BTW. The ampersand ("&") is not needed when referring to the prarmeter.

ATOH, I don't know why the function returns zero. Although your code should not work well, the function should return nonzero anyway. If my above mentioned code doesn't work either, please post again with the err.LastDllError number. That should help to cure the problem. And also: is it NT, Win95/98?

Hope this helps,

Regards, Abel
0
 
LVL 39

Expert Comment

by:abel
ID: 1465549
Sorry, a little mistake in my code. In stead of "|", use "or". Thus:

SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDCHANGE Or SPIF_UPDATEINIFILE)

I forgot to tell you, using these extra parameters ("SPIF_SENDCHANGE" and "SPIF_UPDATEINIFILE") you notify the system that something changed in the registry and it will be saved to the registry as well. Without these constants, nothing notifyable will happen.
0
 

Author Comment

by:fury
ID: 1465550
Here is what I did.....
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
    r& = GetLastError()
    MsgBox "Error code is :" & Err.LastDllError
    MsgBox Format(r&)

both msgbox shows 0

0
 

Author Comment

by:fury
ID: 1465551
Here is what I did.....
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
    r& = GetLastError()
    MsgBox "Error code is :" & Err.LastDllError
    MsgBox Format(r&)

both msgbox shows 0

Win98

0
 

Author Comment

by:fury
ID: 1465552
Here is what I did.....
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
    r& = GetLastError()
    MsgBox "Error code is :" & Err.LastDllError
    MsgBox Format(r&)

both msgbox shows 0
Still doesn't work
Win98

0
 
LVL 39

Expert Comment

by:abel
ID: 1465553
That's interesting.

Err.LastDllError show zero, meaning "ERROR_SUCCESS" and SystemParametersInfo returns also zero, meaning that there should be an error. Very peculiar.
The code you pasted is also the code you used actually? I mean, with no other dll-call between Err.LastDllError and the call to SystemParametersInfo?

I think it has something to do with Win98. I have seen more "funny" behaviour of Win98 when using common controls or "normal" api-calls. I'll try to find some extra info on this (systemParametersInfo and win98). Maybe I find something out. I'll post again as soon as possible.

Regards, Abel
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 39

Expert Comment

by:abel
ID: 1465554
In a fast search through the internet and other resources, I couldn't find a rightfull answer to this strange behaviour to SystemParamersInfo. I don't think Microsoft wants to prohibit the use of setting some parameters in win98, but maybe the constants are changed or so (or a new API should be used). I wasn't able to check MSDN and Tech Net, I didn't get a response from their server. I'll try that tomorrow.

I don't have win98 (yet), so I'm not able to test this particular case for myself. In order to test your code for correctness, you might best try it as well on a Win95/NT machine. On both it should work properly. If it doesn't, something else might be wrong (in stead of using win98).
Something else you can do is spying on windows when the system makes a call to setting the screensavertimeout.

Still, I think this behaviour is very strange: a function reporting something wrong and not setting the error-flag.
Maybe you best reopen this question to other experts - someone else might know a solution and can then answer it instead.

Regards, Abel
0
 

Author Comment

by:fury
ID: 1465555
I tried on 95..it doesn't work either
0
 
LVL 39

Expert Comment

by:abel
ID: 1465556
That's very strange. Could you please make a dummy-project with only the most necessary declarations and code to get this to work and paste is here? I would like to compare your code with mine. I have a fully working app with works on NT4 and Win95 (don't know about 98). If your calls are different or if there's a fault in the declarations, I will probably be able to get it out.

Make sure you paste all the code of a (as small as possible) project.

Regards, Abel
0
 
LVL 39

Expert Comment

by:abel
ID: 1465557
Automatically graded?
Did you get it working in the end, Fury? Hope so.

Regards, Abel
0
 

Author Comment

by:fury
ID: 1465558
oh I  did not get the answer....
'Module

Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_SCREENSAVERRUNNING = 97&
Public Const SPI_SETSCREENSAVETIMEOUT = 15
Public Const SPI_GETSCREENSAVETIMEOUT = 14
Public Const SPIF_SENDWININICHANGE& = &H2
Public Const SPIF_UPDATEINIFILE& = &H1


'Form

Private Sub Command1_Click()
Dim x&
r& = SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, x, 0)
MsgBox "Timeout is " + Format(x)
x& = 2400
r& = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
MsgBox "Set Timeout to: " + Format(x)
r& = SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, x, 0)
MsgBox "Timeout is now: " + Format(x)
End Sub


Thanks for your time :)
0
 
LVL 39

Expert Comment

by:abel
ID: 1465559
You're welcome :)
Do you mean that this is working, or is it still not doing anything?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA to format 3 78
VB 6.0 printer how to align 6 49
to transfer string from C lanaguage to VBA 4 44
using web browser with BING 40 84
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now