hog Posted July 19, 2005 Posted July 19, 2005 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 Quote My website
Simcoder Posted July 19, 2005 Posted July 19, 2005 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 Quote Whatever thy hand findest to do, do it with all thy heart - Jesus
Nazgulled Posted March 18, 2007 Posted March 18, 2007 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? Quote
Administrators PlausiblyDamp Posted March 18, 2007 Administrators Posted March 18, 2007 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nazgulled Posted March 19, 2007 Posted March 19, 2007 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? Quote
Administrators PlausiblyDamp Posted March 19, 2007 Administrators Posted March 19, 2007 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nazgulled Posted March 20, 2007 Posted March 20, 2007 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... Quote
Administrators PlausiblyDamp Posted March 20, 2007 Administrators Posted March 20, 2007 If you specify either Ansi or Unicode then the Auto keyword becomes redundant. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Nazgulled Posted March 24, 2007 Posted March 24, 2007 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... Quote
jo0ls Posted March 25, 2007 Posted March 25, 2007 There's a long instead of an integer in one of the api definitions. My version attached.NativeMethods.zip Quote
Nazgulled Posted May 30, 2007 Posted May 30, 2007 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? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.