Fortran写的dll怎么向外发送消息??
现在有一Fortran写的dll(作为计算用),VC做界面。问题:VC的进度条如何与Dll的计算相关联(显示计算的进度)?
听别的高手说:要dll持续向外发送进度数据,然后进度条进行展示。
现在想问Fortran写的dll怎么向外发送消息??或者有没有更好的方法? 使用Fortran封装的Windows函数:SendMessage()和GetMessage().
古老的PowerStation实现如下(参见http://www.korf.co.uk/fortran_2.html,不知道Intel Fortran是否仍支持):
integer function WinMain( hInstance, hPrevInstance, lpszCmdLine, nCmdShow )
!MS$ ATTRIBUTES STDCALL, ALIAS : '_WinMain@16' :: WinMain
!To use win32 definitions
use msfwin
implicit none
!Function parameters
integer(4), intent(in) :: hInstance, hPrevInstance,nCmdShow,lpszCmdLine
!Function returns and Window+Message Structure
logical(4) :: bret
integer(4) :: hWnd_Static, hWnd_Control, iret, iErr=0
real(8) :: nRead
character (len=1024) :: szText="", szRead=""
character (len=*), parameter :: nl=char(13)//char(10)
type (T_RECT) :: rectStatic
type (T_MSG):: iMsg
!Display main window (only for title)
hWnd_Static = CreateWindow("listbox"C, &
"KFWIN Window (Right Click to Exit)"//char(0), &
IOR(WS_CAPTION, IOR(WS_VISIBLE, WS_DLGFRAME)), &
50, 50, 400, 400, NULL, NULL, hInstance, NULL)
!Get size
iret= GetClientRect (hWnd_Static, rectStatic)
!Display text box with initial text
hWnd_Control = CreateWindow("edit"C, "Right Click to Exit (or type exit)"//nl//nl// &
"Enter number : "//nl//char(0), &
IOR(WS_CHILD, IOR(WS_VSCROLL, IOR(ES_AUTOVSCROLL, IOR(ES_MULTILINE, WS_VISIBLE)))), &
0, 0, rectStatic%Right, rectStatic%Bottom, hWnd_Static, NULL, hInstance, NULL)
!Set focus to Edit box
iret = setfocus(hWnd_control)
iret = SendMessage(hWnd_Control, WM_GETTEXTLENGTH, 0, 0)
iret = SendMessage(hWnd_Control, EM_SETSEL, iret, iret)
!Start simple message loop (can only access POSTED messages)
do while (GetMessage (iMsg, NULL, 0, 0))
if (iMsg%message == WM_RBUTTONUP) then
!This is to QUIT - other, better mesages are only SEND to proc
bret = DestroyWindow(hWnd_Static)
call PostQuitMessage(0)
elseif (iMsg%message == WM_KEYDOWN) then
!See if Enter was pressed
if (iMsg%wParam == 13) then
!Read last line
iret = SendMessage(hWnd_Control, EM_GETLINECOUNT, 0, 0)
iret = SendMessage(hWnd_Control, EM_GETLINE, iret-1, loc(szText))
szText(iret+1:len(szText)) = ""
!First see if "exit" or "end"
if (trim(szText) == "exit" .or. trim(szText) == "end") then
bret = DestroyWindow(hWnd_Static)
call PostQuitMessage(0)
end if
!Internal read into Double
read(szText, *, IOSTAT=iErr) nRead
if (iErr /= 0) then
iret = MessageBox(NULL, "Error"//char(0), "KFWIN"//char(0), MB_OK)
szRead = ""
else
!Now do calcs on input.
nRead = (nRead + 1.0)**2
!Convert result to string fro display
write (szRead,*) nRead; szRead = adjustl(szRead)
end if
!Display results at end of existing text and ask for next input
iret = GetWindowText(hWnd_Control, szText, len(szText))
szText(index(szText,char(0)):len(szText)) = ""
iret = SetWindowText(hWnd_Control, &
trim(szText)//nl// &
"Result of (x+1)^2 = " // &
trim(szRead)//nl// &
"Enter next number below : "//nl//char(0))
!Reset focus in case of msgbox, set caret, and scroll to it
iret = setfocus(hWnd_control)
iret = SendMessage(hWnd_Control, WM_GETTEXTLENGTH, 0, 0)
iret = SendMessage(hWnd_Control, EM_SETSEL, iret, iret)
iret = SendMessage(hWnd_Control, EM_SCROLLCARET, 0, 0)
else
!Do default processing so that Edit acts normally other keys
bret =TranslateMessage(iMsg)
bret =DispatchMessage(iMsg)
end if
else
!Do default processing so that Edit acts normally
bret =TranslateMessage(iMsg)
bret =DispatchMessage(iMsg)
end if
end do
!Show end of loop
iret = MessageBox(NULL, "Message loop terminated"//char(0), "KFWIN"//char(0), MB_OK)
! Exit program
WinMain = iMsg%wParam
end 谢谢qinxl !
页:
[1]