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

Trouble with Lawrence Win32Menu in IVF

engineerik
Beginner
1,004 Views

I am trying to learn how to create windows projects in IVF (11.0.3452.2005)and so I am starting out by following the Lawrence book.
The second example he gives is all about working with menus and I have no problem with the menu stuff at all. However, although the DrawText returns a seemingly good text height value,the window generated does not have any text. The window appears completely empty.
Any ideas why my text is not visible?
Regards,
Erik

0 Kudos
1 Solution
anthonyrichards
New Contributor III
1,004 Views
Quoting - engineerik

Haven't tried this using CVF but as I stated in my original post I am doing this from IVF and my application window is blank. If you zoom in onmy pdf there is the slightest little light gray mark in the upperleft corner of the application window. No 'Hello from Win32!'.

If you run this in IVF do you get text in the application window?

Regards,
Erik

I created an IVF empty project and added your files and built the solution. It uses the default calling conventions (whatever they are). After some playing around, I found that ...

Selecting and resizing the menu window causes the text to disappear and not reappear. If the menu window is then partially covered by the console by selecting the console window with the mouse, and then the menu window is selected using the mouse, the text appears in the redrawn window.

There is clearly something not right about what is done following resizing of the menu window which is done correctly when the menu window is uncovered by the console window and redrawn. See the attached screen shots.

P.S. I used IVF 11.1.035 with MS Visual Studio 2005

View solution in original post

0 Kudos
12 Replies
anthonyrichards
New Contributor III
1,004 Views
Quoting - engineerik

I am trying to learn how to create windows projects in IVF (11.0.3452.2005)and so I am starting out by following the Lawrence book.
The second example he gives is all about working with menus and I have no problem with the menu stuff at all. However, although the DrawText returns a seemingly good text height value,the window generated does not have any text. The window appears completely empty.
Any ideas why my text is not visible?
Regards,
Erik


Can you attach your resource files (script.rc, resource.h and resource.fd) and Win32menu.fi, which are missing?
0 Kudos
engineerik
Beginner
1,004 Views
Quoting - anthonyrichards

Can you attach your resource files (script.rc, resource.h and resource.fd) and Win32menu.fi, which are missing?

Here are the files.

Regards,
Erik
0 Kudos
anthonyrichards
New Contributor III
1,004 Views
Quoting - engineerik

Here are the files.

Regards,
Erik

Using your files, I created a Compaq Visual Fortran project (using my own icon, as your Win32menu.ico was missing) by changing IFWIN and IFWBASE to DFWIN and DFWBASE. The application compiled and ran OK, opening a console window alongside the application window. The words 'Hello from Win32!' appear centred in the application window. When the window is resized, a line is printed to the console window showing the current 'text height'in the resized window. What else is supposed to happen?
There is no response to the 'Text Direction' and 'Text Position' menu items at present. See attached fileshowing a screen shot
0 Kudos
engineerik
Beginner
1,004 Views
Quoting - anthonyrichards
Quoting - engineerik

Here are the files.

Regards,
Erik

Using your files, I created a Compaq Visual Fortran project (using my own icon, as your Win32menu.ico was missing) by changing IFWIN and IFWBASE to DFWIN and DFWBASE. The application compiled and ran OK, opening a console window alongside the application window. The words 'Hello from Win32!' appear centred in the application window. When the window is resized, a line is printed to the console window showing the current 'text height'in the resized window. What else is supposed to happen?
There is no response to the 'Text Direction' and 'Text Position' menu items at present. See attached fileshowing a screen shot

Haven't tried this using CVF but as I stated in my original post I am doing this from IVF and my application window is blank. If you zoom in onmy pdf there is the slightest little light gray mark in the upperleft corner of the application window. No 'Hello from Win32!'.

If you run this in IVF do you get text in the application window?

Regards,
Erik
0 Kudos
anthonyrichards
New Contributor III
1,005 Views
Quoting - engineerik

Haven't tried this using CVF but as I stated in my original post I am doing this from IVF and my application window is blank. If you zoom in onmy pdf there is the slightest little light gray mark in the upperleft corner of the application window. No 'Hello from Win32!'.

If you run this in IVF do you get text in the application window?

Regards,
Erik

I created an IVF empty project and added your files and built the solution. It uses the default calling conventions (whatever they are). After some playing around, I found that ...

Selecting and resizing the menu window causes the text to disappear and not reappear. If the menu window is then partially covered by the console by selecting the console window with the mouse, and then the menu window is selected using the mouse, the text appears in the redrawn window.

There is clearly something not right about what is done following resizing of the menu window which is done correctly when the menu window is uncovered by the console window and redrawn. See the attached screen shots.

P.S. I used IVF 11.1.035 with MS Visual Studio 2005
0 Kudos
engineerik
Beginner
1,004 Views
Thanks so much for confirming that there is an issue here. I appreciate the time you put into it.

Regards,
Erik

0 Kudos
anthonyrichards
New Contributor III
1,004 Views
Quoting - engineerik
Thanks so much for confirming that there is an issue here. I appreciate the time you put into it.

Regards,
Erik


After a little more study, I have discovered the following:

1. When you process the WM_CREATE message and create a logical font, the arguments of the RHS of statements such as

lf%lfPitchAndFamily = fontFamily
lf%lfEscapement = directionText
lf%lfOrientation = directionText
lf%lfHeight = sizeFont
lf%lfItalic = fontItalic
lf%lfWeight = fontWeight

are as expected.

2. By the time that you process the first WM_PAINT message and create your logical font using modifications to the logical font structure LF, by means of similar statements to the above, the RHS arguments have somehow been changed. There must be some corruption going on. In other words, the variables directionText, sizeFont, fontItalic etc.have somehow been overwritten so that the 'good' values originally put into the LF structure during processing of the WM_CREATE message are lost.

3. If you use the LF structure as soon as it is created to create your font (during processing of the WM_CREATE message) and use that font instead of creating the font during processing of the WM_PAINT message, AND you use

rctext=rc
ncount=lstrlen(TextBuf)
alignText = (DT_SINGLELINE.OR.DT_VCENTER).OR.DT_CENTER
iret = DrawText(hDC, TextBuf, ncount, rctext, alignText)

you will find that, when run, you get your text centred horizontally and vertically, and it remains in place when the window is resized, uncovered etc.

I do not know the origin of the corruption that is going on. You will need to run your code in the debugger and watch for changes to the variables directionText, sizeFont, fontItalic etc.

I repeat, there is no problem when compiled and run using Compaq Visual Fortran. Possibly, the problem lies in a difference in an interface for a Windows function between the IFWIN and DFWIN modules (or IFWBASE and DFWBASE modules), the IFWIN one being wrong.

P.S. If you extract the following statements from MainWndProc and put them into the Win32MenuGlobals module instead, it avoids the apparent corruption problem and the text displays as expected. However, there remains the possibility of corruption of other variables whose effects have just not become visible yet!

integer*4 alignText
integer*4 sizeFont
integer*4 directionText
integer*4 fontFamily
integer*4 fontWeight
logical*4 fontItalic
0 Kudos
anthonyrichards
New Contributor III
1,004 Views
The clue to the solution is the observation that removingsome local variables and putting them into a Module solved the problem.

The reason is that IVF, by default,DOESNOTsave the valuesassigned tolocal variables between calls to a subroutine or function, whereas CVF by default does.

So if you just add the statement SAVE in your specification statements, your problem will disappear!(confirmed by testing)!

Alternatively, keep your variables in a module instead and USE the module.

0 Kudos
engineerik
Beginner
1,004 Views
Quoting - anthonyrichards

After a little more study, I have discovered the following:

1. When you process the WM_CREATE message and create a logical font, the arguments of the RHS of statements such as

lf%lfPitchAndFamily = fontFamily
lf%lfEscapement = directionText
lf%lfOrientation = directionText
lf%lfHeight = sizeFont
lf%lfItalic = fontItalic
lf%lfWeight = fontWeight

are as expected.

2. By the time that you process the first WM_PAINT message and create your logical font using modifications to the logical font structure LF, by means of similar statements to the above, the RHS arguments have somehow been changed. There must be some corruption going on. In other words, the variables directionText, sizeFont, fontItalic etc.have somehow been overwritten so that the 'good' values originally put into the LF structure during processing of the WM_CREATE message are lost.

3. If you use the LF structure as soon as it is created to create your font (during processing of the WM_CREATE message) and use that font instead of creating the font during processing of the WM_PAINT message, AND you use

rctext=rc
ncount=lstrlen(TextBuf)
alignText = (DT_SINGLELINE.OR.DT_VCENTER).OR.DT_CENTER
iret = DrawText(hDC, TextBuf, ncount, rctext, alignText)

you will find that, when run, you get your text centred horizontally and vertically, and it remains in place when the window is resized, uncovered etc.

I do not know the origin of the corruption that is going on. You will need to run your code in the debugger and watch for changes to the variables directionText, sizeFont, fontItalic etc.

I repeat, there is no problem when compiled and run using Compaq Visual Fortran. Possibly, the problem lies in a difference in an interface for a Windows function between the IFWIN and DFWIN modules (or IFWBASE and DFWBASE modules), the IFWIN one being wrong.

P.S. If you extract the following statements from MainWndProc and put them into the Win32MenuGlobals module instead, it avoids the corruption problem and the text displays as expeced. However, there remains the possibility of corruption of other variables whose effects have just not become visible yet!

integer*4 alignText
integer*4 sizeFont
integer*4 directionText
integer*4 fontFamily
integer*4 fontWeight
logical*4 fontItalic

Yes placing alignText, sizeFont, directionText, fontFamily, fontWeight, fontItalic in Win32MenuGlobals fixes the issue.
I was relying too heavily on transcribing the code I read in Lawrence to the IDE. I should have seen that they need to be globals in order to keep the values between one WM_PAINT event and the next.
Perhaps the Compaq compiler was automatically saving these values between calls to MainWndProc.
I seem to recall Dr. Fortran writing on that subject.

Regards,
Erik
0 Kudos
Steven_L_Intel1
Employee
1,004 Views
0 Kudos
anthonyrichards
New Contributor III
1,004 Views

Er...404 Error on that link, Steve!
0 Kudos
Steven_L_Intel1
Employee
1,004 Views
Hmm - not sure how that happened. I fixed the link (and your copy).
0 Kudos
Reply