📄 mainwindow.cpp
字号:
SetROP2(hMainWndDC, R2_NOTXORPEN);
SetBkColor(hMainWndDC, (COLORREF)(LogBrush.lbColor));
SetBkMode(hMainWndDC, OPAQUE);
NewR.left = NewPoint.x - 4;
NewR.top = NewPoint.y - 4;
NewR.right = NewPoint.x + 4;
NewR.bottom = NewPoint.y + 4;
OldR.left = OldPoint->x - 4;
OldR.top = OldPoint->y - 4;
OldR.right = OldPoint->x + 4;
OldR.bottom = OldPoint->y + 4;
Rectangle(hMainWndDC, OldR.left, OldR.top, OldR.right, OldR.bottom);
Rectangle(hMainWndDC, NewR.left, NewR.top, NewR.right, NewR.bottom);
DeleteObject(hPen);
SelectObject(hMainWndDC, hOldPen);
DeleteObject(hBrush);
SelectObject(hMainWndDC, hOldBrush);
RestoreDC(hMainWndDC, Index);
*OldPoint = NewPoint;
}
bool CMainWindow::ShowLineWeight(bool IsShow)
{
optionsCAD.IsShowLineWeight = IsShow;
if ((CADImage != NULL) && (SetShowLineWeightCAD(CADImage, (IsShow ? 1: 0)) > 0))
{
RePaint();
return true;
}
return false;
}
bool CMainWindow::SetIsNearestPointMode(bool Checked)
{
optionsCAD.IsNearestPointMode = Checked;
if (CADImage != NULL)
{
RePaint();
return true;
}
return false;
}
bool CMainWindow::SetNullLineWidth(int NullLineWidth)
{
optionsCAD.NullLineWidth = NullLineWidth;
if ((CADImage != NULL) && (SetNullLineWidthCAD(CADImage, optionsCAD.NullLineWidth) > 0))
{
RePaint();
return true;
}
return false;
}
void CMainWindow::StoppingLoad()
{
StopLoading();
}
bool CMainWindow::SetOptionsCAD(CADOPTIONS CADOpts)
{
if (CADImage != NULL)
{
optionsCAD = CADOpts;
SetShowLineWeightCAD(CADImage, (optionsCAD.IsShowLineWeight ? 1: 0));
SetNullLineWidthCAD(CADImage, optionsCAD.NullLineWidth);
if (optionsCAD.IsDrawingBox)
SetDrawingBox();
else
ResetDrawingBox();
return true;
}
return false;
}
bool CMainWindow::GetIsShowLineWeight()
{
return optionsCAD.IsShowLineWeight;
}
bool CMainWindow::GetIsDrawingBox()
{
return optionsCAD.IsDrawingBox;
}
bool CMainWindow::GetIsNearestPointMode()
{
return optionsCAD.IsNearestPointMode;
}
bool CMainWindow::GetIsPocessing()
{
return bIsPocessing;
}
int CMainWindow::GetNullLineWidth()
{
return optionsCAD.NullLineWidth;
}
void CMainWindow::DestroyLayersDlg()
{
if (hwndLayersDlg != NULL)
{
DestroyWindow(hwndLayersDlg);
hwndLayersDlg = NULL;
}
}
void CMainWindow::FillLayersList()
{
if (CADImage == NULL)
return;
DestroyLayersDlg();
ShowLayersDlg(false);
int i, Count, Vis;
LVCOLUMN lvCol;
LVITEM lvItem;
HANDLE hLayer;
HWND hwndList;
DXFDATA dxfData;
Count = CADLayerCount(CADImage);
hwndList = GetDlgItem(hwndLayersDlg, IDC_LISTLAYERS);
ListView_DeleteAllItems(hwndList);
ZeroMemory(&lvCol, sizeof(lvCol));
// Initialize the columns
lvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvCol.fmt = LVCFMT_LEFT;
lvCol.cx = 235;
lvCol.pszText = "Layers names";
ListView_InsertColumn(hwndList, 0, &lvCol);
ListView_SetItemCount(hwndList, Count);
IsAppChangingList = true;
ListView_SetExtendedListViewStyle(hwndList, LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES);
for (i= 0; i< Count; i++)
{
hLayer = CADLayer(CADImage, i, &dxfData);
Vis = (dxfData.Flags & 1) == 0;
ZeroMemory(&lvItem, sizeof(lvItem));
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.iItem = i;
lvItem.iSubItem = 0;
lvItem.pszText = dxfData.Text;
lvItem.lParam = (LPARAM) hLayer;
ListView_InsertItem(hwndList, &lvItem);
ListView_SetItemState(hwndList, i, INDEXTOSTATEIMAGEMASK(UINT((Vis)+1)), LVIS_STATEIMAGEMASK);
}
IsAppChangingList = false;
}
/*
AboutDialogProc
*/
BOOL CALLBACK CMainWindow::AboutDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
break;
case IDCC_MAILTO_SG:
ShellExecute(hDlg, "open", "Mailto:info@cadsofttools.com", NULL, NULL, SW_SHOW);
break;
case IDCC_HOMEPAGE_SG:
ShellExecute(hDlg, "open", "http://www.cadsofttools.com/", NULL, NULL, SW_SHOW);
break;
}
break;
}
return FALSE;
}
/*
ControlProc
*/
LRESULT CALLBACK CMainWindow::ControlProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
{
HDC hdc;
RECT rect;
char text[300];
PAINTSTRUCT ps;
HFONT hOldF, hF = CreateFont(8, 0, 0, 0, 400, FALSE, 1, 0, RUSSIAN_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "MS Sans Serif");
GetWindowText(hWnd, text, sizeof(text));
GetClientRect(hWnd, &rect);
hdc = BeginPaint(hWnd, &ps);
hOldF = (HFONT) SelectObject(hdc, hF);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 0, 255));
DrawText(hdc, text, -1, &rect, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
DeleteObject(hF);
SelectObject(hdc, hOldF);
EndPaint(hWnd, &ps);
break;
}
case WM_LBUTTONDOWN :
SendMessage(GetParent(hWnd), WM_COMMAND, GetWindowLong (hWnd, GWL_ID), (LPARAM) hWnd);
break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}
/*
LayersDialogProc
*/
BOOL CALLBACK CMainWindow::LayersDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
if (hDlg != hwndLayersDlg)
return FALSE;
HWND hwndMainWnd = GetParent(hwndLayersDlg);
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
CheckMenuItem(GetMenu(hwndMainWnd), IDM_OPTIONSLAYERS, MF_UNCHECKED);
ShowWindow(hwndLayersDlg, SW_HIDE);
break;
}
case WM_MOVE:
InvalidateRect(hwndMainWnd, NULL, TRUE);
break;
case WM_NOTIFY:
switch (wParam)
{
case IDC_LISTLAYERS:
NMHDR nmHdr = *((LPNMHDR) lParam);
if (!IsAppChangingList && (nmHdr.code == LVN_ITEMCHANGED))
{
NMLISTVIEW nmListViewItem = *((LPNMLISTVIEW)lParam);
int Vis = (::SendMessage(GetDlgItem(hwndLayersDlg, IDC_LISTLAYERS), LVM_GETITEMSTATE, nmListViewItem.iItem, LVIS_STATEIMAGEMASK) >> 12) - 1;
CADLayerVisible((HANDLE)(nmListViewItem.lParam), Vis);
InvalidateRect(hwndMainWnd, NULL, TRUE);
}
break;
}
}
return FALSE;
}
char *double_to_char(double number)
{
char *buffer, *temp;
int decimal_spot, sign, count, current_location = 0;
int PRECISION = 8;
temp = fcvt(number, PRECISION, &decimal_spot, &sign);
if ((int)strlen (temp) > PRECISION)
buffer = (char *) malloc (strlen (temp) + 3);
else
buffer = (char *) malloc (PRECISION + 3);
/* Add negative sign if required. */
if (sign)
buffer [current_location++] = '-' ;
/* Place decimal point in the correct location. */
if (decimal_spot > 0)
{
strncpy (&buffer [current_location], temp, decimal_spot) ;
buffer [decimal_spot + current_location] = '.' ;
strcpy (&buffer [decimal_spot + current_location + 1],
&temp [decimal_spot]) ;
}
else
{
buffer [current_location] = '.' ;
for(count = current_location;
count<abs(decimal_spot)+current_location; count++)
buffer [count + 1] = '0' ;
strcpy (&buffer [count + 1], temp) ;
}
return (buffer) ;
}
/*
PropertiesDialogProc
*/
BOOL CALLBACK CMainWindow::PropertiesDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
if (hDlg != hwndPropertiesDlg)
return FALSE;
const MAX_WIDTH_VALUE = 100;
HWND hwndMainWnd = GetParent(hDlg);
HWND hwndDlgItem = GetDlgItem(hDlg, IDE_NULLLINEWIDTH);
CMainWindow* pMainWindow = (CMainWindow*) GetWindowLong(hDlg, GWL_USERDATA);
char text[200];
char *cBorderSize;
switch (message)
{
case WM_CREATE:
return TRUE;
case WM_INITDIALOG:
return TRUE;
case WM_SHOWWINDOW:
ZeroMemory(text, 200);
SetWindowText(hwndDlgItem, itoa(pMainWindow->GetNullLineWidth(), text, 10));
if ((lParam != SW_OTHERZOOM) && (lParam != SW_OTHERUNZOOM))
if (wParam)
{
SendDlgItemMessage(hDlg, IDR_GLOBAL, BM_SETCHECK, (WPARAM)(pMainWindow->iBorderType ^ 1), 0);
SendDlgItemMessage(hDlg, IDR_RATIO, BM_SETCHECK, (WPARAM)(pMainWindow->iBorderType), 0);
cBorderSize = double_to_char(pMainWindow->dBorderSize);
SetWindowText(GetDlgItem(hDlg, IDE_BORDERSIZE), cBorderSize);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
if (pMainWindow != NULL)
{
ZeroMemory(text, 200);
GetWindowText(hwndDlgItem, text, 200);
pMainWindow->SetNullLineWidth(atoi(text));
pMainWindow->iBorderType = SendDlgItemMessage(hDlg, IDR_RATIO, BM_GETCHECK, 0, 0);
GetWindowText(GetDlgItem(hDlg, IDE_BORDERSIZE), text, 200);
pMainWindow->dBorderSize = atof(text);
pMainWindow->SetBorder();
}
case IDCANCEL:
CheckMenuItem(GetMenu(hwndMainWnd), IDM_OPTIONSPROPERTIES, MF_UNCHECKED);
ShowWindow(hDlg, SW_HIDE);
break;
case IDC_NEARESTPOINTMODE:
if (pMainWindow != NULL)
{
if (!pMainWindow->GetIsDrawingBox())
pMainWindow->SetIsNearestPointMode((SendDlgItemMessage(hwndPropertiesDlg, IDC_NEARESTPOINTMODE, BM_GETCHECK, 0, 0)) != 0);
else {
SendDlgItemMessage(hwndPropertiesDlg, IDC_NEARESTPOINTMODE, BM_SETCHECK, 0, 1);
MessageBox(hwndMainWnd, "Please reset drawing box for activation \"Nearest point mode\".", "Warning", MB_ICONWARNING);
}
}
break;
case IDR_GLOBAL:
pMainWindow->iBorderType = SendDlgItemMessage(hDlg, IDR_GLOBAL, BM_GETCHECK, 0, 0) ^ 1;
SendDlgItemMessage(hDlg, IDR_RATIO, BM_SETCHECK, (WPARAM)(pMainWindow->iBorderType), 0);
if (pMainWindow->iBorderType == 1)
strcpy((char *)text, "%");
else
strcpy((char *)text, "units");
SetWindowText(GetDlgItem(hDlg, IDL_BORDERUNITS), (LPCTSTR)text);
break;
case IDR_RATIO:
pMainWindow->iBorderType = SendDlgItemMessage(hDlg, IDR_RATIO, BM_GETCHECK, 0, 0);
SendDlgItemMessage(hDlg, IDR_GLOBAL, BM_SETCHECK, (WPARAM)(pMainWindow->iBorderType ^ 1), 0);
if (pMainWindow->iBorderType == 1)
strcpy((char *)text, "%");
else
strcpy((char *)text, "units");
SetWindowText(GetDlgItem(hDlg, IDL_BORDERUNITS), (LPCTSTR)text);
break;
}
case WM_MOVE:
InvalidateRect(hwndMainWnd, NULL, TRUE);
break;
case WM_NOTIFY:
{
LPNMHDR pnmh= (LPNMHDR) lParam;
if (pnmh->code == UDN_DELTAPOS)
{
LPNMUPDOWN code= (LPNMUPDOWN) lParam;
if (code->iDelta > 0)
{
ZeroMemory(text, 200);
GetWindowText(hwndDlgItem, text, 200);
SetWindowText(hwndDlgItem, itoa(atoi(text) - 1, text, 10));
}
else
{
ZeroMemory(text, 200);
GetWindowText(hwndDlgItem, text, 200);
SetWindowText(hwndDlgItem, itoa(atoi(text) + 1, text, 10));
}
// Correcting value
ZeroMemory(text, 200);
GetWindowText(hwndDlgItem, text, 200);
if (strlen(text) > 5 || atoi(text) > MAX_WIDTH_VALUE)
SetWindowText(hwndDlgItem, "100");
else if (strlen(text) == 0 || atoi(text) < 0)
SetWindowText(hwndDlgItem, "0");
}
break;
}
}
return FALSE;
}
/*
ProgressDialogProc
*/
BOOL CALLBACK CMainWindow::ProgressDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
if (hDlg != hwndProgressDlg)
return FALSE;
CMainWindow* pMainWindow = (CMainWindow*) GetWindowLong(hDlg, GWL_USERDATA);
switch (message)
{
case WM_INITDIALOG:
break;
case IDM_PROGRESS:
pMainWindow->SetProgressValue((BYTE) wParam);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDB_CANCEL_PROGRESS:
pMainWindow->StoppingLoad();
break;
}
}
return FALSE;
}
/*
PictureDialogProc
*/
BOOL CALLBACK CMainWindow::PictureDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC dlgDC;
HANDLE hMemDIB;
BOOL res = FALSE;
if (hDlg != hwndPictureDlg)
return FALSE;
CMainWindow* pMainWindow = (CMainWindow*) GetWindowLong(hDlg, GWL_USERDATA);
switch (message)
{
case WM_INITDIALOG:
break;
case WM_SHOWWINDOW:
break;
case WM_PAINT:
RECT R;
GetClientRect(hDlg, &R);
dlgDC = GetDC(hDlg);
R.bottom = int(R.top + (R.right - R.left) * pMainWindow->fKoef);
#ifndef CS_STATIC_DLL
hMemDIB = pMainWindow->DrawCADtoDIB(pMainWindow->CADImage, &R);
#else
hMemDIB = DrawCADtoDIB(pMainWindow->CADImage, &R);
#endif
pMainWindow->StretchDrawDIB(hMemDIB, dlgDC, &R);
ReleaseDC(hDlg, dlgDC);
break;
case WM_SIZE:
GetClientRect(hDlg, &R);
InvalidateRect(hDlg, &R, true);
break;
case WM_COMMAND:
break;
//switch (LOWORD(wParam))
case WM_CLOSE:
EndDialog(hDlg, LOWORD(wParam));
break;
}
return res;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -