home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- Module name: SuperCls.C
- Programmer : Jeffrey M. Richter.
- *****************************************************************************/
-
- #include "..\nowindws.h"
- #undef NOUSER
- #undef NOWINOFFSETS
- #include <windows.h>
-
- #include "supercls.h"
-
- // Offsets of base class values from the high-end of the class extra bytes.
- #define BCWNDPROCINDEX (sizeof(FARPROC))
- #define CBBCCLSEXTRAINDEX (sizeof(FARPROC) + sizeof(int))
- #define CBBCWNDEXTRAINDEX (sizeof(FARPROC) + sizeof(int) + sizeof(int))
-
- #define MINCBCLSADDTIONAL (sizeof(FARPROC) + sizeof(int) + sizeof(int))
-
- static LONG (FAR PASCAL *_lpfnBCWndProc)();
- static int _cbBCClsExtra, _cbBCWndExtra;
-
- BOOL FAR PASCAL RegisterSuperClass (LPWNDCLASS WndClass,
- LONG (FAR PASCAL *lpfnSCWndProc)(),
- int cbClsAdditional, int cbWndAdditional) {
- HWND hWnd;
- _lpfnBCWndProc = WndClass->lpfnWndProc;
- _cbBCClsExtra = WndClass->cbClsExtra;
- _cbBCWndExtra = WndClass->cbWndExtra;
-
- WndClass->cbClsExtra += cbClsAdditional + MINCBCLSADDTIONAL;
- WndClass->cbWndExtra += cbWndAdditional;
- WndClass->lpfnWndProc = lpfnSCWndProc;
- if (!RegisterClass(WndClass)) return(FALSE);
- hWnd = CreateWindow(WndClass->lpszClassName, "", 0, 0, 0, 0, 0,
- NULL, NULL, WndClass->hInstance, 0);
-
- if (hWnd == NULL) {
- UnregisterClass(WndClass->lpszClassName, WndClass->hInstance);
- return(FALSE);
- }
-
- DestroyWindow(hWnd);
- return(TRUE);
- }
-
- void FAR PASCAL SetSuperClassInfo (HWND hWnd) {
- WORD cbClsTotal = GetClassWord(hWnd, GCW_CBCLSEXTRA);
- DWORD dwBCWndProc = GetWindowLong(hWnd, cbClsTotal - BCWNDPROCINDEX);
- if (dwBCWndProc != NULL) return;
- SetClassLong(hWnd, cbClsTotal - BCWNDPROCINDEX, (LONG) _lpfnBCWndProc);
- SetClassWord(hWnd, cbClsTotal - CBBCCLSEXTRAINDEX, _cbBCClsExtra);
- SetClassWord(hWnd, cbClsTotal - CBBCWNDEXTRAINDEX, _cbBCWndExtra);
- }
-
-
- DWORD FAR PASCAL GetBCWndProc (HWND hWnd) {
- DWORD dwBCWndProc;
- int nIndex = GetClassWord(hWnd, GCW_CBCLSEXTRA) - BCWNDPROCINDEX;
- dwBCWndProc = GetClassLong(hWnd, nIndex);
- if (dwBCWndProc != NULL) return(dwBCWndProc);
- return((DWORD) _lpfnBCWndProc);
- }
-
- //****************************************************************************
-
- // Function used internally by the Get/SetClassWord/Long functions.
- static int NEAR PASCAL CalcClassByteIndex (HWND hWnd, int nIndex) {
- int cbBCClsExtraIndex, cbBCClsExtra;
-
- // if nIndex is negative, nIndex points to internal window memory block,
- // same index should be returned.
- if (nIndex < 0) return(nIndex);
-
- // Retrieve index into class extra bytes for the number of class
- // extra bytes used by the base class.
- cbBCClsExtraIndex =
- GetClassWord(hWnd, GCW_CBCLSEXTRA) - CBBCCLSEXTRAINDEX;
-
- // Retrieve number of class extra bytes used by the base class.
- cbBCClsExtra = GetClassWord(hWnd, cbBCClsExtraIndex);
-
- // Return desired index + number of class extra bytes used by base class.
- return(nIndex + cbBCClsExtra);
- }
-
-
-
- // Function used internally by the Get/SetWindowWord/Long functions.
- static int NEAR PASCAL CalcWindowByteIndex (HWND hWnd, int nIndex) {
- int cbBCWndExtraIndex, cbBCWndExtra;
-
- // if nIndex is negative, nIndex points to internal window memory block,
- // same index should be returned.
- if (nIndex < 0) return(nIndex);
-
- // Retrieve index into class extra bytes for the number of window
- // extra bytes used by the base class.
- cbBCWndExtraIndex =
- GetClassWord(hWnd, GCW_CBCLSEXTRA) - CBBCWNDEXTRAINDEX;
-
- // Retrieve number of window extra bytes used by the base class.
- cbBCWndExtra = GetClassWord(hWnd, cbBCWndExtraIndex);
-
- // Return desired index + number of window extra bytes used by base class.
- return(nIndex + cbBCWndExtra);
- }
-
- //****************************************************************************
- // The four Get/SetClassWord/Long functions.
-
- WORD FAR PASCAL SetSCClassWord (HWND hWnd, int nIndex, WORD wNewWord) {
- nIndex = CalcClassByteIndex(hWnd, nIndex);
- return(SetClassWord(hWnd, nIndex, wNewWord));
- }
-
- WORD FAR PASCAL GetSCClassWord (HWND hWnd, int nIndex) {
- nIndex = CalcClassByteIndex(hWnd, nIndex);
- return(GetClassWord(hWnd, nIndex));
- }
-
- DWORD FAR PASCAL SetSCClassLong (HWND hWnd, int nIndex, DWORD dwNewLong) {
- nIndex = CalcClassByteIndex(hWnd, nIndex);
- return(SetClassLong(hWnd, nIndex, dwNewLong));
- }
-
- DWORD FAR PASCAL GetSCClassLong (HWND hWnd, int nIndex) {
- nIndex = CalcClassByteIndex(hWnd, nIndex);
- return(GetClassLong(hWnd, nIndex));
- }
-
- //****************************************************************************
- // The four Get/SetWindowWord/Long functions.
-
- WORD FAR PASCAL SetSCWindowWord (HWND hWnd, int nIndex, WORD wNewWord) {
- nIndex = CalcWindowByteIndex(hWnd, nIndex);
- return(SetWindowWord(hWnd, nIndex, wNewWord));
- }
-
- WORD FAR PASCAL GetSCWindowWord (HWND hWnd, int nIndex) {
- nIndex = CalcWindowByteIndex(hWnd, nIndex);
- return(GetWindowWord(hWnd, nIndex));
- }
-
- DWORD FAR PASCAL SetSCWindowLong (HWND hWnd, int nIndex, DWORD dwNewLong) {
- nIndex = CalcWindowByteIndex(hWnd, nIndex);
- return(SetWindowLong(hWnd, nIndex, dwNewLong));
- }
-
- DWORD FAR PASCAL GetSCWindowLong (HWND hWnd, int nIndex) {
- nIndex = CalcWindowByteIndex(hWnd, nIndex);
- return(GetWindowLong(hWnd, nIndex));
- }
-