winapi - How to prevent another app from moving (MS Excel 2010) in C# -


i need app open excel 2010 , position in specific area of application. need excel unresizable, unmovable , eliminate menu interactions (close, maximize, minimize)

i've found solution everything, apart making unmovable. tried use setwindowpos , set swp_nomove flag , few other flags got no success @ all.

--specifications: i'm using wpf c#.net 4.0 , ms excel 2010.

--below method i've come with. work expected apart setwindowpos (it doesn't have effect @ all)

public static void startexcel(string p_processarguments, int p_x, int p_y, int p_height, int p_width,                                   bool p_startmin = true, bool p_setforeground = true, bool p_useshell = true,                                   bool p_waitinput = true, bool p_setnewstyles = true, bool p_removemenu = true)     {         //make sure there no excel opened (kill them -  if any)         closeallexcelprocesses(true);          //make basic validations , required info.                    if (!validateprocessargument(p_processarguments))             throw new exception("process' argument invalid or incorrectly setted. " + p_processarguments);          processstartinfo psiapp = new processstartinfo("excel", p_processarguments);         if (p_useshell)             psiapp.useshellexecute = true;         else             psiapp.useshellexecute = false;          if (p_startmin)             psiapp.windowstyle = processwindowstyle.minimized;          process papp = process.start(psiapp);         if (p_waitinput)             papp.waitforinputidle();          //wait app receive window handle(id) max limit of 3sec.         (int = 0; < 25; i++)         {             system.threading.thread.sleep(100);         }          if (papp.mainwindowhandle != (intptr)0)         {             if (p_startmin) //now restore state                 win32import.showwindow(papp.mainwindowhandle, windowshowstyle.shownormal);              //set foreground             if (p_setforeground)                 win32import.setforegroundwindow(papp.mainwindowhandle);              if (p_setnewstyles)             {                 //make overlapped window (which has no size border, title bar , etc).                 int style = win32import.getwindowlong(papp.mainwindowhandle, win32import.gwl_style);                 win32import.setwindowlong(papp.mainwindowhandle, win32import.gwl_style, (uint)(style & ~win32.windowstyles.ws_overlappedwindow));                  //not working - apply flags, make unmovable.                 win32import.setwindowpos(papp.mainwindowhandle, (intptr)0, 0, 0, 0, 0, win32.swp.nomove);                 win32import.updatewindow(papp.mainwindowhandle);             }              if (p_removemenu)             {                                     //get app original menu.                 intptr hmenu = win32import.getsystemmenu(papp.mainwindowhandle, false);                 //get amount of menu app has.                 int count = win32import.getmenuitemcount(hmenu);                  //remove existing main menus.                 (uint = 0; < count; i++)                     win32import.removemenu(hmenu, i, (win32import.mf_byposition | win32import.mf_remove));                  //force redraw.                 win32import.drawmenubar(papp.mainwindowhandle);             }              //move window specified location , size (set new position).                             win32import.movewindow(papp.mainwindowhandle, p_x, p_y, p_width, p_height, true);                         }         else         {             throw new exception("startembeddedapp - couldn't embedded app handle.");         }     } 

i've come few different ideas such interceping excel wm_message (perhaps using hwndsource). idea not complicated achieve welcome!

thanks in advance, luís.

i think mistaken swp_nomove parameter. parameter not mean window not movable, means x,y parameters ignored during specific call method setwindowpos. goal of flag use function setwindowpos changing size of target window without changing position.

from setwindowpos in msdn:

swp_nomove 0x0002 retains current position (ignores x , y parameters).

something try create custom window on application handles messages related size , position (examples:wm_size, wm_sizing, wm_windowposchanged, wm_windowposchanging, etc) prevent modifications, set excel window child window of custom window.

you try to remove title bar


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -