#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <commdlg.h>
#include <htmlhelp.h>
#include <stdio.h>
#include <tchar.h>
#include <visa.h>
#include <wchar.h>
#include "propertyGrid.h"
#include "resource.h"
#include "error.h"
#include "connect.h"
#include "hpPlotter.h"
#include "stringFunc.h"
#include "odmenu.h"
#include "iniFile.h"
#include "imageFile.h"
#include "windowState.h"
#define SNAPSHOTHELP _T("SnapShotHelp.chm")
static LPSTR supportedModels[] = { "TDS 420", "TDS 640A", "TDS 754C", "TDS 460A", "8711A", "8751A",
"8753C", "8753D", "4396A", "TDS 754D", "TDS 740", NULL };
static HANDLE ghInstance;
static HWND ghToolBar, ghGrid, ghPictureBox;
static BOOL gfDrag = FALSE; }
else
{
_stprintf(fileEntry, NELEMS(fileEntry),
#ifdef _UNICODE
_T("\\StringFileInfo\\%04X04B0\\%ls"),
#else
_T("\\StringFileInfo\\%04X04B0\\%s"),
#endif
GetUserDefaultLangID(), csEntry);
}
if (retVal == VerQueryValue(versionInfo, fileEntry, (LPVOID *) & retbuf, (UINT *) & vLen))
{
csRet = (LPTSTR)retbuf;
}
else
{
_stprintf(errStr, NELEMS(errStr),
#ifdef _UNICODE
_T("%ls Not Available"),
#else
_T("%s Not Available"),
#endif
csEntry);
csRet = errStr;
}
}
}
UnlockResource(hGlobal);
FreeResource(hGlobal);
}
return csRet;
}
static HWND CreateToolbar_OwnerDrawMenu(HWND hwnd, WORD wBitmapRsc)
{
HWND hToolBar;
HIMAGELIST himl;
TBBUTTON tbb;
int i;
hToolBar = CreateWindow(TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT, 0, 0, 0, 0, hwnd, (HMENU)IDC_TOOLBAR, ghInstance, NULL);
if (!hToolBar)
return NULL;
ToolBar_SetExtendedStyle(hToolBar, TBSTYLE_EX_DOUBLEBUFFER);
ToolBar_ButtonStructSize(hToolBar);
ToolBar_SetBitmapSize(hToolBar, 16, 16);
himl = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 16, 1);
ImageList_AddMasked(himl, LoadImage(ghInstance, MAKEINTRESOURCE(wBitmapRsc), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_DEFAULTCOLOR), RGB(0, 128, 128));
ToolBar_SetImageList(hToolBar, himl);
struct {
WORD idCommand; WORD iBitmap; WORD fsStyle; WORD fsState; }
gaToolbar[] =
{
MNU_OPENCONFIG, 3, TBSTYLE_BUTTON, TBSTATE_ENABLED,
0, 0, TBSTYLE_SEP, TBSTATE_ENABLED,
MNU_IMPORT_HPGL, 11, TBSTYLE_BUTTON, TBSTATE_ENABLED,
0, 0, TBSTYLE_SEP, TBSTATE_ENABLED,
MNU_GETPLOT, 8, TBSTYLE_BUTTON, TBSTATE_ENABLED,
MNU_REFRESHPLOT, 5, TBSTYLE_BUTTON, TBSTATE_ENABLED,
MNU_SAVE, 2, TBSTYLE_BUTTON, TBSTATE_ENABLED,
0, 0, TBSTYLE_SEP, TBSTATE_ENABLED,
MNU_PRINT, 6, TBSTYLE_BUTTON, TBSTATE_ENABLED,
0, 0, TBSTYLE_SEP, TBSTATE_ENABLED,
MNU_SNAPSHOT_HELP, 9, TBSTYLE_BUTTON, TBSTATE_ENABLED,
MNU_CONNECTION, 1, TBSTYLE_BUTTON, TBSTATE_HIDDEN,
MNU_SAVECONFIG, 4, TBSTYLE_BUTTON, TBSTATE_HIDDEN,
MNU_PAGESETUP, 7, TBSTYLE_BUTTON, TBSTATE_HIDDEN,
MNU_EXIT, 10, TBSTYLE_BUTTON, TBSTATE_HIDDEN,
MNU_ABOUT, 0, TBSTYLE_BUTTON, TBSTATE_HIDDEN
};
for (i = 0; i < NELEMS(gaToolbar); i++)
{
tbb.iBitmap = gaToolbar[i].iBitmap;
tbb.idCommand = gaToolbar[i].idCommand;
tbb.fsState = gaToolbar[i].fsState;
tbb.fsStyle = gaToolbar[i].fsStyle;
tbb.iString = 0;
ToolBar_AddButtons(hToolBar, 1, &tbb);
}
ToolBar_AutoSize(hToolBar);
if (!InstallOwnerDrawMenuHandler(hwnd, hToolBar))
return NULL;
return hToolBar;
}
static VOID DoEvents(VOID)
{
MSG Msg;
while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
static SIZE GetDlgItemSize(HWND hwnd, INT nIDDlgItem)
{
static SIZE sz;
RECT rc;
memset(&rc, 0, sizeof(RECT));
GetClientRect(GetDlgItem(hwnd, nIDDlgItem), &rc);
sz.cx = WIDTH(rc);
sz.cy = HEIGHT(rc);
return sz;
}
static VOID DrawLine(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2)
{
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
}
static VOID InvertLine(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2)
{
INT nOldMode = SetROP2(hdc, R2_NOT);
DrawLine(hdc, x1, y1, x2, y2);
SetROP2(hdc, nOldMode);
}
BOOL isOverSlider(INT x)
{
return abs(x - guDrag) < 5;
}
#pragma endregion misc
#pragma region Plotter PropertyGrid
VOID PlotterConfig_LoadFromFile(LPPLOTTER lpp, LPCTSTR filename)
{
__try
{
LPINIFILE lpFile = New_IniFile(filename);
lpp->offset_x = IniFile_ReadInteger(lpFile, _T("Plot Offset"), _T("x"), lpp->offset_x);
lpp->offset_y = IniFile_ReadInteger(lpFile, _T("Plot Offset"), _T("y"), lpp->offset_y);
lpp->offsetText_x = IniFile_ReadInteger(lpFile, _T("Text Offset"), _T("x"), lpp->offsetText_x);
lpp->offsetText_y = IniFile_ReadInteger(lpFile, _T("Text Offset"), _T("y"), lpp->offsetText_y);
lpp->fontWeight = IniFile_ReadInteger(lpFile, _T("Text Font"), _T("weight"), lpp->fontWeight);
_tcsncpy(lpp->fontName, IniFile_ReadString(lpFile, _T("Text Font"), _T("name"), lpp->fontName), NELEMS(lpp->fontName));
lpp->fontScale = IniFile_ReadInteger(lpFile, _T("Text Font"), _T("scale"), lpp->fontScale);
ANTIALIASING aa = lpp->antiAliasing;
LPTSTR szValue =
aa == x8 ? _T("x8") :
aa == x4 ? _T("x4") :
aa == x2 ? _T("x2") :
_T("NONE"); szValue = IniFile_ReadString(lpFile, _T("Plot Options"), _T("anti-ailiasing"), szValue);
szValue = _tcsupr(szValue);
lpp->antiAliasing =
0 == _tcsncmp(_T("X8"), szValue, _tcslen(szValue)) ? x8 :
0 == _tcsncmp(_T("X4"), szValue, _tcslen(szValue)) ? x4 :
0 == _tcsncmp(_T("X2"), szValue, _tcslen(szValue)) ? x2 :
NONE; BYTE r = GetRValue(lpp->backcolor);
BYTE g = GetGValue(lpp->backcolor);
BYTE b = GetBValue(lpp->backcolor);
r = IniFile_ReadInteger(lpFile, _T("Plot Options"), _T("background color R"), r);
g = IniFile_ReadInteger(lpFile, _T("Plot Options"), _T("background color G"), g);
b = IniFile_ReadInteger(lpFile, _T("Plot Options"), _T("background color B"), b);
lpp->backcolor = RGB(r,g,b);
_tcsncpy(lpp->markerSymbol, IniFile_ReadString(lpFile, _T("Plot Options"), _T("marker symbol"), lpp->markerSymbol), NELEMS(lpp->markerSymbol));
lpp->useColorPens = IniFile_ReadBoolean(lpFile, _T("Plot Options"), _T("use color pens"), lpp->useColorPens);
lpp->useCustomLineTypes = IniFile_ReadBoolean(lpFile, _T("Plot Options"), _T("use custom line types"), lpp->useCustomLineTypes);
TCHAR szSection[MAX_PATH] = { 0 };
for (int i = 1; i < lpp->penCount; ++i)
{
_stprintf(szSection, NELEMS(szSection), _T("Pen %d"), i);
lpp->penWidth[i] = IniFile_ReadInteger(lpFile, szSection, _T("width"), lpp->penWidth[i]);
r = GetRValue(lpp->penColor[i]);
g = GetGValue(lpp->penColor[i]);
b = GetBValue(lpp->penColor[i]);
r = IniFile_ReadInteger(lpFile, szSection, _T("color R"), r);
g = IniFile_ReadInteger(lpFile, szSection, _T("color G"), g);
b = IniFile_ReadInteger(lpFile, szSection, _T("color B"), b);
lpp->penColor[i] = RGB(r,g,b);
INT lt = lpp->customLineType[i];
szValue =
lt == PS_DASHDOTDOT ? _T("Dash Dot Dot") :
lt == PS_DASHDOT ? _T("Dash Dot") :
lt == PS_DOT ? _T("Dot") :
lt == PS_DASH ? _T("Dash") :
_T("Solid"); szValue = IniFile_ReadString(lpFile, szSection, _T("line type"), szValue);
szValue = _tcsupr(szValue);
lpp->customLineType[i] =
0 == _tcsncmp(_T("DASH DOT DOT"), szValue, _tcslen(szValue)) ? PS_DASHDOTDOT :
0 == _tcsncmp(_T("DASH DOT"), szValue, _tcslen(szValue)) ? PS_DASHDOT :
0 == _tcsncmp(_T("DOT"), szValue, _tcslen(szValue)) ? PS_DOT :
0 == _tcsncmp(_T("DASH"), szValue, _tcslen(szValue)) ? PS_DASH :
PS_SOLID; }
IniFile_Destroy(lpFile);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
}
}
VOID PlotterConfig_SaveToFile(LPPLOTTER lpp, LPCTSTR filename)
{
__try
{
if(FileExists(filename)) DeleteFile(filename);
LPINIFILE lpFile = New_IniFile(filename);
IniFile_WriteInteger(lpFile, _T("Plot Offset"), _T("x"), lpp->offset_x);
IniFile_WriteInteger(lpFile, _T("Plot Offset"), _T("y"), lpp->offset_y);
IniFile_InsertSeparator(lpFile, _T("Plot Offset"));
IniFile_WriteInteger(lpFile, _T("Text Offset"), _T("x"), lpp->offsetText_x);
IniFile_WriteInteger(lpFile, _T("Text Offset"), _T("y"), lpp->offsetText_y);
IniFile_InsertSeparator(lpFile, _T("Text Offset"));
IniFile_WriteInteger(lpFile, _T("Text Font"), _T("weight"), lpp->fontWeight);
IniFile_WriteString(lpFile, _T("Text Font"), _T("name"), lpp->fontName);
IniFile_WriteInteger(lpFile, _T("Text Font"), _T("scale"), lpp->fontScale);
IniFile_InsertSeparator(lpFile, _T("Text Font"));
IniFile_WriteString(lpFile, _T("Plot Options"), _T("//Note: Valid Anti-ailiasing Values"),
_T(" NONE, x2, x4, and x8"));
ANTIALIASING aa = lpp->antiAliasing;
IniFile_WriteString(lpFile, _T("Plot Options"), _T("anti-ailiasing"),
aa == x8 ? _T("x8") :
aa == x4 ? _T("x4") :
aa == x2 ? _T("x2") :
_T("NONE")); IniFile_WriteInteger(lpFile, _T("Plot Options"), _T("background color R"), GetRValue(lpp->backcolor));
IniFile_WriteInteger(lpFile, _T("Plot Options"), _T("background color G"), GetGValue(lpp->backcolor));
IniFile_WriteInteger(lpFile, _T("Plot Options"), _T("background color B"), GetBValue(lpp->backcolor));
IniFile_WriteString(lpFile, _T("Plot Options"), _T("marker symbol"), lpp->markerSymbol);
IniFile_WriteBoolean(lpFile, _T("Plot Options"), _T("use color pens"), lpp->useColorPens);
IniFile_WriteBoolean(lpFile, _T("Plot Options"), _T("use custom line types"), lpp->useCustomLineTypes);
IniFile_InsertSeparator(lpFile, _T("Plot Options"));
IniFile_WriteString(lpFile, _T("Pen configurations"), _T("//Note: Valid Pen Widths"),
_T(" 1-20"));
IniFile_WriteString(lpFile, _T("Pen configurations"), _T("//Note: Pen Colors"),
_T(" values as R, G, and B respectively and used when \'use color pens\' is set to \'True\'"));
IniFile_WriteString(lpFile, _T("Pen configurations"), _T("//Note: Valid Line Types"),
_T(" Solid, Dash, Dot, Dash Dot, and Dash Dot Dot"));
IniFile_InsertSeparator(lpFile, _T("Pen configurations"));
TCHAR szSection[MAX_PATH] = { 0 };
for (int i = 1; i < lpp->penCount; ++i)
{
_stprintf(szSection, NELEMS(szSection), _T("pen %d"), i);
IniFile_WriteInteger(lpFile, szSection, _T("width"), lpp->penWidth[i]);
IniFile_WriteInteger(lpFile, szSection, _T("color R"), GetRValue(lpp->penColor[i]));
IniFile_WriteInteger(lpFile, szSection, _T("color G"), GetGValue(lpp->penColor[i]));
IniFile_WriteInteger(lpFile, szSection, _T("color B"), GetBValue(lpp->penColor[i]));
INT lt = lpp->customLineType[i];
IniFile_WriteString(lpFile, szSection, _T("line type"),
lt == PS_DASH ? _T("Dash") :
lt == PS_DASHDOT ? _T("Dash Dot") :
lt == PS_DASHDOTDOT ? _T("Dash Dot Dot") :
lt == PS_DOT ? _T("Dot") :
_T("Solid")); IniFile_InsertSeparator(lpFile, szSection);
}
IniFile_Destroy(lpFile);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
}
}
VOID Plotter_UpdateGrid(LPPLOTTER lpp, HWND hGrid)
{
PropGrid_ResetContent(hGrid);
PROPGRIDITEM Item = { 0 };
TCHAR buf[MAX_PATH];
_tmemset(buf, (TCHAR)0, NELEMS(buf));
Item.lpszCatalog = _T("Plot Offset");
Item.lpszPropName = _T("x");
_stprintf(buf, NELEMS(buf), "%d", lpp->offset_x);
Item.lpCurValue = (LPARAM)buf;
Item.lpszPropDesc = _T("Plot origin x coordinate offset.");
Item.iItemType = PIT_EDIT;
PropGrid_AddItem(hGrid, &Item);
Item.lpszPropName = _T("y");
_stprintf(buf, NELEMS(buf), "%d", lpp->offset_y);
Item.lpCurValue = (LPARAM)buf;
Item.lpszPropDesc = _T("Plot origin y coordinate offset.");
Item.iItemType = PIT_EDIT;
PropGrid_AddItem(hGrid, &Item);
Item.lpszCatalog = _T("Text Offset");
Item.lpszPropName = _T("x");
_stprintf(buf, NELEMS(buf), "%d", lpp->offsetText_x);
Item.lpCurValue = (LPARAM)buf;
Item.lpszPropDesc = _T("Plot text offset x.");
Item.iItemType = PIT_EDIT;
PropGrid_AddItem(hGrid, &Item);
Item.lpszPropName = _T("y");
_stprintf(buf, NELEMS(buf), "%d", lpp->offsetText_y);
Item.lpCurValue = (LPARAM)buf;
Item.lpszPropDesc = _T("Plot text offset y.");
Item.iItemType = PIT_EDIT;
PropGrid_AddItem(hGrid, &Item);
Item.lpszCatalog = _T("Text Font");
PROPGRIDFONTITEM ItemLf;
GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &ItemLf.logFont);
ItemLf.logFont.lfWeight = lpp->fontWeight;
_tcsncpy(ItemLf.logFont.lfFaceName, lpp->fontName, NELEMS(ItemLf.logFont.lfFaceName));
ItemLf.crFont = RGB(0, 0, 0);
Item.lpszPropName = _T("Text Font");
Item.lpCurValue = (LPARAM) & ItemLf;
Item.lpszPropDesc = _T("Choose font name and weight.");
Item.iItemType = PIT_FONT;
PropGrid_AddItem(hGrid, &Item);
Item.lpszPropName = _T("Font Scale");
_stprintf(buf, NELEMS(buf), "%d", lpp->fontScale);
Item.lpCurValue = (LPARAM)buf;
Item.lpszPropDesc = _T("Scale of font used on plot (percent).");
Item.iItemType = PIT_EDIT;
PropGrid_AddItem(hGrid, &Item);
Item.lpszCatalog = _T("Plot Options");
Item.lpszPropName = _T("Anti-ailiasing");
ANTIALIASING aa = lpp->antiAliasing;
Item.lpCurValue = (LPARAM)
(aa == x8 ? _T("x8") :
aa == x4 ? _T("x4") :
aa == x2 ? _T("x2") :
_T("NONE")); Item.lpszzCmbItems = _T("NONE\0x2\0x4\0x8\0");
Item.lpszPropDesc = _T("How much Anti-aliasing scale to apply to the image.");
Item.iItemType = PIT_COMBO;
PropGrid_AddItem(hGrid, &Item);
Item.lpszPropName = _T("Background Color");
Item.lpCurValue = (LPARAM)lpp->backcolor;
Item.lpszPropDesc = _T("Color of the plot background (paper color).");
Item.iItemType = PIT_COLOR;
PropGrid_AddItem(hGrid, &Item);
Item.lpszPropName = _T("Marker Symbol");
Item.lpCurValue = (LPARAM)lpp->markerSymbol;
Item.lpszPropDesc = _T("Ascii character or characters to use for markers (device dependent).");
Item.iItemType = PIT_EDIT;
PropGrid_AddItem(hGrid, &Item);
Item.lpszPropName = _T("Use Color Pens");
Item.lpCurValue = (LPARAM)lpp->useColorPens;
Item.lpszPropDesc = _T("If checked specify the color for each pen.");
Item.iItemType = PIT_CHECK;
PropGrid_AddItem(hGrid, &Item);
Item.lpszPropName = _T("Use Custom Line Types");
Item.lpCurValue = (LPARAM)lpp->useCustomLineTypes;
Item.lpszPropDesc = _T("If checked specify the line type for each pen.");
Item.iItemType = PIT_CHECK;
PropGrid_AddItem(hGrid, &Item);
TCHAR szCat[MAX_PATH] = { 0 };
for (int i = 1; i < lpp->penCount; ++i)
{
_stprintf(szCat, NELEMS(szCat), _T("Pen %d"), i);
Item.lpszCatalog = szCat;
Item.lpszPropName = _T("Width");
_stprintf(buf, NELEMS(buf), "%ld", lpp->penWidth[i]);
Item.lpCurValue = (LPARAM)buf;
Item.lpszzCmbItems = _T("1\0002\0003\0004\0005\0006\0007\0008\0009\00010 \
\00011\00012\00013\00014\00015\00016\00017\00018\00019\00020\000");
Item.lpszPropDesc = _T("The desired width of this pen (in pixels).");
Item.iItemType = PIT_COMBO;
PropGrid_AddItem(hGrid, &Item);
if (lpp->useColorPens)
{
Item.lpszPropName = _T("Color");
Item.lpCurValue = (LPARAM)lpp->penColor[i];
Item.lpszPropDesc = _T("The desired Color of this pen.");
Item.iItemType = PIT_COLOR;
PropGrid_AddItem(hGrid, &Item);
}
if (lpp->useCustomLineTypes)
{
Item.lpszPropName = _T("Line Type");
DWORD lt = lpp->customLineType[i];
Item.lpCurValue = (LPARAM)
(lt == PS_DASH ? _T("Dash") :
lt == PS_DASHDOT ? _T("Dash Dot") :
lt == PS_DASHDOTDOT ? _T("Dash Dot Dot") :
lt == PS_DOT ? _T("Dot") :
_T("Solid")); Item.lpszzCmbItems = _T("Solid\0Dash\0Dot\0Dash Dot\0Dash Dot Dot\0");
Item.lpszPropDesc = _T("The desired line type for this pen.");
Item.iItemType = PIT_COMBO;
PropGrid_AddItem(hGrid, &Item);
}
}
PropGrid_ShowToolTips(hGrid, TRUE);
PropGrid_ShowPropertyDescriptions(hGrid, TRUE);
PropGrid_ExpandAllCatalogs(hGrid);
}
static VOID Grid_OnPropertyChange(LPNMPROPGRID lpnmpg, LPPLOTTER lpp)
{
HWND hGrid = lpnmpg->hdr.hwndFrom;
LPPROPGRIDITEM Item = PropGrid_GetItemData(hGrid, lpnmpg->iIndex);
switch (lpnmpg->iIndex)
{
case 0:
lpp->offset_x = atoi((LPTSTR)Item->lpCurValue);
break;
case 1:
lpp->offset_y = atoi((LPTSTR)Item->lpCurValue);
break;
case 2:
lpp->offsetText_x = atoi((LPTSTR)Item->lpCurValue);
break;
case 3:
lpp->offsetText_y = atoi((LPTSTR)Item->lpCurValue);
break;
case 4:
lpp->fontWeight = ((LPPROPGRIDFONTITEM)Item->lpCurValue)->logFont.lfWeight;
_tcsncpy(lpp->fontName, ((LPPROPGRIDFONTITEM)Item->lpCurValue)->logFont.lfFaceName,
NELEMS(((LPPROPGRIDFONTITEM)Item->lpCurValue)->logFont.lfFaceName));
break;
case 5:
lpp->fontScale = atoi((LPTSTR)Item->lpCurValue);
break;
case 6:
{
LPTSTR szValue = Ucase((LPTSTR)Item->lpCurValue);
lpp->antiAliasing =
0 == _tcsncmp(_T("X8"), szValue, _tcslen(szValue)) ? x8 :
0 == _tcsncmp(_T("X4"), szValue, _tcslen(szValue)) ? x4 :
0 == _tcsncmp(_T("X2"), szValue, _tcslen(szValue)) ? x2 :
NONE; }
break;
case 7:
lpp->backcolor = (COLORREF)Item->lpCurValue;
break;
case 8:
_tcsncpy(lpp->markerSymbol, (LPTSTR)Item->lpCurValue, NELEMS(lpp->markerSymbol));
break;
case 9:
lpp->useColorPens = (BOOL)Item->lpCurValue;
break;
case 10:
lpp->useCustomLineTypes = (BOOL)Item->lpCurValue;
break;
default: {
int properties = 1;
if(lpp->useColorPens) ++properties;
if(lpp->useCustomLineTypes) ++properties;
int pen = (int)((lpnmpg->iIndex - 11) / properties) + 1; int prop = (lpnmpg->iIndex - 11) % properties;
switch (prop)
{
case 0:
lpp->penWidth[pen] = atoi((LPTSTR)Item->lpCurValue); break;
case 1:
if(lpp->useColorPens)
{
lpp->penColor[pen] = (COLORREF)Item->lpCurValue; break;
}
case 2:
if(lpp->useCustomLineTypes)
{
LPTSTR szValue = Ucase((LPTSTR)Item->lpCurValue);
lpp->customLineType[pen] =
0 == _tcsncmp(_T("DASH"), szValue, _tcslen(szValue)) ? PS_DASH :
0 == _tcsncmp(_T("DASH DOT"), szValue, _tcslen(szValue)) ? PS_DASHDOT :
0 == _tcsncmp(_T("DASH DOT DOT"), szValue, _tcslen(szValue)) ? PS_DASHDOTDOT :
0 == _tcsncmp(_T("DOT"), szValue, _tcslen(szValue)) ? PS_DOT :
PS_SOLID; break;
}
} } }
if (8 < lpnmpg->iIndex && lpnmpg->iIndex < 11)
{
Plotter_UpdateGrid(lpp, hGrid); PropGrid_SetCurSel(hGrid, lpnmpg->iIndex);
}
}
#pragma endregion Plotter PropertyGrid
static BOOL Main_OnNotify(HWND hwnd, INT id, LPNMHDR pnm)
{
if (IDC_GRID == id && PGN_PROPERTYCHANGE == pnm->code)
{
Grid_OnPropertyChange((LPNMPROPGRID)pnm, glpScreenPlotter);
return TRUE;
}
return FALSE;
}
#pragma region menuHelp
static BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
HWND hTitle = GetDlgItem(hDlg, IDC_ABOUT_TITLE);
SetWindowFont(hTitle, CreateFont(20, 0, 0, 0, FW_HEAVY, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
VARIABLE_PITCH | FF_MODERN, NULL), TRUE);
TCHAR buf[MAX_PATH] = { 0 };
TCHAR ProductVersion[MAX_PATH] = { 0 };
_tcscpy(ProductVersion, GetVersionInfo(_T("ProductVersion")));
TCHAR LegalCopyright[MAX_PATH] = { 0 };
_tcscpy(LegalCopyright, GetVersionInfo(_T("LegalCopyright")));
TCHAR ProductName[MAX_PATH] = { 0 };
_tcscpy(ProductName, GetVersionInfo(_T("ProductName")));
_stprintf(buf, NELEMS(buf),
#ifdef _UNICODE
_T("%ls version %ls, Copyright %ls\n")
_T("David MacDermot\n")
_T("%ls comes with ABSOLUTELY NO WARRANTY.\n")
_T("Licensed under the terms of the Code Project Open License."),
#else
_T("%s version %s, Copyright %s\n")
_T("%s comes with ABSOLUTELY NO WARRANTY.\n")
_T("Licensed under the terms of the Code Project Open License."),
#endif
ProductName, ProductVersion, LegalCopyright, ProductName);
Static_SetText(hTitle, ProductName);
Static_SetText(GetDlgItem(hDlg, IDC_ABOUT_TEXT), buf);
SetWindowPos(hDlg, NULL, ((LPPOINT)lParam)->x, ((LPPOINT)lParam)->y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
return TRUE;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}
static BOOL GetMenuItemRectEx(HWND hwnd, HMENU hMenu, INT id, LPRECT prc)
{
static MENUITEMINFO mii = { 0 };
BOOL fRTN = FALSE;
mii.cbSize = sizeof mii;
mii.fMask = MIIM_ID | MIIM_SUBMENU;
for (int pos = 0, ret = 1; ret; pos++)
{
ret = GetMenuItemInfo(hMenu, pos, TRUE, &mii);
if (NULL != mii.hSubMenu)
{
if (GetMenuItemRectEx(hwnd, mii.hSubMenu, id, prc))
{
fRTN = TRUE;
break;
}
}
else if (id == mii.wID)
{
GetMenuItemRect(hwnd, hMenu, pos, prc);
fRTN = TRUE;
break;
}
}
return fRTN;
}
static VOID MnuAbout_Click(HWND hwnd, INT id)
{
RECT rc = { 0 };
GetMenuItemRectEx(hwnd, GetMenu(hwnd), id, &rc);
DialogBoxParam(ghInstance, MAKEINTRESOURCE(DLG_ABOUT), hwnd, (DLGPROC)AboutDlgProc, (LPARAM) (LPPOINT) & rc.right);
}
static VOID MnuSnapshotHelp_Click(HWND hwnd)
{
TCHAR buf[MAX_PATH] = { 0 };
_stprintf(buf, NELEMS(buf),
#ifdef _UNICODE
_T("%ls\\%ls"),
#else
_T("%s\\%s"),
#endif
gParentDirectory, SNAPSHOTHELP);
HtmlHelp(hwnd, buf, HH_DISPLAY_TOC, 0);
}
static BOOL Main_OnHelp(HWND hwnd, LPHELPINFO lpHelpInfo)
{
return TRUE;
}
#pragma endregion menuHelp
#pragma region mnuPrint
VOID InitPrintDevMode(VOID)
{
DEVMODE *pDevMode;
ghDevMode = GlobalAlloc(GHND, sizeof(DEVMODE)); if (ghDevMode)
{
pDevMode = (DEVMODE *)GlobalLock(ghDevMode); if (pDevMode)
{
pDevMode->dmSize = sizeof(DEVMODE); pDevMode->dmFields = DM_ORIENTATION; pDevMode->dmOrientation = DMORIENT_LANDSCAPE; }
GlobalUnlock(ghDevMode); }
gPsd.rtMargin.left = gPsd.rtMinMargin.left = 166;
gPsd.rtMargin.top = gPsd.rtMinMargin.top = 236;
gPsd.rtMargin.right = gPsd.rtMinMargin.right = 166;
gPsd.rtMargin.bottom = gPsd.rtMinMargin.bottom = 236;
}
HDC GetPrinterDC(HWND hwnd)
{
PRINTDLG pdlg;
memset(&pdlg, 0, sizeof(PRINTDLG));
pdlg.lStructSize = sizeof(PRINTDLG);
pdlg.hDevMode = ghDevMode;
pdlg.hDevNames = gPsd.hDevNames;
pdlg.hwndOwner = hwnd;
pdlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC;
PrintDlg(&pdlg);
DoEvents();
return pdlg.hDC;
}
static VOID MnuPrint_Click(HWND hwnd)
{
HDC hdcPrinter;
int iWidth;
int iHeight;
DOCINFO di;
DIBSECTION ds;
LPPLOTTER lpPrintPlotter;
if (!IsWindow(hwnd))
return;
if (IsEmptyString(glpScreenPlotter->plotCommandData))
return;
hdcPrinter = GetPrinterDC(hwnd);
if (!hdcPrinter)
return;
lpPrintPlotter = Plotter_Clone(glpScreenPlotter);
if (NULL == lpPrintPlotter)
{
DeleteDC(hdcPrinter);
return;
}
ZeroMemory(&di, sizeof(di));
di.cbSize = sizeof(di);
di.lpszDocName = _T("Snap Shot");
if (StartDoc(hdcPrinter, &di) > 0)
{
if (StartPage(hdcPrinter) > 0)
{
lpPrintPlotter->antiAliasing = x4;
lpPrintPlotter->desiredPlotSize.cx = 1074;
lpPrintPlotter->desiredPlotSize.cy = 778;
HBITMAP memBMP = Plotter_Plot(lpPrintPlotter);
if (memBMP != NULL)
{
GetObject(memBMP, sizeof(ds), &ds);
iWidth = GetDeviceCaps(hdcPrinter, HORZRES);
iHeight = GetDeviceCaps(hdcPrinter, VERTRES);
if (iHeight > iWidth)
{
iHeight = iWidth * ds.dsBm.bmHeight / ds.dsBm.bmWidth;
}
HDC memDC = CreateCompatibleDC(hdcPrinter);
HBITMAP hbmOld = (HBITMAP)SelectObject(memDC, memBMP);
StretchBlt(hdcPrinter, gPsd.rtMargin.left, gPsd.rtMargin.top, iWidth - (gPsd.rtMargin.right + gPsd.rtMargin.left), iHeight - (gPsd.rtMargin.bottom + gPsd.rtMargin.top), memDC, 0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight, SRCCOPY);
SelectObject(memDC, hbmOld);
DeleteDC(memDC);
}
EndPage(hdcPrinter);
}
EndDoc(hdcPrinter);
}
Plotter_Destroy(lpPrintPlotter); DeleteDC(hdcPrinter);
}
static VOID MnuPageSetup_Click(HWND hwnd)
{
gPsd.lStructSize = sizeof(PAGESETUPDLG);
gPsd.hwndOwner = hwnd;
gPsd.hInstance = ghInstance;
gPsd.hDevMode = ghDevMode;
gPsd.Flags = PSD_MARGINS;
PageSetupDlg(&gPsd);
}
#pragma endregion mnuPrint
#pragma region mnuGetPlot
static LPSTR GetPlotData(LPVINSTRUMENT pInstr, ULONG Plotter_vi)
{
static LPSTR PlotData;
PlotData = ";";
ULONG actual;
int status;
int bufSize = MAX_PATH;
char buf[bufSize];
LPSTR OS_status = "24";
BOOL replied;
__try {
while (1)
{
status = viRead(Plotter_vi, (UCHAR *)buf, bufSize, &actual);
Sleep(1);
if (status < VI_SUCCESS) {
if (status == VI_ERROR_TMO)
{
break; }
else if (status == VI_ERROR_USER_BUF)
{
viClose(Plotter_vi);
viOpen(pInstr->rm, Join(2, StrToken(pInstr->address, ":", 1), "::INTFC"), 0, 1000, &Plotter_vi);
viClose(Plotter_vi);
return FALSE;
}
else
{
CheckStatus(Plotter_vi, status);
__leave;
}
}
buf[actual] = 0;
StrStrip(buf);
if (!IsEmptyString(buf))
{
_strupr(buf);
replied = FALSE;
if (0 == strncmp(buf, "OE", 2))
{
WriteLine(Plotter_vi, "0");
replied = TRUE;
}
else if (0 == strncmp(buf, "OH", 2))
{
WriteLine(Plotter_vi, "0,0,10000,7500");
replied = TRUE;
}
else if (0 == strncmp(buf, "OI", 2))
{
WriteLine(Plotter_vi, "7470A");
replied = TRUE;
}
else if (0 == strncmp(buf, "OP", 2))
{
WriteLine(Plotter_vi, "0,0,10000,7500");
replied = TRUE;
}
else if (0 == strncmp(buf, "OS", 2))
{
WriteLine(Plotter_vi, OS_status);
OS_status = "16";
replied = TRUE;
}
else {
if (!replied)
{
PlotData = Join(3, PlotData, buf, ";");
if ((NULL != strstr(buf, "SP;")) || (NULL != strstr(buf, "SP0;")))
break; }
}
} } } __except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
return "";
}
return PlotData;
}
void getScreenPlot8711A(HWND hwnd)
{
LPSTR PlotData;
PlotData = ";";
ULONG actual;
ULONG Plotter_vi;
int status, pltAddress;
int bufSize = MAX_PATH;
char buf[bufSize];
BOOL initialized = FALSE;
DWORD delay = 500; __try
{
status = viOpen(gInstrument.rm, Join(2, StrToken(gInstrument.address, ":", 1), "::INTFC"), 0, 500, &Plotter_vi);
CheckStatus(Plotter_vi, status);
WriteLine(gInstrument.vi, "HCOP:DEV2:COL ON");
WriteLine(gInstrument.vi, "HCOP:DEV2:LANG HPGL; PORT GPIB");
WriteLine(gInstrument.vi, "SYST:COMM:GPIB:HCOP:ADDR?");
Sleep(delay);
pltAddress = atoi(Read(gInstrument.vi, bufSize));
SetPrimaryAddress(Plotter_vi, pltAddress);
Sleep(2 * delay);
WriteLine(gInstrument.vi, "HCOP;*WAI"); Sleep(delay);
PassControl(Plotter_vi, gInstrument.address);
Sleep(delay);
while (1)
{
if (!initialized)
{
viRead(Plotter_vi, (UCHAR *)buf, bufSize, &actual);
initialized = TRUE;
}
status = viRead(Plotter_vi, (UCHAR *)buf, bufSize, &actual);
Sleep(1);
if (status < VI_SUCCESS) {
if (status == VI_ERROR_TMO)
{
buf[actual] = 0;
StrStrip(buf);
PlotData = Join(2, PlotData, buf);
break; }
else
{
CheckStatus(Plotter_vi, status);
__leave;
}
}
buf[actual] = 0; StrStrip(buf);
PlotData = Join(2, PlotData, buf);
} }
__finally
{
SendIFC(Plotter_vi);
viClose(Plotter_vi);
SendGoToLocal(gInstrument.vi);
}
if (IsEmptyString(PlotData))
return;
glpScreenPlotter->desiredPlotSize = GetDlgItemSize(hwnd, IDC_PICTUREBOX);
glpScreenPlotter->plotCommandData = PlotData;
Static_SetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP, Plotter_Plot(glpScreenPlotter));
}
void getScreenPlot8751A(HWND hwnd)
{
LPSTR PlotData;
ULONG Plotter_vi;
int status, pltAddress;
int bufSize = MAX_PATH;
char buf[bufSize];
DWORD delay = 500; __try
{
status = viOpen(gInstrument.rm, Join(2, StrToken(gInstrument.address, ":", 1), "::INTFC"), 0, 1000, &Plotter_vi);
CheckStatus(Plotter_vi, status);
WriteLine(gInstrument.vi, Join(2, "ADDRCONT ", StrToken(gInstrument.address, ":", 3)));
Sleep(delay);
WriteLine(gInstrument.vi, "ADDRPLOT?");
Sleep(delay);
pltAddress = atoi(Read(gInstrument.vi, bufSize));
SetPrimaryAddress(Plotter_vi, pltAddress);
Sleep(2 * delay);
WriteLine(gInstrument.vi, "PLOT");
Sleep(delay);
PassControl(Plotter_vi, gInstrument.address);
Sleep(delay);
PlotData = GetPlotData(&gInstrument, Plotter_vi);
}
__finally
{
SendIFC(Plotter_vi);
viClose(Plotter_vi);
SendGoToLocal(gInstrument.vi);
}
if (IsEmptyString(PlotData))
return;
glpScreenPlotter->desiredPlotSize = GetDlgItemSize(hwnd, IDC_PICTUREBOX);
glpScreenPlotter->plotCommandData = PlotData;
Static_SetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP, Plotter_Plot(glpScreenPlotter));
}
void getScreenPlotTDSxxx(HWND hwnd, ViUInt32 bufferSize)
{
LPSTR PlotData = "";
char oldSettings[MAX_PATH];
__try
{
WriteLine(gInstrument.vi, "HARDC?");
LPSTR strRes = Read(gInstrument.vi, MAX_PATH);
if (!IsEmptyString(strRes))
{
LPSTR *cmd;
INT count;
Split(strRes, ";", &cmd, &count);
sprintf(oldSettings, "HARDC:FORM %s\nHARDC:PORT %s\nHARDC:LAY %s\n", cmd[0], cmd[1], cmd[2]);
FreeSplitList(cmd);
}
WriteLine(gInstrument.vi, "HARDC:FORM HPG\nHARDC:PORT GPI\nHARDC:LAY LAN\n");
WriteLine(gInstrument.vi, "HARDC STAR");
ViStatus status;
ViUInt32 actual;
ViByte buf[bufferSize];
while (1)
{
status = viRead(gInstrument.vi, buf, bufferSize, &actual);
Sleep(100);
buf[actual] = 0;
if ((VI_ERROR_TMO == status) || IsEmptyString(buf))
break;
if (status >= VI_SUCCESS)
{
PlotData = Join(2, PlotData, buf);
}
}
}
__finally
{
WriteLine(gInstrument.vi, oldSettings);
SendGoToLocal(gInstrument.vi);
}
if (IsEmptyString(PlotData))
return;
glpScreenPlotter->desiredPlotSize = GetDlgItemSize(hwnd, IDC_PICTUREBOX);
glpScreenPlotter->plotCommandData = PlotData;
Static_SetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP, Plotter_Plot(glpScreenPlotter));
}
void getScreenPlot8753C(HWND hwnd)
{
LPSTR PlotData = "";
int bufSize = MAX_PATH;
char buf[bufSize];
int oldWarn, oldDone;
__try
{
WriteLine(gInstrument.vi, "BEEPWARN?");
oldWarn = atoi(Read(gInstrument.vi, bufSize));
WriteLine(gInstrument.vi, "BEEPDONE?");
oldDone = atoi(Read(gInstrument.vi, bufSize));
WriteLine(gInstrument.vi, "KEY 34");
Sleep(50);
WriteLine(gInstrument.vi, "OUTPPLOT");
for (int count = 0; count <= 4; count++)
{
if (count < 4) {
strncpy(buf, Read(gInstrument.vi, bufSize), bufSize);
PlotData = Join(2, PlotData, buf);
}
else
{
bufSize = 150000;
char buf[bufSize];
strncpy(buf, Read(gInstrument.vi, bufSize), bufSize);
PlotData = Join(2, PlotData, buf);
}
}
}
__finally
{
char cmdStr[MAX_PATH];
sprintf(cmdStr, "BEEPWARN%d; BEEPDONE%d", oldWarn, oldDone);
WriteLine(gInstrument.vi, cmdStr);
SendGoToLocal(gInstrument.vi);
}
if (IsEmptyString(PlotData))
return;
glpScreenPlotter->desiredPlotSize = GetDlgItemSize(hwnd, IDC_PICTUREBOX);
glpScreenPlotter->plotCommandData = PlotData;
Static_SetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP, Plotter_Plot(glpScreenPlotter));
}
void getScreenPlot8753D(HWND hwnd)
{
LPBYTE PlotData;
ULONG count;
int bufSize = MAX_PATH;
char buf[bufSize];
int readBuff = 150000;
int oldWarn, oldDone, oldStamp;
__try
{
WriteLine(gInstrument.vi, "BEEPWARN?");
oldWarn = atoi(Read(gInstrument.vi, bufSize));
WriteLine(gInstrument.vi, "BEEPDONE?");
oldDone = atoi(Read(gInstrument.vi, bufSize));
WriteLine(gInstrument.vi, "TIMESTAM?");
oldStamp = atoi(Read(gInstrument.vi, bufSize));
WriteLine(gInstrument.vi, "TIMESTAM OFF");
WriteLine(gInstrument.vi, "KEY 34");
Sleep(50);
WriteLine(gInstrument.vi, "OUTPPLOT");
PlotData = ReadBytes(gInstrument.vi, readBuff, &count);
PlotData[count] = '\0';
}
__finally
{
char cmdStr[MAX_PATH];
sprintf(cmdStr, "BEEPWARN%d; BEEPDONE%d; TIMESTAM%d", oldWarn, oldDone, oldStamp);
WriteLine(gInstrument.vi, cmdStr);
SendGoToLocal(gInstrument.vi);
}
if (IsEmptyString((LPSTR)PlotData))
return;
glpScreenPlotter->desiredPlotSize = GetDlgItemSize(hwnd, IDC_PICTUREBOX);
glpScreenPlotter->plotCommandData = (LPSTR)PlotData;
Static_SetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP, Plotter_Plot(glpScreenPlotter));
}
static VOID MnuOpenConfig_Click(HWND hwnd)
{
__try
{
TCHAR filename[MAX_PATH] = {0};
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = _T("Instrument Snapshot Configuration (*.cfg)\0*.cfg\0All Files (*.*)\0*.*\0");
ofn.lpstrTitle = _T("Open configuration file");
ofn.lpstrInitialDir = gConfigDirectory;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = _T("cfg");
if (GetOpenFileName(&ofn))
{
HWND hGrid = GetDlgItem(hwnd,IDC_GRID);
DoEvents();
PlotterConfig_LoadFromFile(glpScreenPlotter, filename);
Plotter_UpdateGrid(glpScreenPlotter, hGrid); PropGrid_SetCurSel(hGrid,0);
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
}
}
static VOID MnuSaveConfig_Click(HWND hwnd)
{
__try
{
OPENFILENAME ofn;
TCHAR filename[MAX_PATH] = {0};
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = _T("Instrument Snapshot Configuration (*.cfg)\0*.cfg\0All Files (*.*)\0*.*\0");
ofn.lpstrTitle = _T("Save configuration file");
ofn.lpstrInitialDir = gConfigDirectory;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
ofn.lpstrDefExt = _T("cfg");
if (GetSaveFileName(&ofn))
{
DoEvents(); PlotterConfig_SaveToFile(glpScreenPlotter, filename);
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
}
}
static VOID MnuGetPlot_Click(HWND hwnd)
{
HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
HMENU hMenu = GetMenu(hwnd);
EnableMenuItem(hMenu, MNU_GETPLOT, MF_GRAYED);
EnableMenuItem(hMenu, MNU_REFRESHPLOT, MF_GRAYED);
EnableMenuItem(hMenu, MNU_PRINT, MF_GRAYED);
EnableMenuItem(hMenu, MNU_SAVE, MF_GRAYED);
ToolBar_EnableButton(ghToolBar, MNU_GETPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_REFRESHPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_PRINT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_SAVE, FALSE);
DrawMenuBar(hwnd); __try
{
Static_SetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP, NULL);
Refresh(hwnd);
while (1) {
if (0 == _tcsnicmp(gInstrument.model, _T("8711A"), 5))
{
getScreenPlot8711A(hwnd);
break;
}
if (0 == _tcsnicmp(gInstrument.model, _T("8751A"), 5))
{
getScreenPlot8751A(hwnd);
break;
}
if (0 == _tcsnicmp(gInstrument.model, _T("8753C"), 5))
{
getScreenPlot8753C(hwnd);
break;
}
if (0 == _tcsnicmp(gInstrument.model, _T("8753D"), 5))
{
getScreenPlot8753D(hwnd);
break;
}
if (0 == _tcsnicmp(gInstrument.model, _T("4396A"), 5))
{
getScreenPlot8751A(hwnd);
break;
}
if (0 == _tcsnicmp(gInstrument.model, _T("TDS 420"), 7)
|| 0 == _tcsnicmp(gInstrument.model, _T("TDS 460A"), 8)
|| 0 == _tcsnicmp(gInstrument.model, _T("TDS 640A"), 8))
{
getScreenPlotTDSxxx(hwnd, 2048);
break;
}
if (0 == _tcsnicmp(gInstrument.model, _T("TDS 754D"), 8)
|| 0 == _tcsnicmp(gInstrument.model, _T("TDS 754C"), 8)
|| 0 == _tcsnicmp(gInstrument.model, _T("TDS 740"), 7))
{
getScreenPlotTDSxxx(hwnd, 4096); break;
}
{
MessageBox(NULL, _T("No such model number supported"), _T("Error"), MB_OK | MB_ICONERROR | MB_TOPMOST);
}
break;
}
} __except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
}
SetCursor(hCur);
EnableMenuItem(hMenu, MNU_GETPLOT, MF_ENABLED);
ToolBar_EnableButton(ghToolBar, MNU_GETPLOT, TRUE);
if(NULL != glpScreenPlotter->plotCommandData)
{
EnableMenuItem(hMenu, MNU_REFRESHPLOT, MF_ENABLED);
EnableMenuItem(hMenu, MNU_PRINT, MF_ENABLED);
EnableMenuItem(hMenu, MNU_SAVE, MF_ENABLED);
ToolBar_EnableButton(ghToolBar, MNU_REFRESHPLOT, TRUE);
ToolBar_EnableButton(ghToolBar, MNU_PRINT, TRUE);
ToolBar_EnableButton(ghToolBar, MNU_SAVE, TRUE);
}
DrawMenuBar(hwnd); }
static VOID MnuRefreshPlot_Click(HWND hwnd)
{
if (IsEmptyString(glpScreenPlotter->plotCommandData))
return;
glpScreenPlotter->desiredPlotSize = GetDlgItemSize(hwnd, IDC_PICTUREBOX);
Static_SetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP, Plotter_Plot(glpScreenPlotter));
}
#pragma endregion mnuGetPlot
static VOID ReadHPGL(LPTSTR szFileName)
{
HANDLE hFile;
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD numread, length;
if(0 == (length = GetFileSize(hFile, 0)))
return;
length += 1;
BYTE buf[length];
ReadFile(hFile, &buf, NELEMS(buf), &numread, 0);
glpScreenPlotter->plotCommandData = Join(1,buf);
}
CloseHandle(hFile);
}
static VOID MnuImportHPGL_Click(HWND hwnd)
{
HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
HMENU hMenu = GetMenu(hwnd);
BOOL fGetPlotGreyed = MF_GRAYED & GetMenuState(hMenu, MNU_GETPLOT, MF_BYCOMMAND);
EnableMenuItem(hMenu, MNU_GETPLOT, MF_GRAYED);
EnableMenuItem(hMenu, MNU_REFRESHPLOT, MF_GRAYED);
EnableMenuItem(hMenu, MNU_PRINT, MF_GRAYED);
EnableMenuItem(hMenu, MNU_SAVE, MF_GRAYED);
ToolBar_EnableButton(ghToolBar, MNU_GETPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_REFRESHPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_PRINT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_SAVE, FALSE);
DrawMenuBar(hwnd);
__try
{
TCHAR filename[MAX_PATH] = {0};
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Raw HPGL (*.plt)\0*.plt\0All Files (*.*)\0*.*\0";
ofn.lpstrTitle = "Open HPGL plot file";
ofn.lpstrInitialDir = gPlotDirectory;;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = _T("plt");
if (GetOpenFileName(&ofn))
{
ReadHPGL(filename);
MnuRefreshPlot_Click(hwnd);
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
}
SetCursor(hCur);
if(!fGetPlotGreyed)
{
EnableMenuItem(hMenu, MNU_GETPLOT, MF_ENABLED);
ToolBar_EnableButton(ghToolBar, MNU_GETPLOT, TRUE);
}
if(NULL != glpScreenPlotter->plotCommandData)
{
EnableMenuItem(hMenu, MNU_REFRESHPLOT, MF_ENABLED);
EnableMenuItem(hMenu, MNU_PRINT, MF_ENABLED);
EnableMenuItem(hMenu, MNU_SAVE, MF_ENABLED);
ToolBar_EnableButton(ghToolBar, MNU_REFRESHPLOT, TRUE);
ToolBar_EnableButton(ghToolBar, MNU_PRINT, TRUE);
ToolBar_EnableButton(ghToolBar, MNU_SAVE, TRUE);
}
DrawMenuBar(hwnd); }
static VOID WriteHPGL(LPTSTR szFileName)
{
INT iLen = strlen(glpScreenPlotter->plotCommandData) + 1;
HANDLE hFile; DWORD dwBytesWritten;
hFile = CreateFile(szFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
MessageBox(NULL, "Unable to open file", "OpenFileError", MB_OK | MB_ICONERROR | MB_TOPMOST);
return;
}
WriteFile(hFile, glpScreenPlotter->plotCommandData, iLen, &dwBytesWritten, NULL);
CloseHandle(hFile);
}
static VOID MnuSavePlot_Click(HWND hwnd)
{
OPENFILENAME ofn;
TCHAR szFileName[MAX_PATH] = { 0 };
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Png Image (*.png)\0*.png\0Gif Image (*.gif)\0*.gif\0JPeg Image (*.jpg)\0*.jpg\0Tiff Image (*.tif)\0*.tif\0Bitmap Image (*.bmp)\0*.bmp\0Raw HPGL (*.plt)\0*.plt\0All Files (*.*)\0*.*\0";
ofn.lpstrTitle = "Save an Image File";
ofn.lpstrFile = szFileName;
ofn.lpstrInitialDir = gPlotDirectory;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "png";
if (GetSaveFileName(&ofn))
{
DoEvents();
if (0 != _tcsncmp(szFileName, _T(""), NELEMS(szFileName)))
{
HBITMAP hbmp = Static_GetImage(GetDlgItem(hwnd, IDC_PICTUREBOX), IMAGE_BITMAP);
if (NULL != hbmp)
{
if (6 == ofn.nFilterIndex) {
WriteHPGL(szFileName);
}
else
{
LPIMAGEFILE lpi = New_ImageFile();
if (NULL != lpi)
{
switch (ofn.nFilterIndex)
{
case 5: {
ImageFile_SaveBMP(lpi, hbmp, szFileName);
}
case 4: {
BOOL fCompressLZW = TRUE;
ImageFile_SaveTIFF(lpi, hbmp, fCompressLZW, szFileName);
}
break;
case 3: {
UINT uQuality = 100;
ImageFile_SaveJPEG(lpi, hbmp, uQuality, szFileName);
}
break;
case 2: {
ImageFile_SaveGIF(lpi, hbmp, szFileName);
}
break;
case 1: default:
{
ImageFile_SavePNG(lpi, hbmp, szFileName);
}
}
ImageFile_Destroy(lpi);
} }
}
}
}
}
static VOID MnuConnection_Click(HWND hwnd)
{
HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
__try
{
HMENU mnuMain = GetMenu(hwnd);
gInstrument.supportedModels = supportedModels;
gInstrument.supportedModelsCount = NELEMS(supportedModels) + 1;
gInstrument.instrumentClass = "Supported Instrument";
DlgConnect_Show(ghInstance, hwnd, &gInstrument);
if (!gInstrument.isConnected)
{
EnableMenuItem(mnuMain, MNU_GETPLOT, MF_GRAYED);
EnableMenuItem(mnuMain, MNU_REFRESHPLOT, MF_GRAYED);
EnableMenuItem(mnuMain, MNU_PRINT, MF_GRAYED);
EnableMenuItem(mnuMain, MNU_SAVE, MF_GRAYED);
ToolBar_EnableButton(ghToolBar, MNU_GETPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_REFRESHPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_PRINT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_SAVE, FALSE);
DrawMenuBar(hwnd); }
else
{
DoEvents();
SendGoToLocal(gInstrument.vi);
EnableMenuItem(mnuMain, MNU_GETPLOT, MF_ENABLED);
ToolBar_EnableButton(ghToolBar, MNU_GETPLOT, TRUE);
DrawMenuBar(hwnd); }
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
SetLastError(GetExceptionCode());
ErrorHandler();
}
SetCursor(hCur); }
static VOID Main_OnClose(HWND hwnd)
{
Plotter_Destroy(glpScreenPlotter);
EndDialog(hwnd, 0);
}
static VOID Main_OnCommand(HWND hwnd, INT id, HWND hwndCtl, UINT codeNotify)
{
PropGrid_SetCurSel(GetDlgItem(hwnd,IDC_GRID),0);
switch (id)
{
case MNU_OPENCONFIG:
MnuOpenConfig_Click(hwnd);
break;
case MNU_SAVECONFIG:
MnuSaveConfig_Click(hwnd);
break;
case MNU_GETPLOT:
MnuGetPlot_Click(hwnd);
break;
case MNU_REFRESHPLOT:
MnuRefreshPlot_Click(hwnd);
break;
case MNU_IMPORT_HPGL:
MnuImportHPGL_Click(hwnd);
break;
case MNU_SAVE:
MnuSavePlot_Click(hwnd);
break;
case MNU_SNAPSHOT_HELP:
MnuSnapshotHelp_Click(hwnd);
break;
case MNU_ABOUT:
MnuAbout_Click(hwnd, id);
break;
case MNU_CONNECTION:
MnuConnection_Click(hwnd);
break;
case MNU_PAGESETUP:
MnuPageSetup_Click(hwnd);
break;
case MNU_PRINT:
MnuPrint_Click(hwnd);
break;
case MNU_EXIT:
Main_OnClose(hwnd);
break;
}
}
static BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
GetModuleFileName(ghInstance, gParentDirectory, NELEMS(gParentDirectory));
LPTSTR p = &gParentDirectory[_tcslen(gParentDirectory) + 1];
while(p && *p != _T('\\'))
p--;
*p = _T('\0');
_stprintf(gConfigDirectory, NELEMS(gConfigDirectory),
#ifdef _UNICODE
_T("%ls\\Configurations"),
#else
_T("%s\\Configurations"),
#endif
gParentDirectory);
if (!DirectoryExists(gConfigDirectory))
CreateDirectory(gConfigDirectory, NULL);
_stprintf(gPlotDirectory, NELEMS(gPlotDirectory),
#ifdef _UNICODE
_T("%ls\\Plots"),
#else
_T("%s\\Plots"),
#endif
gParentDirectory);
if (!DirectoryExists(gPlotDirectory))
CreateDirectory(gPlotDirectory, NULL);
InitPrintDevMode();
glpScreenPlotter = New_Plotter();
ghToolBar = CreateToolbar_OwnerDrawMenu(hwnd, gfHires ? IDR_BMP_MNUES_HI : IDR_BMP_MNUES);
if (NULL == ghToolBar)
return FALSE;
HMENU mnuMain = GetMenu(hwnd);
EnableMenuItem(mnuMain, MNU_GETPLOT, MF_GRAYED);
EnableMenuItem(mnuMain, MNU_REFRESHPLOT, MF_GRAYED);
EnableMenuItem(mnuMain, MNU_PRINT, MF_GRAYED);
EnableMenuItem(mnuMain, MNU_SAVE, MF_GRAYED);
ToolBar_EnableButton(ghToolBar, MNU_GETPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_REFRESHPLOT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_PRINT, FALSE);
ToolBar_EnableButton(ghToolBar, MNU_SAVE, FALSE);
DrawMenuBar(hwnd);
ghGrid = GetDlgItem(hwnd, IDC_GRID);
ghPictureBox = GetDlgItem(hwnd, IDC_PICTUREBOX);
RECT rc = { 0 };
GetClientRect(ghGrid, &rc);
guDrag = rc.right + 5;
Plotter_UpdateGrid(glpScreenPlotter, ghGrid);
ShowWindow(ghGrid, SW_SHOW);
InstallWindowStateHandler(hwnd, gParentDirectory);
return FALSE;
}
#pragma region WM_SIZE and Splitter
static VOID Main_OnSize(HWND hwnd, UINT state, int cx, int cy)
{
FORWARD_WM_SIZE(ghToolBar, state, cx, cy, SendMessage);
RECT rc = { 0 };
GetWindowRect(ghToolBar, &rc);
LONG lToolHeight = HEIGHT(rc);
MoveWindow(ghGrid, 0, lToolHeight + 1, guDrag - 1, cy - (lToolHeight + 2), TRUE);
MoveWindow(ghPictureBox, guDrag + 1, lToolHeight + 1, cx - (guDrag + 1), cy - (lToolHeight + 2), TRUE);
Refresh(hwnd);
}
static VOID Main_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
if (isOverSlider(x))
{
RECT rcWindow;
GetWindowRect(hwnd, &rcWindow);
rcWindow.left += 10;
rcWindow.right -= 10;
SetCapture(hwnd);
ClipCursor(&rcWindow);
gfDrag = TRUE;
GetWindowRect(ghToolBar, &rcWindow);
RECT rcClient;
GetClientRect(ghGrid, &rcClient);
nDivTop = HEIGHT(rcWindow) + 2;
nDivBtm = nDivTop + HEIGHT(rcClient);
nOldDivX = x;
HDC hdc = GetDC(hwnd);
HPEN hOld = SelectObject(hdc, CreatePen(PS_SOLID, 3, 0));
InvertLine(hdc, x, nDivTop, x, nDivBtm);
DeleteObject(SelectObject(hdc, hOld));
ReleaseDC(hwnd, hdc);
}
}
static VOID Main_OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags)
{
if (gfDrag)
{
gfDrag = FALSE;
ReleaseCapture();
ClipCursor(NULL);
HDC hdc = GetDC(hwnd);
HPEN hOld = SelectObject(hdc, CreatePen(PS_SOLID, 3, 0));
InvertLine(hdc, x, nDivTop, x, nDivBtm);
DeleteObject(SelectObject(hdc, hOld));
ReleaseDC(hwnd, hdc);
guDrag = x;
RECT rc;
GetClientRect(hwnd, &rc);
Main_OnSize(hwnd, 0, WIDTH(rc), HEIGHT(rc));
MnuRefreshPlot_Click(hwnd);
}
}
static VOID Main_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
{
if (isOverSlider(x))
SetCursor(LoadCursor(NULL, IDC_SIZEWE));
else
SetCursor(LoadCursor(NULL, IDC_ARROW));
if (gfDrag)
{
HDC hdc = GetDC(hwnd);
HPEN hOld = SelectObject(hdc, CreatePen(PS_SOLID, 3, 0));
InvertLine(hdc, nOldDivX, nDivTop, nOldDivX, nDivBtm);
InvertLine(hdc, x, nDivTop, x, nDivBtm);
DeleteObject(SelectObject(hdc, hOld));
ReleaseDC(hwnd, hdc);
nOldDivX = x;
}
}
#pragma endregion //WM_SIZE and Splitter
static VOID Main_OnGetMinMaxInfo(HWND hwnd, LPMINMAXINFO lpMinMaxInfo)
{
lpMinMaxInfo->ptMinTrackSize.x = 546; lpMinMaxInfo->ptMinTrackSize.y = 444;
}
static BOOL CALLBACK Main_DlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
HANDLE_DLGMSG(hwndDlg, WM_HELP, Main_OnHelp);
HANDLE_DLGMSG(hwndDlg, WM_CLOSE, Main_OnClose);
HANDLE_DLGMSG(hwndDlg, WM_COMMAND, Main_OnCommand);
HANDLE_DLGMSG(hwndDlg, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_DLGMSG(hwndDlg, WM_SIZE, Main_OnSize);
HANDLE_DLGMSG(hwndDlg, WM_LBUTTONDOWN, Main_OnLButtonDown);
HANDLE_DLGMSG(hwndDlg, WM_LBUTTONUP, Main_OnLButtonUp);
HANDLE_DLGMSG(hwndDlg, WM_MOUSEMOVE, Main_OnMouseMove);
HANDLE_DLGMSG(hwndDlg, WM_GETMINMAXINFO, Main_OnGetMinMaxInfo);
HANDLE_DLGMSG(hwndDlg, WM_NOTIFY, Main_OnNotify);
case WM_NOTIFYFORMAT:
#ifdef UNICODE
return SetDlgMsgResult(hwndDlg, WM_NOTIFYFORMAT, NFR_UNICODE);
#else
return SetDlgMsgResult(hwndDlg, WM_NOTIFYFORMAT, NFR_ANSI);
#endif
default:
return FALSE;
}
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
INITCOMMONCONTROLSEX icc;
WNDCLASSEX wcx;
ghInstance = hInstance;
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES ;
InitCommonControlsEx(&icc);
InitPropertyGrid(hInstance);
wcx.cbSize = sizeof(wcx);
if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
return 0;
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wcx.lpszClassName = _T("SnapShotClass");
if (!RegisterClassEx(&wcx))
return 0;
gfHires = NULL == strstr(lpszCmdLine, "/b");
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)Main_DlgProc);
}
|