Old 17th June 2019, 21:13   #1
enzeinzen
Junior Member
 
Join Date: Jun 2019
Posts: 4
Post NSIS Function to get main display refresh rate?

Hi' i'm trying to include a function in my script to detect the refresh rate of the main display. However, I do not know how to incorporate the functions into NSIS code.

I already managed to find a way to get the resolution using the following code:

System::Call user32::GetSystemMetrics(i0)i.r0
System::Call user32::GetSystemMetrics(i1)i.r1

However, in order to obtain the refresh rate, one must use EnumDisplayDevices to get the right display and then pass that to EnumDisplaySettings. I do not know how to do that.

Any help would be much appreciated. I am trying to build a portable application using the portableapps.com framework that uses NSIS language.

Thank you and sorry for being a n00b.
enzeinzen is offline   Reply With Quote
Old 17th June 2019, 21:31   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,163
You did say main display which I interpret as the primary monitor.

Quote:
!define /IfNDef VREFRESH 116
System::Call USER32::GetDC(p0)p.r1
System::Call GDI32::GetDeviceCaps(pr1,i${VREFRESH})i.r0
System::Call USER32::ReleaseDC(p0,pr1)
DetailPrint $0
but
Quote:
For display devices: the current vertical refresh rate of the device, in cycles per second (Hz).
A vertical refresh rate value of 0 or 1 represents the display hardware's default refresh rate.
Not sure if recent hardware can report 0 or 1 or maybe it was just Win95/98.

https://nsis.sourceforge.io/NSISMultiMon_plug-in can give you some information about the different monitors. https://nsis.sourceforge.io/ChangeRes_plug-in can change it but I don't think it can read it.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th June 2019, 21:54   #3
enzeinzen
Junior Member
 
Join Date: Jun 2019
Posts: 4
It does seem to work but it only returns 0.
enzeinzen is offline   Reply With Quote
Old 18th June 2019, 13:53   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,163
Quote:
!define /IfNDef CCHDEVICENAME 32
!define /IfNDef CCHFORMNAME 32
!define /IfNDef ENUM_CURRENT_SETTINGS -1
!define /IfNDef DM_DISPLAYFREQUENCY 0x00400000
!include LogicLib.nsh
System::Call '*(&i${CCHDEVICENAME},i,&l2,&i2,i0, i,i,i,i, i,i,&i2,&i${CCHFORMNAME},&i2,i,i,i,i,i)p.r1'
System::Call 'USER32::EnumDisplaySettingsA(p0, i${ENUM_CURRENT_SETTINGS}, pr1)i.r0'
System::Call '*$1(&i${CCHDEVICENAME},i,&l2,&i2,i, i,i,i,i, i,i,&i2,&i${CCHFORMNAME},&i2,i,i,i,i,i.r2)'
System::Free $1
${If} $0 <> 0
DetailPrint $2
${EndIf}
for
Quote:
the current display device on the computer on which the calling thread is running
whatever that means.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd September 2019, 10:18   #5
MaGoth
Junior Member
 
Join Date: Sep 2010
Posts: 21
Hi, enzeinzen
If still relevant, is this solution suitable for you?



MfG MaGoth,
MaGoth is offline   Reply With Quote
Old 11th September 2019, 17:21   #6
enzeinzen
Junior Member
 
Join Date: Jun 2019
Posts: 4
No, sadly I didn't manage to find a way to make this work. What I'm trying to do is incorporate this into a PortableApps.com launcher. Getting a function that is so complex to work within the PA.com framework is, however above my level of competence.
enzeinzen is offline   Reply With Quote
Old 11th September 2019, 17:50   #7
enzeinzen
Junior Member
 
Join Date: Jun 2019
Posts: 4
For example, this is how obtaining the resolution for further use is done:

${SegmentInit}
System::Call user32::GetSystemMetrics(i0)i.r0
System::Call user32::GetSystemMetrics(i1)i.r1

${SetEnvironmentVariable} ScreenWidth $0
${SetEnvironmentVariable} ScreenHeight $1
enzeinzen is offline   Reply With Quote
Old 12th September 2019, 10:48   #8
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,163
What is the problem with the last code I posted?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump