using NoName;
using NoName.Timers;

class Program
{
public static void Main()
{
ExampleManageCls nm = new ExampleManageCls();
nm.running();
}
}

class ExampleManageCls
{
Timer tm = new Timer();
DateTime endTime;

public void running()
{
tm.Elapsed += new ElapsedEventHandler(____time_tick);
tm.Interval = 1000;
tm.Start();

endTime = DateTime.Now.AddMinutes(1);

while(true)
{
if(endTime<DateTime.Now)
{
break;
}
}
}

void ____time_tick(object sender, ElapsedEventArgs e)
{
Console.WriteLine(DateTime.Now.ToString() + "/" + endTime.ToString());
}
}

/*RESULT-------------------------------------------------------
2022-03-28 오전 9:56:47/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:48/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:49/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:50/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:51/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:52/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:53/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:54/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:55/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:56/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:57/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:58/2022-03-28 오전 9:57:13
2022-03-28 오전 9:56:59/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:00/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:01/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:02/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:03/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:04/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:05/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:06/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:07/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:08/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:09/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:10/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:11/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:12/2022-03-28 오전 9:57:13
2022-03-28 오전 9:57:13/2022-03-28 오전 9:57:13

D:\tmp\console>
-------------------------------------------------------*/

/*2개의 Application이 동작한다. 2개의 Application이 Data를 Communication할때에 사용하는 방식이다.
1. Console에서 Key를 동작하여, 다른 Application으로 SendMessage(Text)한다. 일명 조정
2. 다른 Application에서는 WndProc(override frm)에서 WM_COPYDATA를 통해서 데이타를 받은다음에 
Key에 따라서 동작한다.
3. 억지로 말을 붙이자면, 한쪽방향으로의 클라이언트,서버의 관계이다.*/

>주의할점은 Tris Server Frm(No Key) 의 Application의 Handle이 반드시 일단 존재해야 한다.

____snd.cs
0.00MB

 

____rcv.cs
0.01MB

 

/*Data communication between Proesses!!*/

Windows OS
프로세스간 Window Handle 공유를 통한 SendMessage & WndProc(WM_COPYDATA)

참조)
SendMessage/FindWindow/Snd/Rcv Str :: 석수코딩교육 (tistory.com)

Linux & Unix OS
1) 프로세스간 Message Queue 공유를 통한 Message Send & Recv
2) 프로세스간 Semaphor & Shared Meory 공유를 통한 Message Send & Recv(비추)

/*
*상속안할경우 나오는 에러메세지*/


Microsoft (R) Visual C# Compiler version 4.8.4084.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

ex12.cs(18,26): error CS0115: 'WindowsFrmManage.ProcessCmdKey(ref NoName.Windows.Forms.Message,
        NoName.Windows.Forms.Keys)': 재정의할 적절한 메서드를 찾을 수 없습니다.
ex12.cs(40,26): error CS0115: 'WindowsFrmManage.WndProc(ref NoName.Windows.Forms.Message)': 재정의할 적절한 메서드를 찾을 수 없습니다.

using NoName;
using NoName.Windows.Forms;

class Program
{
public static void Main(string[] args)
{
Application.Run(new WindowsFrmManage());
}
}
class WindowsFrmManage
{
public WindowsFrmManage() {}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x0100, WM_KEYUP = 0x0101, WM_CHAR = 0x0102, WM_SYSKEYDOWN = 0x0104, WM_SYSKEYUP = 0x0105, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
         switch (keyData.ToString())
{
case "Down"   :
break;
case "Escape" :
Application.Exit();
break;
         default:
             break;
         }
     }
return base.ProcessCmdKey(ref msg, keyData);
}

protected override void WndProc(ref Message m)//sdw_mh12e
{
const int WM_KEYDOWN = 0x0100, WM_KEYUP = 0x0101, WM_CHAR = 0x0102, WM_SYSKEYDOWN = 0x0104, WM_SYSKEYUP = 0x0105, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

base.WndProc(ref m);

switch(m.Msg)
{
case WM_PAINT :
break;
default:
break;
}
}
}


using NoName;
using NoName.Windows.Forms;

class FrmIndex006 : Form
{
public FrmIndex006()
{
Console.WriteLine(">>>>FrmIndex006");
}
}

class FrmIndex007 : FrmIndex006
{
public FrmIndex007()
{
Console.WriteLine(">>>>FrmIndex007");
}
}

class FrmIndex008 : FrmIndex007
{
public FrmIndex008()
{
Console.WriteLine(">>>>FrmIndex008");
}
}

class FrmIndex009 : FrmIndex008
{
public FrmIndex009()
{
Console.WriteLine(">>>>FrmIndex009");
}
}

class FrmIndex010 : FrmIndex009
{
public FrmIndex010()
{
Console.WriteLine(">>>>FrmIndex010");
}
}

class FrmMain : FrmIndex010
{
public FrmMain()
{
Console.WriteLine(">>>>FrmMain");
}
protected override void WndProc(ref Message m)
{
const int WM_KEYDOWN = 0x0100, WM_SYSKEYDOWN = 0x0104, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

base.WndProc(ref m);

try
{
switch(m.Msg)
{
case WM_PAINT :
DialogResult dialogResult = MessageBox.Show(">>Quit OK!!", "Inform",
              MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

if (dialogResult == DialogResult.OK) Application.Exit();
break;
default:
break;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
/*
D:\tmp\console>sample
>>>>FrmIndex006
>>>>FrmIndex007
>>>>FrmIndex008
>>>>FrmIndex009
>>>>FrmIndex010
>>>>FrmMain

D:\tmp\console>
*/

class Program
{
public static void Main()
{
Application.Run(new FrmMain());
}
}


Server : Redis Server

1. Language : c,pro*c,socket,oracle

Client : Redis Client

1. Language : c#
2. IDE : visual studio 2019 professional
3. Core
    3.1 BackgroundWorker
    3.2 WndProc - WM_COPYDATA
    3.3 SendMessage
    3.4 DLL

다형성(polymorphism)은 무엇인가요?

polymorphism에서 poly는 여러, 다양한(many), morph는 변형(change)이나 형태(form)의 의미를 가지고 있습니다. 
사전적 정의로만 살펴보면 "여러가지 형태"를 나타내는데, 이를 객체 지향 프로그래밍으로 끌고 온다면 "하나의 객체가 여러 개의 형태를 가질 수 있는 능력"이라 말할 수 있습니다. 


우리는 이미 다형성을 접해본 적이 있습니다. 다형성의 일부인 메소드의 오버로딩(이는 ad-hoc polymorphism에 해당)과 오버라이딩(이는 inclusion polymorphism에 해당)에서 말이죠! 
C#도 객체 지향 프로그래밍에 근간을 두고 있으므로 이 다형성이라는 개념은 자주 사용됩니다.

클래스의 상속(Class inheritance)

상속이란 말을 어디선가 들어본 적이 있는 것 같지 않나요? 
짐작하는 그 상속이 맞냐구요? 네 맞습니다. 
혹시나 상속이 뭔지 들어보 적 없는 분들을 위해 무엇인지 알려드리려고 합니다. 
상속이란 네이버 지식백과를 빌어 다음과 같이 정의되어 있습니다. 
'일정한 친족적 관계가 있는 사람 사이에 한 쪽이 사망하거나 법률상의 원인이 발생하였을 때 재산적 또는 친족적 권리와 의무를 계승하는 제도'. 
즉, 부모님이 돌아가셨다고 할 때 그 유산을 자식이 물려받는 것이라고 할 수 있습니다. 
클래스의 상속도 이와 똑같습니다. 
객체 지향 프로그래밍에선 부모 클래스와 자식 클래스가 있는데, 
부모 클래스는 자식 클래스의 기반이 된다 하여 기반 클래스라고 부르기도 하고, 
자식 클래스는 부모 클래스로부터 파생되었다고 해서 파생 클래스라고도 부르기도 합니다.

C#에서, 클래스를 다른 클래스로 상속하려면 다음과 같이 클래스 이름 뒤에 콜론(:)을 추가하고 상속하려는 클래스의 이름을 덧붙이시면 됩니다.

using NoName;
using NoName.Windows.Forms;
using NoName.Timers;

class FrmMain : Form
{
NoName.Timers.Timer tm = new NoName.Timers.Timer();
FrmChild f1 = new FrmChild();

int ____width=0;
int ____height=0;
int ____idx=0;

public FrmMain()
{
this.Text="FrmMain";

tm.Elapsed += new ElapsedEventHandler(____time_tick);
tm.Interval = 1000;
tm.Start();

f1.Show();
}
void ____time_tick(object sender, ElapsedEventArgs e)
{
this.Width = f1.Width + ____width;
this.Height = f1.Height + ____height;

____width += 10;
____height += 10;

____idx++;
if(____idx==13) f1.Close();
if(____idx==14) this.Close();

this.Text = "FrmMain" + ">>>[" + ____idx.ToString("0000") + "]";
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x0100, WM_SYSKEYDOWN = 0x0104, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
         switch (keyData.ToString())
         {
case "Return" :
DialogResult dialogResult = MessageBox.Show("[" + this.Text + "]" + ">>Quit OK!!", "Inform",
              MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

if (dialogResult == DialogResult.OK) Application.Exit();
break;
case "Right"  :
break;
case "Left"   :
break;
         default:
             break;
         }
     }
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void WndProc(ref Message m)
{
const int WM_KEYDOWN = 0x0100, WM_SYSKEYDOWN = 0x0104, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

base.WndProc(ref m);

try
{
switch(m.Msg)
{
case WM_PAINT :
break;
default:
break;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

class FrmChildBase : Form
{
//
}

class FrmChild : FrmChildBase
{
public FrmChild()
{
this.Width=400;
this.Height=400;

this.Text="FrmChild";
}
}

class Program
{
public static void Main()
{
Application.Run(new FrmMain());
}
}






IntPtr 구조체

정의
네임스페이스:
System
어셈블리:
System.Runtime.dll
포인터나 핸들을 나타내는 데 사용되는 플랫폼별 형식입니다.

using NoName;
using NoName.Runtime.InteropServices;

class NotTooSafeStringReverse
{
    static public void Main()
    {
        string stringA = "I seem to be turned around!";
        int copylen = stringA.Length;

        // Allocate HGlobal memory for source and destination strings
        IntPtr sptr = Marshal.StringToHGlobalAnsi(stringA);
        IntPtr dptr = Marshal.AllocHGlobal(copylen + 1);

        // The unsafe section where byte pointers are used.
        unsafe
        {
            byte *src = (byte *)sptr.ToPointer();
            byte *dst = (byte *)dptr.ToPointer();

            if (copylen > 0)
            {
                // set the source pointer to the end of the string
                // to do a reverse copy.
                src += copylen - 1;

                while (copylen-- > 0)
                {
                    *dst++ = *src--;
                }
                *dst = 0;
            }
        }
        string stringB = Marshal.PtrToStringAnsi(dptr);

        Console.WriteLine("Original:\n{0}\n", stringA);
        Console.WriteLine("Reversed:\n{0}", stringB);

        // Free HGlobal memory
        Marshal.FreeHGlobal(dptr);
        Marshal.FreeHGlobal(sptr);
    }
}

/*--------------------------------------------------------------------
D:\tmp\console>csc sample.cs /unsafe
Microsoft (R) Visual C# Compiler version 4.8.4084.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240


D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>ex44
Original:
I seem to be turned around!

Reversed:
!dnuora denrut eb ot mees I

D:\tmp\console>
--------------------------------------------------------------------*/

class Program
{
string drawText;

protected override void OnPaint(NoName.Windows.Forms.PaintEventArgs pea)
{
NoName.Drawing.Graphics formGraphics = pea.Graphics;
NoName.Drawing.Font drawFont = new NoName.Drawing.Font("바탕체", DEPTH);
formGraphics.DrawString(drawText, drawFont, NoName.Drawing.Brushes.SteelBlue, 0, 0); //x,y position display
}
void draw()
{
int ii,kk;

drawText="";

for(ii=0; ii<MAPY-1; ii++)
{
for(kk=1; kk<MAPX-1; kk++)
{
if(tris[ii,kk]==1) drawText=drawText+"()";
else drawText=drawText+"  ";
}
drawText=drawText+"\n";
}

Invalidate();
}
}

1) 핸들을 알았을떄에, 해당frm에 메세지보내기
2) 핸들은 모르지만, 타이틀을 알았을때에 해당frm에 메세지보내기

using NoName;
using NoName.Text;//Encoding
using NoName.ComponentModel;//BackgroundWorker
using NoName.Timers;
using NoName.Windows.Forms;
using NoName.Runtime.InteropServices;

class MessageHandleCls
{
public int WM_COPYDATA=0x004A;
/*--------------------------------------------------------------------------------------------------*/
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int unMsg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
/*--------------------------------------------------------------------------------------------------*/

IntPtr ____handle;

public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}

NoName.Timers.Timer tm = new NoName.Timers.Timer();
NoName.Timers.Timer tmmmm = new NoName.Timers.Timer();
Random rr = new Random();

public void running(IntPtr ____hwnd)
{
____handle=____hwnd;

tm.Elapsed += new ElapsedEventHandler(____time_tick);
tm.Interval = 1000;
tm.Start();

tmmmm.Elapsed += new ElapsedEventHandler(____time_tick_mmm);
tmmmm.Interval = 1000;
tmmmm.Start();
}
void ____time_tick(object sender, ElapsedEventArgs e)
{
int index=0;
int xpos;
string formatText="";

xpos = rr.Next() % 5;

if(xpos % 5 == 0) formatText="RIGHT";
else if(xpos % 5 == 1) formatText="LEFT";
else if(xpos % 5 == 2) formatText="DOWN";
else if(xpos % 5 == 3) formatText="RETURN";
else if(xpos % 5 == 4) formatText="SPACE";

byte[] dataByte=Encoding.UTF8.GetBytes(formatText);

COPYDATASTRUCT cpyData=new COPYDATASTRUCT();
cpyData.dwData=(IntPtr)0;
cpyData.cbData=formatText.Length;
cpyData.lpData=Marshal.AllocHGlobal(dataByte.Length);
Marshal.Copy(dataByte,0,cpyData.lpData,dataByte.Length);

IntPtr sndData=Marshal.AllocHGlobal(Marshal.SizeOf(cpyData));
Marshal.StructureToPtr(cpyData,sndData,true);

Console.WriteLine("Time:[" + DateTime.Now.ToString() + "]::" + ">>>>>>>>>>>SendStr:[" + sndData + "]");

IntPtr ____result=SendMessage(____handle, WM_COPYDATA, (IntPtr)index, sndData);

Marshal.FreeHGlobal(cpyData.lpData);
Marshal.FreeHGlobal(sndData);
}
void ____time_tick_mmm(object sender, ElapsedEventArgs e)
{
int index=0;
int xpos;
string formatText="";
IntPtr ____handle_mmm;

____handle_mmm = FindWindow(null, "DEBUGGING");

xpos = rr.Next() % 5;

if(xpos % 5 == 0) formatText="RIGHT";
else if(xpos % 5 == 1) formatText="LEFT";
else if(xpos % 5 == 2) formatText="DOWN";
else if(xpos % 5 == 3) formatText="RETURN";
else if(xpos % 5 == 4) formatText="SPACE";

byte[] dataByte=Encoding.UTF8.GetBytes(formatText);

COPYDATASTRUCT cpyData=new COPYDATASTRUCT();
cpyData.dwData=(IntPtr)0;
cpyData.cbData=formatText.Length;
cpyData.lpData=Marshal.AllocHGlobal(dataByte.Length);
Marshal.Copy(dataByte,0,cpyData.lpData,dataByte.Length);

IntPtr sndData=Marshal.AllocHGlobal(Marshal.SizeOf(cpyData));
Marshal.StructureToPtr(cpyData,sndData,true);

Console.WriteLine("Time:[" + DateTime.Now.ToString() + "]::" + ">>>>>>>>>>>SendStrTmp:[" + sndData + "]");

IntPtr ____result=SendMessage(____handle_mmm, WM_COPYDATA, (IntPtr)index, sndData);

Marshal.FreeHGlobal(cpyData.lpData);
Marshal.FreeHGlobal(sndData);
}
}

class WindowsManageCls : Form
{
const int WM_COPYDATA=0x004A;

public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}


MessageHandleCls nm = new MessageHandleCls();

public WindowsManageCls()
{
this.Text = "DEBUGGING";

nm.running(this.Handle);
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x0100, WM_SYSKEYDOWN = 0x0104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
         switch (keyData.ToString())
         {
case "Return" :
DialogResult dialogResult = MessageBox.Show("Quit OK!!", "Inform",
              MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

if (dialogResult == DialogResult.OK) Application.Exit();
break;
case "Right"  :
break;
case "Left"   :
break;
         default:
             break;
         }
     }
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

try
{
switch(m.Msg)
{
case WM_COPYDATA :
COPYDATASTRUCT cds=(COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));
byte[] rcvData=new byte[cds.cbData];
Marshal.Copy(cds.lpData,rcvData,0,cds.cbData);
String strText=Encoding.UTF8.GetString(rcvData);
Console.WriteLine("Time:[" + DateTime.Now.ToString() + "]::" + "ReceiveStr:[" + strText + "]");
break;
default:
break;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

class Program
{
public static void Main(string[] args)
{
Application.Run(new WindowsManageCls());
}
}






ex40.cs
0.01MB

//NoName->System 으로 변경//NoName->System 으로 변경//NoName->System 으로 변경//NoName->System 으로 변경//NoName->System 으로 변경
using NoName; 
using NoName.ComponentModel;
using NoName.Windows.Forms;
using NoName.Drawing;
using NoName.Drawing.Drawing2D;
using NoName.Timers;

class Program
{
public static void Main(string[] args)
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);


if(args.Length==1) 
{
if(args[0]=="E") Application.Run(new OtherManageCls());
}
}
}

class OtherManageCls : Form
{
int ____hatchstyle=0;
const int WM_KEYDOWN = 0x0100, WM_KEYUP = 0x0101, WM_CHAR = 0x0102, WM_SYSKEYDOWN = 0x0104, WM_SYSKEYUP = 0x0105, WM_PAINT = 0x000f, WM_SIZE = 0x0005;

public OtherManageCls()
{
this.Width = 700;
this.Height = 300;
}
void draw()
{
int xx,yy,width,height;

xx = this.Width / 4;
yy = this.Height / 4;
width = this.Width / 4 * 2;
height = this.Height / 4;

DrawBackground(0,0,this.Width,this.Height,____hatchstyle);
DrawForeground(xx,yy,width,height,____hatchstyle);

this.Text = "Time:[" + DateTime.Now.ToString() + "]" + ">>HatchStyle Number:[" + ____hatchstyle.ToString("00") + "]";
}
void DrawForeground(int xx, int yy, int width, int height, int ____hatchstyle)
{
HatchStyle hs = (HatchStyle)____hatchstyle;
Brush myBrush = new HatchBrush(hs, NoName.Drawing.Color.SteelBlue);
Pen myPen = new Pen(NoName.Drawing.Color.LightGray, 1);

NoName.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(xx, yy, width, height));
formGraphics.DrawRectangle(myPen , xx, yy, width, height);
}
void DrawBackground(int xx, int yy, int width, int height, int ____hatchstyle)
{
HatchStyle hs = (HatchStyle)____hatchstyle;
Brush myBrush = new HatchBrush(hs, NoName.Drawing.Color.LightYellow);
Pen myPen = new Pen(NoName.Drawing.Color.LightGray, 1);

NoName.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(xx, yy, width, height));
formGraphics.DrawRectangle(myPen , xx, yy, width, height);
}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData.ToString())
{
case "Return" :
DialogResult dialogResult = MessageBox.Show("Quit OK!!", "Inform",
MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

if (dialogResult == DialogResult.OK) Application.Exit();
break;
case "Right"  :
____hatchstyle += 1;
if(____hatchstyle == 53) ____hatchstyle=0;
break;
case "Left"   :
____hatchstyle -= 1;
if(____hatchstyle == -1) ____hatchstyle=52;
break;
default:
break;
}

draw();
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

try
{
switch(m.Msg)
{
case WM_PAINT :
draw();
break;
default:
break;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

'c# 언어 > 중급과정' 카테고리의 다른 글

Data communication between Proesses!!  (0) 2022.03.25
SendMessage/FindWindow/Snd/Rcv Str  (0) 2022.03.15
HatchStyle,HatchBrush,Pen  (0) 2022.03.08
Hexa 4가지 항목으로 점수계산 로직  (0) 2022.03.06
LINQ 쿼리 소개(C#)  (0) 2022.02.23

/*____check.cs*/



using System;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;//DLL
using System.Timers;

class TouchMessageHooking
{
[DllImport("user32.dll")]
public static extern void keybd_event(byte vk, byte scan, int flags, ref int info);

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hwnd, int unMsg, IntPtr wparam, IntPtr lparam);

[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hwnd, int unMsg, int wparam, int lparam);

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string classname, string windowname);

int WM_KEYDOWN=0x0100;
int VK_F5=0x74;
int VK_ENTER=13;
int ____timeinterval=9000 * 4;
int index=0;

System.Timers.Timer tm_basic = new System.Timers.Timer();
System.Timers.Timer tm = new System.Timers.Timer();

IntPtr ____handle_mmmm  = IntPtr.Zero;
IntPtr ____handle_popup = IntPtr.Zero;

int toggle=0;
int ____thread_sleep_time=400;

ConsoleKeyInfo keyinfo;

public void running()
{
tm.Elapsed += new ElapsedEventHandler(____time_tick);
tm.Interval = ____timeinterval;
tm.Start();

tm_basic.Elapsed += new ElapsedEventHandler(____time_tick_basic);
tm_basic.Interval = 1000;
tm_basic.Start();

while(true)
{
keyinfo=Console.ReadKey(true);

if(keyinfo.Key.ToString()=="Escape")
{
break;
}
else if(keyinfo.Key.ToString()=="Spacebar")
{
if(toggle==0)
{
Console.WriteLine("Stop");
tm.Stop();
toggle=100;
}
else
{
Console.WriteLine("Restart");
tm.Start();
toggle=100;
}
}
}
}
void ____time_tick_basic(object sender, ElapsedEventArgs e)
{
Console.WriteLine(DateTime.Now.ToString() + ">>>>Index:[" + index.ToString("0000") + "]");
Console.Title = DateTime.Now.ToString() + ">>>>Index:[" + index.ToString("0000") + "]";

index++;
}
void ____time_tick(object sender, ElapsedEventArgs e)
{
IntPtr ____result=IntPtr.Zero;
bool ____toggle;
string handleCaption="http://10.1.117.11:7101/getDashboardLink.do?dashboard_type=";

____handle_mmmm=FindWindow(null, handleCaption);
____toggle=PostMessage(____handle_mmmm, WM_KEYDOWN, VK_F5, 0);

Console.WriteLine(____handle_mmmm);
if(____toggle==true) Console.WriteLine("PostMessage succ!!");
else Console.WriteLine("PostMessage fail!!");

Thread.Sleep(____thread_sleep_time);
____time_tick_mmmm();

index=0;
}
void ____time_tick_mmmm()
{
IntPtr ____result=IntPtr.Zero;
bool ____toggle;
string handleCaption="Windows Internet Explorer";

____handle_mmmm=FindWindow(null, handleCaption);
____toggle=PostMessage(____handle_mmmm, WM_KEYDOWN, VK_ENTER, 0);

Console.WriteLine(____handle_mmmm);
if(____toggle==true) Console.WriteLine("PostMessage succ!!");
else Console.WriteLine("PostMessage fail!!");
}
}

class Program
{
public static void Main()
{
TouchMessageHooking nm = new TouchMessageHooking();
nm.running();
}
}




/*File Attach*/

 

daily_check.txt
0.00MB

 

____check.cs
0.00MB

 

 

 

https://open.kakao.com/o/sleUyWBd

using System.Drawing;
using System.Drawing.Drawing2D;

void drawforeground(int xx,int yy,int width,int height,int ____hatchstyle)
{
HatchStyle hs = (HatchStyle)____hatchstyle;//0-52까지 가능
Brush myBrush = new HatchBrush(hs, System.Drawing.Color.SteelBlue);
Pen myPen = new Pen(System.Drawing.Color.LightGray, 1);

System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(xx, yy, width, height));
formGraphics.DrawRectangle(myPen , xx, yy, width, height);
}
void drawforeground(int xx,int yy,int width,int height,int ____hatchstyle)
{
HatchStyle hs = (HatchStyle)____hatchstyle;//0-52까지 가능
Brush myBrush = new HatchBrush(hs, System.Drawing.Color.LightYellow);
Pen myPen = new Pen(System.Drawing.Color.LightGray, 1);

System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(xx, yy, width, height));
formGraphics.DrawRectangle(myPen , xx, yy, width, height);
}

ex31.cs
0.00MB
ex11.cs
0.02MB

 

1. Hexa,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

1. Horizon Direction
2. Vertical Direction
3. LeftToRight Direction
4. LightToLeft Direction

2. Tettris,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

1. Horizon Direction

파일첨부

frm_common.cs
0.02MB




LINQ 쿼리 소개(C#)

쿼리 는 데이터 소스에서 데이터를 검색하는 식입니다. 
쿼리는 일반적으로 특수화된 쿼리 언어로 표현됩니다. 
관계형 데이터베이스에는 SQL이 사용되고 XML에는 XQuery가 사용되는 것처럼 시간에 따라 다양한 형식의 데이터 소스에 대해 서로 다른 언어가 개발되었습니다. 
따라서 개발자는 지원해야 하는 데이터 소스의 형식이나 데이터 형식에 따라 새로운 쿼리 언어를 배워야 했습니다. 
LINQ는 다양한 데이터 소스 및 형식에 사용할 수 있는 일관된 모델을 제공함으로써 이러한 상황을 단순화합니다. 
LINQ 쿼리에서는 항상 개체를 사용합니다. 
XML 문서, SQL 데이터베이스, ADO.NET 데이터 세트, .NET 컬렉션 및 LINQ 공급자를 사용할 수 있는 다른 모든 형식에서 데이터를 쿼리하고 변환하는 데 동일한 기본 코딩 패턴을 사용합니다.

쿼리 작업의 세 부분
모든 LINQ 쿼리 작업은 다음과 같은 세 가지 고유한 작업으로 구성됩니다.

1. 데이터 소스 가져오기.(Data Source)
2. 쿼리 만들기.(Query)
3. 쿼리 실행.(Query Execution)


ex)

using System.Linq;
using System;

class IntroToLINQ
{
    static void Main()
    {
        // The Three Parts of a LINQ Query:
        // 1. Data source.
        int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };

        // 2. Query creation.
        // numQuery is an IEnumerable<int>
        var numQuery =
            from num in numbers
            where (num % 2) == 0
            select num;

        // 3. Query execution.
        foreach (int num in numQuery)
        {
            Console.Write("{0,1} ", num);
        }
    }
}

 

/*execution display
D:\tmp\console>ex200
0 2 4 6
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
*/

WinForms와 WPF의 한가지 가장 큰 차이점은 WinForms는 단순히 Standard Windows Control(e.g a TextBox)의 최상단 레이어인 반면에 WPF는 맨처음부터 거의 모든 경우에 Standard Windows Control에 의존하지 않도록 만들어졌다.

# winform이 먼저 발표되었습니다.

마소(마이크로소프트)에서 개발한 윈도우 환경에서 개발자들이 프로그램을 개발하기 위해서는 기계어를 알아야 했지만, 개발 생산성을 올리기 위해서 다양한 프레임워크가 탄생하게 되었는데요. 그중에서 .Net Framework가 있고, 그 중에서 C#으로 개발하는데 사용되는 UI 개발도구로 Winform과 Wpf가 있습니다.

Winform의 경우 .Net 1.0 부터 지원되었고, 이는 드레그 앤 드롭 방식으로 자신이 생성하고 싶은 컨트롤을 UI 개발창에 올리면 자동으로 코드가 생성되고, 결과는 개발자가 볼 수 있는 방식이였습니다. 이는 매우 직관적이고 초보자도 쉽게 개발 할 수 있다는 장점이 있었습니다. 

이런식으로 버튼 하나를 선택해서 원하는 위치에 올리면 Control이 생성되는 방식입니다. 이때 해당 Form에는 디자인코드와 소스코드가 생성되는데요. 디자인코드는 코드보기를 선택하여 해당 Form의 디자인코드를 볼 수 있습니다. 

하지만 이 디자인 코드는 자동으로 생성이 되기 때문에 별도로 수정을 하지 않아도 어느정도 자신이 원하는 컨트롤을 만들 수 있습니다. 

Wpf의 경우 .Net 3.0 부터 지원이 되었고, Winform이 갖고 있던 다양한 한계를 해결하고 만들어졌습니다. 그래서 Winform에 비해서 더 다양한 기능과 확장성을 갖고 있습니다. 

Winform에서는 Form이라면 Wpf에서는 Control이 있습니다. Control을 상속 받아서 다양한 Control이 생성되는데요. Window, UserControl, Button 처럼 다양한 Control을 만들 수 있습니다. 

처음 Wpf 프로젝트를 생성하면 MainWindow.xaml 이라는 것을 볼 수 있는데요. 이는 C# 코드와 xaml 코드가 합쳐진 형태입니다. 그래서 xaml 코드를 이용해서 디자인 작업을 하고 C# 코드를 이용해서 필요한 기능을 구현하기도 합니다. 

위쪽이 C# 코드이고 아래쪽이 xaml 코드입니다. 실제로 xaml 코드는 다양한 곳에서 사용되는데요. 여기서 xaml은 Extensible Application Markup Language 의 약자로 흔히 마크업 언어라고 불리는 언어들 중에 하나인데요. 인터넷 브라우저에서 F12를 누르면 나오는 코드들과 비슷한 형태의 코드라고 보시면 됩니다. 

WPF는 Winform의 한계를 극복하기 위해서 그리고 더 다양한 확장성을 갖기 위해서 만들어진 UI 개발 프레임워크인데요. 처음 WPF와 Winform을 접하는 분들에게는 Winform 더 직관적이고 쉬울 수 있으나, 실제 실무에서는 Winform 보다는 Wpf를 더 많이 사용하고 있고, 다양한 클라이언트의 요구를 만족시키기 위해서라도 Wpf가 더 좋은 선택이라고 생각하는데요. 한번 배우는데, 오래 걸리고 MVVM이나 Binding, DependencyProperty 와 같은 생소한 개념들이 있기 때문에 거부감이 들 수 있지만, 이러한 기능들은 개발자의 편의를 위해서 개발된 기능이기 때문에 충분히 익힌다면, 오히려 도움이 될 것이라고 생각합니다. 


In C#,,,,,,,,

When Owner draw Control ,,,,,,,,,,,,

ex105.cs
0.00MB

#create
alias exe='cd /usr2/sinfo/exe/'
alias shell='cd /usr2/sinfo/exe/shell'
alias src='cd /usr2/sinfo/src/'
alias log='cd /usr2/sweb/logs/receive/'
alias manage='cd /usr2/sweb/data/manage/'

source ~/.bashrc

etc>
-bash-3.00$ source .bashrc_backup
-bash: .bashrc_backup: line 7: syntax error: unexpected end of file


-bash-3.00$ file /home/www/work/.bashrc
/home/www/work/.bashrc: ASCII text, with CRLF line terminators



-bash-3.00$ perl -pi -e "s/\r//g" .bashrc
-bash-3.00$ file .bashrc
.bashrc: ASCII text
-bash-3.00$ source .bashrc


#delete
unalias exe
unalias shell
unalias src
unalias log
unalias manage

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

...

/// <summary>
/// 메시지 보내기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="message">메시지</param>
/// <param name="wParam">WORD 파리미터</param>
/// <param name="lParam">LONG 파라미터</param>
/// <returns>처리 결과</returns>
[DllImport("User32.dll")]
public static extern Int64 SendMessage(IntPtr windowHandle, uint message, IntPtr wParam, IntPtr lParam);

...

/// <summary>
/// WM_PAINT
/// </summary>
private const int WM_PAINT = 0x000f;

...

#region ForcePaint(form)

/// <summary>
/// 강제로 칠하기
/// </summary>
/// <param name="form">폼</param>
public void ForcePaint(Form form)
{
    SendMessage(form.Handle, WM_PAINT, IntPtr.Zero, IntPtr.Zero);
}

#endregion

+ Recent posts