Win32 Conversation (was Win32 tutor)
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Oct 19, 1998
- 608 views
Hello to all interested in Win32 programming, Part 4 of the '''''tutorial''''' (a lot of quote - unquote). As you see I changed the subject name a little, but the contents will remain the same, in general. I thought there was an imminent danger that some people would see me as a 'teacher', and not so much as a fellow programmer exchanging thougths with you concerning the possibilities and pitfalls encountered when trying to write Win32 programs. The problem encountered today is that of screen size. I myself like the main window of a program to cover nearly all of the screen, only leaving free the bar at the bottom. But not everyone is using 800 by 600 resolution, as I do; some bigger, so= me smaller Somewhere I read about the call to a function GetSystemMetrics to get the= width and heigth of your screen. But I also found out that this function call was not (yet) implemented in Cuny's Win32Lib. So I started searching= , using Win32.hlp (the 11 Mb file, that can be downloaded from The Archive)= and the dsearch.exw program found in \Euphoria\Demo\Win32. I struggled with it and eventually got it working. It was not until then that I found out that Jacques Dechenes also had used it in some demo's he= provided. Here are the include file GetSysMs.ew and WinDem01.exw, with some comment= s of mine: -- GetSysMs.ew: implementation of GetSystemMetrics -- function returns (a.o.) width and height of total screen -- to be used as nWidth and nHeight in create() -- 6th and 7th element of this function -- most of the code 'taken' from Jaques Dechenes -- Ad Rienks, september 13, 1998 -- Ad_Rienks at compuserve.com include dll.e include msgbox.e integer ok constant OpenFailed =3D "Failed to open user32.dll" constant DefineFailed =3D "Failed to define one of the user32 functions."= constant FatalErr =3D "Fatal error in user32.ew" constant user32 =3D open_dll("user32.dll") = if not user32 then ok =3D message_box(OpenFailed, FatalErr, 0) abort(1) end if -------------------------- defines ------------------------------------------ constant iGetSystemMetrics =3D define_c_func(user32, "GetSystemMetrics", {C_INT}, C_INT) if iGetSystemMetrics =3D -1 then ok =3D message_box(DefineFailed, FatalErr, 0) abort(1) end if global constant SM_CXSCREEN =3D 0, SM_CYSCREEN =3D 1 = global function GetSystemMetrics(integer Screen) return c_func(iGetSystemMetrics, {Screen}) end function -- end of GetSysMs.ew -- Windem01.exw -- Demo using GetSystemMetrics to read screenwidth and screenheight -- (I like a Windows program to fill (most of) my screen!) include GetSysMs.ew include Win32Lib.ew integer xScreen, yScreen, junk -- (something you throw away after use) -- these are calls to an API function, declared in the GetSysMs.ew includ= e xScreen =3D GetSystemMetrics(SM_CXSCREEN) yScreen =3D GetSystemMetrics(SM_CYSCREEN) constant Main =3D create(Window, "Adjusting screen", 0, 0, 0, xScreen, -- calculated screenwidth yScreen - 30, -- and screenheight - 30 0) global procedure onPaint_Main() -- behaviour when the main window paints/repaints itself setPosition(Main, 0, 0) wPuts(Main, "ScreenWidth =3D " & sprintf("%d ", xScreen) & "ScreenHeight =3D " & sprintf("%d ", yScreen)) end procedure -- linking the onPaint 'event' for the main window and the procedure -- to call (the 'method' in OOP lingo) onPaint[Main] =3D routine_id("onPaint_Main") WinMain(Main) -- end of WinDem01.exw I hope I use the terms in the rigth way; maybe this is the biggest proble= m I encountered, reading about Windhoos programming. You'll have to learn a= whole new jargon, about 'events' that 'send messages' to 'handles' and 'methods' to 'get' and/or 'set' 'properties' of 'instances' of 'objects'.= Maybe I'm swearing in church now, but I don't think you'll have to now exactly what this all means, as long as you understand what the programs are doing and can replicate some of it in your own applications. Homework question for today: Are there other ways to display the information about ScreenWidth and ScreenHeight? How would you do that? The contestants can win the price, donated by Irv. (What was it again, a ticket to DisneyLand? (inside joke!)) comments, bugs, questions, sympathy(?) to: Ad_Rienks at compuserve.com