这段程序仅仅生成一个空白的窗口,如果你彻底理解了,win32编程或许没有想象的那么复杂!
[Fortran] 纯文本查看 复制代码 Module VarGlob
integer( kind = 4 ) :: results ! 存储函数的返回值
logical( kind = 4 ) :: logicalt ! 存储函数的返回值
End Module VarGlob
! windowing程序开始执行的地方(操作系统自动识别)
integer 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
USE IFWIN !包含有用的模块
USE VarGlob !有用的数据模块
Implicit None
integer( kind = 4 ) :: hInstance !定义窗口的实例
integer( kind = 4 ) :: hPrevInstance !定义句柄
integer( kind = 4 ) :: nCmdShow !窗口的显示方式
integer( kind = 4 ) :: lpszCmdLine !指向字符串的指针
!定义函数接口,注意这一段是必须的
interface
integer*4 function MainWndProc ( hwnd, message, wParam, lParam )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'MainWndProc' :: MainWndProc
!DEC$ ENDIF
integer( kind = 4 ) :: hwnd
integer( kind = 4 ) :: message
integer( kind = 4 ) :: wParam
integer( kind = 4 ) :: lParam
end function MainWndProc
end interface
type (T_WNDCLASS) :: wc !窗口类结构体
type (T_MSG) :: msg !消息结构体
integer( kind = 4 ) :: hWnd
character*100 lpszClassName,lpszAppName
lpszClassName = "Generic"C !窗口类名
lpszAppName = "windowing程序框架"C !窗口标题
if(hPrevInstance .eq. 0) then
wc%lpszClassName = LOC(lpszClassName) !窗口类名
wc%lpfnWndProc = LOC(MainWndProc) !窗口回调函数
wc%style = IOR(CS_VREDRAW , CS_HREDRAW) !窗口风格
wc%hInstance = hInstance !窗口实例
wc%hIcon = LoadIcon( NULL, IDI_WINLOGO) !程序图标
wc%hCursor = LoadCursor( NULL, IDC_CROSS ) !程序光标
wc%hbrBackground = GetStockObject(BLACK_BRUSH) !窗口背景颜色
wc%lpszMenuName = 0 !菜单名
wc%cbClsExtra = 0 !无附加消息
wc%cbWndExtra = 0
results = RegisterClass(wc) !注册窗口类
end if
!创建窗口
hWnd = CreateWindowEx(0, & !窗口扩展样式
lpszClassName, & !窗口类名
lpszAppName, & !窗口标题
INT(WS_OVERLAPPEDWINDOW), & !窗口的风格
CW_USEDEFAULT, & !左上角坐标X
0, & !左上角坐标Y
CW_USEDEFAULT, & !窗口宽度尺寸
0, & !窗口高度尺寸
NULL, & !父窗口句柄
NULL, & !主菜单句柄
hInstance, & !窗口实例句柄
NULL & !附加信息的指针
)
!显示窗口
results = ShowWindow( hWnd, SW_SHOWNORMAL)
!进入消息循环
do while( GetMessage (msg, NULL, 0, 0) .NEQV. .FALSE.)
results = TranslateMessage( msg ) !翻译消息
results = DispatchMessage( msg ) !将消息传给windows,然后由windows传给回调函数
end do
WinMain = msg%wParam
End function WinMain
integer function MainWndProc ( hWnd, message, wParam, lParam )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'MainWndProc' :: MainWndProc
!DEC$ ENDIF
USE IFWIN !包含有用的模块
USE VarGlob !有用的数据模块
Implicit None
integer( kind = 4 ) :: hwnd
integer( kind = 4 ) :: message
integer( kind = 4 ) :: wParam
integer( kind = 4 ) :: lParam
select case ( message )
case (WM_DESTROY)
call PostQuitMessage( 0 )
case default
MainWndProc = DefWindowProc( hWnd, message, wParam, lParam )
end select
end function MainWndProc
运行结果:
|