Page 1 of 2

InputBox really modal on all process [Resolved]

Posted: Sun Oct 17, 2010 11:55 pm
by Kwai chang caine
Hello at all

I found this code of AKJ 8)
But the field text loose the focus, if i clic out of the windows
The windows is really modal yes, but the keyboard can't write in the StringGadget
I'm forced to select the windows, and give it focus to write new time in the stringGadget :(

I search an InputBox full modal.
When she is enabled, impossible to do anything, even in another application, and the stringGadget always be active, is it possible ????

http://www.purebasic.fr/english/viewtop ... 71#p166571

Code: Select all

Procedure.s InputBox(txtw, txth, title$, prompt$, def$="", flags=0)
 
; A version of InputRequester() by BackupUser
; Modified by AKJ 18-Oct-06
; Downloaded: www.purebasic.fr/english/viewtopic.php?t=2412
; textw and txth are the outer dimensions of the prompt text gadget
; Available flags are:
;   #PB_String_{BorderLess  LowerCase  Numeric  Password  ReadOnly  Uppercase}
; Features:
; (1) Modal (locks the calling window until done)
; (2) Prompt area is larger
; (3) Prompt area supports multi-line text with Chr(13)
; (4) Cancel button in addition to OK button
; (5) Returns the default string (def$) if the Cancel button is pressed
; (6) Returns "" if an error occurs
; (7) Standard Windows look-And-feel
; (8) Plays the "question" prompt sound
; (9) Works with or without a calling window
;(10) Emulates the Visual Basic InputBox() command
;(11) Supports all #PB_String_xxx flags

Protected winBox, txtPrompt, strInput, butOK, butCancel ; Gadgets
Protected box, ev, id, ret, esc, a, thread1, thread2, text$=""

If txtw<128 
 xtw=128 
EndIf ; To show buttons correctly

If txth<20 
 txth = 20 
EndIf ; Height of a normal text line

winBox=OpenWindow(#PB_Any,0,0,txtw+13,txth+20+23+8*4,title$,#PB_Window_ScreenCentered)
box=WindowID(winBox)

If winBox 
 
 txtPrompt=TextGadget(#PB_Any,6,8,txtw,txth,prompt$)
 
  If flags&#PB_String_Password=0 
   flags|#ES_MULTILINE 
  EndIf
  
  strInput=StringGadget(#PB_Any,6,txth+8*2,txtw,20,def$,flags|#ES_AUTOVSCROLL)
  
  butOK=ButtonGadget(#PB_Any,6,txth+20+8*3,60,23,"OK") ; Set x=txtw-122 for button to be on the right
  butCancel=ButtonGadget(#PB_Any,txtw-54,txth+20+8*3,60,23,"Cancel")
  SendMessage_(GadgetID(strInput),#EM_SETSEL,0,Len(def$))
  GetAsyncKeyState_(#VK_RETURN) 
  GetAsyncKeyState_(#VK_ESCAPE)
  StickyWindow(winBox,#True) 
  SetForegroundWindow_(box) 
  SetActiveGadget(strInput) 
  MessageBeep_(#MB_ICONQUESTION)
  
  Repeat
   
   ev=WaitWindowEvent(1) 
   id=EventGadget() 
   ret=GetAsyncKeyState_(#VK_RETURN)
   esc=GetAsyncKeyState_(#VK_ESCAPE)
   a=GetForegroundWindow_()
   
   If a<>box
    
    thread1=GetWindowThreadProcessId_(@a,0) 
    thread2=GetWindowThreadProcessId_(@box,0)
    
    If thread1<>thread2 
     AttachThreadInput_(thread1,thread2,#True)     
    EndIf
    
    SetForegroundWindow_(box) 
    Sleep_(1)
    
    If thread1<>thread2 
     AttachThreadInput_(thread1,thread2,#False) 
    EndIf
    
    SetActiveGadget(strInput); !!! : MessageBeep_(#MB_ICONQUESTION)
    
   EndIf
    
  Until (ev=#PB_Event_Gadget And (id=butOK Or id=butCancel)) Or ret<>0 Or esc<>0 Or ev=#PB_Event_CloseWindow
   
  If id=butOK Or ret<>0 
   text$=GetGadgetText(strInput) 
  Else 
   text$=def$ 
  EndIf
  
  CloseWindow(winBox)
  
 EndIf
 
 ProcedureReturn text$
 
EndProcedure

; Example using BackupUser's dimensions for the prompt text gadget
Debug InputBox(487, 70, "Test", "Enter something:", "default", #PB_String_UpperCase)
Thanks and good day

Re: InputBox really modal

Posted: Mon Oct 18, 2010 12:21 am
by idle
I'm not sure if I understand what you want but it should only be modal for your process.
Can you explain it a bit better with an example perhaps?

Re: InputBox really modal

Posted: Mon Oct 18, 2010 8:31 am
by Kwai chang caine
Hello IDLE :D
but it should only be modal for your process.
It's not possible to have a window who lock all the OS windows, if she is open ???
And furthermore keep the focus on his StringGadget ????

I want when this windows is open, the user forced to answer at the InputBox or close the InputBox, else he can not do anything else :D

Re: InputBox really modal

Posted: Mon Oct 18, 2010 9:33 am
by Mistrel
Your code doesn't lock anything on my machine. It just sits as a "TOPMOST" window. But I can still activate other ones.

Is this the correct behavior? :|

Re: InputBox really modal

Posted: Mon Oct 18, 2010 9:37 am
by Kwai chang caine
No justly :(

Me i search an InputBox who have truly MODAL with all process
If this InputBox is open, any things can be do, just answer at this InputBox or obvioulsy close or cancel it :wink:

Re: InputBox really modal

Posted: Mon Oct 18, 2010 9:49 am
by flaith
have you tried with DisableWindow ?

Re: InputBox really modal

Posted: Mon Oct 18, 2010 9:53 am
by Kwai chang caine
Hello FLAITH glad to talk to you :D
have you tried with DisableWindow ?
DisableWindow :shock:
If i DisableWindow i can click out of my InputGadget and she lost focus no ???
And me i want my InputGadget keep all the time the focus, and lock all the other user process.
The user is forced to answer at this inputGadget or all his PC is LOCKED

Re: InputBox really modal

Posted: Mon Oct 18, 2010 11:36 am
by flaith
Kwaï chang caïne wrote:Hello FLAITH glad to talk to you :D
Yes so do i :D
Kwaï chang caïne wrote:If i DisableWindow i can click out of my InputGadget and she lost focus no ???
And me i want my InputGadget keep all the time the focus, and lock all the other user process.
The user is forced to answer at this inputGadget or all his PC is LOCKED
Ah ok, i understand, you want a window that block all the system like a password system access ?

Re: InputBox really modal

Posted: Mon Oct 18, 2010 1:09 pm
by Kwai chang caine
Exactely :D

In fact, like you don't ask me why i need that...i say to you :mrgreen:

I have a EEEPC, and i use it outdoor.
In my program i use principaly a inputbox for search a record 45T in a list
So sometime there are too much sun, and my InputGadget loose the focus, furthermore...i loose my mouse pointer too in the screen and all this big light :twisted:

And i'm like a mule, in the middle of people, to make dance with my PC, move up, move down, like a waltz, turn around, for search a little bit of dark to retrieve my mouse :oops:

So i thinking, if i have a FULL MODAL stringgadget, i can press everybody on the keyboard or touchpad, never i loose my mouse 8)

It's a pity ...because KCC dance very well the PC waltz ...because all the people laughing around him and applause :lol:
Image
The nice blond is not my PC :oops:
And i believe the nice man is not me too :mrgreen:

Re: InputBox really modal

Posted: Mon Oct 18, 2010 9:11 pm
by idle
I see what you want now kcc, but I'm not sure how to do it yet.

Re: InputBox really modal

Posted: Mon Oct 18, 2010 9:48 pm
by Kwai chang caine
Never mind IDLE 8)
If you have an idea in the night...remember this adress :lol:

Re: InputBox really modal on all process

Posted: Wed Oct 20, 2010 10:04 am
by Kwai chang caine
Nobody have an idea ???? :(

Re: InputBox really modal on all process

Posted: Wed Oct 20, 2010 10:08 am
by srod
http://support.microsoft.com/kb/147817
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.
Common sense really.

Re: InputBox really modal on all process

Posted: Wed Oct 20, 2010 12:01 pm
by Kwai chang caine
Decidedly....when i have an idea..it's always impossible :cry:
I have not finish to dance with my EEEPC under the sun :oops:

Thanks SROD for your answer :(

Re: InputBox really modal on all process [Resolved]

Posted: Wed Oct 20, 2010 1:10 pm
by RASHAD
Hi KCC
Compile the code and run it from shortcut
You can hook the keyboard to disable windows shortcut (Ctrl-c.......)

Code: Select all

ExamineDesktops()
OpenWindow(0,0,0,DesktopWidth(0),DesktopHeight(0),"",#PB_Window_BorderLess)
SetWindowColor(0,#Red)
SetWindowLong_(WindowID(0),#GWL_EXSTYLE,GetWindowLong_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0),#Red,0,#LWA_COLORKEY)
StringGadget(1,DesktopWidth(0)/2-100,DesktopHeight(0)/2-12, 200,24,"",#ES_CENTER)
ButtonGadget(2,DesktopWidth(0)/2-40,DesktopHeight(0)/2+30,80,22,"Exit")

Repeat
  Select WaitWindowEvent()
       
      Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              
            Case 2
              Q =1
              CloseWindow(0)
              
          EndSelect
  EndSelect 
Until Q =1
:mrgreen: :mrgreen: