如何在工具栏中,加上图标和文字?(How To Add Icon And Text)

博客围绕在工具栏中添加图标和文字展开,给出了函数CreateHotToolBar的代码示例,该函数用于创建主工具栏,还包含设置每个按钮文本的代码逻辑,通过一系列操作实现为工具栏按钮添加文字。

a).如何在工具栏中,加上图标和文字?(How To Add Icon And Text)

/********************************************************************/
/* */
/* Function name : CreateHotToolBar */
/* Description : Create the main toolbar. */
/* */
/********************************************************************/
BOOL CMainFrame::CreateHotToolBar()
{
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC/*| CBRS_GRIPPER*/) ||
!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar/n");
return FALSE; // fail to create
}

// Set the text for each button
CToolBarCtrl& bar = m_wndToolBar.GetToolBarCtrl();

int nIndex = 0;
TBBUTTON tb;

for (nIndex = m_wndToolBar.GetToolBarCtrl().GetButtonCount() - 1; nIndex >= 0; nIndex--)
{
ZeroMemory(&tb, sizeof(TBBUTTON));
m_wndToolBar.GetToolBarCtrl().GetButton(nIndex, &tb);

// Do we have a separator?
if ((tb.fsStyle & TBSTYLE_SEP) == TBSTYLE_SEP)
continue;

// Have we got a valid command id?
if (tb.idCommand == 0)
continue;

// Get the resource string if there is one.
CString strText;
LPCTSTR lpszButtonText = NULL;
CString strButtonText(_T(""));
_TCHAR seps[] = _T("/n");

strText.LoadString(tb.idCommand);

if (!strText.IsEmpty())
{
lpszButtonText = _tcstok((LPTSTR)(LPCTSTR)strText, seps);

while(lpszButtonText)
{
strButtonText = lpszButtonText;
lpszButtonText = _tcstok(NULL, seps);
}
}

if (!strButtonText.IsEmpty())
m_wndToolBar.SetButtonText(nIndex, strButtonText);
}

要使用 Python 向 PPTX 演示文稿的幻灯片形状中添加文本,可以通过 `python-pptx` 库提供的功能实现。该库允许创建、修改操作 PowerPoint (.pptx) 文件,并支持在幻灯片中添加形状文本。 首先,需要导入必要的模块并创建演示文稿对象。接着,通过 `add_slide()` 方法添加幻灯片,然后使用 `add_shape()` 方法在幻灯片上添加形状。形状添加完成后,可以通过 `text` 属性向形状中添加文本内容。以下是一个完整的示例代码: ```python from pptx import Presentation from pptx.util import Inches from pptx.enum.shapes import MSO_SHAPE # 创建一个新的演示文稿 ppt = Presentation() # 添加一个幻灯片,使用空白布局 slide_layout = ppt.slide_layouts[6] # 6 是空白幻灯片布局 slide = ppt.slides.add_slide(slide_layout) # 在幻灯片上添加一个矩形形状 left = Inches(1) top = Inches(1) width = Inches(3) height = Inches(2) shape = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, left, top, width, height) # 向形状中添加文本 text_frame = shape.text_frame text_frame.text = "这是一个矩形形状中的文本" # 保存演示文稿 ppt.save('example_with_text_in_shape.pptx') ``` 上述代码中,首先创建了一个新的演示文稿,并添加了一张空白幻灯片。然后,在指定位置添加了一个矩形形状,并通过 `text_frame.text` 属性向该形状中添加了文本内容。最后,将修改后的演示文稿保存为 `example_with_text_in_shape.pptx` 文件[^3]。 除了直接设置 `text` 属性外,还可以通过 `text_frame` 对象添加多个段落,并对每个段落进行格式化。例如: ```python # 添加多个段落并设置格式 text_frame.text = "第一段文本" p = text_frame.add_paragraph() p.text = "第二段文本" p.level = 1 # 设置为二级段落(缩进) ``` 这样可以实现更丰富的文本格式结构。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值