home *** CD-ROM | disk | FTP | other *** search
- #include "windows.h"
- #include "hello.h"
- #define LINT_ARGS
- #include <stdio.h>
-
- char szAppName[10];
- char szAbout[10];
- char szMessage[15];
- int MessageLength;
- char buffer[100];
-
- DWORD MaxBlock, MemTot;
- int Nchar;
- HDC hDCmy;
- int Nblock;
-
- static HANDLE hInst;
- FARPROC lpprocAbout;
-
- long FAR PASCAL HelloWndProc(HWND, unsigned, WORD, LONG);
-
-
-
- BOOL FAR PASCAL About( hDlg, message, wParam, lParam )
- HWND hDlg; /*--------------------------------------*/
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- if (message == WM_COMMAND) {
- EndDialog( hDlg, TRUE );
- return TRUE;
- }
- else if (message == WM_INITDIALOG)
- return TRUE;
- else return FALSE;
- }
-
-
-
- void GetMem( hDCarg)
- /*--------*/
- HDC hDCarg;
- {
- #define MaxBlk 100
- DWORD Bsize;
- HANDLE hMem, hMemSav[ MaxBlk];
- int NtoFree;
-
- MaxBlock= 0L;
- MemTot= 0L;
- Nblock= -1;
-
- while (TRUE) {
- Bsize= GlobalCompact( 10000000);
- if (Bsize <=0) break;
- if (Bsize >MaxBlock) MaxBlock= Bsize;
- MemTot += Bsize;
- if (Nblock == MaxBlk-1) break;
- hMem= GlobalAlloc( GMEM_FIXED, Bsize);
- if (hMem == NULL) {
- TextOut( hDCarg,
- (short) 1,
- (short) 10,
- (LPSTR) "ERa",
- (short) 3);
- break;
- }
- hMemSav[ ++Nblock]= hMem;
- } /* end while getting blocks*/
-
- NtoFree= Nblock;
- while ( NtoFree >=0) {
- hMem= GlobalFree( hMemSav[ NtoFree--]);
- if (hMem != NULL)
- TextOut( hDCarg,
- (short) 1,
- (short) 10,
- (LPSTR) "ERb",
- (short) 3);
- } /* end while freeing blocks*/
- }
-
-
-
- void HelloPaint( hDC, mess)
- /*----------------------*/
- HDC hDC;
- unsigned mess;
- {
- GetMem( hDC); /* sets MaxBlock, MemTot, Nblock */
- Nchar= sprintf( buffer,
- "Repainted: max block= %lu ",
- MaxBlock);
- TextOut( hDC,
- (short)1,
- (short)1,
- (LPSTR)buffer,
- (short)Nchar);
- Nchar= sprintf( buffer,
- "%d block(s) total %lu ",
- Nblock+1, MemTot);
- TextOut( hDC,
- (short)31,
- (short)10,
- (LPSTR)buffer,
- (short)Nchar);
- }
-
-
-
- BOOL HelloInit( hInstance )
- /*----------------------
- Procedure called when the application is loaded for the first time */
- HANDLE hInstance;
- {PWNDCLASS pHelloClass;
-
- /* Load strings from resource */
- LoadString( hInstance, IDSNAME, (LPSTR)szAppName, 10 );
- LoadString( hInstance, IDSABOUT, (LPSTR)szAbout, 10 );
- MessageLength = LoadString( hInstance, IDSTITLE, (LPSTR)szMessage, 15 );
-
- pHelloClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
-
- pHelloClass->hCursor = LoadCursor( NULL, IDC_ARROW );
- pHelloClass->hIcon = LoadIcon( hInstance, (LPSTR)szAppName );
- pHelloClass->lpszMenuName = (LPSTR)NULL;
- pHelloClass->lpszClassName = (LPSTR)szAppName;
- pHelloClass->hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
- pHelloClass->hInstance = hInstance;
- pHelloClass->style = CS_HREDRAW | CS_VREDRAW;
- pHelloClass->lpfnWndProc = HelloWndProc;
-
- if (!RegisterClass( (LPWNDCLASS)pHelloClass ) )
- /* Initialization failed.
- * Windows will automatically deallocate all allocated memory.
- */
- return FALSE;
-
- LocalFree( (HANDLE)pHelloClass );
- return TRUE; /* Initialization succeeded */
- }
-
-
-
- int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow)
- /*--------------------------------------------------------*/
- HANDLE hInstance, hPrevInstance;
- LPSTR lpszCmdLine;
- int cmdShow;
- {
- MSG msg;
- HWND hWnd;
- HMENU hMenu;
-
- if (!hPrevInstance) {
- /* Call initialization procedure if this is the first instance */
- if (!HelloInit( hInstance ))
- return FALSE;
- }
- else {
- /* Copy data from previous instance */
- GetInstanceData( hPrevInstance, (PSTR)szAppName, 10 );
- GetInstanceData( hPrevInstance, (PSTR)szAbout, 10 );
- GetInstanceData( hPrevInstance, (PSTR)szMessage, 15 );
- GetInstanceData( hPrevInstance, (PSTR)&MessageLength, sizeof(int) );
- }
-
- hWnd = CreateWindow((LPSTR)szAppName,
- (LPSTR)szMessage,
- WS_TILEDWINDOW,
- 0, /* x - ignored for tiled windows */
- 0, /* y - ignored for tiled windows */
- 0, /* cx - ignored for tiled windows */
- 0, /* cy - ignored for tiled windows */
- (HWND)NULL, /* no parent */
- (HMENU)NULL, /* use class menu */
- (HANDLE)hInstance, /* handle to window instance */
- (LPSTR)NULL /* no params to pass on */
- );
-
- /* Save instance handle for DialogBox */
- hInst = hInstance;
-
- /* Bind callback function with module instance */
- lpprocAbout = MakeProcInstance( (FARPROC)About, hInstance );
-
- /* Insert "About..." into system menu */
- hMenu = GetSystemMenu(hWnd, FALSE);
- ChangeMenu(hMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
- ChangeMenu(hMenu, 0, (LPSTR)szAbout, IDSABOUT, MF_APPEND | MF_STRING);
-
- /* Make window visible according to the way the app is activated */
- ShowWindow( hWnd, cmdShow );
- UpdateWindow( hWnd );
-
-
- /* Polling messages from event queue */
- while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
- if ( !PeekMessage( (LPMSG)&msg, hWnd, 0, 0, FALSE)) { /* last one */
- hDCmy= GetDC( hWnd);
- GetMem( hDCmy); /* sets MaxBlock, MemTot, Nblock */
- Nchar= sprintf( buffer,
- "Msg loop: max block= %lu ",
- MaxBlock);
- TextOut( hDCmy,
- (short)1,
- (short)1,
- (LPSTR)buffer,
- (short)Nchar);
- Nchar= sprintf( buffer,
- "%d block(s) total %lu ",
- Nblock+1, MemTot);
- TextOut( hDCmy,
- (short)31,
- (short)10,
- (LPSTR)buffer,
- (short)Nchar);
- ReleaseDC(hWnd, hDCmy);
- } /* !Peek.. */
- TranslateMessage( (LPMSG)&msg);
- DispatchMessage( (LPMSG)&msg);
- }
-
- return (int)msg.wParam;
- }
-
-
- long FAR PASCAL HelloWndProc( hWnd, message, wParam, lParam)
- /* --------------------------------------------
- Procedures which make up the window class. */
- HWND hWnd;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- PAINTSTRUCT ps;
-
- switch (message)
- {
- case WM_SYSCOMMAND:
- switch (wParam)
- {
- case IDSABOUT:
- DialogBox( hInst, MAKEINTRESOURCE(ABOUTBOX), hWnd, lpprocAbout );
- break;
- default:
- return DefWindowProc( hWnd, message, wParam, lParam );
- }
- break;
-
- case WM_DESTROY:
- PostQuitMessage( 0 );
- break;
-
- case WM_PAINT:
- BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
- HelloPaint( ps.hdc, message);
- EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
- break;
-
- default:
- return DefWindowProc( hWnd, message, wParam, lParam );
- break;
- }
- return(0L);
- }