/* CCALLF951.C */ /* Copyright 2002 Lahey Computer Systems, Inc. */ #include #include void factorial_demo(int hwnd); extern void do_random_factorials(int *data_array, int *min_value, int *max_value); #define print(hwnd,string) (void)SendDlgItemMessageA((HWND)hwnd,IDC_LIST1,LB_ADDSTRING,(WPARAM)0,(LPARAM)string); #define TRUE 1 #define FALSE 0 BOOL CALLBACK ModalDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); /* these parameters must match #defines in windemo.rc */ #define IDM_QUIT 101 #define IDM_FACTORIAL 110 #define IDM_ABOUT 200 #define IDC_LIST1 1001 int WINAPI WndProc(HANDLE hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: { switch (wParam) { case IDM_QUIT: DestroyWindow(hwnd); return(0); case IDM_ABOUT: (void)DialogBoxParamA(NULL,"AboutBox",hwnd,(DLGPROC)ModalDlgProc,wParam); return(0); default: (void)DialogBoxParamA(NULL,"Results",hwnd,(DLGPROC)ModalDlgProc,wParam); return(0); } } case WM_DESTROY: PostQuitMessage(0); return(0); default: return(DefWindowProcA(hwnd,message,wParam,lParam)); } } BOOL CALLBACK ModalDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: switch (lParam) { case IDM_FACTORIAL: (void)SendDlgItemMessageA(hwnd,IDC_LIST1,LB_RESETCONTENT,0,0); factorial_demo((int)hwnd); break; } return (TRUE); case WM_SYSCOMMAND: if (wParam == SC_CLOSE) { EndDialog(hwnd, TRUE); return(TRUE); } break; case WM_COMMAND: if (wParam == IDOK) { EndDialog(hwnd, TRUE); return(TRUE); } } return (FALSE); } void demomain(void) { char *szMenuName = "DemoMenu"; char *szClassName = "DemoClass"; char *szWindowName = "Lahey Fortran 90 Windows Static Linking Demo"; WNDCLASS wc; MSG message; HWND hwnd; wc.style = 0; wc.lpfnWndProc = (WNDPROC)&WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = NULL; wc.hIcon = LoadIconA(NULL, IDI_APPLICATION); wc.hCursor = LoadCursorA(NULL, IDC_ARROW); wc.hbrBackground = GetStockObject(WHITE_BRUSH); wc.lpszMenuName = szMenuName; wc.lpszClassName = szClassName; (void)RegisterClassA(&wc); hwnd=CreateWindowExA((DWORD)NULL, szClassName, szWindowName, WS_OVERLAPPEDWINDOW, \ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, \ NULL, NULL, NULL, NULL); (void)ShowWindow(hwnd, SW_SHOWMAXIMIZED); (void)UpdateWindow(hwnd); while (GetMessageA(&message, NULL, 0, 0)) { TranslateMessage(&message); DispatchMessageA(&message); } (void)UnregisterClassA(szClassName,NULL); } void factorial_demo(int hwnd) { #define MAX 12 #define MIN 4 int i,n,factorial; char string[80]; int data_array[MAX-MIN+1][2]; int min_value=MIN, max_value=MAX; SetWindowTextA((HWND)hwnd,"Factorials..."); print(hwnd," Call a Fortran routine to calculate"); print(hwnd," the factorials of randomly ordered"); print(hwnd," integers between 4 and 12."); print(hwnd, " "); do_random_factorials(&data_array[0][0], &min_value, &max_value); for (i=0;i<=max_value-min_value;i++) { sprintf (string," n=%02d factorial(n)=%-9d", data_array[i][0], data_array[i][1]); print(hwnd,string); } }