|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How should one form call another?I have a form with 3 cmdbuttons for 3 choices of action. one action shows a second form. the second form allows interaction with another external app(acad). In the first form (StartFrm) Private Sub CmdPlace_Click() 'hide startup form Me.Hide 'show secondform ShowForm2 End Sub Public Sub ShowForm2() 'create, load, setproperties,show form Set moStdFrm = New DataFrm5 Load moStdFrm 'set control values and positions moStdFrm.Setup 'set whatever properties Set moStdFrm.Propertyx = somevalue 'etc '-------------------------------------------------- 'this seems to work ok 'setparent to acad app via SetParent Api SetParent moStdFrm.hwnd, GetAcadHwnd(moAcadApp) '-------------------------------------------------- 'this doesn't work 'SetParent moStdFrm.hwnd, Me.hwnd '-------------------------------------------------- moStdFrm.Show End sub 'in the second form Private Sub Form2_Terminate() 'return to startup form for further choices StartFrm.Show End Sub is that the "right" (best?) way to show one form from another and return to the first when the second is dismissed? Thanks Mark "MP" <Nomospam@Thanks.com> wrote in message I cant get the first form to reliably show back up after showing the secondnews:43484d46$0$4859$8b463f8a@news.nationwide.net... > Hi > I have a form with 3 cmdbuttons for 3 choices of action. > one action shows a second form. > > the second form allows interaction with another external app(acad). form, and then when the second form is dismissed it's supposed to show the first one again, I'm lost in setparent, modal/modeless, and ownership of forms ignorance I just dont understand the basics of how i'm supposed to get control of when forms show so they happen consistently, This is a std exe with startup item = Sub Main. When the .exe is fired the first form should appear on top of whatever windows are open. then when a cmdbutton is clicked the first form should hide and second form should show and allow interaction with the external app. should I be setting the parent = external app? that seems to work ok for the interaction but don't know if it's causeing problem with not being able to re-show the first form after second is dismissed. Who should own the first form? It is called from a std module Main sub. so I cant do Form1.Show vbModal, Me Who should own the second form? I can do Form2.Show vbModal, Me (when in form1) but then Form2 doesn't show is that because i'm hiding form1 before showing form2 and since form1 is the owner then it doesn't show? I don't understand what ownership does to or for a form...do i need it at all??? when the second form is dismissed, the first form should show back up, again despite whatever other windows may be open. Can anyone explain the basics of what I need to be doing to accomplish that? Do I need to be callng SetWindowForeground or something like that? I dont know why I'm having so much trouble with this rudimentary part of the ui process....well, other than obvious lack of knowlege that is! :-) Thanksmark > SetParent moStdFrm.hwnd, GetAcadHwnd(moAcadApp) SetParent cannot be used with a window in a different process(EXE). Windows is probably ignoring it so it has no effect. You could use SetParent if your project was ActiveX DLL or Control(OCX). If you set your project to ActiveX DLL, then you have to add it to the list of references in VBA of acad, otherwise your DLL doesn't get loaded. A DLL does not run on its own in a separate process, but runs on the same process as acad. > 'in the second form Put this code in Form2_Unload instead. Form_Unload is not called when the > Private Sub Form2_Terminate() > 'return to startup form for further choices > StartFrm.Show > End Sub form is hidden by Hide method. > I'm lost in setparent, modal/modeless, and ownership of forms ignorance From a post I sent to another person:Use the following if you want the user not to go back to Form1 until he or she finishes with Form2: Form2.Show vbModal Use the following if you want the user to go back and forth between the 2 forms: Form2.Show , Me While the ", Me" is optional, it specify the owner window for Form2. When you use it, the 2 forms are minimized together if the user minimized Form1, and unloaded together if the user closed Form1. If you have used just "Form2.Show", then if the user wants to minimize your App to work on another application, he or she has to minimize both forms manually, which would be annoying. For more information click F1 while the cursor is on Show. In Form2, usually the form is unloaded when the user clicks an OK button like this: Private Sub btnOK_Click() Unload Me End Sub Show quoteHide quote "MP" <Nomospam@Thanks.com> wrote in message news:43484d46$0$4859$8b463f8a@news.nationwide.net... > Hi > I have a form with 3 cmdbuttons for 3 choices of action. > one action shows a second form. > > the second form allows interaction with another external app(acad). > > In the first form (StartFrm) > Private Sub CmdPlace_Click() > 'hide startup form > Me.Hide > 'show secondform > ShowForm2 > End Sub > > Public Sub ShowForm2() > 'create, load, setproperties,show form > Set moStdFrm = New DataFrm5 > Load moStdFrm > > 'set control values and positions > moStdFrm.Setup > 'set whatever properties > Set moStdFrm.Propertyx = somevalue > 'etc > > '-------------------------------------------------- > 'this seems to work ok > 'setparent to acad app via SetParent Api > SetParent moStdFrm.hwnd, GetAcadHwnd(moAcadApp) > > '-------------------------------------------------- > 'this doesn't work > 'SetParent moStdFrm.hwnd, Me.hwnd > '-------------------------------------------------- > > moStdFrm.Show > > End sub > > > 'in the second form > Private Sub Form2_Terminate() > 'return to startup form for further choices > StartFrm.Show > End Sub > > is that the "right" (best?) way to show one form from another and return > to > the first when the second is dismissed? > Thanks > Mark > > "Someone" <nob***@cox.net> wrote in message news:Hu_1f.2271$MN6.1535@fed1read04...> > SetParent moStdFrm.hwnd, GetAcadHwnd(moAcadApp) interesting, it does "seem" to work. If I include that line the form is> > SetParent cannot be used with a window in a different process(EXE). Windows > is probably ignoring it so it has no effect. You could use SetParent if your > project was ActiveX DLL or Control(OCX). If you set your project to ActiveX > DLL, then you have to add it to the list of references in VBA of acad, > otherwise your DLL doesn't get loaded. A DLL does not run on its own in a > separate process, but runs on the same process as acad. "trapped" inside acad's window - if I move it past the border of acad window it disappears behind the edge of the window - if i don't have that line it would be a separate window and float off onto the desktop or whatever window was next to the edge of the acad window...weird. > thanks for that I'll try it.> Put this code in Form2_Unload instead. Form_Unload is not called when the > form is hidden by Hide method. Show quoteHide quote > ah so sounds like i want Form2.Show vbModal, Me> > I'm lost in setparent, modal/modeless, and ownership of forms ignorance > > From a post I sent to another person: > > Use the following if you want the user not to go back to Form1 until he or > she finishes with Form2: > > Form2.Show vbModal > > Use the following if you want the user to go back and forth between the 2 > forms: > > Form2.Show , Me > > While the ", Me" is optional, it specify the owner window for Form2. When > you use it, the 2 forms are minimized together if the user minimized Form1, > and unloaded together if the user closed Form1. > > If you have used just "Form2.Show", then if the user wants to minimize your > App to work on another application, he or she has to minimize both forms > manually, which would be annoying. For more information click F1 while the > cursor is on Show. > I'll see if it helps with the problems I was having. Thanks Mark > interesting, it does "seem" to work. If I include that line the form is This may not work in other OS'es, but I haven't used it that way. What OS > "trapped" inside acad's window - if I move it past the border of acad > window > it disappears behind the edge of the window - if i don't have that line it > would be a separate window and float off onto the desktop or whatever > window > was next to the edge of the acad window...weird. are you using? Here are some articles that provide background information: See "Window Relationships" here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp INFO: Window Owners and Parents http://support.microsoft.com/default.aspx?scid=kb;en-us;84190 The above articles show API constants. To see what style constants VB6 used to create these forms, use Spy++ from VS6 Tools in the Start menu. Locate your form and double click it. If it's hard to find, use Spy|Find Window to find it. Make sure that you select the entire form, not just a window inside it. See the Styles and Class tabs. Show quoteHide quote "MP" <nospam@Thanks.com> wrote in message news:lfu2f.116310$3S5.60284@tornado.rdc-kc.rr.com... > "Someone" <nob***@cox.net> wrote in message > news:Hu_1f.2271$MN6.1535@fed1read04... >> > SetParent moStdFrm.hwnd, GetAcadHwnd(moAcadApp) >> >> SetParent cannot be used with a window in a different process(EXE). > Windows >> is probably ignoring it so it has no effect. You could use SetParent if > your >> project was ActiveX DLL or Control(OCX). If you set your project to > ActiveX >> DLL, then you have to add it to the list of references in VBA of acad, >> otherwise your DLL doesn't get loaded. A DLL does not run on its own in a >> separate process, but runs on the same process as acad. > > interesting, it does "seem" to work. If I include that line the form is > "trapped" inside acad's window - if I move it past the border of acad > window > it disappears behind the edge of the window - if i don't have that line it > would be a separate window and float off onto the desktop or whatever > window > was next to the edge of the acad window...weird. > > >> >> Put this code in Form2_Unload instead. Form_Unload is not called when the >> form is hidden by Hide method. > > thanks for that I'll try it. > >> >> > I'm lost in setparent, modal/modeless, and ownership of forms ignorance >> >> From a post I sent to another person: >> >> Use the following if you want the user not to go back to Form1 until he >> or >> she finishes with Form2: >> >> Form2.Show vbModal >> >> Use the following if you want the user to go back and forth between the 2 >> forms: >> >> Form2.Show , Me >> >> While the ", Me" is optional, it specify the owner window for Form2. When >> you use it, the 2 forms are minimized together if the user minimized > Form1, >> and unloaded together if the user closed Form1. >> >> If you have used just "Form2.Show", then if the user wants to minimize > your >> App to work on another application, he or she has to minimize both forms >> manually, which would be annoying. For more information click F1 while >> the >> cursor is on Show. >> > > ah so sounds like i want Form2.Show vbModal, Me > I'll see if it helps with the problems I was having. > Thanks > Mark > > "Someone" <nob***@cox.net> wrote in message news:Mcz2f.2480$MN6.2053@fed1read04...> > interesting, it does "seem" to work. If I include that line the form is win2k pro> > "trapped" inside acad's window - if I move it past the border of acad > > window > > it disappears behind the edge of the window - if i don't have that line it > > would be a separate window and float off onto the desktop or whatever > > window > > was next to the edge of the acad window...weird. > > This may not work in other OS'es, but I haven't used it that way. What OS > are you using? > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowfeatures.asp> Here are some articles that provide background information: > > See "Window Relationships" here: > Show quoteHide quote > thanks for those links, I'll check them out...sounds exactly like the kind> INFO: Window Owners and Parents > http://support.microsoft.com/default.aspx?scid=kb;en-us;84190 > > The above articles show API constants. To see what style constants VB6 used > to create these forms, use Spy++ from VS6 Tools in the Start menu. Locate > your form and double click it. If it's hard to find, use Spy|Find Window to > find it. Make sure that you select the entire form, not just a window inside > it. See the Styles and Class tabs. > > > of knowledge I'm lacking at this point. Show quoteHide quote :-) Mark "MP" <nospam@Thanks.com> wrote in message fwiw, SetParent >can< work to parent a window to a window in another news:rFB2f.116345$3S5.80099@tornado.rdc-kc.rr.com... > > win2k pro process. Thing is, you're setting the parent... that's it. There's no cross-process communication or anything. A form's just as happy inside an autocad window as it is on a desktop.... you can do the same thing to bring Autocad, Word, Excel, whatever into a form in your app. See this sample for "proof" OFramer.exe - Sample: OFramer.exe Automates Excel and Word Inside a VB http://www.cyf-kr.edu.pl/ftp/softlib/full.html From the sounds of things, you'd want to show the form Modal. In that sub, do something like..... Private Sub CmdPlace_Click() 'hide startup form Me.Hide 'show secondform ShowForm2 Me.Show 'since you called Me.Hide, you'll have to Me.Show End Sub in ShowForm2, use: .. code .. code .. code moStdFrm.Show vbModal End sub 'this won't run until moStdFrm is hidden or unloaded -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Please keep all discussions in the groups..
Show quote
Hide quote
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message Thanks, That's indeed what I'm seeing.news:u0ljmlezFHA.3188@TK2MSFTNGP14.phx.gbl... > "MP" <nospam@Thanks.com> wrote in message > news:rFB2f.116345$3S5.80099@tornado.rdc-kc.rr.com... > > > > win2k pro > > fwiw, SetParent >can< work to parent a window to a window in another > process. Thing is, you're setting the parent... that's it. There's no > cross-process communication or anything. A form's just as happy inside an > autocad window as it is on a desktop.... you can do the same thing to bring > Autocad, Word, Excel, whatever into a form in your app. See this sample for > "proof" the "cross process communicating" is occuring because I have a reference to the autocad api, a reference to a running instance of the application, and then make calls on that app from the command buttons of "Form2". Maybe "cross-process communicating" isn't the right name for it...I'm just using the activex object model of an application from a form which is "out-of-process" to that application. (I would have preferred making it an in-process dll but failed to overcome all the obstacles of showing a form from the dll and having it work right.) so I gave up on the dll version and went back to a "standard exe" version. I'm going to read the links provided by "Someone" but for the moment I was guessing that by setting the acad window as parent to 'Form2", that if the user closed acad while my app was running(which they *shouldn't* but they certainly *Could*), that would close my app...which would be preferrable since with no acad my app will be calling a nonexistant object... not good... :-) I'm not sure if "Parentage" does that or if that's more an "ownership"thing...still have to read and digest that info on windows hierarchy issues. Show quoteHide quote > actually in Form2_Terminate I was calling "moStartFrm.Show vbModal"> OFramer.exe - Sample: OFramer.exe Automates Excel and Word Inside a VB > http://www.cyf-kr.edu.pl/ftp/softlib/full.html > > From the sounds of things, you'd want to show the form Modal. In that sub, > do something like..... > > Private Sub CmdPlace_Click() > 'hide startup form > Me.Hide > 'show secondform > ShowForm2 > Me.Show 'since you called Me.Hide, you'll have to Me.Show > End Sub maybe that accomplishes the same thing? or maybe that was what was causeing me problems Private Sub Form_Terminate() 'i tried both of these and sometimes it worked and sometimes not... 'moStartFrm.Show vbmodal 'moStartFrm.Show End Sub Then I was advised to put that in Form_Unload instead of _Terminate. Don't know if that would help. Haven't had time to rewrite and try. For now I've abandoned trying to get form 1 to show form2 and just calling form2 directly from sub Main. What that means is I'll have to create a different command in acad for each of the 3 phases of this project. The original design was to have one autocad command show "Form1" or a better pseudonym would be "StartupForm" Then there were 3 command buttons for the three phases of the project. PhaseOne was what I was referring to above as "Form2" Right now I have to suspend that dream and deal with some errors I'm getting in my core code in Phase Two of the project. I'll have to deal with user interface issues that are giving my ignorance such a workout at a later date - I need to get the functionality available asap. The elegance or lack thereof of the user interface is a secondary requirement at this point. > ah, maybe that's part of my problem...I hide moStdFrm multiple times> in ShowForm2, use: > > . code > . code > . code > moStdFrm.Show vbModal > > End sub 'this won't run until moStdFrm is hidden or unloaded throughout the program in order for the user to pick points or objects in the acad window. It works perfect if I call the form direct from sub main but I was having all kinds of problems trying to call it from StartupForm Is that what was causing my problems? End Sub runs when a modal form is hidden???? Many thanks for your weighing in on this topic Mark |
|||||||||||||||||||||||