|
|
1.1.1.2 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1 root 12: /*---------------------------------------------------------------------------*\ 13: | WINDOW INFORMATION MODULE 14: | This module contains the routines which deal with obtaining the extra 15: | object information associated with a window. For these to work, the 16: | window class must reserve the 0th word of the win-class object to be 17: | used to hold global-memory handle. 18: \*---------------------------------------------------------------------------*/ 19: 20: #include <windows.h> 21: #include "gdidemo.h" 22: 23: /*---------------------------------------------------------------------------*\ 24: | ALLOC WINDOW INFO 25: | This routine allocates memory out of the application heap for storing 26: | extra memory for the window. It is alway referenced as offset 0. 27: \*---------------------------------------------------------------------------*/ 28: BOOL FAR AllocWindowInfo(HWND hWnd, WORD wSize) 29: { 30: HANDLE hsd; 31: 32: 33: if(hsd = LocalAlloc(LHND,(WORD)wSize)) 34: { 35: SetWindowLong(hWnd,0,(LONG)hsd); 36: return(TRUE); 37: } 38: return(FALSE); 39: } 40: 41: 42: /*---------------------------------------------------------------------------*\ 43: | LOCK WINDOW INFO 44: | This routine de-references the extra-memory associated with the window. 45: | it locks the object and gives the caller a pointer to the memory. 46: \*---------------------------------------------------------------------------*/ 47: PVOID FAR LockWindowInfo(HWND hWnd) 48: { 49: HANDLE hMem; 50: PVOID pMem; 51: 52: 53: pMem = NULL; 54: if(hMem = (HANDLE)GetWindowLong(hWnd,0)) 55: pMem = (PVOID)LocalLock(hMem); 56: 57: return(pMem); 58: } 59: 60: 61: /*---------------------------------------------------------------------------*\ 62: | UNLOCK WINDOW INFO 63: | This routine unlocks the memory the caller has previously locked. 64: \*---------------------------------------------------------------------------*/ 65: BOOL FAR UnlockWindowInfo(HWND hWnd) 66: { 67: HANDLE hMem; 68: 69: 70: if(hMem = (HANDLE)GetWindowLong(hWnd,0)) 71: if(!LocalUnlock(hMem)) 72: return(TRUE); 73: 74: return(FALSE); 75: } 76: 77: 78: /*---------------------------------------------------------------------------*\ 79: | FREE WINDOW INFO 80: | This routine frees the object memory associated with the window. 81: \*---------------------------------------------------------------------------*/ 82: BOOL FAR FreeWindowInfo(HWND hWnd) 83: { 84: LOCALHANDLE hMem; 85: 86: 87: if(hMem = (HANDLE)GetWindowLong(hWnd,0)) 88: LocalFree(hMem); 89: return(TRUE); 90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.