Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[UPDATE!]windows API help

Greetings.

Let me start by saying, I think I am getting the hang of ruby and RGSS. The one thing I seem to always get hung up on is interacting with the Windows OS via API calls. Up to now, I have only used API's that others have setup and follow their examples without fully understanding exactly what is going on. Now I find myself wanting to use an API call that I haven't seen used before and I am unsure exactly how to use it. MSDN doesn't help me as I find the layout of code Microsoft provides confusing to me.... :blush:

Anyway, If I provide the name of the api, and a link to the MSDN documentation, can someone show me how to use it within Ruby/RGSS. give me an example script, and possibly, in addition, give me a tutorial on using Windows API in ruby for future reference so I don't have to ask again?

API : EnumDisplaySettings

Thank you,

Draycos Goldaryn

Update:
Check three posts down!
 

Gust

Member

You see this:
EnumDisplaySettings(NULL, index++, &dm)
?
this is the API call. The three parameters are, according to MSDN:
  • Device Name = A string, the name of the display device. It's probably a Wide String, where each character has two bytes, but you won't need to input one so it doesn't matter. You can use 'nil' to refer to the current device.
  • ModeNum = An integer, that indicates the index of the DisplaySetting about which you want info.
  • DevMode = Now, here's the catch. This is a pointer to a structure, of the type DEVMODE, where the function will put your info.
Whenever you need to pass a pointer to a DLL from ruby, you have to pass a string. It must be a string at least the size of said structure. Then you use 'unpack' to interpret the bytes it will put in the string as the information of the structure. Problem is... this is the structure we're talking about. It's pretty complex, so it'd be a pain in the ass.
"zeus81" has a script that could make you life easier: viewtopic.php?f=11&t=74178
I haven't tested it, but it looks good. It'll still be a pain in the ass to simulate the struct that API call, though.

On the other hand, if you can program C or C++, you can make things much simpler by creating a DLL. You can make a simpler function that uses the API call, picks only the information you need and returns it. Then it would be pretty simple to use in Ruby.

What information about the display you need? Maybe I can do that DLL for you.
It's kinda dumb to make a DLL just for one function, but I guess it's the best option here.
 
well, I want to retrieve all the supported resolutions of the current video card / monitor combo so I can then create a customized list of resolution settings in my multiple resolution kit's settings scene.

As it currently is, I have a few resolutions hard-coded into the script, but if the monitor won't support the resolution, it will kick the player out of fullscreen and deny it completely. but If I can get the supported resolutions, then any resolution the player chooses, his/her display should support it and they can go into fullscreen if they wish to.
 
I did it!!!!!

I figured it out on my own after reading the following webpages:

http://msdn.microsoft.com/en-us/library ... 85%29.aspx
http://msdn.microsoft.com/en-us/library ... numerating
http://www.rubytips.org/2008/05/13/acce ... i-library/
http://ruby-doc.org/core/classes/String.html#M001112

here is the code:
[rgss]EnumDisplaySettings = Win32API.new('User32.dll', 'EnumDisplaySettings', ['P','I','P'], 'I')
devmode=' '*128
x=0
settings=Array.new
loop do
  y = EnumDisplaySettings.call(nil,x,devmode)
  if y == 0
    break
  else
    setting = devmode.unpack("I*")
    temp = [setting[27],setting[28]]
    if !settings.include?(temp)
      settings.push(temp)
    end
    x +=1
  end
  Graphics.update
end
p settings #=> [[width, height], [width, height], [width, height], ...]
 
[/rgss]

This stores the supported resolutions in an array in the following format:

settings = [[width, height], [width, height], [width, height]] and so on...

Does anyone have any suggestions for improvement?

Thank you,

Draycos Goldaryn
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top