DEV Community

海前 王
海前 王

Posted on

virtual table

include "n.h"

include

include "nn.h"

include"resource.h"

myapp theapp;

BOOL myapp::InitApplication()
{/*
m_pMainWnd = new main_frame;

m_pMainWnd->SendMessage(WM_CUSTOM_MESSAGE, 333, 44);
m_menu.LoadMenuW(IDM_FILE_OPEN);
m_pMainWnd->DrawMenuBar();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();

MessageBox(NULL, _T("Application initialized!"), _T("Info"), MB_OK);

return CWinApp::InitApplication();
Enter fullscreen mode Exit fullscreen mode

}*/

m_pMainWnd = new main_frame;

// 加载主菜单
m_menu.LoadMenu(IDM_FILE_OPEN);
m_pButton = new CButton;
m_pButton->Create(_T("Button Text"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(10, 10, 100, 30), AfxGetMainWnd(), IDC_BUTTON_OK);


// 获取主菜单的句柄
 m_pMainWnd->SetMenu(&m_menu);
Enter fullscreen mode Exit fullscreen mode

/* if (pMainMenu)
{
// 在主菜单上添加菜单项
CMenu* pSubMenu = m_menu.GetSubMenu(0); // 假设菜单资源中的第一个子菜单是你要添加的菜单项
if (pSubMenu)
{
// 将菜单项插入到主菜单的指定位置
pMainMenu->InsertMenu(1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)pSubMenu->GetSafeHmenu(), _T("New Menu"));
}
}
*/
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();

MessageBox(NULL, _T("Application initialized!"), _T("Info"), MB_OK);


dog* f=new dog;
f->Create(NULL, L"dd", WS_OVERLAPPEDWINDOW, CRect(0, 0, 500, 300));
f->ShowWindow(SW_SHOW);
Enter fullscreen mode Exit fullscreen mode

// f->ShowOwnedWindows(false);
f->UpdateWindow();

return CWinApp::InitApplication();
Enter fullscreen mode Exit fullscreen mode

}

dog::dog()
{
//Create(NULL, L"dd", WS_OVERLAPPEDWINDOW, CRect(0, 0, 500, 300));
}

/*
main_frame::main_frame()
{
Create(NULL, _T("Hello"), WS_OVERLAPPEDWINDOW, CRect(32, 64, 352, 304));

MessageBox( _T("Main frame created!"), _T("Info"), MB_OK);
Enter fullscreen mode Exit fullscreen mode

}

LRESULT main_frame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
MessageBox( _T("Close button clicked!"), _T("Info"), MB_OK|MB_RIGHT);
break;
case WM_LBUTTONDOWN:
MessageBox( _T("Left mouse button clicked!"), _T("Info"), MB_OK);
break;

default:
    return CWnd::WindowProc(message, wParam, lParam);
}

return 0;
Enter fullscreen mode Exit fullscreen mode

}*/

pragma once

include "afxdialogex.h"

include // 如果是对话框类(CDialog)中的函数

//#include // 如果是窗口类(CWnd)中的函数

// nn 对话框

class nn : public CDialog
{
DECLARE_DYNAMIC(nn)
public:
nn(CWnd* pParent = nullptr); // 标准构造函数
BOOL OnInitDialog();

virtual ~nn();
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)  ;

afx_msg BOOL OnEraseBkgnd(CDC* pDC);
void AdjustColumnWidth();
int  GetColumnCount();
Enter fullscreen mode Exit fullscreen mode

// void SetRowHeigt(int);
// void AutoColumn(void)

// 对话框数据

ifdef AFX_DESIGN_TIME

enum { IDD = IDD_DIALOG1 };
Enter fullscreen mode Exit fullscreen mode

endif

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
CListCtrl m_ListCode;

DECLARE_MESSAGE_MAP()
Enter fullscreen mode Exit fullscreen mode

public:
// afx_msg void OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult);
// afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult);
};

include "n.h"

include

include "nn.h"

include"resource.h"

myapp theapp;

BOOL myapp::InitApplication()
{/*
m_pMainWnd = new main_frame;

m_pMainWnd->SendMessage(WM_CUSTOM_MESSAGE, 333, 44);
m_menu.LoadMenuW(IDM_FILE_OPEN);
m_pMainWnd->DrawMenuBar();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();

MessageBox(NULL, _T("Application initialized!"), _T("Info"), MB_OK);

return CWinApp::InitApplication();
Enter fullscreen mode Exit fullscreen mode

}*/

m_pMainWnd = new main_frame;

// 加载主菜单
m_menu.LoadMenu(IDM_FILE_OPEN);
m_pButton = new CButton;
m_pButton->Create(_T("Button Text"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(10, 10, 100, 30), AfxGetMainWnd(), IDC_BUTTON_OK);


// 获取主菜单的句柄
 m_pMainWnd->SetMenu(&m_menu);
Enter fullscreen mode Exit fullscreen mode

/* if (pMainMenu)
{
// 在主菜单上添加菜单项
CMenu* pSubMenu = m_menu.GetSubMenu(0); // 假设菜单资源中的第一个子菜单是你要添加的菜单项
if (pSubMenu)
{
// 将菜单项插入到主菜单的指定位置
pMainMenu->InsertMenu(1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)pSubMenu->GetSafeHmenu(), _T("New Menu"));
}
}
*/
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();

MessageBox(NULL, _T("Application initialized!"), _T("Info"), MB_OK);


dog* f=new dog;
f->Create(NULL, L"dd", WS_OVERLAPPEDWINDOW, CRect(0, 0, 500, 300));
f->ShowWindow(SW_SHOW);
Enter fullscreen mode Exit fullscreen mode

// f->ShowOwnedWindows(false);
f->UpdateWindow();

return CWinApp::InitApplication();
Enter fullscreen mode Exit fullscreen mode

}

dog::dog()
{
//Create(NULL, L"dd", WS_OVERLAPPEDWINDOW, CRect(0, 0, 500, 300));
}

/*
main_frame::main_frame()
{
Create(NULL, _T("Hello"), WS_OVERLAPPEDWINDOW, CRect(32, 64, 352, 304));

MessageBox( _T("Main frame created!"), _T("Info"), MB_OK);
Enter fullscreen mode Exit fullscreen mode

}

LRESULT main_frame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
MessageBox( _T("Close button clicked!"), _T("Info"), MB_OK|MB_RIGHT);
break;
case WM_LBUTTONDOWN:
MessageBox( _T("Left mouse button clicked!"), _T("Info"), MB_OK);
break;

default:
    return CWnd::WindowProc(message, wParam, lParam);
}

return 0;
Enter fullscreen mode Exit fullscreen mode

}*/

// nn.cpp: 实现文件
//

//#include "pch.h"

include "afxdialogex.h"

include "nn.h"

include

include

include "resource.h"

// nn 对话框

IMPLEMENT_DYNAMIC(nn, CDialog)
BEGIN_MESSAGE_MAP(nn, CDialog)
// ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &nn::OnLvnItemchangedList1)
ON_WM_DRAWITEM()
ON_WM_ERASEBKGND()
// ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &nn::OnLvnItemchangedList1)
END_MESSAGE_MAP()

nn::nn(CWnd* pParent /=nullptr/)
: CDialog(IDD_DIALOG1, pParent)
{

}

nn::~nn()
{
}

void nn::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{

if (nIDCtl == IDC_LIST1)
{
    CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect rcItem(lpDrawItemStruct->rcItem);
    int nItem = lpDrawItemStruct->itemID;

    if (lpDrawItemStruct->itemAction & ODA_DRAWENTIRE)
    {
        // 绘制列表项背景色
        pDC->FillSolidRect(rcItem, RGB(255, 255, 255)); // 设置背景色为白色

        // 绘制红色分隔线
        CPen pen(PS_SOLID, 1, RGB(255, 0, 0)); // 设置红色画笔
        CPen* pOldPen = pDC->SelectObject(&pen);
        pDC->MoveTo(rcItem.left, rcItem.bottom - 1);
        pDC->LineTo(rcItem.right, rcItem.bottom - 1);
        pDC->SelectObject(pOldPen);
    }

    // 绘制列表项文本
    CString strText = m_ListCode.GetItemText(nItem, 0);
    rcItem.DeflateRect(2, 2);
    pDC->DrawText(strText, rcItem, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
}
else
{
    CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
Enter fullscreen mode Exit fullscreen mode

}

BOOL nn::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}

void nn::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_ListCode); // 将列表控件与成员变量关联
}

//#include

// 对话框消息映射

// nn 消息处理程序

if 0

BOOL nn::OnInitDialog()
{
CDialog::OnInitDialog();
/* SetWindowPos(NULL, 0, 0, 1000, 960, SWP_NOMOVE | SWP_NOZORDER);
// 设置列表控件风格

DWORD dwStyle = m_ListCode.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT; // 选中整行
dwStyle |= LVS_EX_GRIDLINES; // 列表控件行列分隔线
//设置列表控件分隔线颜色
    m_ListCode.SetBkColor(RGB(255, 255, 255)); // 设置背景色为白色
m_ListCode.SetTextBkColor(RGB(255, 255, 255)); // 设置文本背景色为白色
m_ListCode.SetTextColor(RGB(0, 0, 0)); // 设置文字颜色为黑色
Enter fullscreen mode Exit fullscreen mode

//m_ListCode.SetGridLineColor(RGB(255, 0, 0)); // 设置分隔线颜色为红色

m_ListCode.SetExtendedStyle(dwStyle);
//m_ListCode.SetItemIndexState()
// 添加列表控件列
m_ListCode.InsertColumn(0, _T("代码"), LVCFMT_LEFT, 600*/

// 设置列表控件风格
DWORD dwStyle = m_ListCode.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT; // 选中整行
m_ListCode.SetExtendedStyle(dwStyle);

// 添加列表控件列
m_ListCode.InsertColumn(0, _T("代码"), LVCFMT_LEFT, 600);

// 设置自定义绘制列表控件
m_ListCode.SetExtendedStyle(m_ListCode.GetExtendedStyle() | LVS_OWNERDRAWFIXED);
m_ListCode.SetCallbackMask(LVN_ODCACHEHINT | LVN_GETDISPINFO);
m_ListCode.SetItemCount(100); // 设置列表项数量,根据实际情况修改

// 设置背景色为白色
m_ListCode.SetBkColor(RGB(255, 255, 255));
// 设置文本背景色为白色
m_ListCode.SetTextBkColor(RGB(255, 255, 255));
// 设置文字颜色为黑色
m_ListCode.SetTextColor(RGB(1, 0, 0));


CRect rect;
GetDlgItem(IDC_LIST1)->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.right = rect.left + 1200;  // 设置列表控件的宽度
rect.bottom = rect.top + 1800;  // 设置列表控件的高度
m_ListCode.MoveWindow(rect);
// 打开.nc文件
std::ifstream file("D:\\叶轮粗加工(简单11).NC");
if (!file)
{
    AfxMessageBox(_T("无法打开文件"));
    return FALSE;
}
AfxMessageBox(L"dddd");
std::string line;
int itemIndex = 0;
while (std::getline(file, line))
{
    // 将代码行转换为CString类型
    CString strLine(line.c_str());

    // 添加代码行到列表控件
    m_ListCode.InsertItem(itemIndex, strLine);

    itemIndex++;
   /* 
    CString s = itoa(itemIndex,sizeof(CString), 10);
    CString s1 = " ";
    s.Format(L"the is %s", s);
    OutputDebugString(s);*/
   // CString strLine(line.c_str());

    // 添加代码行到列表控件
   // m_ListCode.InsertItem(itemIndex, strLine);

    itemIndex++;

   CString s;
    s.Format(L"the is %d", itemIndex);
    OutputDebugString(s);

}

file.close(); // 关闭文件

return TRUE;
Enter fullscreen mode Exit fullscreen mode

}

BOOL nn::OnInitDialog()
{
CDialog::OnInitDialog();

// 设置列表控件风格
DWORD dwStyle = m_ListCode.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT; // 选中整行
m_ListCode.SetExtendedStyle(dwStyle);

// 添加列表控件列
m_ListCode.InsertColumn(0, _T("代码"), LVCFMT_LEFT, 600);

// 设置自定义绘制列表控件
m_ListCode.SetExtendedStyle(m_ListCode.GetExtendedStyle() | LVS_OWNERDRAWFIXED);
m_ListCode.SetCallbackMask(LVN_ODCACHEHINT | LVN_GETDISPINFO);
m_ListCode.SetItemCount(100); // 设置列表项数量,根据实际情况修改

// 设置列表控件位置和大小
CRect rect;
GetDlgItem(IDC_LIST1)->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.right = rect.left + 1100;  // 设置列表控件的宽度
rect.bottom = rect.top + 2111;  // 设置列表控件的高度
m_ListCode.MoveWindow(rect);

// 打开.nc文件
std::ifstream file("D:\\叶轮粗加工(简单11).NC");
if (!file)
{
    AfxMessageBox(_T("无法打开文件"));
    return FALSE;
}

std::string line;
int itemIndex = 0;
while (std::getline(file, line))
{
    // 将代码行转换为CString类型
    CString strLine(line.c_str());

    // 添加代码行到列表控件
    int index = m_ListCode.InsertItem(itemIndex, strLine);

    // 调整列宽度以适应数据的长度
    m_ListCode.SetColumnWidth(0, LVSCW_AUTOSIZE);

    itemIndex++;
}

file.close(); // 关闭文件

return TRUE;
Enter fullscreen mode Exit fullscreen mode

}

endif

BOOL nn::OnInitDialog()
{
CDialog::OnInitDialog();

// 设置列表控件风格
DWORD dwStyle = m_ListCode.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT; // 选中整行
m_ListCode.SetExtendedStyle(dwStyle);

// 添加列表控件列
m_ListCode.InsertColumn(0, _T("代码"), LVCFMT_LEFT, 600);

// 设置自定义绘制列表控件
m_ListCode.SetExtendedStyle(m_ListCode.GetExtendedStyle() | LVS_OWNERDRAWFIXED);
m_ListCode.SetCallbackMask(LVN_ODCACHEHINT | LVN_GETDISPINFO);
m_ListCode.SetItemCount(100); // 设置列表项数量,根据实际情况修改

// 设置列表控件位置和大小
CRect rect;
GetDlgItem(IDC_LIST1)->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.right = rect.left + 1200;  // 设置列表控件的宽度
rect.bottom = rect.top + 1800;  // 设置列表控件的高度
m_ListCode.MoveWindow(rect);

// 打开.nc文件
std::ifstream file("D:\\叶轮粗加工(简单11).NC");
if (!file)
{
    AfxMessageBox(_T("无法打开文件"));
    return FALSE;
}

std::string line;
int itemIndex = 0;
while (std::getline(file, line))
{
    // 将代码行转换为CString类型
    CString strLine(line.c_str());

    // 添加代码行到列表控件
    int index = m_ListCode.InsertItem(itemIndex, strLine);

    // 调整列宽度以适应数据的长度
Enter fullscreen mode Exit fullscreen mode

// m_ListCode.SetColumnWidth(0, LVSCW_AUTOSIZE);

    itemIndex++;
}

file.close(); // 关闭文件

return TRUE;
Enter fullscreen mode Exit fullscreen mode

}
/*

void nn::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (nIDCtl == IDC_LIST1)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

    // 设置绘制的字体
    CFont font;
    font.CreateFont(8, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
        CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("Arial"));
    pDC->SelectObject(&font);

    // 计算单元格的位置和大小
    CRect rect(lpDrawItemStruct->rcItem);
    rect.DeflateRect(2, 2); // 减去边距

    // 获取单元格的文本
    CString strText;
    m_ListCode.GetItemText(lpDrawItemStruct->itemID, lpDrawItemStruct->itemData, strText);

    // 绘制单元格的背景
    pDC->FillSolidRect(rect, RGB(255, 255, 255)); // 白色背景

    // 绘制单元格的文本
    pDC->SetTextColor(RGB(0, 0, 0)); // 黑色字体
    pDC->DrawText(strText, rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
}
else
{
    CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
Enter fullscreen mode Exit fullscreen mode

}*/

Top comments (0)