Desktop resolution?

Blitz3D Forums/Blitz3D Beginners Area/Desktop resolution?

Al Mackey(Posted 2003) [#1]
Is there an easy way to determine the user's desktop resolution from within a Blitz app? I'm making a resolution selector for a B3D app, and want to make sure that it can't offer a windowed resolution larger than the screen.


WolRon(Posted 2003) [#2]
Be more specific. Do you want to know the max resolution available or the resolution at the time the program is executed?

You can always set the actual resolution of the screen larger first and then create a windowed resolution that will fit :)


Al Mackey(Posted 2003) [#3]
I just want to know how to find the resolution of the user's desktop is. That is, the resolution that the screen will be in if I don't make my own fullscreen mode. It seems to me that this would be really basic and useful info for any kind of program, but there's no mention of it in the BB docs.


skn3(Posted 2003) [#4]
In b+ you can do it. Using clientwidth(desktop()), and clientheight(desktop()). Not in b3d though...


Binary_Moon(Posted 2003) [#5]
You can do it with a userlib

www.blitzbasic.com/bbs/posts.php?topic=22132


Al Mackey(Posted 2003) [#6]
hmmmm... I don't have much experience with userlibs, but they connect Blitz with calls to DLLs, right? So the "user32.decl" file will call from "user32.dll", I assume.

Anyway, I made a user32.decl file with that line from the other tread in it, but when I try to start up Blitz now it says "Compiler environment error: Error in userlib 'user32.decls' - function decl without lib irective". What am I doing wrong?


Oldefoxx(Posted 2003) [#7]
The DECLS files must be in the UserLibs folder. That is hardcoded. Then the DLL file(s) being referenced need to either be located/copied to the same folder, or need to be somewhere where Windows normally would look for it, such as in the \Windows\System32 folder (or \WinNT\System32 folder for WindowsNt/2000/XP). You can also hardcode the .LIB statement in the DECLS file to point to a specific location where the DLL can be found, such as .LIB "c:\MyDir\MyLib.DLL". Note that you have the burden of making sure that the Function statements in the DECLS file correspond exactly to the requirements of the routines you are trying to reference in the DLLs, which means some further research on your part to find out what they are.

As to the error you are getting, I am assuming that the cause is related to something along these lines. I haven't experienced it myself, and don't intend to if I can help it.


Al Mackey(Posted 2003) [#8]
Ahhh, okay. It works now that I've added a line that says .Lib "user32.dll". Thanks!!


soja(Posted 2003) [#9]
[Whoops, it took too long to type this lengthy post... =) I'll leave it anyway...]

To give an example, here's a very simple decls file:

"[blitzpath]\userlibs\user32.decls":
.lib "user32.dll"
MessageBox%(hWnd%, mytext$, mycaption$, utype%):"MessageBoxA"


...and some .bb code to test it:
MessageBox(0, "Patchwerk is great!", "Hi Al", 0)


If you haven't guessed, this is an easy way to interface with the Windows' MessageBox function. Great for those Blitz3D users without "Notify" (BlitzPlus function).

In the user32.decls file:
.lib "user32.dll"

.lib is the directive that needs a parameter of a valid dll in the current path. It is only used once for each dll.

After that come the declarations for the exported functions of the particular dll, i.e.
GetForegroundWindow%():"GetForegroundWindow"
GetWindowText%(hWnd%, lpString$, nMaxCount%):"GetWindowTextA"
MessageBox%(hWnd%, mytext$, mycaption$, utype%):"MessageBoxA"


The first name can be anything you want (what you call in Blitz), but the last name (in quotes) has to match the exported DLL function name.

Some people like to put DLL-specific function declarations into separate files (i.e. one decls file for kernel32 functions, one for user32 functions, one for msvcrt functions, etc) and others like to put them all in one file, sepearated by the appropriate ".lib" directive, i.e.:

mydecls.decls:
.lib "user32.dll"
<function1>
<function2>
...etc

.lib "NTDLL.dll" 
<function1>
<function2>
...etc


A way I've figured out to find native Windows functions to use as userlibs is this:
1) Get a list of the exported functions of the DLL (I use dumpbin.exe from MSVC++)
2) Look them up in MSDN library
3) Then it's easy to match up Blitz types with Windows types for the parameters

Some userlibs caveats:
1) A particular function may not be compatible with all versions of Windows. Make note from the documentation in MSDN.
2) There's not an easy way to debug them, since you're calling an external DLL. If you crash, it's your fault (usually), but you may not easily know why.
3) When a DLL function calls for a pointer to a struct, just pass in bank from CreateBank. Figure out the needed size in bytes from the documentation.
4) If a parameter can be either a pointer OR NULL, it causes a small problem. To pass NULL, you must declare the parameter as % in the decls file and pass 0 in your call. Conversely, to pass a pointer, you must declare the parameter as * in the decls file. This means you either have to decide which one you want when you're writing the decls file, or if you want both, you have to have two different Blitz Function Declarations for the same DLL function.
5) An constant (and there are many) that's defined in another include file will not be understood by Blitz (obviously). This means you have to look up the value in the .h file yourself, or on the web, or in a pickle, guess, and then declare the constant yourself, or just pass the value itself (as I did above in the MessageBox function).

That's it off the top of my head... let us know how it works out.


Al Mackey(Posted 2003) [#10]
Wow, that's exactly the sort of meaty userlib info I've been looking for, Soja! They should put something like that in the docs somewhere. :>