InputBox really modal on all process [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

InputBox really modal on all process [Resolved]

Post 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
Last edited by Kwai chang caine on Wed Oct 20, 2010 12:03 pm, edited 2 times in total.
ImageThe happiness is a road...
Not a destination
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: InputBox really modal

Post 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?
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InputBox really modal

Post 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
ImageThe happiness is a road...
Not a destination
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: InputBox really modal

Post 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? :|
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InputBox really modal

Post 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:
ImageThe happiness is a road...
Not a destination
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: InputBox really modal

Post by flaith »

have you tried with DisableWindow ?
“Fear is a reaction. Courage is a decision.” - WC
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InputBox really modal

Post 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
ImageThe happiness is a road...
Not a destination
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: InputBox really modal

Post 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 ?
“Fear is a reaction. Courage is a decision.” - WC
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InputBox really modal

Post 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:
ImageThe happiness is a road...
Not a destination
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: InputBox really modal

Post by idle »

I see what you want now kcc, but I'm not sure how to do it yet.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InputBox really modal

Post by Kwai chang caine »

Never mind IDLE 8)
If you have an idea in the night...remember this adress :lol:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InputBox really modal on all process

Post by Kwai chang caine »

Nobody have an idea ???? :(
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: InputBox really modal on all process

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: InputBox really modal on all process

Post 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 :(
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: InputBox really modal on all process [Resolved]

Post 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:
Egypt my love
Post Reply