Pass values (longs) between two PB programs.
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Pass values (longs) between two PB programs.
I'm sure I have seen a post explaining how to do this, but I cannot find it
today.
Program A optionally launches Program B
I really need the Program B to be able to access the contents of a
gadget in Program A (the calling program), manipulate it, and then update
the original gadget's contents in the active Program A.
Anybody got a pointer for me?
today.
Program A optionally launches Program B
I really need the Program B to be able to access the contents of a
gadget in Program A (the calling program), manipulate it, and then update
the original gadget's contents in the active Program A.
Anybody got a pointer for me?
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
Accessing another windows controls is very easy, since controls are publiclly exposed and accessible using SendMessage.
GadgetID() returns the handle needed to identify the gadget.
Compile the following example a A.exe and B.exe.
GadgetID() returns the handle needed to identify the gadget.
Compile the following example a A.exe and B.exe.
Code: Select all
;A.pb
If OpenWindow(0, 0, 0, 100, 50, #PB_Window_WindowCentered|#PB_Window_SystemMenu, "Program A")
If CreateGadgetList(WindowID(0))
StringGadget(0, 0, 0, 100, 20, "")
ButtonGadget(1, 0, 30, 100, 20, "Launch B")
EndIf
EndIf
Repeat
e = WaitWindowEvent()
Select e
Case #PB_Event_Gadget
Select EventGadgetID()
Case 1
RunProgram("B.exe", Str(GadgetID(0)), ".")
EndSelect
EndSelect
Until e = #PB_Event_CloseWindow
Code: Select all
;B.pb
Declare.s GetTextFromA()
Awnd = Val(ProgramParameter())
If OpenWindow(0, 0, 0, 100, 50, #PB_Window_WindowCentered|#PB_Window_SystemMenu, "Program B")
If CreateGadgetList(WindowID(0))
TextGadget(0, 0, 0, 100, 20, "")
ButtonGadget(1, 0, 30, 100, 20, "Get Text from A")
EndIf
EndIf
GetTextFromA()
Repeat
e = WaitWindowEvent()
Select e
Case #PB_Event_Gadget
Select EventGadgetID()
Case 1
GetTextFromA()
EndSelect
EndSelect
Until e = #PB_Event_CloseWindow
Procedure.s GetTextFromA()
Shared Awnd
buffer.s = Space(255)
SendMessage_(Awnd, #WM_GETTEXT, 255, @buffer)
SetGadgetText(0, PeekS(@buffer))
EndProcedure
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
I use normaly the following methode:
I create an invisible window with an unique ID and waiting for messages in his callback.
Another application uses FindWindow_() to get the handle of the recipient window. Then I only use SendMessage_ API to send a user defined Message (#WM_User+x) plus an optional lparam and/ or wparam.
cheers
Mike
I create an invisible window with an unique ID and waiting for messages in his callback.
Another application uses FindWindow_() to get the handle of the recipient window. Then I only use SendMessage_ API to send a user defined Message (#WM_User+x) plus an optional lparam and/ or wparam.
cheers
Mike
Tranquil
-
- Enthusiast
- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
i think u only need to use that wen u use #hwnd_broadcast .....GreenGiant wrote:I'd also reccomend using user-defined messages. But if you are going to use them, don't forget to use RegisterWindowMessage_() to avoid trouble.

if u know the exact hwnd then u can use #wm_user etc
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
-
- Enthusiast
- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
I'm not an expert, but I understood that RegisterWindowMessage should always be used.
Say for example that you are sending a pointer to a string between two programs using #WM_User+17 (directly, not broadcasting it). Suppose another program is broadcasting a pointer to a function and is also using WM_User+17. Then because you didn't use RegisterWindowMessage to get an unique message your program will sometimes be sent the function pointer which could lead to problems if you try to write a string to it.
Say for example that you are sending a pointer to a string between two programs using #WM_User+17 (directly, not broadcasting it). Suppose another program is broadcasting a pointer to a function and is also using WM_User+17. Then because you didn't use RegisterWindowMessage to get an unique message your program will sometimes be sent the function pointer which could lead to problems if you try to write a string to it.
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
well, anyone using a #wm_user value in a broadcast message is pretty silly
doing so can cause all sorts of problems - like in ure example greengiant, u can still use registerwindowmessage to send a message to a hwnd that u know is ures, but if u know the hwnd u can use #wm_user+wateva ....
btw greengiant im not an expert either!!
also is this really needed?
cant it be:
?

btw greengiant im not an expert either!!

also is this really needed?
Code: Select all
SetGadgetText(0, PeekS(@buffer))
Code: Select all
SetGadgetText(0, buffer)
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
I think Terry should walk before he can run.
Once he has the hand of sending standard messages, he can start registering his own.
One the registering of messages the SDK has the following to say:
Once he has the hand of sending standard messages, he can start registering his own.
One the registering of messages the SDK has the following to say:
Only use RegisterWindowMessage when more than one application must process the same message. For sending private messages within a window class, an application can use any integer in the range WM_USER through 0x7FFF. (Messages in this range are private to a window class, not to an application. For example, predefined control classes such as BUTTON, EDIT, LISTBOX, and COMBOBOX may use values in this range.)
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
also, ive found that in purebasic if u use a window callback u can use either sendmessage_() or postmessage_()
but if u dont use a callback it seems as tho u have to use postmessage_() .....
correct me if im wrong please
but if u dont use a callback it seems as tho u have to use postmessage_() .....
correct me if im wrong please

Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact: