home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
TBIWIN12.ZIP
/
TBIWIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-15
|
13KB
|
508 lines
//----------------------------------------------------
// TBIWINDOW.CPP
//----------------------------------------------------
// TBIWindow Ver. 1.2 (c) Copyright Casper Pedersen 1992
// This source must be used, but not changed is it is
// distributed to other people
// If any questions write to
// Casper Pedersen
// P. Knudsensvej 14, 3, V. 11.
// DK-8900 Randers
// Denmark
//
// NOTE
// The TBIWindow will might not work under Win30, that
// is because I use WM_WINDOWPOSCHANGED, which first
// was implemented in Win31.
//----------------------------------------------------
#include "tbiwin.h"
//----------------------------------------------------
// Function to display bitmaps
//----------------------------------------------------
extern "C" void _DisplayCaptionBitmap(HDC hdc, POINT pt, POINT pts, HBITMAP hBit)
{
BITMAP bm;
HDC hdcMem;
POINT ptOrg, ptSize;
hdcMem = CreateCompatibleDC(hdc);
if ( hdcMem == NULL ) return;
SelectObject(hdcMem, hBit);
SetMapMode(hdcMem, GetMapMode(hdc));
GetObject(hBit, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth;
ptSize.y = bm.bmHeight;
ptOrg.x = 0;
ptOrg.y = 0;
DPtoLP(hdcMem, &ptOrg, 1);
StretchBlt(hdc, pt.x, pt.y, pts.x, pts.y, hdcMem, 0, 0, ptSize.x, ptSize.y, SRCCOPY);
DeleteDC(hdcMem);
}
//----------------------------------------------------
// Defines
//----------------------------------------------------
// macro that returns TRUE if the pt(p) is in the rect(r)
#define ISPTINRECT(p, r) ( p.x >= r.left && p.x <= r.right && p.y >= r.top && p.y <= r.bottom )
// they are difined in the win30.h
// but if compiles withe the WIN31 keyword
// the win30.h is not included
#ifndef OBM_CLOSE
#define OBM_CLOSE 32754
#endif
#ifndef OBM_RESTORE
#define OBM_RESTORE 32747
#endif
//----------------------------------------------------
// the constructor
//----------------------------------------------------
TBIWindow::TBIWindow(PTWindowsObject AParent, LPSTR ATitle, LEFTRIGHT LR, PTModule AModule) : TWindow(AParent, ATitle, AModule)
{
WinName = ATitle;
_LR = LR;
ButtonDown = FALSE;
ButtonActive = 0;
ActivatedButton = 0;
WinActive = FALSE;
NoButtonsIn = 0;
head = new TBIList;
tail = new TBIList;
head->next = tail;
head->prev = NULL;
tail->next = NULL;
tail->prev = head;
XStart = XEnd = 0;
}
//----------------------------------------------------
// the destructor
//----------------------------------------------------
TBIWindow::~TBIWindow()
{
PTBIList tmp = head->next;
while(tmp != tail)
{
PTBIList del = tmp;
tmp = tmp->next;
del->prev->next = tmp;
tmp->prev = del->prev;
DeleteObject(del->ButtonDeactive);
DeleteObject(del->ButtonActive);
delete del;
}
delete head;
delete tail;
}
//----------------------------------------------------
void TBIWindow::GetWindowClass(WNDCLASS _FAR &AWndClass)
{
TWindow::GetWindowClass(AWndClass);
// For Borland C++ users see in help, under CS_BYTEALIGNWINDOW
AWndClass.style |= CS_BYTEALIGNWINDOW;
}
//----------------------------------------------------
BOOL TBIWindow::IsInList(UINT ResId)
{
// We will not have two of the same buttons
// in the list
PTBIList tmp = head->next;
while(tmp != tail)
{
if ( tmp->ButtonNo == ResId )
return(TRUE);
tmp = tmp->next;
}
return(FALSE);
}
//----------------------------------------------------
BOOL TBIWindow::AddButton(UINT ResourceID)
{
// no duplets are allowed
if ( IsInList(ResourceID) ) return(FALSE);
PTBIList tmp = new TBIList;
if ( tmp == NULL ) return (FALSE);
tmp->ButtonNo = ResourceID;
HBITMAP hBit = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(ResourceID + 10000));
if ( hBit == NULL )
{
delete tmp;
return (FALSE);
}
tmp->ButtonDeactive = hBit;
hBit = LoadBitmap(GetApplication()->hInstance, MAKEINTRESOURCE(ResourceID + 30000));
if ( hBit == NULL )
{
DeleteObject(tmp->ButtonDeactive);
delete tmp;
return (FALSE);
}
tmp->ButtonActive = hBit;
tmp->prev = tail->prev;
tail->prev->next = tmp;
tmp->next = tail;
tail->prev = tmp;
NoButtonsIn++;
return (TRUE);
}
//----------------------------------------------------
void TBIWindow::ButtonActivated(void)
{
// To be overloaded
}
//----------------------------------------------------
void TBIWindow::WMSize(RTMessage Msg)
{
TWindow::WMSize(Msg);
// We cannot have that the buttons are drawn outside the
// window
// if the window is smaller than our buttons and
// the systemmenu + minimize- and maximizebuttons
// then we resizes the window
int x = (Attr.Style & WS_SYSMENU) ? CloseSize() : 0;
if ( Msg.LP.Lo < ( ((NoButtonsIn + 1) * CloseSize()) + ButtonSize() + x ) )
{
RECT rc;
GetWindowRect(HWindow, &rc);
MoveWindow(HWindow, rc.left, rc.top, ((NoButtonsIn + 1) * CloseSize()) + ButtonSize() + x, rc.bottom - rc.top, TRUE);
}
UpdateCaption();
}
//----------------------------------------------------
void TBIWindow::WMNCLButtonDBLCLK(RTMessage Msg)
{
if ( Msg.WParam == HTCAPTION && LOWORD(Msg.LParam) > XStart && LOWORD(Msg.LParam) < XEnd )
return;
TWindow::DefWndProc(Msg);
}
//----------------------------------------------------
void TBIWindow::WMNCLButtonDown(RTMessage Msg)
{
if ( Msg.WParam == HTCAPTION && LOWORD(Msg.LParam) < XEnd && LOWORD(Msg.LParam) > XStart && WinActive )
{
AKTBut = MAKEPOINT(Msg.LParam);
if ( CalcRect(AKTBut) )
HighLiteButton();
return;
}
TWindow::DefWndProc(Msg);
}
//----------------------------------------------------
void TBIWindow::WMNCLButtonUp(RTMessage Msg)
{
if ( ButtonDown )
HighLiteButton();
// Must react just like MicroSoft buttons
// they do not sendmessages before the button is
// deactivated, and the mousepointer is in the
// button rect.
if ( ISPTINRECT(MAKEPOINT(Msg.LParam), AKTRect) )
SendMessage(HWindow, WM_COMMAND, ButtonActive, 0l);
SetRectEmpty(&AKTRect);
TWindow::DefWndProc(Msg);
}
//----------------------------------------------------
void TBIWindow::WMLButtonUp(RTMessage Msg)
{
SetRectEmpty(&AKTRect);
TWindow::DefWndProc(Msg);
}
//----------------------------------------------------
void TBIWindow::WMNCMouseMove(RTMessage Msg)
{
POINT pt = MAKEPOINT(Msg.LParam);
if ( !ISPTINRECT(pt, AKTRect) && ButtonDown )
HighLiteButton();
else
if ( ISPTINRECT(pt, AKTRect) && !ButtonDown )
HighLiteButton();
TWindow::DefWndProc(Msg);
}
//----------------------------------------------------
void TBIWindow::WMMouseMove(RTMessage Msg)
{
if ( ButtonDown )
HighLiteButton();
TWindow::DefWndProc(Msg);
}
//----------------------------------------------------
void TBIWindow::WMActivate(RTMessage Msg)
{
TWindow::WMActivate(Msg);
// if the window is been activated, either by call, or
// click with the mouse
if (Msg.WParam == WA_CLICKACTIVE || Msg.WParam == WA_ACTIVE )
{
UpdateCaption();
WinActive = TRUE;
}
else
{
// if not active set caption
WinActive = FALSE;
SetCaption(WinName);
}
}
//----------------------------------------------------
void TBIWindow::WMWindowPosChanged(RTMessage Msg)
{
TWindow::DefWndProc(Msg);
if ( IsIconic(HWindow) )
return;
// to be sure that the buttons not are drawn
// when the window is nonactive, and
// when the window is to be closed
LPWINDOWPOS pwp = (WINDOWPOS FAR*) Msg.LParam;
if ( pwp->flags & SWP_HIDEWINDOW )
WinHidden = TRUE;
else
if ( pwp->flags & SWP_SHOWWINDOW )
WinHidden = FALSE;
if ( pwp->flags & SWP_NOACTIVATE )
return;
// Even though Borland, in the help file says that WINDOWPOS.flags
// only can be one of the SWP_... values, it only works when
// I use & (and).
DisplayButton();
}
//----------------------------------------------------
void TBIWindow::UpdateCaption(void)
{
// if not, it look silly when minimized
if ( IsIconic(HWindow) )
return;
DisplayButton();
}
//----------------------------------------------------
void TBIWindow::DisplayButton(void)
{
if ( WinHidden ) return;
if ( head->next == tail ) return;
RECT rc; GetWindowRect(HWindow, &rc);
POINT pt; pt.x = 0; pt.y = 0;
// we must not overwrite the sysmenu
if ( (Attr.Style & WS_SYSMENU) && (_LR != RIGHT) )
pt.x = CloseSize();
// there are more than one FRAME style
if ( (Attr.Style & WS_DLGFRAME) || (Attr.Style & WS_THICKFRAME) )
{
pt.x += GetSystemMetrics(SM_CXDLGFRAME);
pt.y += GetSystemMetrics(SM_CYDLGFRAME);
}
else
{
pt.x += GetSystemMetrics(SM_CXBORDER);
pt.y += GetSystemMetrics(SM_CYBORDER);
}
// the hight of the caption bar, whith small fonts
// it is 19 pixels high
POINT pts; pts.x = pts.y = GetSystemMetrics(SM_CYCAPTION) - 1;
if ( _LR == LEFT )
pt.x += rc.left;
else
if ( _LR == RIGHT )
pt.x = rc.right - ( ButtonSize() + (pts.x * NoButtonsIn) + pt.x );
pt.y += rc.top;
pts.y -= 1;
XStart = pt.x;
HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
if ( hdc == NULL ) return;
PTBIList tmp = head->next;
while(tmp != tail)
{
_DisplayCaptionBitmap(hdc, pt, pts, tmp->ButtonDeactive);
pt.x += pts.x;
tmp = tmp->next;
}
XEnd = pt.x;
DeleteDC(hdc);
}
//----------------------------------------------------
void TBIWindow::HighLiteButton(void)
{
if ( ActivatedButton == -1 )
return;
HDC hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
if ( hdc == NULL ) return;
POINT pt, pts;
pt.x = AKTRect.left;
pt.y = AKTRect.top;
pts.x = AKTRect.right - pt.x;
pts.y = AKTRect.bottom - pt.y - 1;
// we must find the actual button, in the list
PTBIList tmp = head->next;
while (tmp != tail && tmp->ButtonNo != ButtonActive)
{ tmp = tmp->next; }
if (tmp == tail) return;
if ( !ButtonDown )
{
_DisplayCaptionBitmap(hdc, pt, pts, tmp->ButtonActive);
}
else
{
_DisplayCaptionBitmap(hdc, pt, pts, tmp->ButtonDeactive);
}
pt.x += pts.x;
ButtonDown = !ButtonDown;
DeleteDC(hdc);
}
//----------------------------------------------------
BOOL TBIWindow::CalcRect(POINT pt)
{
// not much to explain, we find the
// button no, and the size of it
if ( pt.x >= XStart && pt.x <= XEnd )
{
UINT width = GetSystemMetrics(SM_CYCAPTION) - 1;
RECT rect; GetWindowRect(HWindow, &rect);
rect.top += GetSystemMetrics(SM_CYDLGFRAME);
UINT no = (pt.x - XStart) / width;
AKTRect.top = rect.top;
AKTRect.left = (no * width) + XStart;
AKTRect.bottom = AKTRect.top + width;
AKTRect.right = AKTRect.left + width;
PTBIList tmp = head->next;
for(UINT i = 0; i < no && tmp != tail; i++, tmp = tmp->next );
ButtonActive = tmp->ButtonNo;
ActivatedButton = no;
// call the possible overloaded function
ButtonActivated();
return (TRUE);
}
ActivatedButton = -1;
return (FALSE);
}
//----------------------------------------------------
UINT TBIWindow::CloseSize(void)
{
// Calculates the size of the SystemMenu bitmap
HBITMAP hBit = LoadBitmap(NULL,MAKEINTRESOURCE(OBM_CLOSE));
BITMAP bm;
GetObject(hBit, sizeof(BITMAP), &bm);
UINT width = bm.bmWidth/2;
DeleteObject(hBit);
return(width);
}
//----------------------------------------------------
UINT TBIWindow::ButtonSize(void)
{
// Calculates the size of the MAXIMIZE and MINIMIZE bitmaps
// if they are there.
HBITMAP hBit = LoadBitmap(NULL,MAKEINTRESOURCE(OBM_RESTORE));
BITMAP bm;
GetObject(hBit, sizeof(BITMAP), &bm);
UINT width = 0;
if ( Attr.Style & WS_MAXIMIZEBOX )
width += bm.bmWidth;
if ( Attr.Style & WS_MINIMIZEBOX )
width += bm.bmWidth;
DeleteObject(hBit);
return(width);
}
//----------------------------------------------------
#ifdef USEBWCC
#include <bwcc.h>
#endif
//----------------------------------------------------
void TBIWindow::AboutTBIWindow(void)
{
char str[100];
wsprintf((LPSTR)str, "TBIWindow ver. %x.%x\n(c) Casper Pedersen\nCompiled: %s\nProvided As FreeWare", HIWORD(TBIGetVersion()), LOWORD(TBIGetVersion()), __DATE__ );
#ifdef USEBWCC
BWCCMessageBox(
#else
MessageBox(
#endif
HWindow, str, "About TBIWindow", MB_ICONINFORMATION | MB_OK);
}
//----------------------------------------------------
// END
//----------------------------------------------------