felipEx
Scripting Contest Winner
Posts: 378 Reputation: 24
35 / /
Joined: Jun 2006
|
RE: [Testing] CViewer (Version 1.0)
I made some changes again.
code: var wnd
var trans = 75
var WS_EX_LAYERED = 0x80000
var LWA_ALPHA = 0x2
var GWL_STYLE = -20
var LVNI_SELECTED = 0x2
var LVM_FIRST = 0x1000
var LVM_GETITEM = LVM_FIRST + 5
var LVM_GETNEXTITEM = LVM_FIRST + 12
var LVM_DELETEITEM = 0x1008
var WM_DRAWCLIPBOARD = 0x308
var CF_TEXT = 1
var CF_OEMTEXT = 7
var CF_UNICODETEXT = 13
function OnEvent_Initialize(){
wnd = MsgPlus.CreateWnd('Interface.xml', 'WndHistory');
wnd.RegisterMessageNotification(WM_DRAWCLIPBOARD);
MakeWndTransparent(wnd.Handle, trans);
Interop.Call('user32', 'SetClipboardViewer', wnd.Handle);
}
function OnWndHistoryEvent_MessageNotification(PlusWnd, Message, wParam, lParam){
switch (Message) {
case WM_DRAWCLIPBOARD:
Interop.Call('user32', 'OpenClipboard', PlusWnd.Handle);
if (Interop.Call('user32', 'IsClipboardFormatAvailable', CF_TEXT | CF_OEMTEXT ))
{
var handle= Interop.Call('user32', 'GetClipboardData', CF_UNICODETEXT);
var size = Interop.Call('kernel32', 'GlobalSize', handle);
var str = Interop.Allocate(2 * (size + 1));
var f = false;
Interop.Call('kernel32', 'RtlMoveMemory', str, handle, size);
// a dodgy way to find an item before add data into 'history' listview and prevent many data repeated
for (var i = 0; i < PlusWnd.LstView_GetCount('history'); i++)
if (PlusWnd.LstView_GetItemText('history', i, 0) == str.ReadString(0)){
f = true;
PlusWnd.LstView_SetSelectedState('history', i, true);
break;
}
if (!f){
PlusWnd.LstView_AddItem('history', str.ReadString(0));
}
str.Size = 0;
}
Interop.Call('user32', 'CloseClipboard');
break;
}
}
function OnWndHistoryEvent_CtrlClicked(PlusWnd, ControlId){
var d = 'On' + PlusWnd.WindowId + 'Event_' + ControlId + 'Clicked';
if (eval('typeof(' + d + ')') == 'function') eval(d + '(PlusWnd);');
}
function OnWndHistoryEvent_BtnCopyClicked(PlusWnd){
var i = PlusWnd.SendControlMessage('history', LVM_GETNEXTITEM, -1, LVNI_SELECTED);
if (i < 0)return;
var str = PlusWnd.LstView_GetItemText('history', i, 0);
var size = 2*(str.length+1);
if (Interop.Call('user32', 'OpenClipboard', PlusWnd.Handle)){
var heap = Interop.Call('kernel32', 'GlobalAlloc', 0, size);
var pointer = Interop.Call('kernel32', 'GlobalLock', heap);
Interop.Call('kernel32', 'RtlMoveMemory', pointer, str, size);
Interop.Call('kernel32', 'GlobalUnlock', heap);
if (Interop.Call('user32', 'OpenClipboard', PlusWnd.Handle)){
Interop.Call('user32', 'EmptyClipboard');
Interop.Call('user32', 'SetClipboardData', CF_UNICODETEXT, heap);
Interop.Call('user32', 'CloseClipboard');
}
}
}
function OnWndHistoryEvent_BtnDeleteClicked(PlusWnd){
var i = PlusWnd.SendControlMessage('history', LVM_GETNEXTITEM, -1, LVNI_SELECTED);
if (i < 0)return;
PlusWnd.SendControlMessage('history', LVM_DELETEITEM, i, 0);
}
function OnWndHistoryEvent_LstViewDblClicked(PlusWnd,ControlId,Index){
OnWndHistoryEvent_BtnCopyClicked(PlusWnd);
}
function OnWndHistoryEvent_Cancel(PlusWnd){
PlusWnd.RegisterMessageNotification(WM_DRAWCLIPBOARD, false);
}
function MakeWndTransparent(hWnd, lTransparencyLevel){
var nMsg = Interop.Call('user32', 'GetWindowLongW', hWnd, GWL_STYLE);
nMsg |= WS_EX_LAYERED;
Interop.Call('user32', 'SetWindowLongW', hWnd, GWL_STYLE, nMsg);
Interop.Call('user32', 'SetLayeredWindowAttributes', hWnd, 0, (lTransparencyLevel/100)*255, LWA_ALPHA);
}
As you can see at line 37, there's a loop to check the entire listview and prevent data repeated... Does anyone know a better way?
|
|