#include #include #include #include #include #include PaletteDialog::PaletteDialog(HWND hParent,HPALETTE hPalette) : mhParent(hParent), mhPalette(hPalette) { PALETTEENTRY lpPaletteEntry[256]; mNumColors=::GetPaletteEntries(mhPalette,0,256,(PALETTEENTRY FAR *)&lpPaletteEntry); } PaletteDialog::~PaletteDialog() { } void PaletteDialog::showPalette(void) { HINSTANCE hInstance; #if defined (__FLAT__) hInstance=(HINSTANCE)::GetWindowLong(mhParent,GWL_HINSTANCE); #else hInstance=(HINSTANCE)::GetWindowWord(mhParent,GWW_HINSTANCE); #endif ::DialogBoxParam(hInstance,(LPSTR)"Palette",mhParent,(DLGPROC)DWindow::DialogProcedure,(LONG)((DWindow*)this)); } int PaletteDialog::DlgProc(UINT message,WPARAM wParam,LPARAM lParam) { switch(message) { case WM_INITDIALOG : Main::smhBitmap.associate(IDOK, String(STRING_BITMAPOKFOCUSUP,Main::processInstance()), String(STRING_BITMAPOKNOFUP,Main::processInstance()), String(STRING_BITMAPOKFOCUSDN,Main::processInstance()), OwnerDraw::NOFOCUS); mhGroupWindow=::GetDlgItem(GetHandle(),PALETTE_COLORS); setWindowSize(); return TRUE; case WM_DRAWITEM : switch(((LPDRAWITEMSTRUCT)lParam)->CtlID) { case IDOK : Main::smhBitmap.handleOwnerButton(IDOK,lParam); break; case PALETTE_COLORS : if(ODA_DRAWENTIRE==((LPDRAWITEMSTRUCT)lParam)->itemAction) drawPaletteColors(); break; } return TRUE; case WM_COMMAND : switch(GET_WM_COMMAND_ID(wParam,lParam)) { case IDOK : Main::smhBitmap.freeButton(IDOK); ::EndDialog(GetHandle(),TRUE); return TRUE; } } return FALSE; } void PaletteDialog::drawPaletteColors(void)const { HDC hDC; HBRUSH hBrush; HBRUSH hOldBrush; HPALETTE hOldPalette; HPEN hOldPen; RECT winRect; short xStart=1; short yStart=1; ::GetClientRect(mhGroupWindow,(RECT FAR *)&winRect); hDC=::GetDC(mhGroupWindow); hOldPalette=::SelectPalette(hDC,mhPalette,FALSE); ::RealizePalette(hDC); hOldPen=(HPEN)::SelectObject(hDC,::GetStockObject(BLACK_PEN)); for(int i=0;i=winRect.right) { if(yStart+DELTAY>winRect.bottom)break; xStart=1; yStart=(yStart+DELTAY); } } ::SelectObject(hDC,hOldPen); ::SelectPalette(hDC,hOldPalette,FALSE); ::ReleaseDC(mhGroupWindow,hDC); return; } void PaletteDialog::conformWindow(int heightRegion)const { RECT winRect; RECT grpRect; UINT yRelative; WORD xLen; WORD yLen; ::GetClientRect(mhGroupWindow,(RECT FAR *)&grpRect); heightRegion=grpRect.bottom-heightRegion; ::GetWindowRect(GetHandle(),(RECT FAR *)&winRect); ::GetWindowRect(mhGroupWindow,(RECT FAR *)&grpRect); yRelative=winRect.bottom-grpRect.bottom; grpRect.bottom-=heightRegion; winRect.bottom=grpRect.bottom+yRelative; makeClientRect(grpRect); xLen=grpRect.right-grpRect.left; yLen=grpRect.bottom-grpRect.top; ::MoveWindow(mhGroupWindow,grpRect.left,grpRect.top,xLen,yLen,TRUE); xLen=winRect.right-winRect.left; yLen=winRect.bottom-winRect.top; ::MoveWindow(GetHandle(),winRect.left,winRect.top,xLen,yLen,TRUE); return; } void PaletteDialog::makeClientRect(RECT &screenRect)const { POINT pt; pt.x=screenRect.left; pt.y=screenRect.top; ::ScreenToClient(GetHandle(),(POINT FAR *)&pt); screenRect.left=pt.x; screenRect.top=pt.y; pt.x=screenRect.right; pt.y=screenRect.bottom; ::ScreenToClient(GetHandle(),(POINT FAR *)&pt); screenRect.right=pt.x; screenRect.bottom=pt.y; return; } void PaletteDialog::setWindowSize(void)const { RECT winRect; short xStart=1; short yStart=1; ::GetClientRect(mhGroupWindow,(RECT FAR *)&winRect); for(int i=0;i=winRect.right) { if(yStart+DELTAY>winRect.bottom)break; xStart=1; yStart=(yStart+DELTAY); } } conformWindow(yStart+DELTAY); return; }