📄 winspec.cpp
字号:
RetVal = Rectangle(memDC, x1, y1, x2, y2);
if(RetVal && hgo) return hgo->oRectangle(x1, y1, x2, y2, 0L);
else if (RetVal) return true;
return false;
}
bool
BitMapWin::oSolidLine(POINT *p)
{
if(Polyline(memDC, p, 2)) return true;
return false;
}
bool
BitMapWin::oTextOut(int x, int y, char *txt, int cb)
{
return com_oTextOut(x, y, txt, cb, &hFont, &memDC, &TxtSet, isWIN95, this);
}
bool
BitMapWin::oPolygon(POINT *pts, int cp, char *nam)
{
BOOL RetVal;
RetVal = Polygon(memDC, pts, cp);
if(RetVal && hgo) return hgo->oPolygon(pts, cp);
else if (RetVal) return true;
return false;
}
bool
BitMapWin::oArc(int x1, int y1, int x2, int y2, int quads)
{
return com_Arc(memDC, x1, y1, x2, y2, quads);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Output to windows window
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OutputWin::OutputWin(GraphObj *g, HWND hw):BitMapWin(g, hw)
{
hdc = 0L;
if(g) {
if(!hw) CreateNewWindow(g);
else hWnd = hw;
}
else { //its a dialog window
hWnd = hw;
yAxis.flags = AXIS_INVERT; //drawing origin upper left corner
}
}
OutputWin::~OutputWin()
{
HideTextCursorObj(this);
SendMessage(hWnd, WM_CLOSE, 0, 0L);
//Note: HGDI objects are deleted by the BitMapWin destructor
}
bool
OutputWin::ActualSize(RECT *rc)
{
if(GetClientRect(hWnd, rc)) return true;
return false;
}
void
OutputWin::Caption(char *txt)
{
SetWindowText(hWnd, txt);
}
unsigned char hand_bits[] = { //hand cursor bitmap
0x01, 0x80, 0x1b, 0xf0, 0x3f, 0xf8, 0x3f, 0xfa,
0x1f, 0xff, 0x1f, 0xff, 0x6f, 0xff, 0xff, 0xff,
0xff, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x3f, 0xfc,
0x1f, 0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, 0xf8};
unsigned char hand_mask[] = { //hand cursor mask
0xff, 0xff, 0xfe, 0x7f, 0xe6, 0x4f, 0xe6, 0x4f,
0xf2, 0x4d, 0xf2, 0x49, 0x78, 0x09, 0x98, 0x01,
0x88, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07,
0xf0, 0x07, 0xf8, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f};
unsigned char zoom_bits[] = { //zoom cursor bitmap
0x00, 0x00, 0x00, 0x00, 0x01, 0xa0, 0x06, 0x30,
0x08, 0x08, 0x10, 0x84, 0x10, 0x84, 0x20, 0x02,
0x26, 0x32, 0x20, 0x02, 0x10, 0x84, 0x10, 0x84,
0x08, 0x08, 0x06, 0x30, 0x01, 0xa0, 0x00, 0x00};
unsigned char zoom_mask[] = { //zoom cursor mask
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
void
OutputWin::MouseCursor(int cid, bool force)
{
HCURSOR hc, hoc = 0L;
if(cid == cCursor && !force) return;
if(cid == MC_LAST) cid = cCursor;
switch(cid) {
case MC_ARROW:
hoc = SetCursor(LoadCursor(NULL, IDC_ARROW)); break;
case MC_CROSS: hoc = SetCursor(LoadCursor(NULL, IDC_CROSS)); break;
case MC_WAIT:
hoc = SetCursor(LoadCursor(NULL, IDC_WAIT)); break;
case MC_TEXT: hoc = SetCursor(LoadCursor(NULL, IDC_IBEAM)); break;
case MC_NORTH: hoc = SetCursor(LoadCursor(NULL, IDC_SIZENS)); break;
case MC_NE: hoc = SetCursor(LoadCursor(NULL, IDC_SIZENESW));break;
case MC_EAST: hoc = SetCursor(LoadCursor(NULL, IDC_SIZEWE)); break;
case MC_SE: hoc = SetCursor(LoadCursor(NULL, IDC_SIZENWSE));break;
case MC_SALL: hoc = SetCursor(LoadCursor(NULL, IDC_SIZEALL)); break;
case MC_MOVE:
hc = CreateCursor(hInstance, 8, 8, 16, 16, hand_mask, hand_bits);
hoc = SetCursor(hc);
break;
case MC_ZOOM:
hc = CreateCursor(hInstance, 8, 8, 16, 16, zoom_mask, zoom_bits);
hoc = SetCursor(hc);
break;
default: return;
}
if(hoc) DestroyCursor(hoc);
cCursor = cid;
}
bool
OutputWin::SetScroll(bool isVert, int iMin, int iMax, int iPSize, int iPos)
{
SCROLLINFO si;
if(iPos < iMin) return false;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nMin = iMin;
si.nMax = iMax;
si.nPage = iPSize < iMax ? iPSize : iMax;
si.nPos = iPos;
si.nTrackPos = 0;
SetScrollInfo(hWnd, isVert ? SB_VERT : SB_HORZ, &si, TRUE);
return true;
}
bool
OutputWin::Erase(DWORD Color)
{
bool bRet;
RECT ClientRect;
if(bRet = BitMapWin::Erase(Color)) {
GetClientRect(hWnd, &ClientRect);
InvalidateRect(hWnd, &ClientRect, FALSE);
}
return bRet;
}
bool
OutputWin::StartPage()
{
MrkMode = MRK_NONE;
MrkRect = 0L;
hdc = memDC;
if(hgo && hdc) hgo->StartPage();
return true;
}
bool
OutputWin::EndPage()
{
RECT ClientRect;
hdc = NULL;
GetClientRect(hWnd, &ClientRect);
return UpdateRect(&ClientRect, false);
}
bool
OutputWin::UpdateRect(RECT *rc, bool invert)
{
HDC dc;
BOOL RetVal = FALSE;
if(dc = GetDC(hWnd)) {
RetVal = BitBlt(dc, rc->left, rc->top, rc->right - rc->left,
rc->bottom - rc->top, memDC, rc->left, rc->top, invert ? DSTINVERT : SRCCOPY);
ReleaseDC(hWnd, dc);
}
return (RetVal != 0);
}
bool
OutputWin::UpdateRect(HDC dc, RECT rc)
{
if(BitBlt(dc, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, memDC, rc.left, rc.top, SRCCOPY))return true;
return false;
}
void
OutputWin::ShowBitmap(int x, int y, anyOutput* src)
{
int w, h;
HDC dc;
BitMapWin *sr;
if(!src) return;
sr = (BitMapWin *) src;
w = sr->DeskRect.right - sr->DeskRect.left;
h = sr->DeskRect.bottom - sr->DeskRect.top;
if(dc = GetDC(hWnd)) {
BitBlt(dc, x, y, w, h, sr->memDC, 0, 0, SRCCOPY);
ReleaseDC(hWnd, dc);
}
}
void
OutputWin::ShowLine(POINT * pts, int cp, DWORD color)
{
HDC dc;
HPEN hP, oP;
if((hP = CreatePen(PS_SOLID, 0, color))&& (dc = GetDC(hWnd))) {
oP = (HPEN)SelectObject(dc, hP);
Polyline(dc, pts, cp);
SelectObject(dc, oP);
DeleteObject(hP);
ReleaseDC(hWnd, dc);
}
}
void
OutputWin::ShowEllipse(POINT p1, POINT p2, DWORD color)
{
HDC dc;
HPEN hP, oP;
if((hP = CreatePen(PS_SOLID, 0, color)) && (dc = GetDC(hWnd))) {
oP = (HPEN)SelectObject(dc, hP);
Arc(dc, p1.x, p1.y, p2.x, p2.y, 0, 0, 0, 0);
SelectObject(dc, oP);
DeleteObject(hP);
ReleaseDC(hWnd, dc);
}
}
bool
OutputWin::SetMenu(int type)
{
HMENU hMenu = 0L;
switch(type) {
case MENU_NONE:
break;
case MENU_SPREAD:
hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(MENU_2));
break;
case MENU_GRAPH:
hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(MENU_1));
break;
case MENU_PAGE:
hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(MENU_3));
}
::SetMenu(hWnd, hMenu);
return true;
}
void
OutputWin::CheckMenu(int mid, bool check)
{
HMENU hMenu = GetMenu(hWnd);
if(mid < CM_T_STANDARD) switch(mid){ //tool mode identifier
case TM_STANDARD: mid = CM_T_STANDARD; break;
case TM_DRAW: mid = CM_T_DRAW; break;
case TM_POLYLINE: mid = CM_T_POLYLINE; break;
case TM_POLYGON: mid = CM_T_POLYGON; break;
case TM_RECTANGLE: mid = CM_T_RECTANGLE; break;
case TM_ROUNDREC: mid = CM_T_ROUNDREC; break;
case TM_ELLIPSE: mid = CM_T_ELLIPSE; break;
case TM_ARROW: mid = CM_T_ARROW; break;
case TM_TEXT: mid = CM_T_TEXT; break;
default: return;
}
if(hMenu) CheckMenuItem(hMenu, mid, check ? MF_CHECKED : MF_UNCHECKED);
}
void
OutputWin::FileHistory()
{
HMENU hSubMenu;
char **history[] = {&defs.File1, &defs.File2, &defs.File3, &defs.File4, &defs.File5, &defs.File6};
int i, j, k;
if(!hasHistMenu || !defs.File1) return;
if(!(hSubMenu = GetSubMenu(GetMenu(hWnd), 0))) return;
if(!HistMenuSize) AppendMenu(hSubMenu, MF_SEPARATOR, 0L, 0L);
for(i = 0; i < 6 && *history[i]; i++) {
k = strlen(*history[i]);
for (j = 0; j < k && defs.currPath[j] == (*history[i])[j]; j++);
if((*history[i])[j] == '\\' || (*history[i])[j] == '/') j++;
if(i < HistMenuSize) {
ModifyMenu(hSubMenu, CM_FILE1+i, MF_BYCOMMAND | MF_STRING, CM_FILE1+i, *history[i]+j);
}
else {
AppendMenu(hSubMenu, MF_STRING, CM_FILE1+i, *history[i]+j);
}
}
HistMenuSize = i;
}
void
OutputWin::CreateNewWindow(void *g)
{
hWnd = CreateWindow(name, "RLPlot",
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
SetWindowLong(hWnd, 0, (long)g); // g is the parent graphic obj
SetWindowLong(hWnd, GWL_USERDATA, (long)this);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Copy to Clipboard
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Create Windows Meta File for clipboard
WinCopyWMF::WinCopyWMF(GraphObj *g)
{
DeskRect.left = DeskRect.top = 0;
DeskRect.right = DeskRect.bottom = 0x4fffffffL;
hPen = CreatePen(PS_SOLID, 1, dLineCol = 0x00ffffffL);
hBrush = CreateSolidBrush(dFillCol =dBgCol = 0x00ffffffL);
dPattern = 0L;
go = g;
hgo = 0L;
hres = vres = 1000.0;
}
WinCopyWMF::~WinCopyWMF()
{
if(hgo) delete hgo;
if(hFont) DeleteObject(hFont);
if(hBrush) DeleteObject(hBrush);
if(hPen) DeleteObject(hPen);
}
bool
WinCopyWMF::SetLine(LineDEF *lDef)
{
int iw;
HPEN newPen;
if(!hPen || lDef->width != LineWidth || lDef->width != LineWidth ||
lDef->pattern != dPattern || lDef->color != dLineCol) {
LineWidth = lDef->width;
iw = iround(un2fix(lDef->width));
dPattern = lDef->pattern;
RLP.finc = 256.0/un2fix(lDef->patlength*8.0);
RLP.fp = 0.0;
if(iLine == iw && dLineCol == lDef->color && hPen) return true;
iLine = iw;
dLineCol = lDef->color;
newPen = CreatePen(PS_SOLID, iw > 0 ? iw : 1, dLineCol);
SelectObject(hdc, newPen);
if(hPen) DeleteObject(hPen);
hPen = newPen;
}
return true;
}
bool
WinCopyWMF::SetFill(FillDEF *fill)
{
HBRUSH newBrush;
if(!fill) return false;
if((fill->type & 0xff) != FILL_NONE) {
if(!hgo) hgo = new HatchOut(this);
if(hgo) hgo->SetFill(fill);
}
else {
if(hgo) delete hgo;
hgo = NULL;
}
if(dFillCol != fill->color) {
newBrush = CreateSolidBrush(dFillCol = fill->color);
SelectObject(hdc, newBrush);
if(hBrush) DeleteObject(hBrush);
hBrush = newBrush;
}
dFillCol = fill->color;
dFillCol2 = fill->color2;
return true;
}
bool
WinCopyWMF::SetTextSpec(TextDEF *set)
{
return com_SetTextSpec(set, this, &hFont, &TxtSet, &hdc, true);
}
bool
WinCopyWMF::StartPage()
{
int w, h;
if(!go) return false;
w = un2ix(go->GetSize(SIZE_GRECT_RIGHT) - go->GetSize(SIZE_GRECT_LEFT));
h = un2iy(go->GetSize(SIZE_GRECT_BOTTOM) - go->GetSize(SIZE_GRECT_TOP));
w++; h++;
if(!(hdc = CreateMetaFile(NULL))) return false;
if(hPen)SelectObject(hdc, hPen);
if(hBrush) SelectObject(hdc, hBrush);
VPorg.fy = -co2fiy(go->GetSize(SIZE_GRECT_TOP));
VPorg.fx = -co2fix(go->GetSize(SIZE_GRECT_LEFT));
SetMapMode(hdc, MM_HIENGLISH);
SetWindowExtEx(hdc, w, h, 0L);
SetWindowOrgEx(hdc, 0, 0, 0L);
return true;
}
bool
WinCopyWMF::EndPage()
{
HMETAFILE hmf;
HGLOBAL hGMem;
LPMETAFILEPICT pMFP;
hmf = CloseMetaFile(hdc);
hGMem = GlobalAlloc(GHND, sizeof(METAFILEPICT));
pMFP = (LPMETAFILEPICT)GlobalLock(hGMem);
pMFP->mm = MM_ANISOTROPIC;
pMFP->xExt = (long)(Box1.Xmax+Box1.Xmin);
pMFP->yExt = (long)(Box1.Ymax+Box1.Ymin);
pMFP->hMF = hmf;
GlobalUnlock(hGMem);
// We do not open the Clipboard because we are responding to WM_RENDERFORMAT
SetClipboardData(CF_METAFILEPICT, hGMem);
return true;
}
bool
WinCopyWMF::oCircle(int x1, int y1, int x2, int y2, char* nam)
{
BOOL RetVal;
RetVal = Ellipse(hdc, x1, y1, x2, y2);
if(RetVal && hgo) return hgo->oCircle(x1, y1, x2, y2);
else if(RetVal) return true;
return false;
}
bool
WinCopyWMF::oPolyline(POINT * pts, int cp, char *nam)
{
int i;
if(cp < 1) return false;
if (dPattern) {
for (i = 1; i < cp; i++) PatLine(pts[i-1], pts[i]);
return true;
}
else {
if(Polyline(hdc, pts, cp))return true;
else return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -