改变按钮文本颜色

光庆 1天前 148

   

import win.ui;
/*DSG{{*/
var winform = win.form(text="改变按钮颜色示例";right=279;bottom=239;composited=1)
winform.add(
button={cls="button";text="点这里1";left=16;top=104;right=261;bottom=159;font=LOGFONT(h=-14);z=1};
button2={cls="button";text="点这里2";left=16;top=168;right=261;bottom=223;font=LOGFONT(h=-14);z=3};
edit={cls="edit";text="Edit";left=16;top=16;right=264;bottom=96;edge=1;multiline=1;z=2}
)
/*}}*/
import raw.apiHook
raw.apiHook(
	"user32.dll",
	"DrawTextExW",
	"int(ptr,ptr,int,ptr,int,ptr)", 
	function(hdc,lpchText,cchText,rect,format,lpdtp){
		var str = ..string.fromUtf16(..raw.str(lpchText,true));
		if str="点这里1" ::Gdi32.SetTextColor(hdc,0x0000FF);
		elseif str="点这里2" ::Gdi32.SetTextColor(hdc,0xFF0000);
		owner.callApi(hdc,lpchText,cchText,rect,format,lpdtp); 
		return true;
	}
).install();
winform.show();
win.loopMessage();
import win.ui;
/*DSG{{*/
var winform = win.form(text="改变按钮颜色示例";right=279;bottom=239;composited=1)
winform.add(
button={cls="button";text="点这里1";left=16;top=104;right=261;bottom=159;font=LOGFONT(h=-14);z=1};
button2={cls="button";text="点这里2";left=16;top=168;right=261;bottom=223;font=LOGFONT(h=-14);z=3};
edit={cls="edit";text="Edit";left=16;top=16;right=264;bottom=96;edge=1;multiline=1;z=2}
)
/*}}*/
import raw.apiHook
raw.apiHook(
    "user32.dll",
    "DrawTextExW",
    "int(ptr,ptr,int,ptr,int,ptr)", 
    function(hdc,lpchText,cchText,rect,format,lpdtp){
        var str = ..string.fromUtf16(..raw.str(lpchText,true));
        if str="点这里1" ::Gdi32.SetTextColor(hdc,0x0000FF);
        elseif str="点这里2" ::Gdi32.SetTextColor(hdc,0xFF0000);
        var rc = ::RECT();
        ..raw.convert(rect,rc);
        rc.right-=100;
        gdi.fillRect(hdc,0x00FF00,rc);
        owner.callApi(hdc,lpchText,cchText,rect,format,lpdtp); 
        return true;
    }
).install();
winform.show();
win.loopMessage();


最新回复 (1)
  • 近我者赤 21小时前
    0 2

    大佬无所不能

返回