Change monitor orientation via vba using windows API call.

I would like code that will change monitor orientation via vba, probably using windows API call.  I however can't find much on the web to guide me in the right direction.

The application for this code is I am running an access database on a computer that I access remotely via tightVNC.  This remote computer has it's monitor orientation in "portrait", but tightVNC does not like that orietnation and does not display the monitor content correctly.  So my solution is to be able to hit a button on the remote computer's access program when I am logged in with tight VNC and that will change the windows monitor orientation.
jparisoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
I am not a big fan of screen "Resizers",...
But you can try this:
http://www.peterssoftware.com/ss.htm

It does not change the monitor resolution directly, ...it adjusts the size of the controls to fit the current resolution...

JeffCoachman
Jeffrey CoachmanMIS LiasonCommented:
...oh, ...sorry, I did not read fully where you wanted to change the "orientation".

Why cant the user just use the windows key combination:
    Ctrl+Alt (arrow keys)
...to quickly change the Orientation?
http://www.alphr.com/features/391579/how-to-rotate-a-laptop-or-pc-screen-flip-your-display-sideways

JeffCoachman
jparisoAuthor Commented:
There is no user... all this computer does is display a jobs board for a manufacturing shop.

I log into the computer via tightVNC from some other computer from time to time to troubleshoot.  The problem is, tight VNC shows the content twisted 90 degrees and half of the monitor content is missing.  The biggest problem is the windows task bar is located on the part of the monitor that is not displayed for some reason tightVNC does not allow/show the "screen resolution" menu when right clicking on the windows desktop.  So I'm kinda out of options other then a command button in the access program itself.

TightVNC does not allow all the options that one would have sitting at the local machine, for instance there is no cut and paste shortcuts when using tight VNC... etc.

One other solution as i type this would be to maybe show the windows taskbar at the top of the screen on the remote comptuer, but that is less than ideal.  I will use that as a possible backup solution.
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Nick67Commented:
"for some reason tightVNC does not allow/show the "screen resolution" menu when right clicking on the windows desktop"

Ok

Throw the Control Panel Icon on the desktop, and have it in a place you can double-click it.
Then fire up the Display applet from there.

Or will it not fire up that applet, period?
Jeffrey CoachmanMIS LiasonCommented:
jparisoAuthor Commented:
@Nick

Good to "see" you again.

At first I thought your suggestion was a very clever workaround.  

First, can't totally do the shortcut thing as the one form in access that is open is actually a popup that is modal and can't be moved resized or closed. It also is basically the size of the whole desktop so almost no desktop real estate is even visible.  But i was thinking I could just launch the control panel screen resolution from the access button using stuff located here:

http://www.sevenforums.com/tutorials/24008-screen-resolution-shortcut-create.html

BUT...  I forgot one additional problem. This computer is not logged in as and admin user AND I have the machine totally locked down with software called "security administrator" that pretty much blocks the user from doing everything and anything in windows except literally open the access program.  Any attempt to open any control panel is immediately going to be blocked by the software, that is also why the right click to said menu is blocked!  Any attempt at opening anything that is windows system related is just not going to work.

I am now even more certain only a VBA call to the API to change the orientation is going to be my only solution.
jparisoAuthor Commented:
@Jefferey

Physically moving the monitor does nothing for tightVNC, I could mount the monitor updside on Mars and tight VNC is still going to display the monitor incorrectly on the host. LOL
Jeffrey CoachmanMIS LiasonCommented:
oK, ...
LOL
;-)
jparisoAuthor Commented:
jparisoAuthor Commented:
Here is a powershell solution which is more my speed...

http://stackoverflow.com/questions/12644786/powershell-script-to-change-screen-orientation

I ran this in powershell and it indeed flips the screen 90 degrees.  I guess I can save this powershell script on the host machine and call it out from VB when the command button is hit.  This would be an acceptable solution.

@Nick

Why cant the user just use the windows key combination:
    Ctrl+Alt (arrow keys)
...to quickly change the Orientation?
I did a little more research on this and it appears it only works on certain machines, it depends on whether or not the graphics card supports it, mostly it's an intel thing.

I'm going to leave this open for a week to see if anybody is a guru in C+ to VB conversion, after I will mark this post as my solution.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Why not use a different remote access program that gives you more control than TightVNC? There are several free ones that are far more feature rich.
Nick67Commented:
Here is a powershell solution which is more my speed...
This would be an acceptable solution.


In many ways, its probably the ideal solution, compared to getting the WinAPI stuff flanged up in VBA.
I've come across many of the same posts you did, and looked at the MSDN stuff about how to do it, and its pretty clear that you need to sew it up very carefully or you'll introduce memory leaks and/or crashes -- and I suspect PowerShell will look after those niceties.

When VBA can't do it natively, it's whatever will work :)
If PS can get it done, run with it!
jparisoAuthor Commented:
@Scott

Yes, that is another way to solve the problem but with the powershell solution, on the VNC side, if it's not broke don't fix it!

@Nick

Glad to have a second confirmation on that, that is also my assessment.  I'm just surprised with the rise of tablets, ultra books and orientation switching phones and the like nobody has had the need to force an orientation while running a vb based database.
Nick67Commented:
I'm just surprised with the rise of tablets, ultra books and orientation switching phones and the like nobody has had the need to force an orientation while running a vb based database.

There are questions about auto-resizing forms that get asked occasionally, but there are no good, totally free VBA solutions available.  The usual response is the one you got:
http://www.peterssoftware.com/ss.htm
In general, for Access, you design to the smallest resolution that you know will be in play, and let the chips fall where they may.

The last such question I chimed in on, I asked the Asker to consider the ROI of plowing development time into such resizing.  Perhaps his budget might be better used by throwing some tiny monitors in the bush.  (one of our European friends was horrified -- surely they should be properly recycled!)

So it's not that such questions don't occur, but the reality is if you are looking for adaptive UI, web-based development, and not Access, is where you need to be.  Access doesn't have such facilities and probably never will.
jparisoAuthor Commented:
Perhaps his budget might be better used by throwing some tiny monitors in the bush.  (one of our European friends was horrified -- surely they should be properly recycled!)
^ LOL, that made my day!

In general, for Access, you design to the smallest resolution that you know will be in play, and let the chips fall where they may.
I break design rules in my sleep :)  My access database spans 3 monitors at 2560 x 1600 on administrative machines and the same program scales to 1920 x 1080 for the shops.  I like to make access do things it's not supposed to all day long!

Still, it's just screen orientation, and clearly the powershell script does it via some windows mechanism.  My understanding of C+ is that C+ and VB use the same underlying engine, it's all just syntax. And from what I can tell the C+ part of the powershell script uses DEVMODE which appears to be a Device API.  So it's stands to reason that if C+ can call that API, so can VB.

It seems I keep finding myself in uncharted territory often lately.  I'm just happy I found that powershell script.
Nick67Commented:
My understanding of C+ is that C+ and VB use the same underlying engine, it's all just syntax
No.
Now, with C# and VB.NET that's completely true, and if you create managed code in Visual Studio with any language that uses the CLI and uses the .NET framework, that true at the underlying level.

There are big similarities in how the code samples look because they are doing the same thing:  making calls to Windows API to do what you want, and it's the requirements of the API that call the tune.
So it's stands to reason that if C+ can call that API, so can VB.
VBA, though, has a smaller subset of abilities that VB 6 did -- and except for syntax VB.Net is a different monster altogether.
What always holds true is if it can be done from VBScript, it can be done from VBA.
Not vice versa though.
VBScript cannot call WinAPIs

I like to make access do things it's not supposed to all day long!
Nah, that's phrased wrong.
I like to make Access do everything its capable of doing
Which is far more than some folks suspect :)
jparisoAuthor Commented:
Interesting, thanks for the clarification.  My knowledge of other languages is quite limited outside the VBA realm.

Yes, I find that there really isn't anything access can't do if you willing to spend the time, do the research, and make it work. It really is quite capable...
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You have to remember that VBA is "Visual Basic for Applications", which means that you're working in a flavor of VB that has been customized for use with the specific application (in your case, Access). Many of the C and C++ APIs have been converted for use with VB, and while VBA is very similar to VB, it's not a complete and exact "fit". There are still some APIs that just don't "fit", normally because they return a type of structure or result that VB/VBA cannot understand, or because they manipulate things in a manner that make them unreadable to VB/VBA. In many cases, no one has taken the time to convert the API call to a structure that VB/VBA can understand, either because there is little need for it, or due to one of the limitations suggested above.

So just because you can do something in C or C++ does not mean you can do it in VB (or Java, or any other language).

"I find that there really isn't anything access can't do if you willing to spend the time, do the research, and make it work. It really is quite capable..."

I think perhaps your question would disprove that :). Granted, you were able to make it work with an external call to Powershell ... but you're doing that in Powershell, not in Access.
jparisoAuthor Commented:
Interesting, i wasn't aware the the full api isn't available to vba users.  I have close to 100 API calls and never ran into an issue with a particular API that I needed not being accessible, but there is always a first.

Obviously as a small business, we don't have the luxury of programming purity. Yes there does not seem to be a strictly VBA solution to the problem, but I'm sure we can agree in the real world the only thing that matters is a workable solution to a problem, not the elegance of the solution.

VBA < VB < AND NOT ~ VB.NET  ~  C+  Got It :)
   ^
I'm stuck here like it or not.
jparisoAuthor Commented:
@Scott

Why not use a different remote access program that gives you more control than TightVNC? There are several free ones that are far more feature rich.

I kinda blew by your statement without at least asking for a recomendation, I'm always interested in other options. Do you have a favorite?
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The Windows API calls were basically written for the C/C++ languages. Many have been ported to other languages, like VB, but not all of them (even those that could be ported) - and when you factor in the changes in "bit-ness" (16/32/64), you have thousands upon thousands of API calls available. As mentioned above, it can take time to port them to specific languages, and often those with the knowledge to do so simply don't have the time or inclination. Note that MSFT aren't the ones doing the porting, necessarily. Often that is a developer who really, really had the need to use that particular feature of the API and took the time to figure out how to make the API work for their language.

I'm always interested in other options. Do you have a favorite?
I use ScreenConnect to handle remote access needs, but it's not free (and I'm not sure it's the right "fit" for you). There are many others, however, as evidenced by this Wikipedia article:

https://en.wikipedia.org/wiki/Comparison_of_remote_desktop_software
jparisoAuthor Commented:
I just assumed anything API came from MSFT, had no idea that it was more organic than that with 3rd parties chiming in to do the ground work.  With VBA being low on the totem pole, I'm not surprised then that some of the API's are just not converted then.  Obviously, this is not the first time I have struggled with VB not doing what I need natively, which is why I have in the past had to relay on batch files and more recently powershell scripts to fill in the gaps.

I'll check out ScreenConnect, I'm not adverse to paying for things that are uniquely suited.  Also the wikipedia article is excellent, thanks.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
All Windows API libraries come from MSFT. They just created them for use with the C/C++ languages, and only ported them as needed. Others have ported some of the API calls as well, so that part is somewhat of a hodge-podge. I don't believe MSFT supports any "ports" of their API calls, regardless of who did the work, but I could be wrong about that.
jparisoAuthor Commented:
There doesn't seem to be much in terms of VB solutions on this, the only solution is a C+ version that nobody has converted.  The powershell solution I ran across that I marked as a solution was the one that was the best alternative.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.