/*
* -----
* Screenshot Sender - enumeration_functions.js
* -----
* Enumeration functions for Screenshot Sender
* -----
*/
function SelectedWindow(oChatWnd, Command, Param, SaveImage) {
_debug.getfuncname(arguments);
OpenWindow('WindowSelect');
objCWindows[objWindows['WindowSelect'].Handle] = {
'ChatWnd' : oChatWnd,
'Command' : Command,
'Param' : Param,
'SaveImage' : SaveImage
};
_win32.EnumWindows(Interop.GetCallbackPtr('EnumWindowsProc'), 0);
}
function EnumWindowsProc(hWnd, lParam) {
_debug.getfuncname(arguments);
if (_win32.IsWindowVisible(hWnd)) {
var iLength = _win32.GetWindowTextLengthW(hWnd) + 1;
var lpszTitle = Interop.Allocate(iLength*2 + 2);
_win32.GetWindowTextW(hWnd, lpszTitle, iLength);
if (lpszTitle.ReadString(0) !== '') {
objWindows['WindowSelect'].LstView_AddItem('LvWindows', lpszTitle.ReadString(0), hWnd);
}
}
return true;
}
function SelectedMonitor(oChatWnd, Command, Param, SaveImage, bCountMonitors) {
_debug.getfuncname(arguments);
if (typeof bCountMonitors === TYPE_UNDEFINED) bCountMonitors = false;
nMonitorCount = 0;
if (bCountMonitors === false) {
objMonitors = [];
OpenWindow('MonitorSelect', WNDOPT_INVISIBLE);
_win32.ShowWindow(objWindows['MonitorSelect'].Handle, _win32._const._SW_SHOW);
}
_win32.EnumDisplayMonitors(0, 0, Interop.GetCallbackPtr('MonitorEnumProc'), bCountMonitors);
if (bCountMonitors === false) {
objCWindows[objWindows['MonitorSelect'].Handle] = {
'ChatWnd' : oChatWnd,
'Command' : Command,
'Param' : Param,
'SaveImage' : SaveImage
};
var oListView = new ListView(objWindows['MonitorSelect'], 'LvMonitors'),
objMonitor, iImageIdx = 0, sItemText = _lang.text['SelectedMonitor_Text'] + ' #%1 (%2 × %3)';
for (var i=0, len=objMonitors.length; i<len; ++i) {
objMonitor = objMonitors[i];
iImageIdx = oListView.AddImageToList(objMonitor.hBitmap2);
oListView.InsertItem(
sReplace(sItemText, [
(i+1),
(objMonitor.Width),
(objMonitor.Height)
]),
iImageIdx
);
}
}
return nMonitorCount;
}
function MonitorEnumProc(hMonitor, hdcMonitor, lprcMonitor, dwData) {
_debug.getfuncname(arguments);
++nMonitorCount;
// Used if we only want to count the number of monitors.
// This will allow us to hide this feature if only one monitor exists.
if (dwData) return true;
var RECT = Interop.Allocate(16);
_win32.RtlMoveMemory(RECT, lprcMonitor, 16);
var oGdip = new Gdip();
oGdip.Initialize();
var lWidth = RECT.ReadDWORD(8) - RECT.ReadDWORD(0);
var lHeight = RECT.ReadDWORD(12) - RECT.ReadDWORD(4);
var nImgPtr = oGdip.CaptureWindow(_win32.GetDesktopWindow(), RECT, false, true, false, true);
objMonitors.push({
'RECT' : RECT,
'Width' : lWidth,
'Height' : lHeight,
'hBitmap1' : nImgPtr,
'hBitmap2' : oGdip.CreateThumbnail(nImgPtr)
});
oGdip.Uninitialize();
return true;
}