如何在用SDK写的程序中使用状态栏(Status Bars)和工具栏(Toolbar),请指教。

hezhiroy 2003-10-16 05:40:09
如题,不用MFC。请把源码帖出来,大家讨论一下吧。
...全文
61 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
hezhiroy 2003-10-16
  • 打赏
  • 举报
回复
在对话框里用的状态栏好象在ClientRect里,看来我的控件的位置都要重排了。
icr_mio 2003-10-16
  • 打赏
  • 举报
回复
同意楼上的
shines77 2003-10-16
  • 打赏
  • 举报
回复
在对话框如果不行的话,试试MoveWindow() 把StatusBar移到想要的位置。
hezhiroy 2003-10-16
  • 打赏
  • 举报
回复
刚试了一下,果然是没有用ShowWindow的原故,太感谢楼上的朋友。
不过为什么我的窗体大小变化时,状态栏不是由Windows重新设置大小和位置,还要由程序员自已写代码吗?
icr_mio 2003-10-16
  • 打赏
  • 举报
回复
hStatus=DoCreateStatusBar(hWnd,123,hInst,3);
ShowWindow(hStatus,SW_SHOW); //你ShowWindow了没有?
CloudWater 2003-10-16
  • 打赏
  • 举报
回复
http://www.yesky.com/SoftChannel/72342371928702976/20020730/1622727.shtml
hezhiroy 2003-10-16
  • 打赏
  • 举报
回复
有啊,我用的listview一却都正常,以前没有在SDK的程序里用过Statusbar和Toolbar,无从下手,还请多多指教!
icr_mio 2003-10-16
  • 打赏
  • 举报
回复
你有
// Ensure that the common control DLL is loaded.
InitCommonControls();
这一句吗?
icr_mio 2003-10-16
  • 打赏
  • 举报
回复
// DoCreateStatusBar - creates a status bar and divides it into
// the specified number of parts.
// Returns the handle to the status bar.
// hwndParent - parent window for the status bar.
// nStatusID - child window identifier.
// hinst - handle to the application instance.
// nParts - number of parts into which to divide the status bar.
HWND DoCreateStatusBar(HWND hwndParent, int nStatusID,
HINSTANCE hinst, int nParts)
{
HWND hwndStatus;
RECT rcClient;
HLOCAL hloc;
LPINT lpParts;
int i, nWidth;

// Ensure that the common control DLL is loaded.
InitCommonControls();

// Create the status bar.
hwndStatus = CreateWindowEx(
0, // no extended styles
STATUSCLASSNAME, // name of status bar class
(LPCTSTR) NULL, // no text when first created
SBARS_SIZEGRIP | // includes a sizing grip
WS_CHILD, // creates a child window
0, 0, 0, 0, // ignores size and position
hwndParent, // handle to parent window
(HMENU) nStatusID, // child window identifier
hinst, // handle to application instance
NULL); // no window creation data

// Get the coordinates of the parent window's client area.
GetClientRect(hwndParent, &rcClient);

// Allocate an array for holding the right edge coordinates.
hloc = LocalAlloc(LHND, sizeof(int) * nParts);
lpParts = LocalLock(hloc);

// Calculate the right edge coordinate for each part, and
// copy the coordinates to the array.
nWidth = rcClient.right / nParts;
for (i = 0; i < nParts; i++) {
lpParts[i] = nWidth;
nWidth += nWidth;
}

// Tell the status bar to create the window parts.
SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) nParts,
(LPARAM) lpParts);

// Free the array, and return.
LocalUnlock(hloc);
LocalFree(hloc);
return hwndStatus;
}

hezhiroy 2003-10-16
  • 打赏
  • 举报
回复
忘了说明一下,我用的是DialogBox函数生成的窗体。试过msdn上的使用Statusbar的例子,用CreateWindowEx成功返回状态栏的句柄,但在窗体上却不可见!!!
icr_mio 2003-10-16
  • 打赏
  • 举报
回复
MSDN里的

// CreateAToolBar creates a toolbar and adds a set of buttons to it.
// The function returns the handle to the toolbar if successful,
// or NULL otherwise.
// hwndParent is the handle to the toolbar's parent window.
HWND CreateAToolBar(HWND hwndParent)
{
HWND hwndTB;
TBADDBITMAP tbab;
TBBUTTON tbb[3];
char szBuf[16];
int iCut, iCopy, iPaste;
INITCOMMONCONTROLSEX icex;

// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);

// Create a toolbar.
hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | CCS_ADJUSTABLE, 0, 0, 0, 0, hwndParent,
(HMENU) ID_TOOLBAR, g_hinst, NULL);

// Send the TB_BUTTONSTRUCTSIZE message, which is required for
// backward compatibility.
SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);

// Add the button strings to the toolbar's internal string list.
LoadString(g_hinst, IDS_CUT, szBuf, MAX_LEN-1);
//Save room for second null terminator.
szBuf[lstrlen(szBuf) + 1] = 0; //Double-null terminate.
iCut = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);
LoadString(g_hinst, IDS_COPY, szBuf, MAX_LEN-1);
//Save room for second null terminator.
szBuf[lstrlen(szBuf) + 1] = 0; //Double-null terminate.
iCopy = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0,
(LPARAM) (LPSTR) szBuf);
LoadString(g_hinst, IDS_PASTE, szBuf, MAX_LEN-1);
//Save room for second null terminator.
szBuf[lstrlen(szBuf) + 1] = 0; //Double-null terminate.
iPaste = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0,
(LPARAM) (LPSTR) szBuf);

// Fill the TBBUTTON array with button information, and add the
// buttons to the toolbar. The buttons on this toolbar have text
// but do not have bitmap images.
tbb[0].iBitmap = I_IMAGENONE;
tbb[0].idCommand = IDS_CUT;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = BTNS_BUTTON;
tbb[0].dwData = 0;
tbb[0].iString = iCut;

tbb[1].iBitmap = I_IMAGENONE;
tbb[1].idCommand = IDS_COPY;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = BTNS_BUTTON;
tbb[1].dwData = 0;
tbb[1].iString = iCopy;

tbb[2].iBitmap = I_IMAGENONE;
tbb[2].idCommand = IDS_PASTE;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = BTNS_BUTTON;
tbb[2].dwData = 0;
tbb[2].iString = iPaste;

SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS,
(LPARAM) (LPTBBUTTON) &tbb);

SendMessage(hwndTB, TB_AUTOSIZE, 0, 0);

ShowWindow(hwndTB, SW_SHOW);
return hwndTB;
}
GTK+ 2.0 教程 译者: huzheng,konghui,ferry,carton,yang_yi,ddd,tingle 版本号: V_0.1.0 2002年 6 月25 日 本文是有关通过 C 语言接口使用 GTK (the GIMP Toolkit) 的教程。 Table of Contents 文版说明 简介 从这里开始 用 GTK 来 Hello World 编译 Hello World 程序 信号和回调函数的原理 事件 Hello World 详解 继续 数据类型 深入探索信号处理函数 改进了的 Hello World 组装构件 组装盒的原理 盒的细节 组装示范程序 用表组装 表组装示例 构件概述 类型转换 构件的组织 无窗口构件 按钮构件 一般按钮 Normal Buttons 开关按钮 Toggle Buttons 复选按钮 Check Buttons 单选按钮 Radio Buttons 调整对象 Adjustments 创建一个调整对象 轻松使用调整对象 “调整对象”的内部机制 范围构件 Range Widgets 滚动条构件 Scrollbar Widgets 比例构件 Scale Widgets 创建一个比例构件 函数和信号(至少讲了函数) 常用的范围函数 设置更新方式 获得和设置调整对象 键盘和鼠标绑定 示例 杂项构件 标签 Labels 箭头 Arrows 工具提示对象 The Tooltips Object 进度条 Progress Bars 对话框 Dialogs 标尺 Rulers 状态栏 Statusbars 文本输入构件 Text Entries 微调按钮 Spin Buttons 组合框 Combo Box 日历 Calendar 颜色选择 Color Selection 文件选择 File Selections 容器构件 Container Widgets 事件盒 The EventBox 对齐构件 The Alignment widget 固定容器 Fixed Container 布局容器 Layout Container 框架 Frames 比例框架 Aspect Frames 分栏窗口构件 Paned Window Widgets 视角 Viewports 滚动窗口 Scrolled Windows 按钮盒 Button Boxes 工具栏 Toolbar 笔记本 Notebooks 菜单构件 手工创建菜单 手工菜单示例 使用套件 套件示例 无文档构件 快捷标签 Accel Label 选项菜单 Option Menu 菜单项 Menu Items 复选菜单项 Check Menu Item 单选菜单项 Radio Menu Item 分隔菜单项 Separator Menu Item 分离菜单项 Tearoff Menu Item 曲线图 Curves 绘图区 Drawing Area 字体选择对话框 Font Selection Dialog 消息对话框 Message Dialog Gamma 曲线图 图像 Image 插头和插座 Plugs and Sockets 树视区 Tree View 文本视区 Text View 设置构件的属性 超时、IO 和 Idle 函数 超时 Timeouts 监控IO Idle 函数 高级事件和信号处理 信号函数 连接和断开信号处理函数 阻塞和反阻塞信号处理函数 发出和停止信号 信号的发射和传播 操作选区 概述 获取选区信息 提供选区 拖放 概述 属性 函数 设置源构件 源构件上的信号 设置目的构件 目的构件上的信号 GLib 定义 双向链表 单向链表 存储管理 计时器 字符串处理 实用程序和错误处理函数 GTK 的 rc 文件 rc 文件的功能 GTK rc 文件的格式 rc 文件示例 编你自己的构件 概述 一个构件的剖析 创建一个复合构件 介绍 选择一个父类 头文件 _get_type() 函数 _class_init() 函数 _init() 函数 其余的... 从头创建构件 介绍 在屏幕上显示构件 表盘构件的原形 主体 gtk_dial_realize() 大小磋商 gtk_dial_expose() 事件处理 可能的增强 深入的学习 涂鸦板,一个简单的绘图程序 概述 事件处理 绘图区构件和绘图 添加XInput支持 允许扩展设备信息 使用扩展设备信息 得到更多关于设备的信息 进一步的讲解 编 GTK 应用程序的技巧 投稿 鸣谢 教程的版权和许可声明

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧