📄 cardwindow.cpp
字号:
EndPaint(hwnd, &ps);
return 0;
case WM_TIMER:
//find the timer object in the registered funcs
/*if(wParam >= 0x10000)
{
for(i = 0; i < nRegFuncs; i++)
{
if(RegFuncs[i].id == wParam)
{
KillTimer(hwnd, wParam);
//call the registered function!!
RegFuncs[i].func(RegFuncs[i].dwParam);
RegFuncs[i] = RegFuncs[nRegFuncs-1];
nRegFuncs--;
}
}
}
else*/
{
//find the cardstack
CardRegion *stackobj = (CardRegion *)wParam;//CardStackFromId(wParam);
stackobj->DoFlash();
}
return 0;
case WM_LBUTTONDBLCLK:
x = (short)LOWORD(lParam);
y = (short)HIWORD(lParam);
if((buttonptr = CardButtonFromPoint(x, y)) != 0)
{
buttonptr->OnLButtonDown(hwnd, x, y);
return 0;
}
if((stackptr = CardRegionFromPoint(x, y)) != 0)
{
stackptr->OnLButtonDblClk(x, y);
stackptr = 0;
}
return 0;
case WM_LBUTTONDOWN:
x = (short)LOWORD(lParam);
y = (short)HIWORD(lParam);
//if clicked on a button
if((buttonptr = CardButtonFromPoint(x, y)) != 0)
{
if(buttonptr->OnLButtonDown(hwnd, x, y) == 0)
buttonptr = 0;
return 0;
}
if((stackptr = CardRegionFromPoint(x, y)) != 0)
{
if(!stackptr->OnLButtonDown(x, y))
stackptr = 0;
}
return 0;
case WM_LBUTTONUP:
x = (short)LOWORD(lParam);
y = (short)HIWORD(lParam);
//
// if we were clicking a button
//
if(buttonptr != 0)
{
buttonptr->OnLButtonUp(hwnd, x, y);
buttonptr = 0;
return 0;
}
if(stackptr != 0)
{
stackptr->OnLButtonUp(x, y);
stackptr = 0;
return 0;
}
return 0;
case WM_MOUSEMOVE:
x = (short)LOWORD(lParam);
y = (short)HIWORD(lParam);
// if we were clicking a button
if(buttonptr != 0)
{
buttonptr->OnMouseMove(hwnd, x, y);
return 0;
}
if(stackptr != 0)
{
return stackptr->OnMouseMove(x, y);
}
return 0;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
CardRegion* CardWindow::CardRegionFromId(int id)
{
for(int i = 0; i < nNumCardRegions; i++)
{
if(Regions[i]->id == id)
return Regions[i];
}
return 0;
}
CardButton* CardWindow::CardButtonFromId(int id)
{
for(int i = 0; i < nNumButtons; i++)
{
if(Buttons[i]->id == id)
return Buttons[i];
}
return 0;
}
void CardWindow::Redraw()
{
InvalidateRect(m_hWnd, 0, 0);
UpdateWindow(m_hWnd);
}
bool CardWindow::DeleteButton(CardButton *pButton)
{
for(int i = 0; i < nNumButtons; i++)
{
if(Buttons[i] == pButton)
{
CardButton *cb = Buttons[i];
//shift any after this one backwards
for(int j = i; j < nNumButtons - 1; j++)
{
Buttons[j] = Buttons[j + 1];
}
delete cb;
nNumButtons--;
return true;
}
}
return false;
}
bool CardWindow::DeleteRegion(CardRegion *pRegion)
{
for(int i = 0; i < nNumCardRegions; i++)
{
if(Regions[i] == pRegion)
{
CardRegion *cr = Regions[i];
//shift any after this one backwards
for(int j = i; j < nNumCardRegions - 1; j++)
{
Regions[j] = Regions[j + 1];
}
delete cr;
nNumCardRegions--;
return true;
}
}
return false;
}
void CardWindow::EmptyStacks(void)
{
for(int i = 0; i < nNumCardRegions; i++)
{
Regions[i]->Clear();
Regions[i]->Update();
}
Redraw();
}
bool CardWindow::DistributeStacks(int nIdFrom, int nNumStacks, UINT xJustify, int xSpacing, int nStartX)
{
int numvisiblestacks = 0;
int curx = nStartX;
int startindex = -1;
int i;
//find the stack which starts with our ID
for(i = 0; i < nNumCardRegions; i++)
{
if(Regions[i]->Id() == nIdFrom)
{
startindex = i;
break;
}
}
//if didn't find, return
if(i == nNumCardRegions) return false;
//count the stacks that are visible
for(i = startindex; i < startindex + nNumStacks; i++)
{
if(Regions[i]->IsVisible())
numvisiblestacks++;
}
if(xJustify == CS_XJUST_CENTER)
{
//startx -= ((numvisiblestacks + spacing) * cardwidth - spacing) / 2;
int viswidth;
viswidth = numvisiblestacks * __cardwidth;
viswidth += xSpacing * (numvisiblestacks - 1);
curx = -(viswidth - __cardwidth) / 2;
for(i = startindex; i < startindex + nNumStacks; i++)
{
if(Regions[i]->IsVisible())
{
Regions[i]->xadjust = curx;
Regions[i]->xjustify = CS_XJUST_CENTER;
curx += Regions[i]->width + xSpacing;
}
}
}
if(xJustify == CS_XJUST_RIGHT)
{
nStartX -= ((numvisiblestacks + xSpacing) * __cardwidth - xSpacing);
}
if(xJustify == CS_XJUST_NONE)
{
for(i = startindex; i < startindex + nNumStacks; i++)
{
if(Regions[i]->IsVisible())
{
Regions[i]->xpos = curx;
curx += Regions[i]->width + xSpacing;
Regions[i]->UpdateSize();
}
}
}
return 0;
}
void CardWindow::Update()
{
for(int i = 0; i < nNumCardRegions; i++)
{
Regions[i]->AdjustPosition(nWidth, nHeight);
}
}
void CardWindow::SetResizeProc(pResizeWndProc proc)
{
ResizeWndCallback = proc;
}
HPALETTE CardWindow::CreateCardPalette()
{
COLORREF cols[10];
int nNumCols;
//include button text colours
cols[0] = RGB(0, 0, 0);
cols[1] = RGB(255, 255, 255);
//include the base background colour
cols[1] = crBackgnd;
//include the standard button colours...
cols[3] = CardButton::GetHighlight(crBackgnd);
cols[4] = CardButton::GetShadow(crBackgnd);
cols[5] = CardButton::GetFace(crBackgnd);
//include the sunken image bitmap colours...
GetSinkCols(crBackgnd, &cols[6], &cols[7], &cols[8], &cols[9]);
nNumCols = 10;
return MakePaletteFromCols(cols, nNumCols);
}
void CardWindow::SetBackCardIdx(UINT uBackIdx)
{
if(uBackIdx >= 52 && uBackIdx <= 68)
nBackCardIdx = uBackIdx;
for(int i = 0; i < nNumCardRegions; i++)
Regions[i]->SetBackCardIdx(uBackIdx);
}
UINT CardWindow::GetBackCardIdx()
{
return nBackCardIdx;
}
void CardWindow::PaintCardRgn(HDC hdc, int dx, int dy, int width, int height, int sx, int sy)
{
RECT rect;
//if just a solid background colour
if(hbmBackImage == 0)
{
SetRect(&rect, dx, dy, dx+width, dy+height);
/*if(GetVersion() < 0x80000000)
{
PaintRect(hdc, &rect, MAKE_PALETTERGB(crBackgnd));
}
else*/
{
HBRUSH hbr = CreateSolidBrush(MAKE_PALETTERGB(crBackgnd));
FillRect(hdc, &rect, hbr);
DeleteObject(hbr);
}
}
//otherwise, paint using the bitmap
else
{
// Draw whatever part of background we can
BitBlt(hdc, dx, dy, width, height, hdcBackImage, sx, sy, SRCCOPY);
// Now we need to paint any area outside the bitmap,
// just in case the bitmap is too small to fill whole window
if(0)//sx + width > bm.bmWidth || sy + height > bm.bmHeight)
{
// Find out size of bitmap
BITMAP bm;
GetObject(hbmBackImage, sizeof(bm), &bm);
HRGN hr1 = CreateRectRgn(sx, sy, sx+width, sy+height);
HRGN hr2 = CreateRectRgn(0, 0, bm.bmWidth, bm.bmHeight);
HRGN hr3 = CreateRectRgn(0,0, 1, 1);
HRGN hr4 = CreateRectRgn(0,0, 1, 1);
CombineRgn(hr3, hr1, hr2, RGN_DIFF);
GetClipRgn(hdc, hr4);
CombineRgn(hr3, hr4, hr3, RGN_AND);
SelectClipRgn(hdc, hr3);
// Fill remaining space not filled with bitmap
HBRUSH hbr = CreateSolidBrush(crBackgnd);
FillRgn(hdc, hr3, hbr);
DeleteObject(hbr);
// Clean up
SelectClipRgn(hdc, hr4);
DeleteObject(hr1);
DeleteObject(hr2);
DeleteObject(hr3);
DeleteObject(hr4);
}
}
}
void CardWindow::SetBackImage(HBITMAP hBitmap)
{
//delete current image?? NO!
if(hdcBackImage == 0)
{
hdcBackImage = CreateCompatibleDC(0);
}
hbmBackImage = hBitmap;
if(hBitmap)
SelectObject(hdcBackImage, hBitmap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -