rwg
New Member
Posts: 49
|
Post by rwg on Apr 8, 2019 7:38:19 GMT -5
i prefer to have my inputs from the mainwin. when i open a graphics window, the graphic window is active and i have to click on the mainwin to make it active and continue with my inputs. i've tried dll "setactivewindow" but cant get the syntax right. can anyone out there help ?
|
|
|
Post by Rod on Apr 8, 2019 9:09:44 GMT -5
It is probably possible to find the handle of the mainwin and with API calls to set the focus on it. However it will still need moved about and sent to back / brought to front etc. That's a lot of API code. It would be much simpler to add a textbox or texteditor to the foot of the graphicbox. It will be 100% better integrated than the mainwin.
The mainwin is really designed for testing and debugging, it shouldn't be there when the program is running well. That's why it has (relatively) limited functionality.
What kind of text input do you need? is it command strings, instructions or general text? Folks could code examples of alternative input if you described the task in hand a little more.
|
|
|
Post by metro on Apr 8, 2019 9:53:24 GMT -5
I agree with Rod use a GUI but I did play around with an api some time back, I was using mainwin to check my logic and results and wanted it to close after closing my GUI and not have to close two forms....some of the code is here
CallDLL #user32, "GetActiveWindow",_ hMainwin As uLong 'returns handle of MainWin
x=200 : y=350 : w=450 : h = 350 CallDLL #user32, "MoveWindow",_ hMainwin As uLong,_ 'handle x As Long,_ 'x location y As Long,_ 'y location w As Long,_ 'width h As Long,_ 'height 1 As Boolean,_ 'repaint, 1=true r As Boolean 'nonzero=success
[setup.main.Window]
'-----Begin code for #main
' nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
graphicbox #main.graphicbox1, 5, 5, 100, 100 button #main.btn1,"Click me",[dosomething],UL ,150,100 '-----End GUI objects code
open "untitled" for window as #main h1= hwnd(#main) ' print #main.graphicbox1, "down; fill white; flush"
' print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
[main.inputLoop] 'wait here for input event 'maybe useful ' CallDLL #user32,"SetForegroundWindow",_ 'hMain as uLong,_ ' result as Void
'CallDLL #user32, "SetActiveWindow",_ 'h1 As uLong 'returns handle of MainWin '#main.btn1, "!setfocus"
'print hMainwin 'print h1
wait [dosomething] wait
[quit.main] 'End the program close #main
'close MainWin without ending program Calldll #user32, "DestroyWindow",_ hMainwin as uLong,_ result as boolean 'nonzero=success end
|
|
rwg
New Member
Posts: 49
|
Post by rwg on Apr 8, 2019 15:48:43 GMT -5
many thanks Rod and Metro. i know it sounds odd but the mainwindow is v handy in my application. i'll try out Metro's solution. looks the goods
|
|
rwg
New Member
Posts: 49
|
Post by rwg on Apr 8, 2019 16:36:42 GMT -5
hi Metro - i'm not an great code writer. I've tried to break this down to something really simple. The following code sets the size of the mainwin and places it on the upper left hand side of the screen. It then opens a simple graphics window called PLOT. This window becomes the active window. All I want to do is to make the mainwin the active window. I've tried bits of your code but still cant nail it. Would be great if you could help. cheers rwg
|
|
rwg
New Member
Posts: 49
|
Post by rwg on Apr 8, 2019 16:42:09 GMT -5
sorry Metro - here's the code open "user32" for dll as #1 calldll #user32,"GetActiveWindow",_ mainwinhandle as short calldll #user32,"MoveWindow", _ mainwinhandle as word, _ 0 as short, _ 0 as short, _ 300 as short, _ 600 as short, _ 1 as word, _ result as void close #1 open "PLOT" for graphics_nsb_nf as #w.g calldll #user32, "SetActiveWindow",_ mainwinhandle as short ' ?
|
|
|
Post by Chris Iverson on Apr 8, 2019 16:55:37 GMT -5
Where did you get "short" and "word" from? Window handles should always be ULONG.
Additionally, you've left off the return value on SetActiveWindow(). Even if you don't use it, you still need to collect it.
Also, you don't need to open user32 as #1 if you're using it as #user32(which is opened by LB by default).
Aside from those, you actually got it very close.
calldll #user32,"GetActiveWindow",_ mainwinhandle as ulong
calldll #user32,"MoveWindow", _ mainwinhandle as ulong, _ 0 as short, _ 0 as short, _ 300 as short, _ 600 as short, _ 1 as word, _ result as void
open "PLOT" for graphics_nsb_nf as #w.g
calldll #user32, "SetActiveWindow",_ mainwinhandle as ulong,_ ret as ulong
|
|
rwg
New Member
Posts: 49
|
Post by rwg on Apr 8, 2019 20:54:03 GMT -5
many thanks chris. most grateful. works fine
|
|