Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29235 Discussions

Need help calling Win32 API function from Quickwin

dboggs
New Contributor I
1,014 Views
I'm a novice at this, and any help will be highly appreciated. I am either doing something stupid, failing to do something obvious, or trying to do something that can't be done.

In my Quickwin graphics program, I need to call certain API drawing functions instead of the Quickwin functions. Here is a code snippet, which attempts to use the API function "lineto" for example:


SUBROUTINE LINETOAPI

use dflib

use dfwin

use gdi32

!use kernel32 !no help

TYPE (WXYCOORD) WXY

integer(4) lu, penstyle

integer(4) hndle, nxend, nyend, hpen, colorref, nwidth, hpenold

logical(4) ret

! Draw a test line using QuickWin, just to demonstrate things are working.

call moveto_w (0._8, 0._8, wxy)

ISTAT = LINETO_W (.5_8, -.5_8)

! Now try a line using Windows API.

! First, get a handle to the active child window.

hndle = gethwndqq (lu) ! (returns 2884274, 3277512, ...)

! Create a pen.

nwidth = 0

colorref = 255

penstyle = 1

hpen = createpen (penstyle, nwidth, colorref) ! (returns -181401624, -516944594, ...)

! Connect the pen to the window.

hpenOld = SelectObject (hndle, hpen) ! (returns 0)

! Draw a line.

nxend = 10

nyend = -10

ret = msfwin$LineTo (hndle, nxend, nyend) ! (returns .false.)

! That's it.

END


This code does not work. Note the several functions that return handles, where I have noted the response ! (like this). The "createpen" functions returns a negative number, which seems suspicious to me. The "selectobject" function returns 0, indicating failure. The "lineto" function (which I renamed according to online documentation to avoid name conflict with quickwin) returns .false., also indicating failure.

Help!

0 Kudos
11 Replies
Paul_Curtis
Valued Contributor I
1,014 Views
For starters, in order to create graphic output using the Win32 API, you need to initialize a Device Context, represented by its handle, hDC; each device (screen, printer, etc.) will have a different DC. This is missing from your code sample, and is one of the (many) reasons your code fails.

In general, you should strongly consider abandoning "Quickwin" and creating standard Win32 programs in which you initialize all the required objects and have explicit proc function code for message loop processing. This is straightforward to do wholly in Fortran90 using the resources supplied with IVF (the DVF Win32 resources do work but they are outdated and incomplete). See any of Petzold's older books for instruction on how to write Win32 code.
0 Kudos
dboggs
New Contributor I
1,014 Views
Thanks for the quick response Paul. I appreciate your comments. Unfortunately, there is already a lot invested in this Quickwin graphics application, and it basically works fine, except for the issue of a pen width parameter that doesn't appear to be supported in Quickwin. So, right or wrong, good or bad, I'm highly motivated to pursue this, if there is any chance of it working.

Other information, including the online documentation, strongly implies that the API calls I'm trying should work in Quickwin, so I thought I'd give it a try. If it really is hard or nearly impossible to do, then I will give up.

Re. the device context handle, I thought that the line
hndle = gethwndqq (lu)
would take care of this. Or, possibly
hndle = gethwndqq (qwin$framewindow)
which works for other API calls.

I know I have a lot to learn. I'm just trying to bite off a little at a time. I don't understand why this attempt to use "lineto" seems to be such a big gulp compared to my previous tasks!

Daryl
0 Kudos
anthonyrichards
New Contributor III
1,014 Views
Paul is correct - you have to get hold of the handle to the device context used to draw your graphics window. To do this, you are going to have to subclass your graphics window, then process the WM_PAINT messages and make your pen and background selections in your subclass procedure. To find out about subclassing, just do a search on this forum using 'subclass' string.

However, IIRC, QuickWin is multithreaded and uses double-buffering, so you cannot make the change you want using Windows API. You need to switch completely to using the Windows API as Paul Curtis suggests.
0 Kudos
dboggs
New Contributor I
1,014 Views
OK, I was afraid of this. Thank both of you for responding.

I do have a big complaint about the on-line documentation: it implies quite strongly that calls to these API functions will work in quickwin.

Daryl
0 Kudos
Steven_L_Intel1
Employee
1,014 Views
They do work. But you're asking how to modify operations QuickWin is doing on your behalf, which is different.
0 Kudos
dboggs
New Contributor I
1,014 Views
Steve,

If I understand your statement, you're saying that quickwin has a version of the API function "lineto" that works. I understand that. But are you saying that the actual API call can work in quickwin? Like the documentation says, to use it just rename it to MSFWIN$LINETO? If this works, can you give me a sample code?

The quickwin lineto is crippled, that's why I wanted to use the API lineto. The API lineto either works from quickwin, or it doesn't.

Daryl
0 Kudos
Steven_L_Intel1
Employee
1,014 Views
No, that's not what I'm saying.

You can call Win32 API routines from QuickWin. But you may need to go to extra lengths to get the proper handles, DCs, etc, because normally QuickWin handles all of that for you and does not let you extend its functionality. I am not an expert on this - some things you can do with subclassing, as mentioned earlier.

The issue with LINETO is that this name is used both by QuickWin and by Win32. If you have done a USE IFQWIN, you get the QuickWin version. If you want access to the Win32 routine by the same name (but with a different calling sequence) from module GDI32, use MSFWIN$LINETO.

The Poker sample demonstrates subclassing.
0 Kudos
dboggs
New Contributor I
1,014 Views
Thanks for the clarification, Steve. I'll have a look at the Poker sample.
0 Kudos
Paul_Curtis
Valued Contributor I
1,014 Views
All of the Win32 API functions are fully operational and can be called from any Fortran code, whether Quickwin is used or not. Quickwin by itself supplies only a very limited subset of the full Windows context, and there are many operations and aspects of Windows functionality which are beyond the scope of Quickwin's limited goals which, as I understand them, are mostly aimed at providing simple dialogs with menus, and specifically exclude complex graphics.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,014 Views
The quickwin lineto is crippled, that's why I wanted to use the API lineto. The API lineto either works from quickwin, or it doesn't.

Daryl

Well, the API LineTo does work (given the right device context), but the catch is that interferes with QuickWin drawing. You can draw using QuickWin, or using API, but not both simultaneously.

You may be interested in my QW_XFT sample, which mixes QuickWin and Xeffort library (which is a thin layer around Win32 API, so the sample uses subclassing, but under the hood). Xeffort provides a rather rich set of wrappers around Win32 GDI functions, inspired by QuickWin (so there's for example XLineTo_W)... or you can call API LineTo(xDC%hDC, ....) directly.

0 Kudos
dboggs
New Contributor I
1,014 Views
Thanks Jugoslav, I appreciate the response.
0 Kudos
Reply