当然运行下面的代码先得有个绘图板,先上个图看看效果(小孩在涂鸦):
import win.ui; /*DSG{{*/ var winform = win.form(text="请使用压感笔在绘图板上画图";right=759;bottom=469) winform.add() /*}}*/ //<a href="http://www.wacomeng.com/windows/" rel="nofollow" target="_blank">http://www.wacomeng.com/windows/</a> ::Wintab32 := ..raw.loadDll("Wintab32.dll"); var lContext = { WORD lcName[40/*_LCNAMELEN*/]; INT lcOptions; INT lcStatus; INT lcLocks; INT lcMsgBase; INT lcDevice; INT lcPktRate; INT lcPktData; INT lcPktMode; INT lcMoveMask; INT lcBtnDnMask; INT lcBtnUpMask; int lcInOrgX; int lcInOrgY; int lcInOrgZ; int lcInExtX; int lcInExtY; int lcInExtZ; int lcOutOrgX; int lcOutOrgY; int lcOutOrgZ; int lcOutExtX; int lcOutExtY; int lcOutExtZ; INT lcSensX; INT lcSensY; INT lcSensZ; int lcSysMode; int lcSysOrgX; int lcSysOrgY; int lcSysExtX; int lcSysExtY; INT lcSysSensX; INT lcSysSensY; } ::Wintab32.WTInfoW( 3/*WTI_DEFCONTEXT*/, 0, lContext); lContext.lcOptions = 4/*_CXO_MESSAGES*/; lContext.lcPktData = 0x40/*_PK_BUTTONS*/ | 0x400/*_PK_NORMAL_PRESSURE*/ | 0x80/*_PK_X*/ | 0x100/*_PK_Y*/ | 0x200/*_PK_Z*/; //准备GDI+绘图对象 import gdip.pen; import gdip.graphics; var graphics = gdip.graphics(winform); var pen = gdip.pen(0xFF000000, 1, 2); var brush = gdip.solidBrush(0xFF000000); winform.prevX, winform.prevY = 0, 0; winform.prevNormalPressure = 0; //响应绘图板消息 winform.wndproc = { [0x7FF0/*_WT_PACKET*/] = function(hwnd, message, wParam, lParam){ var packet = { INT pkButtons; int pkX; int pkY; int pkZ; INT pkNormalPressure; }; //获取绘图板数据 ::Wintab32.WTPacket(winform.hTablet, wParam, packet); var x,y,cx,cy = winform.getPos(); if packet.pkNormalPressure{ ::User32.SetCursor(null);//隐藏光标 x = (cx * packet.pkX) / lContext.lcInExtX; //获取压感笔x坐标 y = cy - (cy * packet.pkY) / lContext.lcInExtY; //获取压感笔y坐标 if winform.prevNormalPressure == 0{ winform.prevX, winform.prevY = x, y } select packet.pkButtons{ case 1{ var size = packet.pkNormalPressure * 20 / 1024; //压力转换为笔尖大小 pen.width = size brush.color = 0xFF000000 pen.color = brush.color graphics.fillEllipse(brush, winform.prevX - size / 2, winform.prevY - size / 2, size, size) graphics.drawLine(pen, x, y, winform.prevX, winform.prevY) } case 3{ var size = packet.pkNormalPressure * 50 / 1024 //压力转换为笔尖大小 pen.width = size brush.color = 0xFFEEEEEE; pen.color = brush.color graphics.fillEllipse(brush, winform.prevX - size / 2, winform.prevY - size / 2, size, size) graphics.drawLine(pen, x, y, winform.prevX, winform.prevY) } } winform.prevX, winform.prevY = x, y } winform.prevNormalPressure = packet.pkNormalPressure return 0; } } winform.show() //打开绘图板 winform.hTablet = ::Wintab32.WTOpenW(winform.hwnd, lContext, true); win.setActive(winform.hwnd); //不然要鼠标点一下才能画 win.loopMessage();