Thread: How to detect screen resolution and set wallpaper

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    6

    How to detect screen resolution and set wallpaper

    I've been playing around with C++, and decided on a simple app to change wallpaper depending on screen resolution, since at college(sixth form) some of our computers are 16:9 and others are 4:3.

    What I want to know is what Windows API calls do I need to make in order to achieve this? And also what syntax? (e.g. Resolution(width, height)), I've had a look on google and here, but I'm still a little mystified. If there is anything compiler specific, I'm using GCC.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    > I've had a look on google

    Really ?!
    What did you type ?
    Found in 0.25 seconds in Google Groups
    ... and MSDN of course with complete application in SDK which does that.
    (SystemParametersInfo, EnumDisplaySettingsEx, and so on)
    Last edited by Alex31; 10-14-2009 at 07:49 AM.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    6
    Yes, I found info, and I think I have an idea, and I'm about to try something, which I found on Google and if it doesn't work I will post source code to find out what's wrong, happy?

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    6
    Ok, several compiling errors, I assume I have something fundamentally wrong in my code, any ideas? I'm not asking to be spoon fed, just a pointer or two.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
    	int cx = GetSystemMetrics(SM_CXSCREEN);
    	/*int cy = GetSystemMetrics(SM_CYSCREEN)*/
    
    	if (cx = 1440)
    	{
    		SystemParametersInfo(SPI_SETDESKWALLPAPER,TRUE,(LPVOID)"E:\\my_docs\\test.bmp",SPIF_SENDWININICHANGE| SPIF_UPDATEINIFILE);
    	}
    	else
    	{
    		SystemParametersInfo(SPI_SETDESKWALLPAPER,TRUE,(LPVOID)"E:\\my_docs\\test2.bmp",SPIF_SENDWININICHANGE| SPIF_UPDATEINIFILE);
    	}
    }
    Compile Errors:
    H:\Projects\C++\wallpaper.cpp|6|error: `main' must return `int'|
    H:\Projects\C++\wallpaper.cpp||In function `int main(...)':|
    H:\Projects\C++\wallpaper.cpp|7|error: `SM_CXSCREEN' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|7|error: `GetSystemMetrics' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|12|error: `SPI_SETDESKWALLPAPER' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|12|error: `TRUE' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|12|error: `LPVOID' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|12|error: `SPIF_SENDWININICHANGE' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|12|error: `SPIF_UPDATEINIFILE' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|12|error: `SystemParametersInfo' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|16|error: `SPI_SETDESKWALLPAPER' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|16|error: `TRUE' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|16|error: `LPVOID' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|16|error: `SPIF_SENDWININICHANGE' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|16|error: `SPIF_UPDATEINIFILE' was not declared in this scope|
    H:\Projects\C++\wallpaper.cpp|16|error: `SystemParametersInfo' was not declared in this scope|
    ||=== Build finished: 15 errors, 0 warnings ===|

    It appears that it is trying to read the various declarations as variables, but they're not.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Code:
    #pragma comment(lib, "user32.lib")
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main(void)
    {
    	int cx = GetSystemMetrics(SM_CXSCREEN);
    	/*int cy = GetSystemMetrics(SM_CYSCREEN)*/
    
    	if (cx = 1440)
    	{
    		SystemParametersInfo(SPI_SETDESKWALLPAPER,TRUE,(LPVOID)"E:\\my_docs\\test.bmp",SPIF_SENDWININICHANGE| SPIF_UPDATEINIFILE);
    	}
    	else
    	{
    		SystemParametersInfo(SPI_SETDESKWALLPAPER,TRUE,(LPVOID)"E:\\my_docs\\test2.bmp",SPIF_SENDWININICHANGE| SPIF_UPDATEINIFILE);
    	}
    }

  6. #6
    Registered User
    Join Date
    Oct 2009
    Posts
    6
    Of course, I hadn't realised I needed Windows specific libraries having not used them before. Thanks. Forgive my complete and utter ignorance, still learning, having come from a mostly VB.NET environment, and I'm a novice there as well. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screen Resolution
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-25-2003, 06:43 PM
  2. Console Screen Resolution!!!!
    By Perica in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2002, 07:45 AM
  3. How to set screen resulution and...
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 05-01-2002, 11:44 AM
  4. MSVC++ allegro tutorial
    By bobish in forum Game Programming
    Replies: 5
    Last Post: 02-13-2002, 04:11 PM
  5. FAQ: MSVC++ allegro tutorial
    By bobish in forum FAQ Board
    Replies: 3
    Last Post: 02-09-2002, 07:48 PM