Click here to Skip to main content
15,897,273 members
Home / Discussions / C#
   

C#

 
QuestionThe server committed a protocol violation. Pin
Kevin Mark18-Apr-09 15:25
Kevin Mark18-Apr-09 15:25 
AnswerRe: The server committed a protocol violation. Pin
Henry Minute19-Apr-09 0:18
Henry Minute19-Apr-09 0:18 
QuestionRe: The server committed a protocol violation. Pin
Kevin Mark19-Apr-09 9:18
Kevin Mark19-Apr-09 9:18 
AnswerRe: The server committed a protocol violation. Pin
Henry Minute19-Apr-09 12:51
Henry Minute19-Apr-09 12:51 
GeneralRe: The server committed a protocol violation. Pin
Kevin Mark19-Apr-09 14:49
Kevin Mark19-Apr-09 14:49 
Questionneed help with this error Pin
john231318-Apr-09 12:10
john231318-Apr-09 12:10 
AnswerRe: need help with this error Pin
Colin Angus Mackay18-Apr-09 13:34
Colin Angus Mackay18-Apr-09 13:34 
QuestionNew to C#, please explain how this works... Pin
Vengeful Emus18-Apr-09 11:14
Vengeful Emus18-Apr-09 11:14 
I'm fairly new to C#, and have written a small app to test something I needed to do in a bigger app. The app is simple, has a single main form and the routine creates a task bar icon. The only event that is serviced is when the user doble-clicks on the icon in the tray. Double clicking will hide the main window, double clicking again will show the main window. All that I understand, but he mapping of the ShowWindow functions has me seriously confused. I kind of understand the mapping of the ShowWindow function, but the Handle argument with the call makes no sense. Handle isn't declared anywhere, isn't intialized and yet the thing works. I've included thye code below:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Foo_Bar
{

///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
//
// notifyIcon1
//
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(192, 110);
this.Name = "Form1";
this.Text = "Form1";

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private System.Windows.Forms.NotifyIcon notifyIcon1;

private const int SW_HIDE = 0;
private const int SW_RESTORE = 1;
private static bool VisibleBoolean = true;

[System.Runtime.InteropServices.DllImport(
"user32",
EntryPoint="ShowWindow",
ExactSpelling=true,
CharSet=System.Runtime.InteropServices.CharSet.Ansi,
SetLastError=true)]
public static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
{
if (VisibleBoolean)
{
ShowWindow(Handle, SW_HIDE);
VisibleBoolean = false;
}
else
{
ShowWindow(Handle, SW_RESTORE);
VisibleBoolean = true;
}
}
}
}

Help
AnswerRe: New to C#, please explain how this works... Pin
Ravi Bhavnani18-Apr-09 12:06
professionalRavi Bhavnani18-Apr-09 12:06 
AnswerRe: New to C#, please explain how this works... Pin
Jimmanuel18-Apr-09 12:11
Jimmanuel18-Apr-09 12:11 
QuestionRe: New to C#, please explain how this works... Pin
Vengeful Emus18-Apr-09 12:41
Vengeful Emus18-Apr-09 12:41 
AnswerRe: New to C#, please explain how this works... Pin
Jimmanuel18-Apr-09 13:10
Jimmanuel18-Apr-09 13:10 
AnswerRe: New to C#, please explain how this works... Pin
Naruki19-Apr-09 15:49
Naruki19-Apr-09 15:49 
QuestionCreate multiple derived instance in property grid for a property Pin
robert aaza18-Apr-09 6:50
robert aaza18-Apr-09 6:50 
Questiondialpad Pin
Roland Szigeti18-Apr-09 6:25
Roland Szigeti18-Apr-09 6:25 
AnswerRe: dialpad Pin
N a v a n e e t h18-Apr-09 6:51
N a v a n e e t h18-Apr-09 6:51 
GeneralRe: dialpad Pin
Roland Szigeti18-Apr-09 8:08
Roland Szigeti18-Apr-09 8:08 
GeneralRe: dialpad Pin
dan!sh 18-Apr-09 8:11
professional dan!sh 18-Apr-09 8:11 
AnswerRe: dialpad Pin
Luc Pattyn18-Apr-09 8:16
sitebuilderLuc Pattyn18-Apr-09 8:16 
QuestionADO.Net question Pin
Rafone18-Apr-09 6:10
Rafone18-Apr-09 6:10 
AnswerRe: ADO.Net question Pin
Henry Minute18-Apr-09 7:21
Henry Minute18-Apr-09 7:21 
GeneralRe: ADO.Net question Pin
Rafone18-Apr-09 7:45
Rafone18-Apr-09 7:45 
GeneralRe: ADO.Net question Pin
Henry Minute18-Apr-09 7:55
Henry Minute18-Apr-09 7:55 
QuestionTwo title bars active at the same time [modified] Pin
stardust161118-Apr-09 4:58
stardust161118-Apr-09 4:58 
AnswerRe: Two title bars active at the same time Pin
Henry Minute18-Apr-09 7:24
Henry Minute18-Apr-09 7:24 

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.