Posts: 1,001
Threads: 50
Joined: May 2022
Reputation:
27
10-26-2022, 10:50 PM
(This post was last modified: 10-26-2022, 11:00 PM by Kernelpanic.)
Quote:You have two windows open/ In the pick, look at the title bar. It shows the second window is active. You need to click that first widow to make it active, and then type.
Damned! What a banality!
Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
Yep, the horrors of programming. There have been times I've swore at the computer some trivial thing I messed up in the code is causing the problem, I can can't readily see it. I keep at it, because I know the system isn't the problem.
Oh well, we all can be as brilliant as Steve, but thank Go most of us have exceptionally good looks to compensate for that.
Pete
Posts: 3,932
Threads: 175
Joined: Apr 2022
Reputation:
215
"Oh well, we all can be as brilliant as Steve, but thank Go most of us have exceptionally good looks to compensate for that. Big Grin"
And the others just get a couple of guns to shoot off!
b = b + ...
Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
Yosemite Sam. Taking video game bullet hell to a whole new level!
Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
10-28-2022, 10:43 AM
(This post was last modified: 10-28-2022, 10:45 AM by Pete.)
@Spriggsy
There has to be a better way?!
I thought for fun I'd try to put in a Windows API method of making the window ready to send the message active. The receiving window would become active when it received the message. So now the user just types. No need to click to activate the window anymore, before typing.
So SetActiveWindow and AllowSetForegroundWindow didn't work in this case, so I used a hack that hides, min. and restores the window to mimic the effect. Surely there must be some simple method I'm misssing that could accomplish the some thing without the unwanted special effects. Any ideas?
Name and save as messenger_host
Code: (Select All) DECLARE DYNAMIC LIBRARY "user32"
FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'handle by title
FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
FUNCTION SetForegroundWindow%& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
REM FUNCTION SetActiveWindow& (BYVAL hwnd AS _OFFSET)
FUNCTION GetForegroundWindow%& 'Find currently focused process handle
END DECLARE
_SCREENMOVE 0, 0
title$ = "Messenger_Host"
_TITLE (title$)
_DELAY .1
_SCREENMOVE 0, 0 ' Set up this host window to the left of your desktop.
WIDTH 60, 25
DIM AS STRING host_msg, client_msg
DO
IF initiate = 0 THEN ' This only needs to be performed once, to open the client window.
DO UNTIL x ' Stay in loop until window determines if it is the host or client window.
x = _OPENCLIENT("TCP/IP:1234:localhost") ' Used to establish a TCP/IP routine.
IF x = 0 THEN
x = _OPENHOST("TCP/IP:1234") ' Note the host and clinet must have the same 1234 I.D. number.
a$ = "Opening as host." ' x channel is now open and this window becomes the host.
ELSE
a$ = "Opening as client." ' Should not go here for this demo.
END IF
PRINT a$
LOOP
SHELL _DONTWAIT "messenger_client.exe" ' Open the client window.
initiate = -1 ' Switches this block statement off for all subsequent loops.
END IF
IF z = 0 THEN ' Initiates an open channel number when zero.
DO
z = _OPENCONNECTION(x) ' Checks if host is available to transfer data.
LOOP UNTIL z
PRINT "Connection established."
_DELAY 1
LOCATE 2: PRINT SPACE$(_WIDTH * 2) ' Remove these lines.
LOCATE 3, 1
GOSUB focus ' Sends focus back to host window.
END IF
' Okay, time to input something on the host that will be communicated to the client.
LINE INPUT "Message to client: "; host_msg: PRINT
PUT #z, , host_msg ' Input is now entered into TCP/IP routine.
DO
GET #z, , client_msg
LOOP UNTIL LEN(client_msg) ' Exits loop when a return msg is received.
PRINT "Message from client: "; client_msg: PRINT
host_msg = "": PUT #z, , host_msg$ ' Now put our client value back into the routine. Failure to do so would result in the client not waiting in the GET #x DO/LOOP.
_KEYCLEAR ' Prevents typing before ready.
GOSUB focus
LOOP
focus:
DO UNTIL hwnd%&
_LIMIT 10
hwnd%& = FindWindowA(0, title$ + CHR$(0))
LOOP
FGwin%& = GetForegroundWindow%& 'get current process in focus.
_DELAY .1
IF FGwin%& <> hwnd%& THEN
y& = ShowWindow&(hwnd%&, 0)
y& = ShowWindow&(hwnd%&, 2)
y& = ShowWindow&(hwnd%&, 9)
DO
_LIMIT 10
REM focus%& = SetForegroundWindow%&(hwnd%&) 'Set focus, but not needed with ShowWindows.
FGwin%& = GetForegroundWindow%&
LOOP UNTIL FGwin%& = hwnd%&
END IF
RETURN
Name and save as messenger_client
Code: (Select All) DECLARE DYNAMIC LIBRARY "user32"
FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'handle by title
FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
FUNCTION SetForegroundWindow%& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
REM FUNCTION SetActiveWindow& (BYVAL hwnd AS _OFFSET)
FUNCTION GetForegroundWindow%& 'Find currently focused process handle
END DECLARE
title$ = "Messenger_Client"
_TITLE (title$)
_DELAY .1
DIM AS STRING host_msg, client_msg
_SCREENMOVE 600, 0 ' Set up this client window next to your host window.
WIDTH 50, 25
x = _OPENCLIENT("TCP/IP:1234:localhost") ' Used to establish a TCP/IP routine.
PRINT "Opened as client.": PRINT
DO UNTIL x = 0 ' Prevents running if this app is opened without using host.
DO
_LIMIT 30
GET #x, , host_msg ' Waits until it receives message sent from the host.
LOOP UNTIL LEN(host_msg)
PRINT "Message from host: "; host_msg
PRINT
_KEYCLEAR ' Prevents typing before ready.
GOSUB focus
LINE INPUT "Message to host: "; client_msg: PRINT
PUT #x, , client_msg
LOOP
END
focus:
DO UNTIL hwnd%&
_LIMIT 10
hwnd%& = FindWindowA(0, title$ + CHR$(0))
LOOP
FGwin%& = GetForegroundWindow%& 'get current process in focus.
_DELAY .1
IF FGwin%& <> hwnd%& THEN
y& = ShowWindow&(hwnd%&, 0)
y& = ShowWindow&(hwnd%&, 2)
y& = ShowWindow&(hwnd%&, 9)
DO
_LIMIT 10
FGwin%& = GetForegroundWindow%&
LOOP UNTIL FGwin%& = hwnd%&
END IF
RETURN
Pete
Posts: 1,001
Threads: 50
Joined: May 2022
Reputation:
27
Where are my pictures? Have they all been deleted?
Posts: 2,160
Threads: 222
Joined: Apr 2022
Reputation:
102
Imgbb isn't showing the page that photo was linked to. It seems the page was lost in their database. I checked another post of yours and that pic was still up: https://ibb.co/TWtc6LS
This would never happen at my QBasic Forum, for two reasons.
1) Tapatalk hosts all pics posted to our account.
2) There is no one there to posts pics!
Well, let's hope this Imgbb glitch doesn't become more prevalent. An alternative to using Imgbb is to link sites from your own site, if you have one, or... what we can all do, add the pics as an attachment instead of choosing "Upload a pic" from the menu bar.
Pete
Posts: 1,001
Threads: 50
Joined: May 2022
Reputation:
27
Thanks for the hint! Another picture has disappeared, I noticed it earlier. But I'm not looking at all the pictures now, ne.
https://qb64phoenix.com/forum/showthread...07#pid8607
Posts: 1,001
Threads: 50
Joined: May 2022
Reputation:
27
10-28-2022, 08:28 PM
(This post was last modified: 10-28-2022, 08:28 PM by Kernelpanic.)
Quote:2) There is no one there to posts pics!
Ha-ha-ha! But, a picture says more than a thousand words! Mostly!
Posts: 1,587
Threads: 59
Joined: Jul 2022
Reputation:
52
I took the tip here from @Kernelpanic to use the other image-sharing site. It's because I belong to other forums and they're not as lenient as this one uploading content. Most of the time things need to be uploaded fast where the pressure comes from. The quota on this forum is "unlimited" but I'm not going to trust that. It's likely I would go crazy posting ZIP files with source code and related files, such as for a fancy-looking video game...
|