collapse collapse

* Who's Online

  • Dot Guests: 118
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11164
  • stats Total Topics: 1700
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 1470

Author Topic: Exporting display resolution to text file?  (Read 7811 times)

0 Members and 1 Guest are viewing this topic.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Exporting display resolution to text file?
« on: April 21, 2010, 10:25:03 am »
I'm looking for a script that would be able to detect the resolution of a second display/monitor and export the numbers to a text file.

The software I'm using this for doesn't have its own auto detection, but it reads its window resolution from a text file. I'm trying to get the master script to replace those numbers depending on what the resolution of that 2nd monitor is.

Not too sure if there's a preferred language for this kind of thing but the master script is in java.
« Last Edit: April 21, 2010, 10:28:20 am by K Mak »

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #1 on: April 21, 2010, 11:45:07 am »
Using C++, the code below should work.
Just call the application through your Java script and it will print out to th efile in WIDTHxHEIGHT resolution. You can change the format as you like.
Code: C++
  1. #include <iostream>
  2. #include <fstream>
  3. #include <Windows.h>
  4. using namespace std;
  5.  
  6. int main(){
  7.         ofstream fout("Resolution.txt", ios::out);
  8.         if(!fout)
  9.                 cout << "Error! Could not create file!\n";
  10.         HDC hdc;
  11.         hdc = GetDC(NULL);
  12.         int Width = GetDeviceCaps(hdc, HORZRES);
  13.         int Height = GetDeviceCaps(hdc, VERTRES);
  14.         cout << Width << "x" << Height << endl;
  15.         fout << Width << "x" << Height << endl;
  16.         fout.close();
  17.         system("PAUSE");
  18. };
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Re: Exporting display resolution to text file?
« Reply #2 on: April 21, 2010, 01:52:33 pm »
Does this detect the resolution of the second monitor or the primary?

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #3 on: April 21, 2010, 03:38:08 pm »
Ah, it does the primary, one sec, I'll update the code.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #4 on: April 21, 2010, 05:28:16 pm »
Okay, sorry for taking so long. I was to make sure it worked properly before posting. This detects the size of both monitors and saves it inside a file called Resolution.txt. My file as a example prints out

Monitor 1: 1920x1080
Monitor 2: 800x600

Code: C++
  1. #include <iostream>
  2. #include <fstream>
  3. #include <Windows.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main(){
  9.         ofstream fout("Resolution.txt", ios::out);
  10.         if(!fout)
  11.                 cout << "Error! Could not create file!\n";
  12.         HDC                     hMon;
  13.         hMon = GetDC(NULL);
  14.  
  15.         int width = GetDeviceCaps(hMon, HORZRES);
  16.         int height= GetDeviceCaps(hMon, VERTRES);
  17.         cout << width << " " << height << endl;
  18.  
  19.         POINT pt = {width+20, height/2};
  20.         HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
  21.         if(hMonitor == NULL)
  22.                 cout << "Error!";
  23.         MONITORINFO mi;
  24.         mi.cbSize = sizeof(MONITORINFO);
  25.         GetMonitorInfo(hMonitor, &mi);
  26.         int width2 = mi.rcWork.right-width;
  27.         int height2=  mi.rcWork.bottom;
  28.  
  29.         cout << mi.rcWork.right-width << " " << mi.rcWork.bottom << endl;
  30.         cout << mi.rcMonitor.right-width << " " << mi.rcMonitor.bottom << endl;
  31.  
  32.         fout << "Monitor 1: " << width << "x" << height << endl;
  33.         fout << "Monitor 2: " << width2<< "x" << height2 << endl;
  34.        
  35.         system("PAUSE");
  36. };
« Last Edit: April 21, 2010, 05:29:51 pm by Celestialkey »
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Re: Exporting display resolution to text file?
« Reply #5 on: April 25, 2010, 12:43:36 pm »
I don't have a 2nd monitor at home to test it on, will do so tomorrow when I'm back in the lab but how come when I try it on my single monitor setup, the output is:

Monitor 1: 1920x1080
Monitor 2: 0x1040

Can I get it to just pop an error message that states a 2nd display device is not connected? It would be fine to do it in the console window.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #6 on: April 25, 2010, 08:30:40 pm »
Yea, just check if the [value]x... is 0. Meaning if your resolution for the second is 0x1040, then that 0 means no monitor is attached or connected.
Then if your using windows as a platform for running this project of yours, you can call a Messagebox() to say error. Course, using the above code is Windows specific anyhow since each OS handles multiple monitors differently.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Re: Exporting display resolution to text file?
« Reply #7 on: April 28, 2010, 12:25:03 am »
How can I build the .exe to not require Visual Studio 2008 library files to be installed on the computer in question? The file runs fine on my computer but if I move it to the computer we have our setup on, which has no compilers installed, it can't run.

I read somewhere else that I'm supposed to set my project to not use the runtime library but then my file doesn't build at all.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #8 on: April 28, 2010, 07:14:24 am »
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Re: Exporting display resolution to text file?
« Reply #9 on: April 28, 2010, 09:49:15 am »
So that means in addition to the project properties changes, I should add the library files to my project before building the .exe?

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #10 on: April 28, 2010, 10:28:57 am »
Yea, but there are no library files required for this. Just change the settings properly.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Re: Exporting display resolution to text file?
« Reply #11 on: May 03, 2010, 10:47:40 pm »
Rather than generate our own parameter file, we've decided to see if we can modify the existing one.

I've attached a sample parameter file to my post, its extension is .prm but it's nothing more than a text file that can be viewed in notepad.

On lines 65 and 66 there are a string of numbers. We're not too sure what the second and third numbers represent, but we know the first number in each row represents the size of the window we want to modify.

Application:Window:ApplicationBase int WindowWidth= 1024 640 0 % // width of application window
Application:Window:ApplicationBase int WindowHeight= 768 480 0 % // height of application window

I need help modifying the 2nd monitor resolution export code from before to replace those first numbers in each row (so the width of monitor 2 replaces the 768 and the height replaces 1024), but it would always have to leave a space between it and the next number in the row (so it has to adapt to resolution values of 3 and 4 digits).

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #12 on: May 04, 2010, 07:43:18 am »
The numbers represent backup modes. For example, if the graphics card is unable to display the 1024x768, it reverts to the most common standard that most computers will support by default even without a graphics card, 640x680. I suspect the third parameter on each option is a backup backup, but it should never bit hit, thus they just default it to 0.

By changing the previous code to modify those lines only. Do you mean you want the file to simple be modified without having the entire thing written over again? If thats the case, since you know the exact line number it is on, you could just do something along the lines of reading the file in one line at a time until you hit that spot, but it gets trouble some at that point. So I'll show you the simplest way below.
Code: C++
  1. #include <iostream>
  2. #include <fstream>
  3. #include <Windows.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main(){
  9.         // This is the easiest way of doing what you want.
  10.         std::ofstream fout("TestBattery_1.txt", ios::out);
  11.        
  12.         // Go ahead and print out all that excess data...
  13.         fout << "System:Configuration matrix OperatorVersion= { Framework Revision Build } 1 2.0 2512:2513,%202009/08/27%2016:53:25 2009/08/27%2016:54:02 // operator module version information\n";
  14.         fout << "System:State%20Vector int StateVectorLength= 14 16 1 30 // length of the state vector in bytes\n";
  15.         fout << "Source:Signal%20Properties:DataIOFilter int SourceCh= 8 16 1 % // number of digitized and stored channels\n";
  16.         // etc... Ensure to add a \n\r at the end of each line. Linux only requires \n, but some Windows systems need both character to newline in a file.
  17.  
  18.  
  19.         if(!fout)
  20.                 cout << "Error! Could not create file!\n";
  21.         HDC                     hMon;
  22.         hMon = GetDC(NULL);
  23.  
  24.         int width = GetDeviceCaps(hMon, HORZRES);
  25.         int height= GetDeviceCaps(hMon, VERTRES);
  26.         cout << width << " " << height << endl;
  27.  
  28.         POINT pt = {width+20, height/2};
  29.         HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
  30.         if(hMonitor == NULL)
  31.                 cout << "Error!";
  32.         MONITORINFO mi;
  33.         mi.cbSize = sizeof(MONITORINFO);
  34.         GetMonitorInfo(hMonitor, &mi);
  35.         int width2 = mi.rcWork.right-width;
  36.         int height2=  mi.rcWork.bottom;
  37.  
  38.         cout << mi.rcWork.right-width << " " << mi.rcWork.bottom << endl;
  39.         cout << mi.rcMonitor.right-width << " " << mi.rcMonitor.bottom << endl;
  40.  
  41.         // At this point, we should be where this part is located, so we just go ahead and print it
  42.                
  43.         fout << "Application:Text%20Window:P3SpellerTask int TextWindowWidth= " << width2 << " 512 0 % // Text Window Width \n\r";
  44.         fout << "Application:Text%20Window:P3SpellerTask int TextWindowHeight= " << height2 << " 512 0 % // Text Window Height\n\r";
  45.        
  46.  
  47.         // Then continue printing the rest fo your settings. This is the simplist way without reading the file into memory and doing changes while in memory.
  48.         // That gets a bit more advanced :)
  49.         system("PAUSE");
  50. };
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline jho

  • The flamboyant FLOSS fanatic
  • Sr. Member
  • *
  • Posts: 352
  • Reputation 1199
  • Gender: Male
    • View Profile
    • http://hajotus.net
Re: Exporting display resolution to text file?
« Reply #13 on: May 04, 2010, 09:59:40 am »
The numbers represent backup modes. For example, if the graphics card is unable to display the 1024x768, it reverts to the most common standard that most computers will support by default even without a graphics card, 640x680. I suspect the third parameter on each option is a backup backup, but it should never bit hit, thus they just default it to 0.
How can you display something "without a graphics card"? There's nothing to plug the display to in that case.

Quote
By changing the previous code to modify those lines only. Do you mean you want the file to simple be modified without having the entire thing written over again? If thats the case, since you know the exact line number it is on, you could just do something along the lines of reading the file in one line at a time until you hit that spot, but it gets trouble some at that point. So I'll show you the simplest way below.

That can get a bit troublesome if, as I think, the file is a configuration file where the other lines may (and will) change too, depending on the user's settings.
Windows uses CR+LF (\r\n), not \n\r, and you could just use std::endl and it works in every system.
Also, why in ${DEITY}'s name would anyone go and talk about portability, but then use system("PAUSE")?

How about this (Windows-specific parts not tested, as I don't have a Windows machine at hand):
Code: C++
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <windows.h>
  5. #include <cstdlib>
  6. #include <cstdio>
  7.  
  8. using namespace std;
  9.  
  10. #define TMPFILE "TestBattery_1.prm.tmp"
  11.  
  12. int main(void)
  13. {
  14.     std::ofstream fout(TMPFILE, ios::out);
  15.     std::ifstream fin("TestBattery_1.prm", ios::in);
  16.  
  17.     if(!fout || !fin)
  18.     {  
  19.         cerr << "Couldn't open the needed files.\n";
  20.         return EXIT_FAILURE;
  21.     }  
  22.    
  23.     HDC hMon = GetDC(NULL);
  24.     int width = GetDeviceCaps(hMon, HORZRES);
  25.     int height = GetDeviceCaps(hMon, VERTRES);
  26.  
  27.     POINT pt = {width+20, height/2};
  28.     HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
  29.     if(hMonitor == NULL)
  30.     {
  31.         cerr << "Error: Couldn't find a monitor\n";
  32.         return EXIT_FAILURE;
  33.     }
  34.     MONITORINFO mi;
  35.     mi.cbSize = sizeof(MONITORINFO);
  36.     GetMonitorInfo(hMonitor, &mi);
  37.     width = mi.rcWork.right-width;
  38.     height = mi.rcWork.bottom;
  39.     string s;
  40.    
  41.     while(getline(fin, s))
  42.     {  
  43.         if(s.find("Application:Window:ApplicationBase int WindowWidth=") != string::npos)
  44.         {  
  45.             fout << "Application:Window:ApplicationBase int WindowWidth= " << width
  46.                 << " 640 0 % // width of application window" << endl;
  47.         }  
  48.         else if(s.find("Application:Window:ApplicationBase int WindowHeight=") != string::npos)
  49.         {
  50.             fout << "Application:Window:ApplicationBase int WindowHeight= " << height
  51.                 << " 480 0 % // height of application window" << endl;
  52.         }
  53.         else
  54.         {
  55.             fout << s << endl;
  56.         }
  57.     }
  58.  
  59.     fin.close();
  60.     fout.close();
  61.  
  62.     /* lastly we'll just write the new file over the old one and then remove the temporary file */
  63.     std::ifstream fin2(TMPFILE, ios::in);
  64.     std::ofstream fout2("TestBattery_1.prm", ios::out);
  65.  
  66.     if(!fout2 || !fin2)
  67.     {
  68.         cerr << "Couldn't open the needed files.\n";
  69.         return EXIT_FAILURE;
  70.     }
  71.  
  72.     while(getline(fin2, s))
  73.     {
  74.         fout2 << s << endl;
  75.     }
  76.  
  77.     fin2.close();
  78.     fout2.close();
  79.     remove(TMPFILE);
  80.  
  81.     return EXIT_SUCCESS;
  82. }
  83.  
"I'm sorry, I only accept criticism in the form of sed expressions."

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #14 on: May 04, 2010, 12:09:28 pm »
Quote
How can you display something "without a graphics card"? There's nothing to plug the display to in that case.
I meant if they did not have a actual graphics card, but instead used integrated graphics. Some integrated graphics will use 640 480 by default since it is the most common standard (or use to be anyhow, now I think it is 1024x768).

Quote
Also, why in ${DEITY}'s name would anyone go and talk about portability, but then use system("PAUSE")?

Lol, I was just giving him a example app. of how to do it. I never intended for him to actually use the program directly as I wrote it. In a real situation, you would not want the application to stay open anyhow so that line would be removed. As a side note, I'm not even sure the method for getting the resolution is even cross platform. I'm a windows guy. Hated or not, doubt that will change.


[edited name=Celestialkey date=1272993113][/edited]
« Last Edit: May 04, 2010, 12:14:42 pm by Celestialkey »
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Re: Exporting display resolution to text file?
« Reply #15 on: May 04, 2010, 12:24:06 pm »
I get the attached errors when I try to build jho's method, I don't know enough about C++ to make any sense of them.

As for CK's method, is there any other way to go about doing this? I don't necessarily need it to be easy as no one will ever see the code again, this entire program's intent is only to replace those two numbers in that one file.

Offline K Mak

  • Newbie
  • *
  • Posts: 23
  • Reputation 49
    • View Profile
Re: Exporting display resolution to text file?
« Reply #16 on: May 04, 2010, 12:26:14 pm »
Quote
How can you display something "without a graphics card"? There's nothing to plug the display to in that case.
I meant if they did not have a actual graphics card, but instead used integrated graphics. Some integrated graphics will use 640 480 by default since it is the most common standard (or use to be anyhow, now I think it is 1024x768).

Quote
Also, why in ${DEITY}'s name would anyone go and talk about portability, but then use system("PAUSE")?

Lol, I was just giving him a example app. of how to do it. I never intended for him to actually use the program directly as I wrote it. In a real situation, you would not want the application to stay open anyhow so that line would be removed. As a side note, I'm not even sure the method for getting the resolution is even cross platform. I'm a windows guy. Hated or not, doubt that will change.


[edited name=Celestialkey date=1272993113][/edited]

The software platform for the main interface (BCI2000) is Windows only so it's fine that the method isn't cross platform.

Offline jho

  • The flamboyant FLOSS fanatic
  • Sr. Member
  • *
  • Posts: 352
  • Reputation 1199
  • Gender: Male
    • View Profile
    • http://hajotus.net
Re: Exporting display resolution to text file?
« Reply #17 on: May 04, 2010, 02:23:52 pm »
Well the Chinese makes it a bit hard to follow, and besides it compiles just fine for me even with the most strict error reporting possible (the warnings are because of the the sloppy wrapper header I wrote in a hurry, not from the actual code):
Code: [Select]
~ % g++ -Wall -Wextra -pedantic k_mak.cpp
In file included from k_mak.cpp:4:
wrapper.h:25: warning: unused parameter ‘v’
wrapper.h:27: warning: unused parameter ‘d’
wrapper.h:39: warning: unused parameter ‘p’
wrapper.h:39: warning: unused parameter ‘i’
wrapper.h:44: warning: unused parameter ‘h’
k_mak.cpp: In function ‘int main()’:
k_mak.cpp:29: warning: NULL used in arithmetic
~ %

Here is the wrapper file for reference, but you shouldn't use it on Windows. It just provides a hackish interfaces for the <windows.h> specific features used in the code.
Code: C++
  1. #ifndef __wrapper_h_
  2. #define __wrapper_h_
  3.  
  4. #define HORZRES 0x1
  5. #define VERTRES 0x2
  6. #define MONITOR_DEFAULTTONEAREST 0x1
  7.  
  8. #define HRES 1440
  9. #define VRES 900
  10.  
  11. typedef int HDC;
  12. typedef float POINT[2];
  13. typedef int HMONITOR;
  14.  
  15. typedef struct r {
  16.     int right;
  17.     int bottom;
  18. } rcw;
  19.  
  20. typedef struct mi {
  21.     int cbSize;
  22.     rcw rcWork;
  23. } MONITORINFO;
  24.  
  25. HDC GetDC(void* v){ return 1; }
  26.  
  27. int GetDeviceCaps(HDC d, int dimension)
  28. {
  29.     switch(dimension)
  30.     {
  31.         case HORZRES:
  32.             return HRES * 2;
  33.         case VERTRES:
  34.             return VRES;
  35.     }
  36.     return -1;
  37. }
  38.  
  39. HMONITOR MonitorFromPoint(POINT p, int i)
  40. {
  41.     return 1;
  42. }
  43.  
  44. void GetMonitorInfo(HMONITOR h, MONITORINFO* m)
  45. {
  46.     m->rcWork.right = HRES;
  47.     m->rcWork.bottom = VRES;
  48. }
  49.  
  50. #endif
  51.  
"I'm sorry, I only accept criticism in the form of sed expressions."

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #18 on: May 04, 2010, 04:47:21 pm »
I get the attached errors when I try to build jho's method, I don't know enough about C++ to make any sense of them.

As for CK's method, is there any other way to go about doing this? I don't necessarily need it to be easy as no one will ever see the code again, this entire program's intent is only to replace those two numbers in that one file.
There are other ways... But... Yea... I really think you should use the simplest method possible. Helps in debugging since both ways get the job done. There are multiple ways of doing this, but reading files is a serialize process. You can't "leap" to a point in a file without going though the entire part before that point. fseek() just offsets a number of bytes in the file until slamming into the position you asked for. So essentially you just loop to that part, however to CHANGE that position in file, you run into a few problems. One of which being your unable to use the standard file in out stream. The streams only let you do one type of operation on a file at once such as reading OR writing, not both. using FILE* and the C method it should be possible to load the file and rewrite the file after finding that location in memory and modifying it there. That method is a little precarious unless you understand EVERYTHING going on and how to insert the data properly without overwriting the array just after that position.

The best method I can think of though goes to Jho's method. He did was I was originally going to do. The only problem with his is that the file cannot be opened twice in any single process. you are either reading from it or writing to it at any single time. Because of that, two files are required. Meaning your either copying the original file, opening that, then writing to the original, or your just opening the original, and writing to a new file. Either way, I was trying to avoid the use of two files and just stick with one. I highly suggest you simply use the first method I gave you where you just print each line out that you need so the file is recreated on run time. This may take the longest to set up, however it is almost guaranteed to succeed each time since your ONLY writing the file. It also makes things easier to insert into that text at any point in time.


So to sum up that long ramble I did. Just take the time and complete the simplest way of doing it. It wont kill you and it is the method least likely to fail.
« Last Edit: May 04, 2010, 05:12:31 pm by Celestialkey »
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline jho

  • The flamboyant FLOSS fanatic
  • Sr. Member
  • *
  • Posts: 352
  • Reputation 1199
  • Gender: Male
    • View Profile
    • http://hajotus.net
Re: Exporting display resolution to text file?
« Reply #19 on: May 04, 2010, 06:42:52 pm »
I really think using the "simplest method possible" becomes the most troublesome method possible when other values than the screen resolution in the config file must change. YMMV, but I've never ran into an end-user who would be willing to change hardcoded values in the source code and then recompile the application just to change a simple option in the finished application.
"I'm sorry, I only accept criticism in the form of sed expressions."

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: Exporting display resolution to text file?
« Reply #20 on: May 04, 2010, 06:58:07 pm »
True enough. He did say that it is only those values that change though and that once compiled, no one will even look at the source from that point on. I doubt reusability is on the top of his list.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

 

Donate


* Search


* Recent Posts

I miss the chatbox by Shishka
[August 27, 2019, 11:52:39 pm]


Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]