c++自定义按钮图标
c++ custom button icon
我想创建一个动态宽度的按钮。下面是我的代码:
CreateWindowEx(BS_PUSHBUTTON, "BUTTON", "OK",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
50, 220, 100, 24, hwnd,
(HMENU)ID_BUTTON,
GetModuleHandle(NULL),
0);
但是如果我把标签"OK"改为"SOMETHING LONGER",那么按钮就不够宽了。如何设置动态宽度?
试试Button_GetIdealSize宏。
好的,David,请下次提供更多的信息,提到你不理解的一切,因为从你在评论中的问题中我可以推断出你不仅不熟悉Win API,而且对C/c++编程也是非常陌生的。
HWND buttonHandle = CreateWindowEx(BS_PUSHBUTTON, "BUTTON", "OK",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
50, 220, 100, 24,
hwnd,
(HMENU)ID_BUTTON,
GetModuleHandle(NULL),
0);
SIZE size;
if (!Button_GetIdealSize(buttonHandle, &size)) {
// Call of `Button_GetIdealSize` failed, do proper error handling here.
// For that you have various options:
// 1. Exit current scope and return error code;
// 2. Throw an exception;
// 3. Terminate execution of your application and print an error message.
// Of course these options can be mixed.
// If you don't understand what I'm talking about here, then either skip this
// check or start reading books on software development with C/C++.
}
// At this point `size` variable was filled with proper dimensions.
// Now we can use it to actually resize our button...
if (!MoveWindow(buttonHandle, 50, 220, (int)size.cx, (int)size.cy, TRUE)) {
// Call of `MoveWindow` failed, do proper error handling here, again.
}
// We are done!
注意:你的题目提错了。c++与按钮和Win API没有任何关系,顺便说一下,这是纯C。更好的标题是:Win API:如何正确调整按钮大小以适合其内容?
相关文章:
- 问:如何使用C++中的按钮从窗口打开窗口
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- QML按钮点击功能执行顺序
- 如何在 c++ 中将图标放在按钮上?
- 如何在 VC6 中的对话框中将图标设置为按钮
- GTK 3 C++按钮中带有标签的图标
- GTK 卷按钮图标显示初始值 c++
- 单击工具按钮后,在GTKMM工具栏中更改工具按钮图标
- 如何在Qt应用程序中使用样式表更改QPush按钮图标大小
- 使用 Win32 API 禁用消息框中右上角C++ X 按钮图标?
- CToolbar是否支持带有32位图标的按钮
- Q按钮上的圆形图标
- 在q按钮上设置图标
- Gtk::缩放按钮:构造函数中的图标
- 在文本上方为 MFC 按钮制作图标
- MS功能区:从代码中绘制按钮图标
- 如何创建桌面图标/按钮来启动用户Windows屏幕保护程序,并设置选项
- 如何在MFC对话框按钮上设置管理权限图标
- c++自定义按钮图标
- Qt复选框/工具按钮,带有自定义/不同的检查/未选中的图标