122 lines
2.5 KiB
C++
122 lines
2.5 KiB
C++
#include <string.h>
|
|
#include <mdiwin/main.hpp>
|
|
#include <mdiwin/font.hpp>
|
|
#include <mdiwin/bwindow.hpp>
|
|
|
|
char BWindow::szClassName[]="BWindow";
|
|
char BWindow::szMenuName[]={'\0'};
|
|
|
|
BWindow::BWindow(HWND hParent)
|
|
: mhParent(hParent)
|
|
{
|
|
RECT parentRect;
|
|
|
|
mLastText[0]=0;
|
|
#if defined(__FLAT__)
|
|
mhInstance=(HINSTANCE)::GetWindowLong(hParent,GWL_HINSTANCE);
|
|
#else
|
|
mhInstance=(HINSTANCE)::GetWindowWord(hParent,GWW_HINSTANCE);
|
|
#endif
|
|
::GetClientRect(hParent,&parentRect);
|
|
::CreateWindow(szClassName,0,
|
|
WS_CHILDWINDOW,
|
|
0,0,
|
|
parentRect.right,WindowHeight,
|
|
hParent,(HMENU)0x0A,
|
|
mhInstance,
|
|
(LPSTR)this);
|
|
Show(SW_HIDE);
|
|
Update();
|
|
}
|
|
|
|
BWindow::~BWindow()
|
|
{
|
|
}
|
|
|
|
void BWindow::registerClass(void)
|
|
{
|
|
WNDCLASS wndclass;
|
|
wndclass.style =CS_HREDRAW|CS_VREDRAW;
|
|
wndclass.lpfnWndProc =(WNDPROC)Window::WndProc;
|
|
wndclass.cbClsExtra =0;
|
|
wndclass.cbWndExtra =sizeof(BWindow*);
|
|
wndclass.hInstance =Main::smhInstance;
|
|
wndclass.hIcon =0;
|
|
wndclass.hCursor =::LoadCursor(NULL,IDC_ARROW);
|
|
wndclass.hbrBackground =(HBRUSH)::GetStockObject(GRAY_BRUSH);
|
|
wndclass.lpszMenuName =0;
|
|
wndclass.lpszClassName =szClassName;
|
|
RegisterClass(&wndclass);
|
|
}
|
|
|
|
long BWindow::WndProc(UINT message,WPARAM wParam,LPARAM lParam)
|
|
{
|
|
switch(message)
|
|
{
|
|
case WM_CREATE :
|
|
return FALSE;
|
|
case WM_SIZE :
|
|
resize(LOWORD(lParam));
|
|
return FALSE;
|
|
case WM_PAINT :
|
|
paint();
|
|
return FALSE;
|
|
case WM_DESTROY :
|
|
return FALSE;
|
|
}
|
|
return DefWindowProc(GetHandle(),message,wParam,lParam);
|
|
}
|
|
|
|
void BWindow::paint(void)
|
|
{
|
|
PAINTSTRUCT ps;
|
|
|
|
::BeginPaint(GetHandle(),(PAINTSTRUCT far*)&ps);
|
|
setText();
|
|
::EndPaint(GetHandle(),(PAINTSTRUCT far*)&ps);
|
|
}
|
|
|
|
void BWindow::resize(int NewParentWidth)
|
|
{
|
|
::InvalidateRect(GetHandle(),0,1);
|
|
::MoveWindow(GetHandle(),0,0,NewParentWidth,WindowHeight,FALSE);
|
|
}
|
|
|
|
void BWindow::setText()
|
|
{
|
|
HDC hdc;
|
|
hdc=::GetDC(GetHandle());
|
|
Font textFont(GetHandle(),WindowHeight-2,WindowHeight-2);
|
|
textFont.DrawText(1,1,mLastText,RGB(128,128,128),RGB(255,255,255));
|
|
::ReleaseDC(GetHandle(),hdc);
|
|
}
|
|
|
|
void BWindow::setText(char *text)
|
|
{
|
|
::strcpy(mLastText,text);
|
|
if(!::strlen(text))
|
|
{
|
|
if(::IsWindowVisible(GetHandle()))::ShowWindow(GetHandle(),SW_HIDE);
|
|
}
|
|
else
|
|
{
|
|
if(!::IsWindowVisible(GetHandle()))::ShowWindow(GetHandle(),SW_SHOW);
|
|
::InvalidateRect(GetHandle(),0,TRUE);
|
|
::UpdateWindow(GetHandle());
|
|
setText();
|
|
}
|
|
::UpdateWindow(GetHandle());
|
|
yieldTask();
|
|
}
|
|
|
|
void BWindow::yieldTask(void)
|
|
{
|
|
MSG msg;
|
|
|
|
if(::PeekMessage((MSG far *)&msg,0,0,0,PM_REMOVE))
|
|
{
|
|
::TranslateMessage(&msg);
|
|
::DispatchMessage(&msg);
|
|
}
|
|
}
|