Autor Beitrag
sataan1337
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 08.02.09 22:30 
moin

ich wollte mal etwas rumprobieren (bin blutiger anfänger ^^ - sollte ich dazusagen) - und ein fenster im "hintergrund" halten - also quasi an den desktop heften
(wer sich jetzt nach dem sinn des ganzen fragt - gute frage ^^ - auf die idee gekommen bin ich über den mandriva-desktop)

bin dabei via google auf den setwindowpos() befehl gestossen - der bei mir nur irgendwie nicht richtig funktionieren will ^^ - vielleicht findet ja von euch jemand was ich falsch gemacht haben könnte

hier mal der code:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace hintergrundfenster
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
            int Y, int cx, int cy, uint uFlags);

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

        const UInt32 SWP_NOSIZE = 0x0001;
        const UInt32 SWP_NOMOVE = 0x0002;
        const UInt32 SWP_NOZORDER = 0x0004;
        const UInt32 SWP_NOREDRAW = 0x0008;
        const UInt32 SWP_NOACTIVATE = 0x0010;
        const UInt32 SWP_FRAMECHANGED = 0x0020;  /* The frame changed: send WM_NCCALCSIZE */
        const UInt32 SWP_SHOWWINDOW = 0x0040;
        const UInt32 SWP_HIDEWINDOW = 0x0080;
        const UInt32 SWP_NOCOPYBITS = 0x0100;
        const UInt32 SWP_NOOWNERZORDER = 0x0200;  /* Don't do owner Z ordering */
        const UInt32 SWP_NOSENDCHANGING = 0x0400;  /* Don't send WM_WINDOWPOSCHANGING */

        const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;


        public static void MakeBackMost(Form form)
        {
            SetWindowPos(form.Handle, HWND_BOTTOM, 0000, SWP_NOSIZE | SWP_NOMOVE);
        }
        public static void MakeTopMost(Form form)
        {
            SetWindowPos(form.Handle, HWND_TOPMOST, 0000, TOPMOST_FLAGS);
         }

        public static void MakeNormal(Form form)
        {
            SetWindowPos(form.Handle, HWND_NOTOPMOST, 0000, TOPMOST_FLAGS);
         }
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            test();
            //MakeTopMost(this);    //<-- funktioniert
            MakeBackMost(this);     //<-- funktioniert nicht
        }
        public void test()
        {
            
        }
    }
}


*edit: sry - weiss grad nicht ob/wie man hier c#-code posten kann ^^

Moderiert von user profile iconChristian S.: Code- durch C#-Tags ersetzt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19317
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 08.02.09 22:47 
In Delphi würde ich CreateParams des Formulars überschreiben, WndParent auf das Desktopfenster setzen und Style auf WS_CHILD. Als Kindfenster im Desktop sollte genau dieser Effekt passieren.

In C# könnte das evtl. genauso gehen:
msdn.microsoft.com/e...ol.createparams.aspx
Das muss ich mal selbst ausprobieren. ;-)

// EDIT:
Habs probiert, klappt:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
    public partial class Form1 : Form
    {
        [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
        public static extern IntPtr GetDesktopWindow();
        
        protected override CreateParams CreateParams
        {
            get
            {
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

                CreateParams cp = base.CreateParams;
                cp.Parent = GetDesktopWindow();
                cp.Style |= 0x40000000// WS_CHILD

                return cp;
            }
        }
    ...


user profile iconsataan1337 hat folgendes geschrieben Zum zitierten Posting springen:
*edit: sry - weiss grad nicht ob/wie man hier c#-code posten kann ^^
So: ;-)
ausblenden Quelltext
1:
<span class="inlineSyntax">{PROTECTTAG6698e95c0f82f77b8a5c8d8ddeb8f28d}</span>