Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original
Este tópico ainda não foi avaliado como - Avalie este tópico

Estrutura Message

Implementa uma mensagem do Windows.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (em System.Windows.Forms.dll)
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public struct Message

The Message estrutura de quebra de mensagens que o Windows envia. Você pode usar essa estrutura para empacotar uma mensagem e atribuí-la para o procedimento de janela a ser despachado. Você também pode usar essa estrutura para obter informações sobre uma mensagem o sistema envia ao seu aplicativo ou controles.

Não é possível criar o Message diretamente. Em vez disso, use o Create método. Para fins de eficiência, a Message usa seu pool de existente Messages em vez de instanciar um novo, se possível. No entanto, se um Message é não está disponível no pool, um novo é instanciado.

O exemplo de código a seguir demonstra substituindo o WndProc método para manipular identificadas nas mensagens do sistema operacional a Message. A mensagem de sistema operacional WM_ACTIVATEAPP é tratada neste exemplo saber quando outro aplicativo está se tornando ativo. Consulte a referência de documentação de plataforma SDK localizada na biblioteca MSDN para entender o disponívelMessage.Msg, Message.LParam, e Message.WParam valores. constante de valores real podem ser encontrados no arquivo de cabeçalho Windows.h incluído no baixar do plataforma SDK (seção Core SDK), que também está disponível no MSDN.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace csTempWindowsApplication1
{
    publicclass Form1 : System.Windows.Forms.Form
    {
        // Constant value was found in the "windows.h" header file.
        privateconstint WM_ACTIVATEAPP = 0x001C;
        privatebool appActive = true;

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

        public Form1()
        {
            this.Size = new System.Drawing.Size(300,300);
            this.Text = "Form1";
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
        }

        protectedoverridevoid OnPaint(PaintEventArgs e) 
        {
            // Paint a string in different styles depending on whether the// application is active.if (appActive) 
            {
                e.Graphics.FillRectangle(SystemBrushes.ActiveCaption,20,20,260,50);
                e.Graphics.DrawString("Application is active", this.Font, SystemBrushes.ActiveCaptionText, 20,20);
            }
            else 
            {
                e.Graphics.FillRectangle(SystemBrushes.InactiveCaption,20,20,260,50);
                e.Graphics.DrawString("Application is Inactive", this.Font, SystemBrushes.ActiveCaptionText, 20,20);
            }
        }

	[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
        protectedoverridevoid WndProc(ref Message m) 
        {
            // Listen for operating system messages.switch (m.Msg)
            {
                // The WM_ACTIVATEAPP message occurs when the application// becomes the active application or becomes inactive.case WM_ACTIVATEAPP:

                    // The WParam value identifies what is occurring.
                    appActive = (((int)m.WParam != 0));

                    // Invalidate to get new text painted.this.Invalidate();

                    break;                
            }
            base.WndProc(ref m);
        }
    }
}


package JSLTempWindowsApplication1; 

import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;
import System.Security.Permissions.*;

public class Form1 extends System.Windows.Forms.Form
{
    // Constant value was found in the "windows.h" header file.
    private final int WM_ACTIVATEAPP = 0x1C;
    private boolean appActive = true;

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main

    public Form1()
    {
        this.set_Size(new System.Drawing.Size(300, 300));
        this.set_Text("Form1");
        this.set_Font(new System.Drawing.Font("Microsoft Sans Serif", 18, 
            System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
            (ubyte)0));
    } //Form1

    protected void OnPaint(PaintEventArgs e)
    {
        // Paint a string in different styles depending on whether the
        // application is active.
        if (appActive) {
            e.get_Graphics().FillRectangle(SystemBrushes.get_ActiveCaption(), 
                20, 20, 260, 50);
            e.get_Graphics().DrawString("Application is active", 
                this.get_Font(), SystemBrushes.get_ActiveCaptionText(), 
                20, 20);
        }
        else {
            e.get_Graphics().FillRectangle(SystemBrushes.get_InactiveCaption(), 
                20, 20, 260, 50);
            e.get_Graphics().DrawString("Application is Inactive", 
                this.get_Font(), SystemBrushes.get_ActiveCaptionText(),
                20, 20);
        }
    } //OnPaint

    /** @attribute SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)
    */
    protected void WndProc(/** @ref */Message m)
    {
        // Listen for operating system messages.
        switch (m.get_Msg()) {
            // The WM_ACTIVATEAPP message occurs when the application
            // becomes the active application or becomes inactive.
            case WM_ACTIVATEAPP:
                // The WParam value identifies what is occurring.
                appActive = m.get_WParam().ToInt32() != 0;
                // Invalidate to get new text painted.
                this.Invalidate();
                break;
        }
        super.WndProc(m);
    } //WndProc
} //Form1


Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.

.NET Framework

Compatível com: 3.5, 3.0, 2.0, 1.1, 1.0
Isso foi útil para você?
(1500 caracteres restantes)
Conteúdo da Comunidade Adicionar