--lua
local WM_COMMAND = 0x0111
local ffi = require("ffi")
ffi.cdef[[
unsigned int GetMenuItemID(int hMenu, int nPos);
int PostMessageA(int hWnd, unsigned int Msg, unsigned int wParam, long lParam);
]]
package.path = "LuaWindow\\winapi\\?.lua;" .. package.path
package.path = "LuaWindow\\events\\?.lua;" .. package.path
package.path = "LuaWindow\\?.lua;" .. package.path
setfenv(1, require'winapi')
require'ansi_utf'
require'winapi'
require'winapi.windowclass'
require'winapi.buttonclass'
require'winapi.checkboxclass'
-- создание окна и контролов
local win = Window{w = 290, h = 200, x = 200, y = 100, title = utf('Диалог'), topmost = true}
local buttonSR = Button{parent = win, x = 10, y = 10, w = 60, h = 20, text = utf('SR')}
local buttonSi = Button{parent = win, x = 10, y = 35, w = 60, h = 20, text = utf('Si')}
local buttonGZ = Button{parent = win, x = 10, y = 60, w = 60, h = 20, text = utf('GZ')}
local buttonYN = Button{parent = win, x = 10, y = 85, w = 60, h = 20, text = utf('YN')}
local button1 = Button{parent = win, x = 80, y = 10, w = 30, h = 95, text = utf('1')}
local button5 = Button{parent = win, x = 115, y = 10, w = 30, h = 95, text = utf('5')}
local button30 = Button{parent = win, x = 150, y = 10, w = 30, h = 95, text = utf('30')}
local buttonD = Button{parent = win, x = 185, y = 10, w = 30, h = 95, text = utf('D')}
local buttonW = Button{parent = win, x = 220, y = 10, w = 30, h = 95, text = utf('W')}
local check1 = CheckBox{parent = win, x = 10, y = 120, w = 80, h = 20, text = 'Check1', checked = false}
local window_name = ''
-- флаги
local flag_close = 0
local flag_buttonSR, flag_buttonSi, flag_buttonGZ, flag_buttonYN = 0, 0, 0, 0
local flag_button1, flag_button5, flag_button30, flag_buttonD, flag_buttonW = 0, 0, 0, 0, 0
function activate_window(window_name)
if #window_name < 3 then return end
local h = findwindow(window_name)
if h then
showwindow(h[1][1], 'TOP') -- или RESTORE
else
hint('Окно с именем: ' .. window_name .. ' Не найдено')
end
window_name = ''
end
-- функции сообщений
function buttonSR:on_click() flag_buttonSR = 1 end
function buttonSi:on_click() flag_buttonSi = 1 end
function buttonGZ:on_click() flag_buttonGZ = 1 end
function buttonYN:on_click() flag_buttonYN = 1 end
function button1:on_click() flag_button1 = 1 end
function button5:on_click() flag_button5 = 1 end
function button30:on_click() flag_button30 = 1 end
function buttonD:on_click() flag_buttonD = 1 end
function buttonW:on_click() flag_buttonW = 1 end
function win:on_close() flag_close = bit.bxor(flag_close, 1) end
function check1:on_click() -- если был клик по галке
local menuiteminfo = ffi.new('MENUITEMINFOW', {ffi.sizeof('MENUITEMINFOW'), MIIM_STATE })
local handle = findwindow('Canon iP2700') -- имя окна очереди печати
if handle then
local h_menu = ffi.C.GetMenu(ffi.cast('HWND', handle[1][1]))
if h_menu then
local h_submenu = ffi.C.GetSubMenu(h_menu, 0) -- 0 - Принтер
local id_item = ffi.C.GetMenuItemID(ffi.cast('int', h_submenu), 6) -- 6 - Приостановить печать
if check1.checked then menuiteminfo.fState = MFS_CHECKED
else menuiteminfo.fState = MFS_UNCHECKED
end
ffi.C.SetMenuItemInfoW(h_submenu, id_item, false, menuiteminfo) -- установить галку на пункт меню
-- ffi.C.PostMessageA(handle[1][1], WM_COMMAND, id_item, 0) -- может надо, может нет
end
else
log ('Окно очереди печати не найдено')
end
end
win:show()
while flag_close == 0 do
while ProcessNextMessage() do wait (1) end
if flag_buttonSR == 1 then flag_buttonSR = 0 window_name='SR' end
if flag_buttonSi == 1 then flag_buttonSi = 0 window_name='Si' end
if flag_buttonGZ == 1 then flag_buttonGZ = 0 window_name='GZ' end
if flag_buttonYN == 1 then flag_buttonYN = 0 window_name='YN' end
if flag_button1 == 1 then flag_button1 = 0 activate_window(window_name .. '1') window_name='' end
if flag_button5 == 1 then flag_button5 = 0 activate_window(window_name .. '5') window_name='' end
if flag_button30 == 1 then flag_button30 = 0 activate_window(window_name .. '30') window_name='' end
if flag_buttonD == 1 then flag_buttonD = 0 activate_window(window_name .. 'D') window_name='' end
if flag_buttonW == 1 then flag_buttonW = 0 activate_window(window_name .. 'W') window_name='' end
wait(10)
end