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

WinMain question (adding menu to a simple dialog-based app)

dan789
Beginner
1,144 Views
Hi,
I haveadded a menu in CVF to my dialog-based application (the app worked fine before). The program now starts as follows:

integer*4 function WinMain( hInstance, hPrevInstance, lpszCmdLine, nCmdShow )

!DEC$ IF DEFINED(_X86_)

!DEC$ ATTRIBUTES STDCALL, ALIAS : '_WinMain@16' :: WinMain

!DEC$ ELSE

!DEC$ ATTRIBUTES STDCALL, ALIAS : 'WinMain' :: WinMain

!DEC$ ENDIF

But the compiler returns error:

Linking...

dfqwin.lib(qwkentry.obj) : error LNK2005: _WinMain@16 already defined in MainProgram.obj

dformt.lib(DFORMAIN.OBJ) : error LNK2001: unresolved external symbol _MAIN__

The WinMain is defined only once in the .f90 file and the interface to WinMain is written once in the .fi file as follows:

!DEC$ FREEFORM

interface

integer*4 function MainWndProc ( hwnd, mesg, wParam, lParam )

!DEC$ IF DEFINED(_X86_)

!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc

!DEC$ ELSE

!DEC$ ATTRIBUTES STDCALL, ALIAS : 'MainWndProc' :: MainWndProc

!DEC$ ENDIF

integer*4 hwnd

integer*4 mesg

integer*4 wParam

integer*4 lParam

end function

end interface

So I dont understand why I get the compiler error. Perhaps WinMain is also defined in one of the libraries I use? But I use only user32, kernel32, and dialogm. Could you please help?

0 Kudos
6 Replies
anthonyrichards
New Contributor III
1,144 Views
The compiler error message references to DFQWIN.LIB and DFORMT.LIB indicates that you have started your project as a QuickWin project, so the compiler looks in the QuickWin lib raries (QuickWin is a multithreaded application, hence the reference to the MultiThreaded library ...MT.LIB).
However, you have coded it as a standard Win32 project, which must have WinMain function as its entry point, which you appear to have supplied. So, there are two WinMains, one supplied by default when you define it as Quickwin application.
If it is a true Quickwin project, all you supply is
Program Whatever.
...(QuickWIn menu code)
Infinite time-wasting loop
...
end program
which sets up the Quickwin menus and callbacks and starts an infinite loop while the QuickWin-supplied WInMain and default MainWndProc take over the windowsa message-handling in another thread.
You need to either recast your project as a standard win32 application (with
a WinMain that calls RegisterClass to define and register your window class and then CreateWindowEx to create your window, anda MainWndProc of your own) or dump the WinMAin and MainWndProc and make it a true QuickWin project.
0 Kudos
dan789
Beginner
1,144 Views
I see, thank you! I understand the problem now. But what concrete functions are to deal with the menu in a QuickWin project? I have found only one way to operate with menu in the CVF Programmer's Guide:

Using the Menu

To use a menu bar in your Fortran application, you must load the menu resource and use it when creating the main window of the application. Code to do this is created automatically by the Fortran Windows AppWizard. The code that loads the menu resource is:

ghMenu = LoadMenu(hInstance, LOC(lpszMenuName))

The returned menu handle is then used in the call to CreatWindowEx:

ghwndMain = CreateWindowEx( 0, lpszClassName, &

lpszAppName, &

INT(WS_OVERLAPPEDWINDOW), &

CW_USEDEFAULT, &

0, &

CW_USEDEFAULT, &

0, &

NULL, &

ghMenu, &

hInstance, &

NULL &

)

0 Kudos
anthonyrichards
New Contributor III
1,144 Views
What you are developing is a true Windows 32-bit (WIn32 for short)application, that defines and creates its own windows and has its own message-handling loop. A QUickwin project, such as the one I attach,is very different, and its documentation can be found under the CVF help (Using Quickwin).
QuickWIn uses finctions such as INSERTMENUQQ and APPENDMENUQQ to modify the standard QuickWin menu. You write your own callback routines and associate them with the appropriate menu items (I have replaced the call backs with 'NUL' to get the program to run).
You can develop your own dialogs using the CVF module DFLOGM and the functions DlgInit, DlgSet, DlgGet etc. Look in the Help for these. In teh program you are writing, you will have your own window procedure (call it what you will, MyWNdProc) that receives the messages when you click on your menu items and which then opens the appropriate dialog, or whatever is appropriate to that menu item. You point to the location of this procedure when you create your window class e.g.
Code:
type (T_WNDCLASS)       wc
character*100 lpszClassName, lpszIconName, lpszMenuName, lpszAppName
character*100 lpszAcceltabname, lpszChildClassNAme
... ... lpszAcceltabname="MyAccelerator"C lpszClassName ="Myclass"C lpszAppName ="My program"C lpszMenuName ="Mymenu"C lpszIconName ="MyIcon"C ! Register the MAIN window class, if not already ! registered by a previous instance if(hPrevInstance .eq. 0) then wc%lpszClassName = LOC(lpszClassName) wc%lpfnWndProc = LOC(MyWndProc) wc%style = IOR(IOR(CS_VREDRAW , CS_HREDRAW),CS_OWNDC) wc%hInstance = hInstance wc%hIcon = LoadIcon( hInstance, LOC(lpszIconName)) wc%hCursor = LoadCursor( NULL, IDC_ARROW ) wc%hbrBackground = ( COLOR_WINDOW+1 ) wc%lpszMenuName = 0 wc%cbClsExtra = 0 wc%cbWndExtra = 0
If you want quick results, go with quickwin. If you persevere with learning the windows API, you can find lots of help on these boards by doing appropriate searches and it is well worth while, if you have the time that is. Regards
0 Kudos
csmao
Beginner
1,144 Views
Anthony:

I find your quickwin program helpful. Could you please list some codes of menu callback routines for your program? Coming from the world of Lahey, I am new to IVF and programming menus has given me a hard time. A concrete example would definitely help. Thanks in advance.

Mao
0 Kudos
anthonyrichards
New Contributor III
1,144 Views
Ok. Here is an expanded version of the previous project, with a call back added for the first sub-menu item under the 'Graphic' item in the main QuickWIn menu (normally it would be greyed-out until a file has been loaded and displayed). The call-back opens a dialog box.
I have also added the code that permits the display of a standard Explorer-type 'Open File' dialog by selecting 'Open File' under the QuickWIn 'File' menu item. Hope this helps.
0 Kudos
csmao
Beginner
1,144 Views
Thanks a lot, Anthony.

Mao
0 Kudos
Reply