error c# : operator == cannot be applied to operands of type 'System.IntPtr' and 'int'

csharp , operator , int Norwich, United Kingdom
  • 10 years ago

    Hi All,

    I get this error operator == cannot be applied to operands of type 'System.IntPtr' and 'int'

    firstly I had this code

    private void SNGPH_KeyUp(object sender, KeyEventArgs e) {

            if (e.KeyCode != Keys.ControlKey)
                return;
    
            POINT curpos = new POINT();
            User32.GetCursorPos(ref curpos);
            IntPtr handle = User32.WindowFromPoint(curpos);
            handle = User32.GetAncestor(handle, 2);
    
            for (int i = 0; i < listBoxTables.Items.Count; i++)
                if (((PokerTable)listBoxTables.Items[i]).HWND == handle)
                {
                    listBoxTables.SelectedIndex = i;
                    setFormsAndDoCalc(true, null);
                    e.Handled = true;
                    return;
                }
    
            pictureBox1.Image = SystemIcons.Error.ToBitmap();
            labelWarning.Text = "Couldn't find selected window from pokertables";
        }
    

    which is fine when you click control key over a table it then finds the table in the list (listboxtable) and executes it. Now I tried to make this into every foreground window to do the same thing and show handle in text bar.

    Heres the code I get an error with

    private void GetActiveWindow() { const int nChars = 256; int handle = 0; StringBuilder Buff = new StringBuilder(nChars); handle = GetForegroundWindow();

            if (GetWindowText(handle, Buff, nChars) > 0)
            {
                this.textBox1.Text = handle.ToString();
    
                for (int i = 0; i < listBoxTables.Items.Count; i++)
                if (((PokerTable)listBoxTables.Items[i]).HWND == handle)
                {
                    listBoxTables.SelectedIndex = i;
                    setFormsAndDoCalc(true, null);
                    return;
                }
    
            }
        }
    

    Can anyone please help, not sure whats wrong the handle im sure is an int in both cases?

    Thanks in advance!!

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup