i have winform application (.net 2.0 c#). application, want start process (another winform application) , dock window (or @ least make docked). far, can find information docking controls, not windows in separate processes. first thought handle of window , use unmanaged system calls set height/width , position of window docking area. before got started, wanted check see if of people have done similar. have access source code of application want docked rather not make changes if can avoid it. have complete programming control on parent application. advice? in advance!
the solution have used before set application window child of control want dock in.
using system.diagnostics; using system.runtime.interopservices; private process pdocked; private intptr hwndoriginalparent; private intptr hwnddocked; [dllimport("user32.dll")] public static extern intptr setparent(intptr hwndchild, intptr hwndnewparent); [dllimport("user32.dll", setlasterror = true)] public static extern bool movewindow(intptr hwnd, int x, int y, int nwidth, int nheight, bool brepaint); private void dockit() { if (hwnddocked != intptr.zero) //don't if there's window docked. return; hwndparent = intptr.zero; pdocked = process.start(@"notepad"); while (hwnddocked == intptr.zero) { pdocked.waitforinputidle(1000); //wait window ready input; pdocked.refresh(); //update process info if (pdocked.hasexited) { return; //abort if process finished before got handle. } hwnddocked = pdocked.mainwindowhandle; //cache window handle } //windows api call change parent of target window. //it returns hwnd of window's parent prior call. hwndoriginalparent = setparent(hwnddocked, panel1.handle); //wire event keep window sized match control panel1.sizechanged += new eventhandler(panel1_resize); //perform initial call set size. panel1_resize(new object(), new eventargs()); } private void undockit() { //restores application it's original parent. setparent(hwnddocked, hwndoriginalparent); } private void panel1_resize(object sender, eventargs e) { //change docked windows size match parent's size. movewindow(hwnddocked, 0, 0, panel1.width, panel1.height, true); }
Comments
Post a Comment