|
沙发

楼主 |
发表于 2016-11-5 16:05:42
|
只看该作者
这是可能会出现一些麻烦,UI 所以推荐创建 多线程
实现多线程 代码如下
[Fortran] 纯文本查看 复制代码 004 | use , intrinsic :: ISO_C_BINDING |
005 | integer ( HANDLE ) :: hThread 1 , hThread 2 |
006 | logical :: Isrun = .TRUE. |
009 | integer ( LONG ) function WindowProc ( hWnd , uMsg , wParam , lParam ) |
011 | use , intrinsic :: ISO_C_BINDING |
012 | !DEC$ ATTRIBUTES STDCALL :: WindowProc |
013 | integer ( HANDLE ) :: hWnd |
015 | integer ( fWPARAM ) :: wParam |
016 | integer ( fLPARAM ) :: lParam |
017 | integer ( HANDLE ) :: hret |
018 | integer ( BOOL ) :: rectret |
019 | integer ( SINT ) :: DrawTextret |
020 | type ( T_PAINTSTRUCT ) :: ps |
029 | hret = closehandle ( hThread 1 ) |
030 | hret = closehandle ( hThread 2 ) |
031 | call PostQuitMessage ( 0 ) |
035 | hret = BeginPaint ( hWnd , ps ) |
036 | rectret = GetClientRect ( hwnd , rect ) |
037 | DrawTextret = DrawText ( hret , "Hello, 这是我自己的窗口!" / / char ( 0 ) , -1 , rect , & |
038 | IOR ( DT_SINGLELINE , IOR ( DT_CENTER , DT_VCENTER ) ) ) |
039 | hret = EndPaint ( hWnd , ps ) |
040 | if ( hret == 1 ) print * , '窗体重绘' |
046 | WindowProc = DefWindowProc ( hWnd , uMsg , wParam , lParam ) |
048 | end function WindowProc |
051 | integer ( LONG ) function Test_ThreadProc 1 ( lpParam ) |
052 | !DEC$ ATTRIBUTES STDCALL:: Test_ThreadProc1 |
053 | integer , intent ( in ) :: lpParam |
055 | print * , 'this is Thread 1' |
058 | Test_ThreadProc 1 = 10000 |
059 | end function Test_ThreadProc 1 |
061 | integer ( LONG ) function Test_ThreadProc 2 ( lpParam ) |
062 | !DEC$ ATTRIBUTES STDCALL:: Test_ThreadProc2 |
063 | integer , intent ( in ) :: lpParam |
065 | print * , 'this is Thread 2' |
068 | Test_ThreadProc 2 = 10000 |
069 | end function Test_ThreadProc 2 |
072 | end module Windows_MDL |
075 | function WinMain ( hCurrentInst , hPreviousInst , lpszCmdLine , nCmdShow ) |
076 | !DEC$ ATTRIBUTES STDCALL,DECORATE,ALIAS:"WinMain" :: WinMain |
080 | integer ( SINT ) :: WinMain |
081 | integer ( HANDLE ) , intent ( IN ) :: hCurrentInst , hPreviousInst |
082 | integer ( LPCSTR ) , intent ( IN ) :: lpszCmdLine |
083 | integer ( SINT ) , intent ( IN ) :: nCmdShow |
085 | integer ( HANDLE ) :: hWnd |
086 | integer ( HANDLE ) :: hInstance |
087 | integer ( SINT ) :: ret , retclass |
088 | integer ( BOOL ) :: bret , AllocConsole_ret |
090 | type ( T_WNDCLASSEX ) :: wndclass |
091 | character ( len = * ) , parameter :: szClassName = "Windows" C |
095 | AllocConsole_ret = AllocConsole ( ) |
097 | if ( AllocConsole_ret /= 0 ) print * , '创建控制台成功' |
098 | hThread 1 = CreateThread ( NULL , 0 , loc ( Test_ThreadProc 1 ) , NULL , 0 , NULL ) |
099 | hThread 2 = CreateThread ( NULL , 0 , loc ( Test_ThreadProc 2 ) , NULL , 0 , NULL ) |
103 | hInstance = GetModuleHandle ( NULL ) |
104 | wndclass.cbSize = sizeof ( wndclass ) |
105 | wndclass.style = CS_OWNDC |
106 | wndclass.lpfnWndProc = loc ( WindowProc ) |
107 | wndclass.cbClsExtra = 0 |
108 | wndclass.cbWndExtra = 0 |
109 | wndclass.hInstance = hInstance |
110 | wndclass.hIcon = LoadIcon ( 0 _HANDLE , int ( IDI_WINLOGO , LPVOID ) ) |
111 | wndclass.hCursor = LoadCursor ( 0 _HANDLE , int ( IDC_ARROW , LPVOID ) ) |
112 | wndclass.hbrBackground = ( COLOR_WINDOW + 1 ) |
113 | wndclass.lpszMenuName = NULL |
114 | wndclass.lpszClassName = loc ( szClassName ) |
115 | wndclass.hIconSm = NULL |
117 | retclass = RegisterClassEx ( wndclass ) |
119 | if ( retclass /= 0 ) print * , 'RegisterClass成功' |
122 | hWnd = CreateWindowEx ( 0 , & |
125 | WS_OVERLAPPEDWINDOW , 200 , 0 , 400 , 400 , & |
131 | if ( hwnd == NULL ) return |
133 | bret = ShowWindow ( hWND , SW_SHOW ) |
134 | bret = UpdateWindow ( hWnd ) |
136 | mainloop : do while ( Isrun ) |
138 | if ( PeekMessage ( msg , hWnd , 0 , 0 , PM_REMOVE ) /= 0 ) then |
139 | if ( msg % message == WM_QUIT ) exit mainloop |
140 | bret = TranslateMessage ( msg ) |
141 | bret = DispatchMessage ( msg ) |
|
|