FreeBasic编程NM_CUSTOMDRAW实现按钮自绘仿MT4风格

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

一、前言:

  当引用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、函数实现部分

'-------------------------------------------------------------------------------
' 创建主控窗口
'-----
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值