1. Newbie Win32Lib questions
- Posted by "Bruce M. Axtens" <bruce_axtens at SIL.ORG> Jun 16, 1999
- 422 views
Dear All, Re: Win32Lib Ok, how do I do it. I want to create a simple window and then write text to it. No font niceties required, just a simple log of the progress of the program (which in case you wanted to know is pinging a series of addresses and displaying the address and the average ping time in milliseconds). Basically I'm after the Windows equivalent of printing to stdout but I want it in a window, not the console. Also re: Win32Lib How do I do a RasHangUp? How do I do a RasDial? How do I do a RasEnumConnections and how do I make sense of parameters like LPRASDIALEXTENSIONS, LPTSTR, LPRASDIALPARAMS, DWORD, LPVOID, LPHRASCONN etc. Thanks for your help. Bruce.
2. Re: Newbie Win32Lib questions
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> Jun 16, 1999
- 446 views
Bruce M. Axtens wrote: > I want to create a simple window and > then write text to it. Take a look at ex12.exw - it shows how to place text in the window. Just stick the text in a sequence, and when you get an paint request, repaint it. Something like this: procedure onPaint( integer x1, integer y1, integer x2, integer y2 ) -- redraw theText in the current window integer fontX, fontY, winX, winY, line object info -- get the font size info = getTextSize( MyWindow ) fontX = info[1] fontY = info[2] -- get the window size info = getWindowSize( MyWindow ) winX = info[1] winY = info[2] -- display all the text line = 0 for y = 1 to winY by fontY do -- increment the line of text being displayed line += 1 -- past end of text? if line > length( theText ) then -- leave the loop exit end if -- position the cursor at the line setPosition( MyWindow, 0, y ) -- display the text wPuts( MyWindow, text[ line ] ) end for end procedure It's a bit brute force (it ignores the repaint parameters, for example), but it should get the job done. Every time that you get update information, update theText and call repaintWindow( MyWindow ). This forces the entire window to be repainted, and triggers your onPaint event. The easiest way to handle text scrolling to *prepend* the new text, so the most current information is at the top of the screen. If you want to scroll in the opposite direction, it gets a bit more complex. > How do I do a RasHangUp? > How do I do a RasDial? > How do I do a RasEnumConnections I assume you have the Win32 Programmer's Reference help file. If not, it's at the RDS site. You will need to link to RASAPI32.DLL; it's not one of the common DLLs that Win32Lib uses. This is done with: constant rasapi32 = linkDLL("RASAPI32.DLL") or in plain Euphoria: constant rasapi32 = open_dll("RASAPI32.DLL") The only difference between the two is that linkDll (a Win32Lib function) does some error checking with the result before handing it back. Then you need to tell Euphoria what the functions look like. For example, RasHangUp looks like this in C: DWORD RasHangUp( HRASCONN hrasconn ) To declare it in Win32Lib, write something like this: constant xRasHangUp = linkFunc( rasapi, "RasHangUp", {C_POINTER}, C_LONG ) or in plain Euphoria: constant xRasHangUp = define_c_func( rasapi, "RasHangUp", {C_POINTER}, C_LONG ) Again, the only difference is that the Win32Lib version does some error checking on the result before handing it back. To then use the function, you would call using c_func like this: result = c_func( xRasHangUp, {hRasConn} ) That's how you can access the routines in Win32Lib. Not having used any of those functions, I can only refer you to the Win32 help file for more information. > and how do I make sense of parameters like > LPRASDIALEXTENSIONS, LPTSTR, > LPRASDIALPARAMS, DWORD, LPVOID, LPHRASCONN etc. It helps to have some C programming background. The best advice is to find a good Win32 book that focuses on C programming, like Petzold's text. The key here is that the function names use something called "Hungarian notation"; the first few characters are a prefix to the data type. For example: lp = long pointer d = double so: lpRadDialExtentions is a long (double word) pointer data type. I posted a general discussion on reading and writing C struture yesterday; you might want to take a look at that. There are a tools in Win32Lib to declare and work with data structures. As an example, compare the definition of a RECT data structure: typedef struct _RECT { // rc LONG left; LONG top; LONG right; LONG bottom; } RECT; and how Win32Lib defines it: -- Type RECT constant rectLeft = allot( Long ), rectTop = allot( Long ), rectRight = allot( Long ), rectBottom = allot( Long ), SIZEOF_RECT = allotted_size() It looks pretty much the same, doesn't it? In order to create the data structure, you need to use allocate() to grab memory, and free() to release it when you are done. In Win32Lib, I use the function allocate_struct(), which calls allocate(), and then fills the allocated memory with zeros. You can see an example of a RECT data structure being constructed and filled in the repaintRect() procedure: -- hold address of rect atom rect -- allocate rectangle rect = allocate_struct( SIZEOF_RECT ) -- store the information store( rect, rectLeft, x1 ) store( rect, rectTop, y1 ) store( rect, rectRight, x2 ) store( rect, rectBottom, y2 ) The routine getWindowSize() shows how Win32Lib reads information from a rectangle: -- get points left = fetch( rect, rectLeft ) top = fetch( rect, rectTop ) right = fetch( rect, rectRight ) bottom = fetch( rect, rectBottom ) This should be enough to get you going. Take a look in win32lib.doc under "Data Structure Tools" for more information. Hope this helps! -- David Cuny
3. Re: Newbie Win32Lib questions
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> Jun 16, 1999
- 408 views
I had written: constant xRasHangUp = linkFunc( rasapi, "RasHangUp" ... ) instead of: constant xRasHangUp = linkFunc( rasapi32, "RasHangUp" ... ) Sorry. -- David Cuny