Notifications
Clear all
[Closed] Challenge #NEXT. Windows and Messages
Jul 27, 2016 3:21 am
Here is a snippet (window, dialog)
try (destroydialog aDialog) catch()
rcmenu aDiaogmenu
(
local item = if item != ok then item else ok
fn enabled = (item != ok)
menuitem current_it "" enabled:off
seperator sp0 filter:enabled
submenu "Print" filter:enabled
(
menuitem forward "Forward" enabled:(enabled())
menuitem backward "Backward" enabled:(enabled())
)
on forward picked do
(
format ">> %
" item
)
on backward picked do
(
text = ""
for k=item.count to 1 by -1 do text += item[k]
format "<< %
" text
)
on aDiaogmenu open do
(
current_it.text = if item != ok then item else "<NOTHING selected>"
)
)
rollout aDialog "" width:200
(
multilistbox lb items:#("Rats live on no evil star", "Never odd or even", "Madam, I'm Adam") width:190 height:6 align:#center
on lb rightclick do
(
aDiaogmenu.item = for k in lb.selection do exit with lb.items[k]
popUpMenu aDiaogmenu
)
)
createdialog aDialog
run it… use RC menu. Have a fun playing with some well known English palindromes…
well…
This is a challenge:
#1 you don’t know a code and can’t use any definitions from the code
#2 using only pure MXS do be able “print any line of menu Forward and Backward”
Have a fun!
3 Replies
Jul 27, 2016 3:21 am
Any hints? What I tried doesn’t quite work, no idea how to click the Forward/Backward submenu.
counter = 3
mouseOffset = [20, 40]
prevHWNDs = #()
countDown = dotNetObject "Timer"
cursor = dotNetClass "System.Windows.Forms.Cursor"
fn moveCursor pos offset =
cursor.Position = dotNetObject "System.Drawing.Point" (pos.x + offset.x) (pos.y + offset.y)
fn makeParam LoWord HiWord =
bit.or (bit.shift HiWord 16) (bit.and LoWord 0xFFFF)
fn sendMouseClick hwnd type:#left pos: =
(
local lParam = if pos == unsupplied then 0 else makeParam (int pos.x) (int pos.y)
local btnDown = case type of
(
#left : 0x0201
#right : 0x0204
#middle : 0x0207
)
windows.postMessage hwnd btnDown 0 lParam
windows.postMessage hwnd (btnDown + 1) 0 lParam
)
fn selectSubmenu =
(
local hwnds = for item in (windows.getChildrenHWND 0) collect item
if hwnds.count > prevHWNDs.count AND (
local hwnd = for hwnd in hwnds where findItem prevHWNDs hwnd[1] == 0 AND hwnd[4] == "#32768" do exit with hwnd[1]
isKindOf hwnd Number
) then
(
append prevHWNDs hwnd
moveCursor mouse.screenPos mouseOffset
mouseOffset = [-50, 0]
counter -= 1
countDown.Start()
true
)
else false
)
fn onTick sender arg = case counter of
(
3 :
(
sender.Stop()
dialogMonitorOps.enabled = true
dialogMonitorOps.unRegisterNotification id:#open_RMB_menu
dialogMonitorOps.registerNotification ::selectSubmenu id:#select_submenu
)
1 : counter -= 1
0 :
(
sender.Stop()
print (windows.getHWNDData prevHWNDs[prevHWNDs.count]) #nomap
sendMouseClick prevHWNDs[prevHWNDs.count]
dialogMonitorOps.unRegisterNotification id:#select_submenu
dialogMonitorOps.enabled = false
)
)
fn openRMBMenu =
(
local hwnd = dialogMonitorOps.getWindowHandle()
if hwnd != 0 then
(
prevHWNDs = for item in (windows.getChildrenHWND 0) collect item[1]
local listboxHWND = for ctrl in (windows.getChildrenHWND hwnd) where ctrl[4] == "ListBox" do exit with ctrl[1]
dialogMonitorOps.unRegisterNotification id:#open_RMB_menu
dialogMonitorOps.enabled = false
sendMouseClick listboxHWND pos:[20, 22]
sendMouseClick listboxHWND type:#right
countDown.Start()
true
)
else false
)
dialogMonitorOps.unRegisterNotification id:#select_submenu
dialogMonitorOps.unRegisterNotification id:#open_RMB_menu
dotNet.addEventHandler countDown "Tick" onTick
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.registerNotification openRMBMenu id:#open_RMB_menu
createDialog aDialog
Jul 27, 2016 3:21 am
I don’t understand what the challenge is??
But thanks for making me more aware of what extra functionality I’d missed in the RCMenu. I didn’t realise you could do that sort of thing!