mardi 28 janvier 2014

[Help] Transparent window returns no drawing topic




Hi Friends!

As the title Suggests, I have a problem with the output of my drawings and my written text. In another project, in Which I practiced drawing a line and write a text. Since I Could See the results. But Because The background what not transparent!

Can someone tell me what I'm doing wrong here?

Thank you!


Here is my exercise code:

PHP Code:







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.Security.Permissions;

using System.Runtime.InteropServices;

using System.Threading;

using Microsoft.DirectX;

using Microsoft.DirectX.Direct3D;


namespace 
DX3D_First

{

    public 
partial class frmOverlay Form

    
{

        
#region DLL-IMPORT


        
internal struct Margins

        
{

            public 
int LeftRightTopBottom;

        }


        [
DllImport"user32.dll"SetLastError true )]

        public static 
extern UInt32 GetWindowLongIntPtr hWndint nIndex );


        [
DllImport"user32.dll" )]

        static 
extern int SetWindowLongIntPtr hWndint nIndexIntPtr dwNewLong );


        [
DllImport"user32.dll" )]

        static 
extern bool SetLayeredWindowAttributesIntPtr hwnduint crKeybyte bAlphauint dwFlags );


        [
DllImport"dwmapi.dll" )]

        static 
extern void DwmExtendFrameIntoClientAreaIntPtr hWndref Margins pMargins );


        public const 
int GWL_EXSTYLE = -20;


        public const 
int WS_EX_LAYERED 0x80000;


        public const 
int WS_EX_TRANSPARENT 0x20;


        public const 
int LWA_ALPHA 0x2;


        public const 
int LWA_COLORKEY 0x1;


        
#endregion

        

        
Device device null;


        
Microsoft.DirectX.Direct3D.Font dxText;

        
Microsoft.DirectX.Direct3D.Line dxLine;


        
Margins marg;

        
bool bStopThread false;


        protected 
override CreateParams CreateParams

        
{

            
get

            
{

                new 
SecurityPermissionSecurityPermissionFlag.UnmanagedCode ).Demand();

                
CreateParams CP base.CreateParams;


                
CP.ExStyle CP.ExStyle 0x00000020;


                return 
CP;

            }

        }


        public 
frmOverlay()

        {

            
InitializeComponent();


            
Gfx();


            
Thread dx = new Thread( new ThreadStartdxThread ) );

            
dx.IsBackground true;

            
dx.Start();

        }



        protected 
override void OnPaintPaintEventArgs e )

        {

            
marg.Left 0;

            
marg.Top 0;

            
marg.Right this.Width;

            
marg.Bottom this.Height;


            
DwmExtendFrameIntoClientAreathis.Handleref marg );

        }


        public 
bool Gfx()

        {

            try

            {

                
SetWindowLongthis.HandleGWL_EXSTYLE, ( IntPtr )( GetWindowLongthis.HandleGWL_EXSTYLE ) | WS_EX_LAYERED WS_EX_TRANSPARENT ) );

                
SetLayeredWindowAttributesthis.Handle0255LWA_ALPHA );


                
PresentParameters pp = new PresentParameters();


                
pp.Windowed true;

                
pp.SwapEffect SwapEffect.Discard;

                
pp.BackBufferFormat Format.A8B8G8R8;


                
device = new Device0DeviceType.HardwarethisCreateFlags.HardwareVertexProcessingpp );


                
dxLine = new Microsoft.DirectX.Direct3D.Linedevice );

                
dxText = new Microsoft.DirectX.Direct3D.Fontdevice, new System.Drawing.Font"Arial"12 ) );


                return 
true;

            }

            catch (
DirectXException)

            {

                return 
false;

            }

        }


        public 
void DrawRectint _Xint _Yint _Widthint _HeightColor _Color )

        {

            
Vector2[] Lines = new Vector2];


            
Lines]._X;

            
Lines]._Y;


            
Lines]._X _Width;

            
Lines]._Y;


            
Lines]._X _Width;

            
Lines]._Y _Height;


            
Lines]._X;

            
Lines]._Y _Height;


            
Lines]._X;

            
Lines]._Y;


            
dxLine.DrawLines_Color );

        }


        public 
void dxThread()

        {

            while(!
bStopThread)

            {

                if( 
device == null ) return;


                
device.ClearClearFlags.TargetColor.FromArgb000), 1.0f);

                
device.RenderState.ZBufferEnable false;

                
device.RenderState.Lighting false;

                
device.RenderState.CullMode Cull.None;

                
device.Transform.Projection Matrix.OrthoOffCenterLH0this.Widththis.Height00);

                
device.BeginScene();


                
// Rendering

                
DrawRect1020100150Color.Blue );


                
dxText.DrawTextnull"Hello World!"100100Color.Red );


                
device.EndScene();

                
device.Present();


                
Application.DoEvents();

            }


            
device.Dispose();


            
Application.Exit();

        }






        public 
void FillRectfloat xfloat yfloat wfloat hint rint gint b )

        {

            
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored];


            
verts].Position = new Vector4xh00.5f );

            
verts].Position = new Vector4xy00.5f );

            
verts].Position = new Vector4wh00.5f );

            
verts].Position = new Vector4wy00.5f );

            
//or make it with for(int i = 0; i < 4; i++) to write less code

            
verts].Color System.Drawing.Color.FromArgbrg).ToArgb();

            
verts].Color System.Drawing.Color.FromArgbrg).ToArgb();

            
verts].Color System.Drawing.Color.FromArgbrg).ToArgb();

            
verts].Color System.Drawing.Color.FromArgbrg).ToArgb();


            
device.VertexFormat CustomVertex.TransformedColored.Format;

            
device.DrawUserPrimitivesPrimitiveType.TriangleStrip2verts );

        }




        public 
void DrawRectanglefloat xfloat yfloat wfloat hColor color )

        {

            
float thickness = ( 25 );

            
//Vertical bar 1

            
FillRect- ( ), - ( ), thickness/*just to keep our width consistent*/hcolor.Rcolor.Gcolor.);

            
////Horiz 1

            
FillRect- ( ), - ( ), wthicknesscolor.Rcolor.Gcolor.);

            
////Horizontal bar 2, -50 because we want the exact center of the crosshair to be 

            ////at our X,Y coords and not the far left on crosshair on them

            
FillRect- ( ), + ( ), wthicknesscolor.Rcolor.Gcolor.);

            
////Vertical bar 2

            
FillRect+ ( ), - ( ), thicknesshcolor.Rcolor.Gcolor.);

        }

    }
















Aucun commentaire:

Enregistrer un commentaire