From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help modifying example that sets screen resolution programmatically

Hello,

 

I'm wondering if anyone could help modify the following example: http://www.ni.com/example/27650/en/. Currently, it sets different screen parameters (ie: resolution, pixel depth and refresh rate) for a default screen. I'd like to use it with two monitors. I found the function calls needed to do this; unfortunately, I'm unable to piece it together due to lack of function prototype translation knowhow.

You'll quickly notice that the first CLF would change from EnumDisplaySettingsA to EnumDisplaySettingsExA (http://msdn.microsoft.com/en-us/library/dd162612(v=vs.85).aspx).

The second CLF changes from ChangeDisplaySettingsA to ChangeDisplaySettingsExA (http://msdn.microsoft.com/en-us/library/dd183413(v=vs.85).aspx). The key implementation I'm after is the C++ example code shown almost at the bottom of this MSDN page - it first enters the desired resolutions for both monitors and then sets both simultaneously.

Any help anyone can offer is greatly appreciated. The final example, of course, can be made available for the community to benefit from.

 

Jorge

0 Kudos
Message 1 of 7
(2,716 Views)

Jorgein,

 

I am resarching this issue, but unfortunately the "right" way to do it has changed a fair bit since this example code was created. It is possible to brute force it by calling the .dll directly (as this example does) but a better course of action is calling it through .net. I will update you as I make progress.

 

Thanks



Notes for Branch AE:
Please reply to This Post within 24 hours
The US AE is expected to reply to all of your posts within 24 hours. Having this expectation will keep the escalation moving quickly and toward a fast resolution.

You can also use other communication channels: Phone, Skype, etc. to discuss the issue with the US AE. This can help with troubleshooting and quick diagnosis of the issue.

Click here to provide kudos for a post on this page
Message 2 of 7
(2,657 Views)

That sounds awesome !!

I thought about going w .NET also but again I could use "higher" level assistance.

Looking forward to what you come up with !

Thanks !

Jorge

0 Kudos
Message 3 of 7
(2,645 Views)

Just wanted to let you know I'm still working on this. I have a functioning vi, but would like to do it the "right way" before releasing it.

--------------------------------------
0 Kudos
Message 4 of 7
(2,584 Views)

Thanks a lot Chris !

I appreciate your help and look forward to playing with the VI.

Jorge

0 Kudos
Message 5 of 7
(2,568 Views)

Well, unfortunately this isn't as simple as it seems.

 

If your example code works properly, all you should need to do is reference system.windows.forms.screen in .net. Using property nodes you can get all screens, then use the device name property within a for-loop to come up with an array of the actual device names.

 

Then you just need to feed those device names in to the example code, but encased in a for-loop so that they displays are accessed individually. 

 

Unfortunately, I'm currently getting a complete crash when I do this. I think it's due to a problem with changes in the EnumDisplaySetttingsA function since this code was originally written (which was quite some time ago). 

 

Either way, this is not a recommended procedure for most situations. I would recommend consulting the MSDN documentation you referenced and pursuing this further if it's something that you really need to do.

--------------------------------------
0 Kudos
Message 6 of 7
(2,519 Views)

Thank you so much for the effort to get this to work Christopher. I can take a stab at it; specially with your input on what .NET assemblies to use. The MSDN docs are helpful too.

Once more, thank you !

If I get this to work I'll respond to this thread with the code.

Jorge

0 Kudos
Message 7 of 7
(2,509 Views)