//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Tablet.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall TTablet::TTablet() { hTab = 0; hLibrary = LoadLibrary("Wintab32.dll"); if (hLibrary) { #ifdef UNICODE WTInfo = (TWTInfo)GetProcAddress(hLibrary, "WTInfoW"); WTOpen = (TWTOpen)GetProcAddress(hLibrary, "WTOpenW"); #else WTInfo = (TWTInfo)GetProcAddress(hLibrary, "WTInfoA"); WTOpen = (TWTOpen)GetProcAddress(hLibrary, "WTOpenA"); #endif WTClose = (TWTClose)GetProcAddress(hLibrary, "WTClose"); WTPacketsGet = (TWTPacketsGet)GetProcAddress(hLibrary, "WTPacketsGet"); WTPacket = (TWTPacket)GetProcAddress(hLibrary, "WTPacket"); WTEnable = (TWTEnable)GetProcAddress(hLibrary, "WTEnable"); WTOverlap = (TWTOverlap)GetProcAddress(hLibrary, "WTOverlap"); WTConfig = (TWTConfig)GetProcAddress(hLibrary, "WTConfig"); #ifdef UNICODE WTGet = (TWTGet)GetProcAddress(hLibrary, "WTGetW"); WTSet = (TWTSet)GetProcAddress(hLibrary, "WTSetW"); #else WTGet = (TWTGet)GetProcAddress(hLibrary, "WTGetA"); WTSet = (TWTSet)GetProcAddress(hLibrary, "WTSetA"); #endif WTExtGet = (TWTExtGet)GetProcAddress(hLibrary, "WTExtGet"); WTExtSet = (TWTExtSet)GetProcAddress(hLibrary, "WTExtSet"); WTSave = (TWTSave)GetProcAddress(hLibrary, "WTSave"); WTRestore = (TWTRestore)GetProcAddress(hLibrary, "WTRestore"); WTPacketsPeek = (TWTPacketsPeek)GetProcAddress(hLibrary, "WTPacketsPeek"); WTDataGet = (TWTDataGet)GetProcAddress(hLibrary, "WTDataGet"); WTDataPeek = (TWTDataPeek)GetProcAddress(hLibrary, "WTDataPeek"); WTQueueSizeGet = (TWTQueueSizeGet)GetProcAddress(hLibrary, "WTQueueSizeGet"); WTQueueSizeSet = (TWTQueueSizeSet)GetProcAddress(hLibrary, "WTQueueSizeSet"); WTMgrOpen = (TWTMgrOpen)GetProcAddress(hLibrary, "WTMgrOpen"); WTMgrClose = (TWTMgrClose)GetProcAddress(hLibrary, "WTMgrClose"); WTMgrContextEnum = (TWTMgrContextEnum)GetProcAddress(hLibrary, "WTMgrContextEnum"); WTMgrContextOwner = (TWTMgrContextOwner)GetProcAddress(hLibrary, "WTMgrContextOwner"); WTMgrDefContext = (TWTMgrDefContext)GetProcAddress(hLibrary, "WTMgrDefContext"); WTMgrDeviceConfig = (TWTMgrDeviceConfig)GetProcAddress(hLibrary, "WTMgrDeviceConfig"); WTMgrExt = (TWTMgrExt)GetProcAddress(hLibrary, "WTMgrExt"); WTMgrCsrEnable = (TWTMgrCsrEnable)GetProcAddress(hLibrary, "WTMgrCsrEnable"); WTMgrCsrButtonMap = (TWTMgrCsrButtonMap)GetProcAddress(hLibrary, "WTMgrCsrButtonMap"); WTMgrCsrPressureBtnMarks = (TWTMgrCsrPressureBtnMarks)GetProcAddress(hLibrary, "WTMgrCsrPressureBtnMarks"); WTMgrCsrPressureResponse = (TWTMgrCsrPressureResponse)GetProcAddress(hLibrary, "WTMgrCsrPressureResponse"); WTMgrCsrExt = (TWTMgrCsrExt)GetProcAddress(hLibrary, "WTMgrCsrExt"); WTQueuePacketsEx = (TWTQueuePacketsEx)GetProcAddress(hLibrary, "WTQueuePacketsEx"); #ifdef UNICODE WTMgrConfigReplaceEx = (TWTMgrConfigReplaceEx)GetProcAddress(hLibrary, "WTMgrConfigReplaceExW"); #else WTMgrConfigReplaceEx = (TWTMgrConfigReplaceEx)GetProcAddress(hLibrary, "WTMgrConfigReplaceExA"); #endif #ifdef UNICODE WTMgrPacketHookEx = (TWTMgrPacketHookEx)GetProcAddress(hLibrary, "WTMgrPacketHookExW"); #else WTMgrPacketHookEx = (TWTMgrPacketHookEx)GetProcAddress(hLibrary, "WTMgrPacketHookExA"); #endif WTMgrPacketUnhook = (TWTMgrPacketUnhook)GetProcAddress(hLibrary, "WTMgrPacketUnhook"); WTMgrPacketHookNext = (TWTMgrPacketHookNext)GetProcAddress(hLibrary, "WTMgrPacketHookNext"); WTMgrCsrPressureBtnMarksEx = (TWTMgrCsrPressureBtnMarksEx)GetProcAddress(hLibrary, "WTMgrCsrPressureBtnMarksEx"); } } //--------------------------------------------------------------------------- __fastcall TTablet::~TTablet() { if (hLibrary) { if (hTab) WTClose(hTab); FreeLibrary(hLibrary); } } //--------------------------------------------------------------------------- // Public Method //--------------------------------------------------------------------------- bool __fastcall TTablet::Init(HWND hWnd, char *rfn) { LOGCONTEXT lcMine; // The context of the tablet AXIS TabletX, TabletY; // The maximum tablet size AXIS NPressure; if (hLibrary==NULL) return false; if (!WTInfo(0, 0, NULL)) return false; // get default region WTInfo(WTI_DEFCONTEXT, 0, &lcMine); // modify the digitizing region lcMine.lcOptions = lcMine.lcOptions | CXO_SYSTEM | CXO_MESSAGES; lcMine.lcPktData = PACKETDATA; lcMine.lcPktMode = PACKETMODE; lcMine.lcMoveMask = PACKETDATA; lcMine.lcBtnUpMask = lcMine.lcBtnDnMask; // Set the entire tablet as active WTInfo(WTI_DEVICES, DVC_X, &TabletX); WTInfo(WTI_DEVICES, DVC_Y, &TabletY); //================================== 2001.4.13 by lhskys tablet »ç¿ë size ¶§¹®¿¡ ¸·À½... /* lcMine.lcInOrgX = 0; lcMine.lcInOrgY = 0; lcMine.lcInExtX = TabletX.axMax; lcMine.lcInExtY = TabletY.axMax; */ //================================= // output the data in screen coords lcMine.lcOutOrgX = 0; lcMine.lcOutOrgY = 0; lcMine.lcOutExtX = GetSystemMetrics(SM_CXSCREEN); // move origin to upper left lcMine.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN); /* open the context */ hTab = WTOpen(hWnd, &lcMine, TRUE); WTInfo(WTI_DEVICES, DVC_NPRESSURE, &NPressure); MaxNPressure = NPressure.axMax-NPressure.axMin; if (rfn) { TRegIniFile *RegIniFile = new TRegIniFile(rfn); RegIniFile->RootKey = HKEY_LOCAL_MACHINE; RegIniFile->OpenKey("SOFTWARE\\YoungWoo\\Texpro\\8.0\\",true); if (RegIniFile) { MaxNPressure = StrToInt(RegIniFile->ReadString("Common", "MaxNPressure", AnsiString(MaxNPressure))); delete RegIniFile; } } return true; } //--------------------------------------------------------------------------- bool __fastcall TTablet::Activate() { if (hTab) WTOverlap(hTab, TRUE); } //--------------------------------------------------------------------------- WTPKT TTablet::WTMPacket(TMessage &Message) { PACKET pkt; // the current packet WTPKT Result; Result = 0; if (hLibrary && hTab) { if (WTPacket(Message.LParam, Message.WParam, &pkt)) { // old co-ordinates used for comparisons curOld = curNew; btnOld = btnNew; ptOld = ptNew; prsOld = prsNew; ortOld = ortNew; // save new co-ordinates curNew = pkt.pkCursor; btnNew = pkt.pkButtons; ptNew.x = pkt.pkX; ptNew.y = pkt.pkY; prsNew = pkt.pkNormalPressure; ortNew = pkt.pkOrientation; // If the visual changes update the main graphic if (curNew!=curOld) Result = Result | PK_CURSOR; if (btnNew!=btnOld) Result = Result | PK_BUTTONS; if (ptNew.x!=ptOld.x) Result = Result | PK_X; if (ptNew.y!=ptOld.y) Result = Result | PK_Y; if (prsNew!=prsOld) Result = Result | PK_NORMAL_PRESSURE; if (ortNew.orAzimuth!=ortOld.orAzimuth || ortNew.orAltitude!=ortOld.orAltitude || ortNew.orTwist!=ortOld.orTwist) Result = Result | PK_ORIENTATION; } } return Result; } //--------------------------------------------------------------------------- bool __fastcall TTablet::IsDevice() { return hLibrary && hTab; } //--------------------------------------------------------------------------- AnsiString __fastcall TTablet::GetDeviceName() { char name[100]; WTInfo(WTI_DEVICES, DVC_NAME, name); return AnsiString(name); } //---------------------------------------------------------------------------