一、前言:
当引用Comctl32.dll版本6.0时,控件将会向上级窗口发送WM_NOTIFY消息,lParam参数为指向一个NMHDR的结构体地址,其中CODE包含NM_CUSTOMDRAW(自绘)通知码。
我们可以在NM_CUSTOMDRAW消息下,完成对控件的自绘。
那么如何在FreeBasic编程中实现按钮控件的自绘呢?在反复实验后终于实现了仿MT4按钮风格。其中部分细节与PB有些区别也暗藏技术坑。
二、实现代码:
1、创建XPTheme.xml文件,指定对Comctl32.dll版本6.0的引用
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
name="CompanyName.ProductName.YourApplication"
processorArchitecture="*"
version="0.0.0.0"
type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
2、创建资源文件dialog.rc,定义按钮控件ID
#define IDD_DIALOG1 101
#define IDC_BUTTON1 1003
#define IDC_BUTTON2 1004
#define IDC_BUTTON3 1005
//#FBForms Begin Manifest
1 24 XPTheme.xml
//#FBForms End Manifest
3、程序头函数定义
#pragma once
#ifndef UNICODE
#define UNICODE
#endif
#lang "fb"
#INCLUDE ONCE "windows.bi"
#INCLUDE ONCE "win/mmsystem.bi"
#INCLUDE ONCE "win/windowsx.bi"
#INCLUDE ONCE "win/commctrl.bi"
#INCLUDE ONCE "win/wingdi.bi"
#INCLUDE ONCE "win/uxtheme.bi"
#define IDD_DIALOG1 101
#define IDC_BUTTON1 1003
#define IDC_BUTTON2 1004
#define IDC_BUTTON3 1005
#define LRCF CHR(10,13)
declare function WinMain( byval hInstance as HINSTANCE, _
byval hPrevInstance as HINSTANCE, _
byval szCmdLine as zstring ptr, _
byval iCmdShow as integer ) as integer
end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
declare function DIALOG_NEW ( byval hParent as HINSTANCE, _
byval WinProc as any ptr, _
byval ClassName as string, _
byval id as integer, _
byref title as string, _
byval w as integer, _
byval h as integer, _
byval styles as uinteger, _
byval exstyle as uinteger ) as HWND
declare function CONTROL_ADD ( byval hWndParent as HWND, _
byval ControlName as string, _
byval id as integer, _
byref text as string, _
byval x as integer, _
byval y as integer, _
byval w as integer, _
byval h as integer, _
byval styles as uinteger, _
byval exstyle as uinteger ) as HWND
declare sub FBFormsInitComCtls ( byval dwICC as DWORD )
declare sub DrawMtBottonControl ( byval lpdis as NMCUSTOMDRAW ptr, _
byval BottonBkColor as COLORREF, _
byval BottonFxColor as COLORREF )
4、函数实现部分
'-------------------------------------------------------------------------------
' 创建主控窗口
'-----

本文详细介绍了如何在FreeBasic编程环境中,通过引用Comctl32.dll版本6.0并利用WM_NOTIFY消息的NM_CUSTOMDRAW通知码,实现仿MT4风格的按钮自绘制。首先创建XPTheme.xml和dialog.rc文件,然后定义窗口和控件,接着在函数中实现自定义绘制函数DrawMtBottonControl,最后在窗口过程中处理WM_NOTIFY消息进行自绘。通过这种方法,开发者可以创建具有特定视觉效果的按钮控件。
最低0.47元/天 解锁文章
378

被折叠的 条评论
为什么被折叠?



