on 09-18-2013 9:19 PM
I have a powerbuilder application and now we are taking part of this application and migrating them to our new
.net app. Our delimma is that we must use both applications at this time and in order to move back and forth
between these applications both applications must pass data between both apps to determine the modules user is
working with.
Our .net developers tell me that they have created a method in thier app that when there app is called, if app
is not already running it starts the app but if app is running the instance that is running somehow determines
this call to launch and then since it is already running does not start another instance of the app and simply
takes the parms passed via commandline and passes them to the instance of the app already running. (how they do that I have no idea because I am under the impression that even the .net app will fire the open event of the app (.net app is window based app) and will try to start a new instance why it tries to send this to an instance that is already running I am not sure but they claim it is happening)
Is this possible in my PB application? I know I can code the open event of my app and check for the main window
winhandle = FindWindow( 0, "w_main")
if I have defined the FindWindow fucntion from user32.dll as an external fucntion and if an instance is already
open then I can get the Commandline argument in the open event to get the commandline parms and not open another
instance but these commandline parms will be in the context of the second instance that was being strated.
The first instance already running have no clue about the commandline parms but I want these commandline parms
to be used in the first instance? is this even possible? does my question make sense? Please help.
Hi Javed:
I built a small test case that hopefully helps.
Here's the outline:
Global External functions:
PUBLIC FUNCTION unsignedlong FindWindow (long classname, string windowname) LIBRARY "user32.dll" ALIAS FOR FindWindowW
PUBLIC FUNCTION int SetForegroundWindow (unsignedlong hwnd) LIBRARY "user32.dll"
PB application Open:
unsignedlong hwnd
hwnd = FindWindow( 0, "MyPBApp")
if hwnd = 0 then
// No previous instance, so open the main window
open( w_myapp )
else
// Open the previous instance window and halt
SetForegroundWindow( hwnd )
// Save new command line in Registry
RegistrySet("HKEY_LOCAL_MACHINE\Software\MyPBApp","commandline", RegString!, commandline)
// Trigger pbm_custom01 event on currently open MyPBApp to read new commandline
Send(hwnd, 1024, 1, 0)
HALT CLOSE
end if
Define a user event on your main window (MyPBApp) mapped to pbm_custom01 populated with hte following Powerscript:
string commandline
RegistryGet("HKEY_LOCAL_MACHINE\Software\MyPBApp","commandline", RegString!, commandline)
MessageBox("New commandline", commandline)
I tested and it seems to work. Let me know if you need clarification.
Cheers...Bob
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can tell without testing it that bob your idea will work great, however many thanks to scott before that for explaining, this is great. I know powerbuilder but I do not consider myself a guru but the advice I have received is definitely great advice, let me implement and I will report back.
Bob: I have not tried the solution u have suggested but I am surely going to try it since of all the suggestions I have this makes most sense in my case. I am going to put a proof of concept together using this approach and I will let you know how it goes, the only thing is that I am juggling so many different balls that this have to wait for right now.
Javed
Hi Bob: I knew I am going to end up asking u some questions about this, because my experience with using windows api function has not been very pleasant. As I expected findwindow(0,"w_main") is not bale to find this window even when it is open inside the exe. I am assuming that I will have to pass the same window to findwindow method that has my custom event coded in it since Send(hwnd, 1024, 1, 0) is the handle that I acquired via findwindow method. Is my understanding incorrect and do I have to pass something else to findwindow method, I doubt it but I am not sure what am I doing wrong. Thanks for your help.
Bob: never mind my previous question about findwindow method not working. I found out that the second parm passed to findwindow method must be the 'title' of the window and not the acutal name of the window which makes sense because api can probably find the title because title is an attribute of the window that stays valid through out the life of the object whereas the object name may only be internal to the program (it makes sense) and after I passed to window title the findwindow method was able to find the handle and hence I was able to call my custom event I wrote for that window and now everything is working seamlessley, thanks to you for your idea.
User | Count |
---|---|
78 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.