home *** CD-ROM | disk | FTP | other *** search
- #ifndef _INC_LIO_HPP
- #define _INC_LIO_HPP
- typedef short Int2;
- typedef unsigned short UInt2;
- typedef int Int4;
- typedef unsigned int UInt4;
-
- typedef int SLong;
- typedef unsigned int ULong;
- typedef short SWord;
- typedef unsigned short UWord;
-
- typedef int Boolean;
-
- #define true 1
- #define false 0
-
- #define LOSHORT(l) ((short)((WORD)(l)))
- #define HISHORT(l) ((short)((WORD)((DWORD)(l) >> 16)))
-
- #define SetClassCursor(hwnd,hc) SetClassLong( hwnd, GCL_HCURSOR, (DWORD)hc )
- #define GetClassCursor(hwnd) ((HCURSOR)GetClassLong( hwnd, GCL_HCURSOR ))
- #define SetWindowStyle(hwnd,dw) SetWindowLong(hwnd,GWL_STYLE,dw)
- #define SetWindowExStyle(hwnd,dw) SetWindowLong(hwnd,GWL_EXSTYLE,dw)
- #define SetRedraw(hwnd, fRedraw) SendMessage(hwnd,WM_SETREDRAW,fRedraw,0)
-
- //#define GetWindowInstance(hwnd) ((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE))
- //#define GetWindowStyle(hwnd) GetWindowLong(hwnd,GWL_STYLE)
- //#define GetWindowExStyle(hwnd) GetWindowLong(hwnd,GWL_EXSTYLE)
-
- //#define SetWindowFont(hwnd,hFont,fRedraw) SendMessage(hwnd,WM_SETFONT,(WPARAM)hFont,fRedraw)
- //#define GetWindowFont(hwnd) ((HFONT)SendMessage(hwnd,WM_GETFONT,0,0))
-
-
- #define Loop for(;;)
- #define sizeofarray(a) (sizeof(a)/sizeof(a[0]))
- //#define _PRINT_BUF_SIZE 8000
- #define SPLIT_D 6
-
- #define ConstrInit0(a,b) memset( (char*)&a, 0,\
- sizeof(b) + (((char*)&b) - ((char*)&a)) )
-
- #define ZeroMem(a) memset(&a,0,sizeof(a))
-
- #define Make4C(ch0, ch1, ch2, ch3) \
- ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) | \
- ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
- #define COLORIDX_Black 0
- #define COLORIDX_DkRed 1
- #define COLORIDX_DkGreen 2
- #define COLORIDX_Brown 3
- #define COLORIDX_DkBlue 4
- #define COLORIDX_DkMagenta 5
- #define COLORIDX_DkCyan 6
- #define COLORIDX_LtGray 7
- #define COLORIDX_Gray 7
- #define COLORIDX_DkGray 8
- #define COLORIDX_Red 9
- #define COLORIDX_LtRed 9
- #define COLORIDX_Green 10
- #define COLORIDX_LtGreen 10
- #define COLORIDX_Yellow 11
- #define COLORIDX_Blue 12
- #define COLORIDX_LtBlue 12
- #define COLORIDX_Magenta 13
- #define COLORIDX_Cyan 14
- #define COLORIDX_LtCyan 14
- #define COLORIDX_White 15
-
- #define COLORIDX_SysText 16
- #define COLORIDX_SysBack 17
- #define COLORIDX_SysSelText 18
- #define COLORIDX_SysSelBack 19
-
-
- #define STD_VGA_COLORS_16 \
- RGB(0,0,0), RGB(128,0,0), RGB(0,128,0), RGB(128,128,0),\
- RGB(0,0,128), RGB(128,0,128), RGB(0,128,128), RGB(192,192,192),\
- RGB(128,128,128), RGB(255,0,0), RGB(0,255,0), RGB(255,255,0),\
- RGB(0,0,255), RGB(255,0,255), RGB(0,255,255), RGB(255,255,255)
-
-
- inline COLORREF VgaColor(int idx)
- {
- static COLORREF colors[16] = { STD_VGA_COLORS_16 };
- static int sc[4] = {
- COLOR_WINDOWTEXT, COLOR_WINDOW,
- COLOR_HIGHLIGHTTEXT, COLOR_HIGHLIGHT };
-
- if( idx >= 0 && idx < 16 ) return colors[idx];
- return GetSysColor( sc[idx-16] );
- }
-
- extern "C"
- {
-
- typedef struct POSITION_Tag
- {
- int x;
- int y;
- int cx;
- int cy;
- }
- POSITION;
-
- typedef struct SPOSITION_Tag
- {
- short x;
- short y;
- short cx;
- short cy;
- }
- SPOSITION;
-
- }; // extern "C"
- typedef struct
- {
- BITMAPINFOHEADER bih;
- RGBQUAD rgbq [ 256 ];
- }
- BITMAPINFO256;
-
- typedef struct
- {
- BITMAPINFOHEADER bih;
- RGBQUAD rgbq [ 16 ];
- }
- BITMAPINFO16;
-
- typedef struct {
- BITMAPINFOHEADER bih;
- RGBQUAD rgbq [ 2 ];
- }
- BITMAPINFO2;
-
-
-
- #pragma pack(1)
- typedef struct
- {
- WORD w1; // 0
- WORD type; // 1-icon, 2-cursor
- WORD w2; // 1
- BYTE cx;
- BYTE cy;
- WORD colors;
- WORD xhs;
- WORD yhs;
- DWORD size2; // sizeof(file) - sizeof(ICON_HEADER)
- DWORD size1; // sizeof(ICON_HEADER)
- }
- ICON_HEADER;
- #pragma pack()
-
- #define GET_CHILD_RECT(hwnd,rc) \
- GetWindowRect( hwnd, rc );\
- {POINT pt; pt.x=pt.y=0;\
- ClientToScreen( GetParent(hwnd), &pt);\
- OffsetRect( rc, -pt.x, -pt.y );}
-
- #define sNull tc_sNull
- #define String TC_CString
-
- #define ArrayC TC_TArrayC
- #define ArrayCPP TC_TArrayCPP
- #define ArrayPTR TC_TArrayPTR
- #define ArrayString TC_CArrayString
- #define ArrayStrStr TCArrayStrStr
- #define ArrayINT TCArrayINT
- #define ArrayUINT TCArrayUINT
- #define ArrayLONG TCArrayLONG
- #define ArrayULONG TCArrayULONG
-
- #define ArrayHWND TCArrayHWND
- #define ArrayCHAR TCArrayCHAR
-
- #define AReg TC_CRegistry
- #define AWin TC_CWindow
- #define AWaitCursor TC_CWaitCursor
-
-
- // **********************************************************************
- class APen
- {
- public: HPEN m_HPen ;
- public: APen (COLORREF color, int width=1)
- {
- m_HPen = CreatePen( PS_SOLID, width, color );
-
- } // end of func
- // **********************************************************************
-
- public: ~APen ()
- {
- if(m_HPen) DeleteObject(m_HPen);
- } // end of func
- // **********************************************************************
-
- public: operator HPEN ()
- {
- return m_HPen;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class APen
-
- // **********************************************************************
-
- // **********************************************************************
- class ABrush
- {
- public: HBRUSH m_HBrush ;
- public: ABrush (COLORREF color)
- {
- m_HBrush = CreateSolidBrush( color );
- } // end of func
- // **********************************************************************
-
- public: ~ABrush ()
- {
- if(m_HBrush) DeleteObject(m_HBrush);
- } // end of func
- // **********************************************************************
-
- public: operator HBRUSH ()
- {
- return m_HBrush;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class ABrush
-
- // **********************************************************************
-
- // **********************************************************************
- class ADC
- {
- public:
- enum {
- Mode_Simple,
- Mode_Paint,
- Mode_Get,
- Mode_Create,
- };
- public: HDC hDC ;
- public: HWND hWnd ;
- public: PAINTSTRUCT P_S ;
- public: int _Mode ;
- public: ADC (HWND hwnd, int mode, HDC hdc=0)
- {
- hWnd = hwnd;
- _Mode = mode;
-
- switch(_Mode)
- {
- case Mode_Simple : hDC = hdc; break;
- case Mode_Paint : hDC = BeginPaint(hWnd,&P_S); break;
- case Mode_Get : hDC = GetDC(hWnd); break;
- case Mode_Create : hDC = CreateCompatibleDC(0); break;
- }
- } // end of func
- // **********************************************************************
-
- public: ~ADC ()
- {
- switch(_Mode)
- {
- case Mode_Simple : break;
- case Mode_Paint : EndPaint(hWnd,&P_S); break;
- case Mode_Get : ReleaseDC(hWnd,hDC); break;
- case Mode_Create : DeleteDC(hDC); break;
- }
-
- hWnd = 0;
- hDC = 0;
- _Mode = 0;
-
- } // end of func
- // **********************************************************************
-
- public: operator HDC ()
- {
- return hDC;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class ADC
-
- // **********************************************************************
-
- // **********************************************************************
- class ACheckHDC
- {
- public: HDC m_hDC ;
- public: HWND m_hWnd ;
- public: ACheckHDC (HWND hWnd, HDC &hDC)
- {
- m_hDC = 0;
- m_hWnd = 0;
-
- if( hDC == 0 )
- {
- hDC = GetDC(hWnd);
- m_hDC = hDC;
- m_hWnd = hWnd;
- }
- } // end of func
- // **********************************************************************
-
- public: ~ACheckHDC ()
- {
- if( m_hDC ) ReleaseDC(m_hWnd,m_hDC);
- } // end of func
- // **********************************************************************
-
-
- }; // end of class ACheckHDC
-
- // **********************************************************************
-
- // **********************************************************************
- class ASimpleFont
- {
- public: HFONT hMS [2];
- public: HFONT hSM [2];
- public: int cy_MS ;
- public: int cy_SM ;
- public: ASimpleFont ()
- {
- LOGFONT lf;
-
- memset( &lf, 0, sizeof(lf) );
- lf. lfHeight = -11;
- lf. lfOutPrecision = OUT_DEFAULT_PRECIS;
- lf. lfClipPrecision = CLIP_DEFAULT_PRECIS;
- lf. lfQuality = DEFAULT_QUALITY;
- lf. lfPitchAndFamily = FF_ROMAN;
- strcpy( lf. lfFaceName, "MS Sans Serif" );
-
- lf. lfWeight = 400;
- hMS[0] = CreateFontIndirect( &lf );
- lf. lfWeight = 700;
- hMS[1] = CreateFontIndirect( &lf );
-
- memset( &lf, 0, sizeof(lf) );
- lf. lfHeight = -9;
- lf. lfOutPrecision = OUT_DEFAULT_PRECIS;
- lf. lfClipPrecision = CLIP_DEFAULT_PRECIS;
- lf. lfQuality = DEFAULT_QUALITY;
- lf. lfPitchAndFamily = FF_ROMAN;
- strcpy( lf. lfFaceName, "Small Fonts" );
-
- lf. lfWeight = 400;
- hSM[0] = CreateFontIndirect( &lf );
- lf. lfWeight = 700;
- hSM[1] = CreateFontIndirect( &lf );
-
-
- HDC hDC = GetDC(0);
- TEXTMETRIC tm;
- HFONT old_f =
-
- SelectObject( hDC, hMS[0] );
- GetTextMetrics(hDC,&tm);
- cy_MS = tm.tmHeight;
-
- SelectObject( hDC, hSM[0] );
- GetTextMetrics(hDC,&tm);
- cy_SM = tm.tmHeight;
-
- SelectObject( hDC, old_f );
- ReleaseDC(0,hDC);
- } // end of func
- // **********************************************************************
-
- public: ~ASimpleFont ()
- {
- if( hMS[0] ) DeleteObject(hMS[0]);
- if( hMS[1] ) DeleteObject(hMS[1]);
- if( hSM[0] ) DeleteObject(hSM[0]);
- if( hSM[1] ) DeleteObject(hSM[1]);
- } // end of func
- // **********************************************************************
-
- public: HFONT MS (int idx)
- {
- return hMS[idx];
- } // end of func
- // **********************************************************************
-
- public: HFONT SM (int idx)
- {
- return hSM[idx];
- } // end of func
- // **********************************************************************
-
- public: int CyMS ()
- {
- return cy_MS;
- } // end of func
- // **********************************************************************
-
- public: int CySM ()
- {
- return cy_SM;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class ASimpleFont
-
- // **********************************************************************
- inline void Line ( HDC hDC, int x1, int y1, int x2, int y2 )
- {
- MoveToEx(hDC,x1,y1,0);
- LineTo(hDC,x2,y2);
- } // end of func
- // **********************************************************************
-
- inline void VLine (HDC hDC, int x, int y1, int y2)
- {
- MoveToEx( hDC, x, y1, 0 );
- LineTo ( hDC, x, y2 );
- } // end of func
- // **********************************************************************
-
- inline void HLine (HDC hDC, int y, int x1, int x2)
- {
- MoveToEx( hDC, x1, y, 0 );
- LineTo ( hDC, x2, y );
- } // end of func
- // **********************************************************************
-
- inline void VLine (HDC hDC,HPEN pen,int x,int y1,int y2)
- {
- HPEN old = SelectObject( hDC, pen );
- MoveToEx( hDC, x, y1, 0 );
- LineTo ( hDC, x, y2 );
- SelectObject( hDC, old );
- } // end of func
- // **********************************************************************
-
- inline void HLine (HDC hDC,HPEN pen,int y,int x1,int x2)
- {
- HPEN old = SelectObject( hDC, pen );
- MoveToEx( hDC, x1, y, 0 );
- LineTo ( hDC, x2, y );
- SelectObject( hDC, old );
- } // end of func
- // **********************************************************************
-
- inline void Beep (int i =0)
- {
- ::MessageBeep( i );
- } // end of func
- // **********************************************************************
-
- inline void Fill_Rect (HDC hDC,RECT *rc,COLORREF color)
- {
- FillRect( hDC, rc, ABrush(color) );
- } // end of func
- // **********************************************************************
-
- inline void Fill_Rect (HDC hDC,HBRUSH br,int x,int y,int cx,int cy)
- {
- RECT r; SetRect(&r,x,y,x+cx,y+cy);
- FillRect(hDC,&r,br);
- } // end of func
- // **********************************************************************
-
- inline void RectLines (HDC hDC, int x, int y, int cx, int cy)
- {
- Line( hDC, x, y, x, y+cy );
- Line( hDC, x, y, x+cx, y );
- Line( hDC, x+cx-1, y, x+cx-1, y+cy );
- Line( hDC, x, y+cy-1, x+cx, y+cy-1 );
- } // end of func
- // **********************************************************************
-
- inline void swinout (LPCSTR text)
- {
- ATOM at = GlobalAddAtom(text);
- if( at )
- {
- SendMessage( FindWindow("WINOUT",0), WM_USER+666, at, 0 );
- GlobalDeleteAtom(at);
- }
- } // end of func
- // **********************************************************************
-
- inline int GetVScrollPos (HWND hwnd)
- {
- return GetScrollPos(hwnd,SB_VERT);
- } // end of func
- // **********************************************************************
-
- inline int GetHScrollPos (HWND hwnd)
- {
- return GetScrollPos(hwnd,SB_HORZ);
- } // end of func
- // **********************************************************************
-
- inline int GetVScrollMax (HWND hwnd)
- {
- int min_,max_=0;
- GetScrollRange(hwnd,SB_VERT,&min_,&max_);
- return max_;
- } // end of func
- // **********************************************************************
-
- inline int GetHScrollMax (HWND hwnd)
- {
- int min_,max_=0;
- GetScrollRange(hwnd,SB_HORZ,&min_,&max_);
- return max_;
- } // end of func
- // **********************************************************************
-
- inline void Release_Capture (HWND hwnd)
- {
- if( hwnd && GetCapture() == hwnd ) ReleaseCapture();
- } // end of func
- // **********************************************************************
-
- inline POINT LioPtClientToScreen (HWND hWnd)
- {
- POINT pt;
- pt.x=pt.y=0;
- ClientToScreen(hWnd,&pt);
- return pt;
- } // end of func
- // **********************************************************************
-
- inline HBITMAP HBitmapFromBuffer (LPCSTR src)
- {
- HDC hDC = GetDC(0);
-
- HBITMAP hbmp =
- CreateDIBitmap(hDC,
- (BITMAPINFOHEADER*)(src+sizeof(BITMAPFILEHEADER)),
- CBM_INIT,
- src + ((BITMAPFILEHEADER*)src)->bfOffBits,
- (BITMAPINFO*)(src+sizeof(BITMAPFILEHEADER)),
- DIB_RGB_COLORS
- );
-
- ReleaseDC(0,hDC);
-
- return hbmp;
- } // end of func
- // **********************************************************************
-
- inline HCURSOR HCursorFromBuffer (LPCSTR src)
- {
- int cnt;
- int add1 = 22 + sizeof(BITMAPINFOHEADER) + 4*2;
- int add2 = add1 + 32*4;
-
- DWORD * p1 = (DWORD*)(src+add1);
- DWORD * p2 = p1+31;
- DWORD * p3 = (DWORD*)(src+add2);
- DWORD * p4 = p3+31;
-
- for( cnt=0; cnt < 16; cnt++ )
- {
- DWORD dw = *p1;
- *p1 = *p2;
- *p2 = dw;
- p1++;
- p2--;
-
- dw = *p3;
- *p3 = *p4;
- *p4 = dw;
- p3++;
- p4--;
- }
-
- short * hs = (short*)(src+10);
- return CreateCursor( GetModuleHandle(0),
- hs[0], hs[1], 32, 32,
- src+add2, src+add1 );
- } // end of func
- // **********************************************************************
-
- inline int Strlen ( const char * str )
- {
- return (str ? strlen(str) : 0);
- } // end of func
- // **********************************************************************
-
- inline int Strcmp (const char *s1, const char *s2)
- {
- return strcmp( (s1) ? s1 : "", (s2) ? s2 : "" );
- } // end of func
- // **********************************************************************
-
- inline BOOL Zero (const char * s)
- {
- if( ! s || ! *s ) return TRUE;
- return FALSE;
- } // end of func
- // **********************************************************************
-
- inline BOOL Clipboard_WritePtr (UINT type, void *ptr, int size)
- {
- if( type == CF_TEXT && size == -1 ) size = 1+strlen( (char*)ptr );
-
- //if( !IsWindow(hwnd) ) return FALSE;
- if( !OpenClipboard(0) ) return FALSE;
- EmptyClipboard();
- HGLOBAL hg = GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, size );
- if( !hg ) { CloseClipboard(); return FALSE; }
- char * lpc = (char*)GlobalLock( hg );
- if( !lpc ) { GlobalFree(hg); CloseClipboard(); return FALSE; }
- memcpy( lpc, ptr, size );
- GlobalUnlock( hg );
- SetClipboardData( type, hg );
- CloseClipboard();
- return TRUE;
- } // end of func
- // **********************************************************************
-
-
- // **********************************************************************
- class Clipboard_ReadPtr
- {
- private: char* m_Ptr ;
- private: HGLOBAL m_HG ;
- private: BOOL m_Open ;
- private: int m_Size ;
- public: Clipboard_ReadPtr (UINT type)
- {
- m_HG = 0;
- m_Open = 0;
- m_Ptr = 0;
- m_Size = 0;
-
- //if( !IsWindow(hwnd) ) return;
- if( !IsClipboardFormatAvailable(type) ) return;
- if( !OpenClipboard(0) ) return;
- m_Open = TRUE;
-
- m_HG = (HGLOBAL)GetClipboardData(type);
- if( m_HG )
- {
- m_Size = GlobalSize(m_HG);
- m_Ptr = (char*)GlobalLock(m_HG);
- }
- } // end of func
- // **********************************************************************
-
- public: ~Clipboard_ReadPtr ()
- {
- if( m_HG && m_Ptr ) GlobalUnlock(m_HG);
- if( m_Open ) CloseClipboard();
- } // end of func
- // **********************************************************************
-
- public: BOOL Ok ()
- {
- return (m_Ptr != 0);
- } // end of func
- // **********************************************************************
-
- public: void* Ptr ()
- {
- return m_Ptr;
- } // end of func
- // **********************************************************************
-
- public: int Size ()
- {
- return m_Size;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class Clipboard_ReadPtr
-
- // **********************************************************************
-
- // **********************************************************************
- class Clipboard_ReadHandle
- {
- private: HANDLE m_Handle ;
- private: BOOL m_Open ;
- public: Clipboard_ReadHandle (UINT type)
- {
- m_Handle = 0;
- m_Open = 0;
-
- if( !IsClipboardFormatAvailable(type) ) return;
- if( !OpenClipboard(0) ) return;
- m_Open = TRUE;
- m_Handle = GetClipboardData(type);
- } // end of func
- // **********************************************************************
-
- public: ~Clipboard_ReadHandle ()
- {
- if( m_Open ) CloseClipboard();
- } // end of func
- // **********************************************************************
-
- public: BOOL Ok ()
- {
- return (m_Handle != 0);
- } // end of func
- // **********************************************************************
-
- public: HANDLE Handle ()
- {
- return m_Handle;
- } // end of func
- // **********************************************************************
-
-
- }; // end of class Clipboard_ReadHandle
-
- // **********************************************************************
-
- #endif // _INC_LIO_HPP
-