Autor Beitrag
alcedo707
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Di 11.10.11 20:25 
Hallo,

Ich habe ein Problem.. Erst ungefähr nach dem 10. mal Starten, wird das programm bzw die Oberfläche korrekt gestartet. Mein gui ist transparent außer 2 labels (Mit TransparencyKey und Background Color transparent gemacht).

Manchmal funktioniert es beim starten (Label1 und Label2 wird korrekt dargestellt) und manchmal nicht (Der Hintergrund und Vordergrund von Label1 + Label2 wird weiß dargestellt). Manchmal wird auch nur 1 Label korrekt angezeigt, und die andere bleibt weiß.



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:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;

namespace hookdiag
{
    public partial class Form1 : Form
    {


        public Form1()
        {
            InitializeComponent();
            TopMost = true;
            label1.Visible = false;
            label2.Visible = false;
            label1.Visible = true;
            label2.Visible = true;
            

        }

        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int X;
            public int Y;
            public int Width;
            public int Height;

        }

        

        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

        

        private void timer1_Tick(object sender, EventArgs e)
        {
            IntPtr hWnd = FindWindow(null, "Command Prompt");
            RECT rect;



            GetWindowRect(hWnd, out rect);
            if (rect.X == -32000)
            {
                // the game is minimized
                this.WindowState = FormWindowState.Minimized;
            }

            int gefunden = hWnd.ToInt32();
            if (gefunden == 0)
            {
                label2.Text = "Fenster nicht gefunden";
                label2.ForeColor = Color.DarkRed;

            }
            else if (gefunden > 0)
            {
                label2.ForeColor = Color.DarkGreen;
                label2.Text = "Fenster gefunden!";
                this.WindowState = FormWindowState.Normal;
                this.Location = new Point(rect.X + 2, rect.Y + 3);
            }

        }
        
    }
}
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4809
Erhaltene Danke: 1061

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 12.10.11 10:27 
Hallo alcedo707,

das sind leider nicht genügend Infos, um dir eine Antwort zu geben.
Was soll die Timer-Methode bewirken und funktioniert es denn ohne diese? Und auf welchem Intervall steht dein Timer?
Wichtiger in Bezug auf deine GUI ist jedoch, ob du noch weiteren Code in deinem Programm hast? Dies deutet alles darauf hin, daß du dir deine GUI irgendwie blockierst.
Kannst du denn das Fenster danach noch verschieben? Oder erscheint dann "das Programm reagiert nicht mehr"?

Und
ausblenden C#-Quelltext
1:
2:
3:
4:
label1.Visible = false;
label2.Visible = false;
label1.Visible = true;
label2.Visible = true;

hast du sicherlich nur zum Testen, oder (denn es ist ja so "sinnfrei")?

P.S: Und sinnvollere Benennung deiner Form und Controls wäre auch angebracht ;-)