| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- (*# check(stack=>off,
- index=>off,
- range=>off,
- overflow=>off,
- nil_ptr=>off) *)
- IMPLEMENTATION MODULE MWMain;
- IMPORT Windows;
- CONST
- (* String table constants *)
- IDSNAME = 100;
- IDSABOUT = 200;
- IDSTITLE = 300;
- (* About Dialog box resource id *)
- ABOUTBOX = 1;
- VAR
- szAppName: ARRAY [0..9] OF CHAR;
- szAbout: ARRAY [0..9] OF CHAR;
- szMessage: ARRAY [0..25] OF CHAR;
- MessageLength: CARDINAL;
- hInst: Windows.HANDLE;
- lpprocAbout: Windows.FARPROC;
- PROCEDURE MessagePaint(hdc: Windows.HDC);
- BEGIN
- Windows.TextOut(hdc, 10, 10, szMessage, MessageLength );
- END MessagePaint;
- (* Procedures which make up the window class. *)
- PROCEDURE WndProc(hWnd: Windows.HWND; message: CARDINAL; wParam: CARDINAL; lParam: LONGINT ): LONGINT;
- VAR
- ps: Windows.PAINTSTRUCT;
- BEGIN
- CASE message OF
- | Windows.WM_SYSCOMMAND:
- CASE wParam OF
- | IDSABOUT:
- Windows.DialogBox( hInst, FarADDRESS(LONGCARD(ABOUTBOX)), hWnd, lpprocAbout );
- ELSE
- RETURN Windows.DefWindowProc( hWnd, message, wParam, lParam);
- END;
- | Windows.WM_DESTROY:
- Windows.PostQuitMessage(0);
- | Windows.WM_PAINT:
- Windows.BeginPaint(hWnd, ps);
- MessagePaint(ps.hdc);
- Windows.EndPaint(hWnd, ps);
- ELSE
- RETURN Windows.DefWindowProc( hWnd, message, wParam, lParam);
- END;
- RETURN 0;
- END WndProc;
- PROCEDURE About ( hDlg : Windows.HWND;
- message : CARDINAL;
- wParam : WORD;
- lParam : LONGINT ) : Windows.BOOL ;
- BEGIN
- IF message = Windows.WM_COMMAND THEN
- Windows.EndDialog( hDlg, CARDINAL(TRUE) );
- RETURN INTEGER(TRUE);
- ELSIF message = Windows.WM_INITDIALOG THEN
- RETURN INTEGER(TRUE);
- ELSE
- RETURN INTEGER(FALSE);
- END;
- END About;
- (* This procedure called when the program is loaded for the first time *)
- PROCEDURE DemoInit(hInstance: Windows.HANDLE): BOOLEAN;
- VAR
- DemoClass: Windows.WNDCLASS;
- BEGIN
- (* Load strings from resource *)
- Windows.LoadString(hInstance, IDSNAME, szAppName, 10);
- Windows.LoadString(hInstance, IDSABOUT, szAbout, 10);
- MessageLength:=Windows.LoadString(hInstance, IDSTITLE, szMessage, 25);
- DemoClass.hCursor := Windows.LoadCursor(Windows.HANDLE(0), FarADDRESS(Windows.IDC_ARROW));
- DemoClass.hIcon := Windows.LoadIcon(hInstance, FarADR("wdemo"));
- DemoClass.lpszMenuName := FarNIL;
- DemoClass.lpszClassName := Windows.LPSTR(FarADR(szAppName));
- DemoClass.hbrBackground := Windows.HBRUSH(Windows.GetStockObject(Windows.WHITE_BRUSH));
- DemoClass.hInstance:=hInstance;
- DemoClass.style := Windows.CS_HREDRAW + Windows.CS_VREDRAW;
- DemoClass.lpfnWndProc := FarADR(WndProc);
- DemoClass.cbClsExtra := 0;
- DemoClass.cbWndExtra := 0;
- IF Windows.RegisterClass(DemoClass) = 0 THEN
- RETURN FALSE; (* Initialization failed. *)
- END;
- RETURN TRUE; (* Success *)
- END DemoInit;
- PROCEDURE WinMain(hInstance: Windows.HANDLE; hPrevInstance: Windows.HANDLE; lpszCmdLine: Windows.LPSTR; cmdShow: INTEGER): Windows.BOOL;
- VAR
- msg: Windows.MSG;
- hWnd: Windows.HWND;
- hMenu: Windows.HMENU;
- BEGIN
- IF hPrevInstance = Windows.HANDLE(0) THEN
- (* Call initialization procedure if this is the first instance *)
- IF NOT DemoInit(hInstance) THEN
- RETURN INTEGER(FALSE);
- END;
- ELSE
- (* Copy data from previous instance *)
- Windows.GetInstanceData(hPrevInstance, NearADR(szAppName), 10);
- Windows.GetInstanceData(hPrevInstance, NearADR(szAbout), 10);
- Windows.GetInstanceData(hPrevInstance, NearADR(szMessage), 25);
- Windows.GetInstanceData(hPrevInstance, NearADR(MessageLength),SIZE(CARDINAL));
- END;
- hWnd := Windows.CreateWindow(FarADR(szAppName),
- szMessage,
- Windows.WS_TILEDWINDOW ,
- Windows.CW_USEDEFAULT,
- Windows.CW_USEDEFAULT,
- Windows.CW_USEDEFAULT,
- Windows.CW_USEDEFAULT,
- Windows.HWND(0), (* no parent *)
- Windows.HMENU(0), (* use class menu *)
- hInstance, (* handle to window instance *)
- FarNIL (* no params to pass on *)
- );
- (* Save instance handle for DialogBox *)
- hInst := hInstance;
- lpprocAbout := Windows.MakeProcInstance( Windows.FARPROC(FarADR(About)), hInstance );
- (* Insert About *)
- hMenu:= Windows.GetSystemMenu(hWnd, Windows.False);
- Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
- Windows.ChangeMenu(hMenu, 0, FarADR(szAbout), IDSABOUT, Windows.MF_APPEND + Windows.MF_STRING);
- (* Make window visible according to the way the app is activated *)
- Windows.ShowWindow(hWnd, cmdShow);
- Windows.UpdateWindow(hWnd);
- (* Polling messages from event queue *)
- WHILE (Windows.GetMessage(msg, Windows.HWND(0), 0, 0)) # 0 DO
- Windows.TranslateMessage(msg);
- Windows.DispatchMessage(msg);
- END;
- RETURN msg.wParam;
- END WinMain;
- END MWMain.
|