Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I have been away from VB.NET for coming up to a year now and am well rusty to my horry :(

 

I have an app which will have two forms, one 1024*768 and one 800*600.

 

I want my application to determine what resolution they are running at and open the correct form.

 

Any pointers to what object I should be using? I tried the screen object but that talks about rectangles etc?

 

Thnx

 

Hog

My website
Posted

If you want to determine the users current resolution, you can use the following code

 

SystemInformation.PrimaryMonitorSize.Width
SystemInformation.PrimaryMonitorSize.Height

 

I've attached a class that you can use in your project to change the resolution. Don't remember where I found it but it works. Just call the

ChangeRes method and give it the height and width that you want to change your users resolution too. Hope this helps.

 

-=Simcoder=-

ClassResolution.zip

Whatever thy hand findest to do, do it with all thy heart - Jesus
  • 1 year later...
Posted
I've attached a class that you can use in your project to change the resolution. Don't remember where I found it but it works. Just call the

ChangeRes method and give it the height and width that you want to change your users resolution too. Hope this helps.

 

I've used the class and it was successful, however, on the line lResult = ChangeDisplaySettings(DevM, CDS_TEST) and also on the line lResult = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY) I get the following:

 

PInvokeStackImbalance was detected

Message: A call to PInvoke function 'ChangeResolution!WindowsApplication1.Resolution::ChangeDisplaySettings' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

 

Is this some kind of warning? Is it safe to use it anyways? Is it possible to fix? How?

  • Administrators
Posted

It sounds like one of the definitions is incorrect try

Private Declare Auto Function EnumDisplaySettings Lib "user32" (ByVal deviceName As String, ByVal modeNum As Integer, ByRef deviceMode As DEVMODE) As Integer

Private Declare Auto Function ChangeDisplaySettings Lib "user32" (ByRef deviceMode As DEVMODE, ByVal flags As Integer) As Integer

for the declarations and see if that makes a difference.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

With your declarations, it didn't work... However, I added the "Alias" from the old declarations into yours and it worked... Is this ok?

 

But I have another problem (not yet tested with these new declarations), I'm trying to run this on Vista too, but it does not work as on XP. I have created a form with 2 buttons, one changes the res to 1024x768 and the other to 1280x800. These works fine on XP, I can change to either one of them, but on Vista, I can change the res to 1024 but I can't change it back to 1280... The code is exact the same, any reason why?

  • Administrators
Posted

Out of interest try changing the declares to begin with

Private Declare Unicode

but without the alias and see if that makes a difference, the only thing I can imagine causing problems on Vista is the security / UAC model - will check when I get home tonigh as I'm not running Vista on this PC.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

What about the Auto keyword? should I add it or not?

 

I don't think it's the UAC, I'm running VS2005 with administrator rights (maybe the compiled application is not), anyway, as I said, the resolution changes to 1024x768 when I'm at 1280x800 but I can't change back from 1024x768 to 1280x800, dunno why...

Posted

Didn't work, I tried Unicode instead of Auto and with out the Alias but it didn't work so I just reverted to Auto with the Alias. It works that way...

 

However, the same problem persists... On Vista, I can easily change to 1024x768 but not back to 1280x800... Dunno why... Already tried to run the compiled exe with the administrative privileges but it didn't help...

  • 2 months later...
Posted
There's a long instead of an integer in one of the api definitions.

 

My version attached.

 

I tried to use your code but it still doens't work on Vista... It works fine on XP, I can change to 1024x768 and 1280x800 back and forth, but on Vista, I can't swap to 1280x800 but it works swapping to 1024x768...

 

Anyone knows why?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...