Windows下如何自定义窗体控件
来源:互联网 发布:朱生豪情书集 淘宝 编辑:程序博客网 时间:2024/06/06 04:24
Win32窗体的所有控件都认为是窗体,所以创建一个自定义的控件跟创建一个win32的窗体是相似的
参考此篇文章
http://www.codeproject.com/KB/miscctrl/custbutton001.aspx
先通过RegisterClassEx注册一个window class,然后就在消息循环里获取消息绘制控件.
在MFC中自定义控件
依照此思想,在MFC中也是如此做法,让一个控件继承自CWnd,然后通过AfxRegisterClass方法注册,可以参考此篇文章
http://www.codeproject.com/KB/miscctrl/customcontrol.aspx
主要的代码
CBitmapViewer::CBitmapViewer(){ RegisterWindowClass();}CBitmapViewer::~CBitmapViewer(){}// Register the window class if it has not already been registered.BOOL CBitmapViewer::RegisterWindowClass(){ WNDCLASS wndcls; HINSTANCE hInst = AfxGetInstanceHandle(); if (!(::GetClassInfo(hInst, BITMAPVIEWER_CLASSNAME, &wndcls))) { // otherwise we need to register a new class wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wndcls.lpfnWndProc = ::DefWindowProc; wndcls.cbClsExtra = wndcls.cbWndExtra = 0; wndcls.hInstance = hInst; wndcls.hIcon = NULL; wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1); wndcls.lpszMenuName = NULL; wndcls.lpszClassName = BITMAPVIEWER_CLASSNAME; if (!AfxRegisterClass(&wndcls)) { AfxThrowResourceException(); return FALSE; } } return TRUE;}/////////////////////////////////////////////////////////////////////////////// CBitmapViewer methodsBOOL CBitmapViewer::Create(CWnd* pParentWnd, const RECT& rect, UINT nID, DWORD dwStyle /*=WS_VISIBLE*/){ return CWnd::Create(BITMAPVIEWER_CLASSNAME, _T(""), dwStyle, rect, pParentWnd, nID);}
默认windows系统皮肤
win32的控件在不同windows版本下皮肤不一样,默认创建的win32程序和mfc程序的皮肤还是老版本的样式.为了使用新的皮肤必须初始化一个类库
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
把这句话加到头文件中,然后会生产到manifest文件中
<dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency>
参考此文
http://www.codeproject.com/KB/cpp/xpstylemfc.aspx
- Windows下如何自定义窗体控件
- Winform下ToolStrip承载自定义控件或 Windows 窗体控件。
- 如何跨线程调用Windows窗体控件
- 如何跨线程调用Windows窗体控件
- 【BS】 如何向aspx窗体中添加一个自定义控件
- Windows 窗体 CheckBox 控件
- windows窗体高级控件
- windows窗体及控件
- Windows窗体与控件
- 如何:对 Windows 窗体控件进行线程安全调用
- 如何:对 Windows 窗体控件进行线程安全调用
- 如何:对 Windows 窗体控件进行线程安全调用
- 如何:对 Windows 窗体控件进行线程安全调用
- 如何:在 Windows 窗体 DataGridView 单元格中承载控件
- 如何:操作 Windows 窗体 DataGridView 控件中的列
- 如何:将数据绑定到 Windows 窗体 DataGridView 控件
- 如何:对 Windows 窗体控件进行线程安全调用
- c#中如何跨线程调用windows窗体控件?
- 内存碎片产生原因及处理技术
- mfc 9.0 类结构图
- 使用内存池的原因,内存池的应用
- 从CScrollView继承一个,然后可以往里面添加Dialog,类似于Panle
- mfc中CImageList的使用
- Windows下如何自定义窗体控件
- MFC工具栏添加自定义控件
- TCP/IP详讲
- 黑马程序员——Html、Css、JavaScript、Dom
- note : Call SetWindowsHookEx In DLL
- Html.RenderPartial与Html.RenderAction 用法
- 数字出现次数
- 软件测试
- Windows Server 2012 R2超级虚拟化之二 增强的用户体验