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 와 같은 생소한 개념들이 있기 때문에 거부감이 들 수 있지만, 이러한 기능들은 개발자의 편의를 위해서 개발된 기능이기 때문에 충분히 익힌다면, 오히려 도움이 될 것이라고 생각합니다. 

+ Recent posts