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

List-View Control

intelandmicrosoft
481 Views
The following code compiles at the command line "ifort /winapp fortran.f90 /link ComCtl32.Lib" without any errors at all. A grey bar appears at the top of the window as my list-control but I can'tfigure out how toaddtext to the column or even if the view-list control initialized properly. I believe the problem is somewhere in the InitListViewColumns FUNCTION. Maybe I am passing an address when it expects a value or vice versa. I can't figure it out. I'm not totally sure if the InitListViewColumns is even the problem. Please Help. I've been at this for days.
CODE THAT DOES COMPILE WITHOUT ERRORS AND KINDA WORKS!:
!****************************************************************
INTEGER FUNCTION WinMain( hInstance, hPrevInstance, lpszCmdLine, nCmdShow )
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_WinMain@16' :: WinMain
USE IFWIN
INTEGER hInstance, hPrevInstance, nCmdShow, lpszCmdLine
type (T_WNDCLASS) wc
type (T_MSG) mesg
INTEGER hWnd, iRet, ghInstance
COMMON /globdata/ ghInstance
!/********************** Prototypes **************************/
INTERFACE
INTEGER FUNCTION MainWndProc ( hwnd, mesg, wParam, longParam )
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
INTEGER hwnd, mesg, wParam, longParam
END FUNCTION
END INTERFACE
!/******************** END Prototypes ************************/
IF( hPrevInstance .eq. 0 ) THEN
wc%style = IOR ( CS_VREDRAW, CS_HREDRAW )
wc%lpfnWndProc = LOC ( MainWndProc )
wc%cbClsExtra = 0
wc%cbWndExtra = 0
wc%hInstance = hInstance
wc%hIcon = LoadIcon ( hInstance, IDI_APPLICATION)
wc%hCursor = LoadCursor( NULL, IDC_ARROW )
wc%hbrBackground = GetStockObject ( WHITE_BRUSH )
wc%lpszMenuName = 0
wc%lpszClassName = LOC ( "Generic_Class_Name" )
iRet = RegisterClass( wc )
END IF
ghInstance = hInstance
hWnd = CreateWindowEx ( 0, &
"Generic_Class_Name", &
"Generic_App_Name", &
INT(WS_OVERLAPPEDWINDOW), &
CW_USEDEFAULT, &
CW_USEDEFAULT, &
CW_USEDEFAULT, &
CW_USEDEFAULT, &
NULL, &
NULL, &
ghInstance, &
NULL &
)
iRet = ShowWindow (hWnd, SW_SHOWNORMAL)
DO WHILE ( GetMessage (mesg, NULL, 0, 0) .NEQV. .FALSE. )
iRet = TranslateMessage ( mesg )
iRet = DispatchMessage ( mesg )
END DO
WinMain = mesg.wParam
END FUNCTION WinMain
!****************************************************************
INTEGER FUNCTION MainWndProc ( hWnd, mesg, wParam, lParam )
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
USE IFWIN
INTEGER hWnd, mesg, wParam, lParam
INTEGER hWndListView, iRet
SELECT CASE ( mesg )
CASE ( WM_CREATE )
hWndListView = CreateListView ( hWnd )
iRet = InitListViewColumns ( hWndListView )
CASE ( WM_DESTROY )
CALL PostQuitMessage( 0 )
CASE DEFAULT
MainWndProc = DefWindowProc ( hWnd, mesg, wParam, lParam )
END SELECT
END FUNCTION MainWndProc
!****************************************************************
INTEGER FUNCTION CreateListView ( hWnd )
USE IFWIN
USE comctl32
INTEGER hWnd
INTEGER iRet
TYPE (T_RECT) rcl
TYPE (T_INITCOMMONCONTROLSEX) iccex
iccex%dwSize = sizeof ( iccex )
iccex%dwICC = INT ( ICC_LISTVIEW_CLASSES )
iRet = InitCommonControlsEx ( iccex )
IF ( iRet == .FALSE. ) THEN
i = MessageBox ( NULL, "InitCommonControlsEx", NULL, MB_OK )
END IF
iRet = GetClientRect ( hWnd, rcl )
IF ( iRet == 0 ) THEN
i = MessageBox( NULL, "GetClientRect", NULL, MB_OK )
END IF
CreateListView = CreateWindow( &
WC_LISTVIEW, &
"", &
IOR (IOR ( LVS_REPORT, WS_CHILD ), WS_VISIBLE ), &
0, &
0, &
(rcl%right - rcl%left), &
(rcl%bottom - rcl%top), &
hWnd, &
INT(9001), &
ghInstance, &
NULL)
IF ( CreateListView == NULL ) THEN
i = MessageBox ( NULL, "CreateWindow", NULL, MB_OK )
END IF
END FUNCTION CreateListView
!****************************************************************
INTEGER FUNCTION InitListViewColumns ( hWndListView )
USE IFWIN
INTEGER hWndListView
INTEGER iRet
type (T_LVCOLUMN) lvc
lvc%mask = IOR ( IOR ( LVCF_FMT, LVCF_WIDTH), LVCF_TEXT)
lvc%cx = 1000
lvc%fmt = INT ( LVCFMT_LEFT )
lvc%pszText= LOC("SubItem1"c )
iRet = SendMessage ( hWndListView, INT ( LVM_INSERTCOLUMN ), 1, LOC(lvc) )
lvc%pszText= LOC ( "SubItem2"C )
END FUNCTION InitListViewColumns
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
481 Views
IMPLICIT NONE is your friend:
Code:
INTEGER FUNCTION MainWndProc ( hWnd, mesg, wParam, lParam )
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
USE IFWIN
INTEGER hWnd, mesg, wParam, lParam
INTEGER hWndListView, iRet
    INTEGER, EXTERNAL::  CreateListView
Without explicit declaration of CreateListView, the return value is REAL, and INTEGER<->REAL typecasts screw the value ofhWndListView.
My style isto put such codes in MODULEs (one module per window) with IMPLICIT NONE on the top -- it helps the organization and avoids such mistakes.
Jugoslav
0 Kudos
intelandmicrosoft
481 Views
Thanks that did it. Works perfect now.
0 Kudos
Reply