Click here to Skip to main content
15,881,600 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
Luc Pattyn2-Jan-18 12:41
sitebuilderLuc Pattyn2-Jan-18 12:41 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk32-Jan-18 13:08
turbosupramk32-Jan-18 13:08 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
Luc Pattyn2-Jan-18 13:31
sitebuilderLuc Pattyn2-Jan-18 13:31 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk33-Jan-18 2:51
turbosupramk33-Jan-18 2:51 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
Richard MacCutchan3-Jan-18 23:18
mveRichard MacCutchan3-Jan-18 23:18 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk35-Jan-18 16:43
turbosupramk35-Jan-18 16:43 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
Richard MacCutchan5-Jan-18 22:24
mveRichard MacCutchan5-Jan-18 22:24 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk36-Jan-18 2:21
turbosupramk36-Jan-18 2:21 
Sure thing, the first block is my Pininvoke code, then the standard function and then the test button.

The standard function code will put the form to topmost, but will not remove the topmost flag. The test button will remove the topmost flag after the standard function places the topmost flag.



private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
        private static readonly IntPtr HWND_TOP = new IntPtr(0);

        private const UInt32 SWP_NOSIZE = 0x0001;
        private const UInt32 SWP_NOMOVE = 0x0002;
        private const UInt32 SWP_NOZORDER = 0x0004;
        private const UInt32 SWP_NOREDRAW = 0x0008;
        private const UInt32 SWP_NOACTIVATE = 0x0010;
        private const UInt32 SWP_DRAWFRAME = 0x0020;
        private const UInt32 SWP_FRAMECHANGED = 0x0020;
        private const UInt32 SWP_SHOWWINDOW = 0x0040;
        private const UInt32 SWP_HIDEWINDOW = 0x0080;
        private const UInt32 SWP_NOCOPYBITS = 0x0100;
        private const UInt32 SWP_NOOWNERZORDER = 0x0200;
        private const UInt32 SWP_NOREPOSITION = 0x0200;
        private const UInt32 SWP_NOSENDCHANGING = 0x0400;
        private const UInt32 SWP_DEFERERASE = 0x2000;
        private const UInt32 SWP_ASYNCWINDOWPOS = 0x4000;

        private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
        private const UInt32 NOTOPMOST_FLAGS = TOPMOST_FLAGS | SWP_SHOWWINDOW;

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);


private void btnType_Click(object sender, EventArgs e)
{
    try
    {
        if (tbxTagList.Text == "")
        {
            MessageBox.Show("Please enter in at least 1 tag");
            return;
        }

        int x = Convert.ToInt32(tbxXCoordinates.Text);
        int y = Convert.ToInt32(tbxYCoordinates.Text);
        SimulateMouseClick(x, y);
        foreach (char character in tbxTagList.Text)
        {

            if ((character != '\n') && (character != '\r'))
            {
                SendKeys.Send(character.ToString());
            }

            if (character == '\n')
            {
                SendKeys.Send("{Enter}");
                Thread.Sleep(3); // 1/2/18
            }

            Thread.Sleep(3);
        }

        tbxXCoordinates.Text = "";
        tbxYCoordinates.Text = "";
        //Thread.Sleep(250);
        SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, NOTOPMOST_FLAGS);
        //Application.DoEvents();
        //btnTest.PerformClick();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message + " | " + ex.Source + " | " + ex.InnerException + " | " + ex.StackTrace);
    }
}



private void btnTest_Click(object sender, EventArgs e)
       {
           SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, NOTOPMOST_FLAGS);
       }

GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
Richard MacCutchan6-Jan-18 5:53
mveRichard MacCutchan6-Jan-18 5:53 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk36-Jan-18 6:17
turbosupramk36-Jan-18 6:17 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk36-Jan-18 12:09
turbosupramk36-Jan-18 12:09 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
Richard MacCutchan6-Jan-18 20:44
mveRichard MacCutchan6-Jan-18 20:44 
Questionusing MVC in WPF Pin
abboudi_ammar1-Jan-18 5:38
abboudi_ammar1-Jan-18 5:38 
AnswerRe: using MVC in WPF Pin
Dave Kreskowiak1-Jan-18 6:16
mveDave Kreskowiak1-Jan-18 6:16 
GeneralRe: using MVC in WPF Pin
abboudi_ammar1-Jan-18 6:24
abboudi_ammar1-Jan-18 6:24 
GeneralRe: using MVC in WPF Pin
Dave Kreskowiak1-Jan-18 7:27
mveDave Kreskowiak1-Jan-18 7:27 
Questionstruck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 2:33
Mohiyuddin Khan1-Jan-18 2:33 
AnswerRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 2:41
mveOriginalGriff1-Jan-18 2:41 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 3:15
Mohiyuddin Khan1-Jan-18 3:15 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 3:37
mveOriginalGriff1-Jan-18 3:37 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 3:50
Mohiyuddin Khan1-Jan-18 3:50 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 4:19
mveOriginalGriff1-Jan-18 4:19 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 18:16
Mohiyuddin Khan1-Jan-18 18:16 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 23:16
Mohiyuddin Khan1-Jan-18 23:16 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 23:31
mveOriginalGriff1-Jan-18 23:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.