Page 1 of 2
Modal Window Workaround(Win XP-Vista-7)
Posted: Fri Oct 22, 2010 5:39 pm
by RASHAD
More work to do
Tested on Win XP x86,Win 7 x64
Code: Select all
Structure KBDLLHOOKSTRUCT
vkCode.i
scanCode.i
flags.i
time.i
dwExtraInfo.i
EndStructure
Procedure KeyboardHook(iCode, wParam, lParam)
Protected *key.KBDLLHOOKSTRUCT = lparam
If (iCode < 0 Or iCode <> #HC_ACTION)
ProcedureReturn CallNextHookEx_(Hook, iCode, wParam, lParam)
EndIf
If wParam = #WM_KEYDOWN Or wParam = #WM_KEYUP
If *key\vkCode = #VK_LWIN Or *key\vkCode = #VK_RWIN
ProcedureReturn 1
EndIf
EndIf
ProcedureReturn CallNextHookEx_(Hook, iCode, wParam, lParam)
EndProcedure
ExamineDesktops()
OpenWindow(0,0,0,DesktopWidth(0),DesktopHeight(0),"",#PB_Window_BorderLess)
SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0),0,1,#LWA_ALPHA)
OpenWindow(1,0,0,400,300,"Modal Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(2,10,10, 200,24,"",#ES_CENTER)
ButtonGadget(3,10,270,80,22,"Exit")
Hook = SetWindowsHookEx_(#WH_KEYBOARD_LL, @KeyboardHook(), GetModuleHandle_(#Null), 0)
Repeat
If GetActiveWindow() <> 1
SetActiveWindow(1)
EndIf
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
UnhookWindowsHookEx_(Hook)
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
Case 3
UnhookWindowsHookEx_(Hook)
Q = 1
EndSelect
EndSelect
Until Q =1
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Fri Oct 22, 2010 7:04 pm
by chi
nice one, thanks!
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Fri Oct 22, 2010 7:22 pm
by Mistrel
My attempt to kill the program with the big red "Kill Program" button on the IDE failed miserably!
I don't know what you would use this for but it certainly works.
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Fri Oct 22, 2010 9:28 pm
by cas
I just press Alt+Tab to switch to PB IDE and then i can close it. Or Open Task Manager and switch to PB IDE from there...
But, if any application would block other windows like this code does, i would delete it immediately from my computer. There are other ways (non-abusable) to get attention from user to input data.
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Fri Oct 22, 2010 11:18 pm
by RASHAD
Hi chi
Hi Mistrel
@cas Hi
Alt-Tab and the task manager that is why I wrote "More work to do"
But I will not go any further it does not worth it
I do not like to leave something behind so you can consider it how to skin Win XP
as long as #LWA_COLORKEY did not work with that OS
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Sat Oct 23, 2010 5:34 pm
by Kwai chang caine
cas wrote:But, if any application would block other windows like this code does, i would delete it immediately from my computer
No CAS sometime that can be very useful....if you want know why...see my link :roll:
@RASHAD
Yeeeaaahhh !!! RASHAD !!!!
A window like i need.....
http://www.purebasic.fr/english/viewtop ... 80#p336780
But this time...no "malicious" screenshot
You are too strong...you have add a function that MICROSOFT hitself don't want to do, like SROD have proof it's impossible, when he found this link for me
http://support.microsoft.com/kb/147817
Microsoft wrote:NOTE: An equivalent Win32 API function for SetSysModalWindow does not exist. System modal windows contradict the concept of multitasking and thus are not implemented in Win32.
Well you have proved your turn, that impossible is not
RASHAD
Thanks a lot for sharing this code
Have a good day
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Sat Oct 23, 2010 6:31 pm
by p2hicy
That only works on the primary screen. On my 3 monitor setup, I'm still able to use the other two.
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Mon Oct 25, 2010 3:14 am
by RASHAD
- Alt-Tab blocked
- Task-Manager switching blocked
- And may be Multi-Monitors as well
Updated :
- Alt-Esc blocked
- Ctrl-Esc blocked
- May be Winamp as well
Code: Select all
Structure KBDLLHOOKSTRUCT
vkCode.l
scanCode.l
flags.l
time.l
dwExtraInfo.l
EndStructure
Global r.RECT,p.POINT
Procedure HookMK(nCode,wParam,lParam)
*key.KBDLLHOOKSTRUCT = lparam
If (iCode < 0 Or iCode <> #HC_ACTION)
ProcedureReturn CallNextHookEx_(Hook, iCode, wParam, lParam)
EndIf
If Not PtInRect_(@r,PeekQ(@p))
If wParam=#WM_LBUTTONDOWN Or wParam=#WM_LBUTTONDBLCLK
;#WM_RBUTTONDOWN,#WM_RBUTTONUP,#WM_RBUTTONDBLCLK,#WM_MBUTTONDOWN,#WM_MBUTTONDBLCLK
ProcedureReturn 1
EndIf
EndIf
If wParam = #WM_KEYDOWN Or wParam = #WM_KEYUP
If *key\vkCode = #VK_LWIN Or *key\vkCode = #VK_RWIN Or *key\vkCode = #VK_LCONTROL Or *key\vkCode = #VK_RCONTROL
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndIf
If (*key\vkCode ! #VK_MENU And *key\vkCode = #VK_TAB ) Or (*key\vkCode ! #VK_MENU And *key\vkCode = #VK_ESCAPE)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
ProcedureReturn CallNextHookEx_(0,nCode,wParam,lParam)
EndProcedure
ExamineDesktops()
OpenWindow(0,0,0,DesktopWidth(0),DesktopHeight(0),"",#PB_Window_BorderLess)
SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0),0,1,#LWA_ALPHA)
SetForegroundWindow_(WindowID(0))
OpenWindow(1,0,0,400,300,"Modal Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StickyWindow(1,1)
StringGadget(2,10,10, 200,24,"",#ES_CENTER)
ButtonGadget(3,10,270,80,22,"Exit")
MouseHook = SetWindowsHookEx_(#WH_MOUSE_LL,@HookMK(),GetModuleHandle_(0),0)
KeyHook = SetWindowsHookEx_(#WH_KEYBOARD_LL,@HookMK(),GetModuleHandle_(0),0)
Repeat
GetCursorPos_(@p.point)
GetWindowRect_(WindowID(1),r.RECT)
If GetActiveWindow() <> 1
SetActiveWindow(1)
EndIf
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
Case 3
Q = 1
EndSelect
EndSelect
Until Q =1
UnhookWindowsHookEx_(MouseHook)
UnhookWindowsHookEx_(KeyHook)
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Mon Oct 25, 2010 3:25 am
by rsts
Pretty close.
For some reason, winamp will still respond. Nothing else seems to, but if winamp is running (and is a front window) it still responds to mouse clicks.
Nice one.
cheers
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Mon Oct 25, 2010 5:20 pm
by netmaestro
Winamp will be using a lowlevel mouse hook that gets processed before this hook does.
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Mon Oct 25, 2010 7:31 pm
by Alireza
Good Cod, Thanks
maybe u can add Ctrl-esc for more performance .

Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Tue Oct 26, 2010 3:20 am
by RASHAD
Previous Post just updated
- Alt-Esc blocked
- Ctrl-Esc blocked
@rsts
Please report your config for Winamp(see if winamp still in front or not)
Or if it is as 'netmaestro' stated
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Tue Oct 26, 2010 1:52 pm
by Alireza
Thanks dear Rashad

Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Wed Oct 27, 2010 4:41 am
by kvitaliy
Combination Ctrl + Alt + Del ?
Re: Modal Window Workaround(Win XP-Vista-7)
Posted: Wed Oct 27, 2010 2:18 pm
by rsts
RASHAD wrote:
@rsts
Please report your config for Winamp(see if winamp still in front or not)
Or if it is as 'netmaestro' stated
Mr Rashad,
My bad. I run a multiple monitor setup. Winamp was on another monitor.
All is blocked when on the same screen.
cheers