static ser_map_t ser_map_ims[] = 
{
#ifdef SERCLI
    {"cmd_ops_check", icsCmdOsp},
#endif

#ifdef SERCMD
    {"cmd_osp_check_s", icsCmdOspMain},
#endif
    {NULL,NULL}
};

위에서 SERCLI와 SERCMD는 위 코드전에 선언이 되어져 있어야 한다. 아래와 같이.
#define SERCLI
#define SERCMD

만약에 아무리 찾아봐도 없다면(???????)

Makefile을 열어보면 답을 알수 있다. 
------------------------------------------------------------------------------------------------------------
#define, -D옵션, CFLAGS, avr-gcc에서 Makefile의 CFLAGS, 인수(매개변수)가 있는 사용자 정의 함수
------------------------------------------------------------------------------------------------------------

CFLAGS=-DSERCMD 로 선언이 되어 있으면, 굳이 소스코드에 넣지 않아도 컴파일시에 반영이 되도록 할수 있다.

비고)Makefile

CC=gcc
SRC=./
EXE=./
INC=./
CFLAGS=-DSERCMD - DDEBUG -DLOGGING -I.
LIBS = -lcrypt -lnsl -lm

BIN=$(EXE)
all: $(BIN)/sample \

.c.o:
    $(CC) $(CFLAGS) -c -g $*.c

$(BIN)/sample: sample.o
    $(CC) -o $@ sample.o (LIBS) -s

clean:
    rm *.o

 


#컴파일과정에서 코드추가 가능(#define PIE 3.1416을 대신할수 있다.)
#컴파일과정에서 코드추가 가능(#define PIE 3.1416을 대신할수 있다.)

비고) Makefile 사용시에는 CFLAGS를 추가해서 구성할수 있다.

#include<stdio.h>
int main()
{
    int radius;
    float circumference;

    radius=5;
    circumference = (radius + radius) * PIE;

    printf("The circumference of circle is %7.2f \n", circumference);
    return(0);
}

>gcc -o sample sample.c
>PIE undeclared(first use in this function)
컴파일과정에서 코드추가 가능(#define PIE 3.1416을 대신할수 있다.)
>gcc -DPIE=3.1416 -o sample sample.c

가장 많이 사용하는 경우는 전처리기일것이다.

int main()
{
#ifdef INFO_DEBUG
printf("error ,mmmm1\n");
#endif

#ifdef ERROR_DEBUG
printf("error ,mmmm2\n");
#endif

printf("program terminated,mmmm\n");
}

gcc -o sample sample.c
or
gcc -DINFO_DEBUG -DERROR_DEBUG -o sample sample.c

닷넷 프레임워크

닷넷 프레임워크(.NET Framework, 이전 이름: 닷넷)는 마이크로소프트에서 개발한 윈도우 프로그램 개발 및 실행 환경이다. 
네트워크 작업, 인터페이스 등의 많은 작업을 캡슐화하였고, 
공통 언어 런타임(Common Language Runtime)(CLR)이라는 이름의 가상 머신 위에서 작동한다.

닷넷 프레임워크의 구조

.NET 프레임워크의 가장 중요한 콤포넌트는 공통 언어 기반(Common Language Infrastructure)이다. 
다른 말로 CLI라고 한다. 
CLI를 둔 목적은 애플리케이션의 개발과 실행 시 언어에 종속적이지 않은 플랫폼을 제공하기 위해서이다. 
예외 처리, 가비지 콜렉션, 보안, 호환 등을 위한 소프트웨어 콤포넌트를 포함한다. 
마이크로소프트가 구현한 CLI를 일컬어, 공통 언어 런타임(Common Language Runtime, CLR)이라고 한다.

 



#YYYY-MM-DD HH:MM:SS 에서 MM이 변경되면 출력
#YYYY-MM-DD HH:MM:SS 에서 MM이 변경되면 출력
#YYYY-MM-DD HH:MM:SS 에서 MM이 변경되면 출력

using System;
using System.IO;
using System.Timers;

namespace ____trigia_pyeongchon
{
    class Program
    {
        public static void Main(string[] args)
        {
            ___proud_hill pro = new ___proud_hill();

            pro.running();
        }
    }

    class ___proud_hill
    {
        ConsoleKeyInfo keyinfo;
        int xpos,ypos;
        Timer tm;
        string ____old_month, ____now_month;

        public void running()
        {
            tm = new Timer();
            tm.Interval = 1000;

            xpos=ypos=2;

            ____old_month="INIT";
            ____now_month="INIT";

            tm.Elapsed += new ElapsedEventHandler(__time_tick);
            tm.Start();

            Logging("Start");

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

                if(keyinfo.Key == ConsoleKey.RightArrow) xpos++;
                else
                if(keyinfo.Key == ConsoleKey.LeftArrow) xpos--;
                else
                if(keyinfo.Key == ConsoleKey.UpArrow) ypos++;
                else
                if(keyinfo.Key == ConsoleKey.DownArrow) ypos++;
                else
                if(keyinfo.Key == ConsoleKey.Escape) break;

                if(keyinfo.KeyChar=='+')
                {
                    tm.Stop();
                    tm.Interval += 10;
                    tm.Start();
                }
                else
                if(keyinfo.KeyChar=='-')
                {
                    tm.Stop();
                    tm.Interval -= 10;
                    tm.Start();
                }

                Logging("Key");
            }
            tm.Stop();
            tm.Elapsed -= __time_tick;

            Logging("Stop");
        }

        void __time_tick(object sender, ElapsedEventArgs e)
        {
            ypos++;

            Logging("Time");
        }

        void Logging(string msg)
        {
            DateTime now;

            now = DateTime.Now;

            ____now_month = now.ToString("mm");
            if(____now_month != ____old_month)
            {
                if(____old_month !="INIT" )
                {
                    Console.WriteLine("Minute is changed!!!!!, KeyBoard HIT is needed!!");
                }
            }

            Console.WriteLine("Debug>>Time:" + now.ToString("yyyy-MM-dd hh:mm:ss") + 
                  " YYYY:" + now.ToString("yyyy") + 
                  " MM:" + now.ToString("MM") + 
                  " mm:" + now.ToString("mm") + 
                  " Pos:[" + ypos.ToString("000000") + "," + xpos.ToString("000000") + "]" +
                  " Interval:" + tm.Interval + 
                  " Event:" + msg);
            ____old_month = ____now_month;
        }
    } //end of class
} //end of namespace





    

(BEGIN)RPUSH & BLPOP Usage-------------------------------------------------
1. 터미널에서 RPUSH 커맨드로 list2 키를 추가한다.
127.0.0.1:6379> RPUSH list2 a b c
(integer) 3

2. 터미널에서 BLPOP 커맨드를 호출한다. 리스트의 앞 엘리먼트부터 pop한 것을 확인할 수 있다.
127.0.0.1:6379> BLPOP list1 list2 0
1) "list2"
2) "a"

127.0.0.1:6379> BLPOP list1 list2 0
1) "list2"
2) "b"

127.0.0.1:6379> BLPOP list1 list2 0
1) "list2"
2) "c"

127.0.0.1:6379> BLPOP list1 list2 0
(블럭됨)
(END)RPUSH & BLPOP Usage-------------------------------------------------

c# code example(approximately)
c# code example(approximately)

RedisClient sendRedis = null;
RedisClient recvRedis = null;
byte[] jsonByteData = sendQueue.Dequeue();

int rc = sendRedis.RPush("QCS", jsonByteData);
jsonByteData = recvRedis.BLPop("CLI:" + ClientCurrentId.GetInstance.MyID,10);

#Redis의 기본지식이 필요하다.
#Redis의 기본지식이 필요하다.
#Redis의 기본지식이 필요하다.

#IDE를 이용해서, NuGet패키지관리자에서 StackExchange.Redis 검색및 설치를 진행합니다.
#IDE를 이용해서, NuGet패키지관리자에서 StackExchange.Redis 검색및 설치를 진행합니다.
#IDE를 이용해서, NuGet패키지관리자에서 StackExchange.Redis 검색및 설치를 진행합니다.

#Redis Server를 이용한 데이타 저장(Key,Value)과 불러오기(Key)
#Redis Server를 이용한 데이타 저장(Key,Value)과 불러오기(Key)
#Redis Server를 이용한 데이타 저장(Key,Value)과 불러오기(Key)

using StackExchange.Redis;

class Redis
{
    private ConnectionMultiplexer redisConnection;
    private IDatabase db;

    public Redis()
    {
        //
    }

    public bool Init(string host, int port)
    {
        try
        {
            this.redisConnection = ConnectionMultiplexer.Connect(host + ":" + port);
            if(this.redisConnection.IsConnected)
            {
                this.db = this.redisConnection.GetDatabase();
                return true;
            }
            return false;
        }
        catch(Exception e)
        {
            return false;
        }
    }
    //Load-------------------------------------------------
    public string GetString(string key)
    {
        return this.db.StringGet(key);
    }
    //Save--------------------------------------------------
    public string SetString(string key, string val)
    {
        return this.db.StringSet(key, val);
    }
}

#위의 Redis class를 이용한 실행프로그램은 다음글에서 작성할예정입니다.

/*
 * static Color [] fogarr = new Color[140];
 */

fogarr[0]= Color.FromArgb(240,248,255);
fogarr[1]= Color.FromArgb(255,160,122);
fogarr[2]= Color.FromArgb(250,235,215);
fogarr[3]= Color.FromArgb(32,178,170);
fogarr[4]= Color.FromArgb(0,255,255);
fogarr[5]= Color.FromArgb(135,206,250);
fogarr[6]= Color.FromArgb(127,255,212);
fogarr[7]= Color.FromArgb(119,136,153);
fogarr[8]= Color.FromArgb(240,255,255);
fogarr[9]= Color.FromArgb(176,196,222);
fogarr[10]= Color.FromArgb(245,245,220);
fogarr[11]= Color.FromArgb(255,255,224);
fogarr[12]= Color.FromArgb(255,228,196);
fogarr[13]= Color.FromArgb(0,255,0);
fogarr[14]= Color.FromArgb(0,0,0);
fogarr[15]= Color.FromArgb(50,205,50);
fogarr[16]= Color.FromArgb(255,255,205);
fogarr[17]= Color.FromArgb(250,240,230);
fogarr[18]= Color.FromArgb(0,0,255);
fogarr[19]= Color.FromArgb(255,0,255);
fogarr[20]= Color.FromArgb(138,43,226);
fogarr[21]= Color.FromArgb(128,0,0);
fogarr[22]= Color.FromArgb(165,42,42);
fogarr[23]= Color.FromArgb(102,205,170);
fogarr[24]= Color.FromArgb(222,184,135);
fogarr[25]= Color.FromArgb(0,0,205);
fogarr[26]= Color.FromArgb(95,158,160);
fogarr[27]= Color.FromArgb(186,85,211);
fogarr[28]= Color.FromArgb(127,255,0);
fogarr[29]= Color.FromArgb(147,112,219);
fogarr[30]= Color.FromArgb(210,105,30);
fogarr[31]= Color.FromArgb(60,179,113);
fogarr[32]= Color.FromArgb(255,127,80);
fogarr[33]= Color.FromArgb(123,104,238);
fogarr[34]= Color.FromArgb(100,149,237);
fogarr[35]= Color.FromArgb(0,250,154);
fogarr[36]= Color.FromArgb(255,248,220);
fogarr[37]= Color.FromArgb(72,209,204);
fogarr[38]= Color.FromArgb(220,20,60);
fogarr[39]= Color.FromArgb(199,21,112);
fogarr[40]= Color.FromArgb(0,255,255);
fogarr[41]= Color.FromArgb(25,25,112);
fogarr[42]= Color.FromArgb(0,0,139);
fogarr[43]= Color.FromArgb(245,255,250);
fogarr[44]= Color.FromArgb(0,139,139);
fogarr[45]= Color.FromArgb(255,228,225);
fogarr[46]= Color.FromArgb(184,134,11);
fogarr[47]= Color.FromArgb(255,228,181);
fogarr[48]= Color.FromArgb(169,169,169);
fogarr[49]= Color.FromArgb(255,222,173);
fogarr[50]= Color.FromArgb(0,100,0);
fogarr[51]= Color.FromArgb(0,0,128);
fogarr[52]= Color.FromArgb(189,183,107);
fogarr[53]= Color.FromArgb(253,245,230);
fogarr[54]= Color.FromArgb(139,0,139);
fogarr[55]= Color.FromArgb(128,128,0);
fogarr[56]= Color.FromArgb(85,107,47);
fogarr[57]= Color.FromArgb(107,142,45);
fogarr[58]= Color.FromArgb(255,140,0);
fogarr[59]= Color.FromArgb(255,165,0);
fogarr[60]= Color.FromArgb(153,50,204);
fogarr[61]= Color.FromArgb(255,69,0);
fogarr[62]= Color.FromArgb(139,0,0);
fogarr[63]= Color.FromArgb(218,112,214);
fogarr[64]= Color.FromArgb(233,150,122);
fogarr[65]= Color.FromArgb(238,232,170);
fogarr[66]= Color.FromArgb(143,188,143);
fogarr[67]= Color.FromArgb(152,251,152);
fogarr[68]= Color.FromArgb(72,61,139);
fogarr[69]= Color.FromArgb(175,238,238);
fogarr[70]= Color.FromArgb(40,79,79);
fogarr[71]= Color.FromArgb(219,112,147);
fogarr[72]= Color.FromArgb(0,206,209);
fogarr[73]= Color.FromArgb(255,239,213);
fogarr[74]= Color.FromArgb(148,0,211);
fogarr[75]= Color.FromArgb(255,218,155);
fogarr[76]= Color.FromArgb(255,20,147);
fogarr[77]= Color.FromArgb(205,133,63);
fogarr[78]= Color.FromArgb(0,191,255);
fogarr[79]= Color.FromArgb(255,192,203);
fogarr[80]= Color.FromArgb(105,105,105);
fogarr[81]= Color.FromArgb(221,160,221);
fogarr[82]= Color.FromArgb(30,144,255);
fogarr[83]= Color.FromArgb(176,224,230);
fogarr[84]= Color.FromArgb(178,34,34);
fogarr[85]= Color.FromArgb(128,0,128);
fogarr[86]= Color.FromArgb(255,250,240);
fogarr[87]= Color.FromArgb(255,0,0);
fogarr[88]= Color.FromArgb(34,139,34);
fogarr[89]= Color.FromArgb(188,143,143);
fogarr[90]= Color.FromArgb(255,0,255);
fogarr[91]= Color.FromArgb(65,105,225);
fogarr[92]= Color.FromArgb(220,220,220);
fogarr[93]= Color.FromArgb(139,69,19);
fogarr[94]= Color.FromArgb(248,248,255);
fogarr[95]= Color.FromArgb(250,128,114);
fogarr[96]= Color.FromArgb(255,215,0);
fogarr[97]= Color.FromArgb(244,164,96);
fogarr[98]= Color.FromArgb(218,165,32);
fogarr[99]= Color.FromArgb(46,139,87);
fogarr[100]= Color.FromArgb(128,128,128);
fogarr[101]= Color.FromArgb(255,245,238);
fogarr[102]= Color.FromArgb(0,128,0);
fogarr[103]= Color.FromArgb(160,82,45);
fogarr[104]= Color.FromArgb(173,255,47);
fogarr[105]= Color.FromArgb(192,192,192);
fogarr[106]= Color.FromArgb(240,255,240);
fogarr[107]= Color.FromArgb(135,206,235);
fogarr[108]= Color.FromArgb(255,105,180);
fogarr[109]= Color.FromArgb(106,90,205);
fogarr[110]= Color.FromArgb(205,92,92);
fogarr[111]= Color.FromArgb(112,128,144);
fogarr[112]= Color.FromArgb(75,0,130);
fogarr[113]= Color.FromArgb(255,250,250);
fogarr[114]= Color.FromArgb(255,240,240);
fogarr[115]= Color.FromArgb(0,255,127);
fogarr[116]= Color.FromArgb(240,230,140);
fogarr[117]= Color.FromArgb(70,130,180);
fogarr[118]= Color.FromArgb(230,230,250);
fogarr[119]= Color.FromArgb(210,180,140);
fogarr[120]= Color.FromArgb(255,240,245);
fogarr[121]= Color.FromArgb(0,128,128);
fogarr[122]= Color.FromArgb(124,252,0);
fogarr[123]= Color.FromArgb(216,191,216);
fogarr[124]= Color.FromArgb(255,250,205);
fogarr[125]= Color.FromArgb(253,99,71);
fogarr[126]= Color.FromArgb(173,216,230);
fogarr[127]= Color.FromArgb(64,224,208);
fogarr[128]= Color.FromArgb(240,128,128);
fogarr[129]= Color.FromArgb(238,130,238);
fogarr[130]= Color.FromArgb(224,255,255);
fogarr[131]= Color.FromArgb(245,222,179);
fogarr[132]= Color.FromArgb(250,250,210);
fogarr[133]= Color.FromArgb(255,255,255);
fogarr[134]= Color.FromArgb(144,238,144);
fogarr[135]= Color.FromArgb(245,245,245);
fogarr[136]= Color.FromArgb(211,211,211);
fogarr[137]= Color.FromArgb(255,255,0);
fogarr[138]= Color.FromArgb(255,182,193);
fogarr[139]= Color.FromArgb(154,205,50);

#Color class 배열을 이용한 다양한 색상나타내기
#Color class 배열을 이용한 다양한 색상나타내기

#현재 Form에 대한 this 핸들얻기
#현재 Form에 대한 this 핸들얻기

#Color 배열(140개)



using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Drawing2D;

class Program : Form
{
    private const int WM_KEYDOWN = 0x0100;
    private const int WM_PAINT = 0x000F;
    private const int WM_CREATE = 0x0001;

    static Graphics graphics;
    static Font font;
    static Color [] fogarr = new Color[140]; //배열선언
    static int toggle=0;
    static int ____index=0;
    static Program fi;

    [STAThread]
    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Program());
    }

    static void __time_tick(object sender, ElapsedEventArgs e)
    {
        for (int h = 0; h <= 52; h++)
        {
            HatchStyle hs = (HatchStyle)h;
            Brush hb = new HatchBrush(hs, fogarr[____index % 140]);
            graphics.FillRectangle(hb, new Rectangle((h/26)*250, (h%26)*20, 50, 20));
            graphics.DrawString(hs.ToString(), font, Brushes.DarkGreen, (h/26)*250+50, (h%26)*20);
        }
        fi.Text = fogarr[____index % 140].ToString();
        ____index++;
    }

    protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);

        switch(m.Msg)
        {
            case WM_PAINT:
            if(toggle==0)
            {
                this.Size = new Size(800,600);
                this.Text = "HatchStyle Window Information";

                graphics = this.CreateGraphics();
                font = new Font("고딕", 12, FontStyle.Bold);
                toggle=100;
            }
            break;
            case WM_CREATE :
               

                fi = new Program();
                fi = this;


                fogarr[0]= Color.FromArgb(240,248,255); //초기화 
                fogarr[1]= Color.FromArgb(255,160,122);
                fogarr[2]= Color.FromArgb(250,235,215);
                fogarr[3]= Color.FromArgb(32,178,170);
                fogarr[4]= Color.FromArgb(0,255,255);
                fogarr[5]= Color.FromArgb(135,206,250);
                /*
                ,, 자세한 Color.FromArgb List는 c#강의리스트에 올려놓았습니다. 참고부탁드려요.^
                */
                fogarr[134]= Color.FromArgb(144,238,144);
                fogarr[135]= Color.FromArgb(245,245,245);
                fogarr[136]= Color.FromArgb(211,211,211);
                fogarr[137]= Color.FromArgb(255,255,0);
                fogarr[138]= Color.FromArgb(255,182,193);
                fogarr[139]= Color.FromArgb(154,205,50);
                break;
            case WM_KEYDOWN :

            Keys keyCode = (Keys)m.WParam & Keys.KeyCode;

            if(keyCode.ToString() == "F1")
            {
                tm = new System.Timers.Timer();
                tm.Interval=100;
                tm.Elapsed += new ElapsedEventHandler(__time_tick);
                tm.Start();
            }
            else if(keyCode.ToString() == "F2")
            {

                if(tm != null)   //예외 사항체크
                {
                    tm.Stop();
                    tm.Elapsed -= __time_tick;
                }            }
            else
            {
                for (int h = 0; h <= 52; h++)
                {
                    HatchStyle hs = (HatchStyle)h;
                    Brush hb = new HatchBrush(hs, fogarr[____index % 140]);
                    graphics.FillRectangle(hb, new Rectangle((h/26)*250, (h%26)*20, 50, 20));
                    graphics.DrawString(hs.ToString(), font, Brushes.DarkGreen, (h/26)*250+50, (h%26)*20);
                }
                this.Text = fogarr[____index % 140].ToString();
                ____index++;
                break;
            }//end if else

        }//end of switch
    }//end of method
}//end of class

#컨트롤에 포커스가 자동으로 안갈 때
#컨트롤에 포커스가 자동으로 안갈 때
#컨트롤에 포커스가 자동으로 안갈 때
#컨트롤에 포커스가 자동으로 안갈 때



case WM_PAINT:
if(toggle==0)
{
this.Size = new Size(1000,600);
this.Text = "TRIS BY CONSOLE FORM";

graphics = CreateGraphics();
font = new Font("바탕체", 17, FontStyle.Bold);

toggle=100;

timer = new System.Timers.Timer();
timer.Interval = 800;
timer.Elapsed += new ElapsedEventHandler(__time_tick);
timer.Start();

mainBackColor = this.BackColor;

MessageBox.Show("TRIS START, Time Interval:" + timer.Interval);

//Form에 focus가 가도록 하기. 키보드 컨트롤을 이용할수 있다.
this.Activate();
this.Focus();


var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE); // 숨기기

init(ref t_tris, ref xpos, ref ypos, ref __design);
DrawTerisAll(t_tris);
}
break;

#설명:Windows10 Console창에서 실행하는 테트리스 프로그램 소스입니다.
#메모장에서 코드작성후에, C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe 로 컴파일 & 링크
#IDE는 사용하지 않습니다.(Visual Studio와 같은)

#HatchStyle 적용

#Tris Form Game by console base
#Tris Form Game by console base

#IDE(No Needed), Memo is sufficient, Window10 csc.exe is sufficient.

 

if(____t_tris[mm, nn]==0) 
{
#if false
    Brush brush = new SolidBrush(mainBackColor);
    graphics.FillRectangle(brush, 
    new Rectangle(50 + nn * ____WIDTH, 
                      40 + mm * ____HEIGHT, 
                      ____WIDTH-1, ____HEIGHT-1));
#endif   
  
#if true
    HatchStyle hs = (HatchStyle)____hatch_style;
    Brush hb = new HatchBrush(hs, mainBackColor);
    graphics.FillRectangle(hb, new Rectangle(50 + nn * ____WIDTH, 
                  40 + mm * ____HEIGHT, 
                  ____WIDTH-1, ____HEIGHT-1));
#endif   
}
else
{
#if false
    Brush brush = new SolidBrush(realBackColor[ ____t_tris[mm, nn] ]);
    graphics.FillRectangle(brush, 
                new Rectangle(50 + nn * ____WIDTH, 
                  40 + mm * ____HEIGHT, 
                  ____WIDTH-1, ____HEIGHT-1));
#endif   
  
#if true
    HatchStyle hs = (HatchStyle)____hatch_style;
    Brush hb = new HatchBrush(hs, realBackColor[ ____t_tris[mm, nn] ]);
    graphics.FillRectangle(hb, new Rectangle(50 + nn * ____WIDTH, 
                  40 + mm * ____HEIGHT, 
                  ____WIDTH-1, ____HEIGHT-1));
#endif   
}

 

#File Attach

f33.cs
0.04MB

Graphics graphics = CreateGraphics();
Graphics graphics = CreateGraphics();
Graphics graphics = CreateGraphics(); ????? 알아보도록 하자.

선 및 도형을 그리거나, 텍스트를 렌더링 하거나, GDI +를 사용 하 여 이미지를 표시 하 고 조작 하려면 먼저 Graphics 개체를 만들어야 합니다. Graphics개체는 GDI + 그리기 화면을 나타내며 그래픽 이미지를 만드는 데 사용 되는 개체입니다.

그래픽 작업에는 두 가지 단계가 있습니다.

  1. 개체 만들기 Graphics
  2. 개체를 사용 하 여 Graphics 선과 도형을 그리거나, 텍스트를 렌더링 하거나, 이미지를 표시 하 고 조작 합니다.

그래픽 개체 만들기

그래픽 개체는 다양 한 방법으로 만들 수 있습니다.

그래픽 개체를 만들려면

  • PaintEventArgs폼 또는 컨트롤의 경우의 일부로 그래픽 개체에 대 한 참조를 받습니다 Paint . 일반적으로 컨트롤의 그리기 코드를 만들 때 그래픽 개체에 대 한 참조를 가져오는 방법입니다. 마찬가지로, PrintPageEventArgs PrintPage 에 대 한 이벤트를 처리할 때 그래픽 개체를의 속성으로 가져올 수도 있습니다 PrintDocument .
  • 또는
  • 컨트롤이 나 폼의 메서드를 호출 하 여 CreateGraphics Graphics 해당 컨트롤이 나 폼의 그리기 화면을 나타내는 개체에 대 한 참조를 가져옵니다. 이미 존재 하는 폼 이나 컨트롤에 그리려는 경우이 메서드를 사용 합니다.
  • 또는
  • Graphics에서 상속 되는 개체에서 개체를 만듭니다 Image . 이 방법은 이미 존재 하는 이미지를 변경 하려는 경우에 유용 합니다.
  • 다음 섹션에서는 이러한 각 프로세스에 대 한 세부 정보를 제공 합니다.

Paint 이벤트 처리기의 PaintEventArgs

컨트롤 또는의에 대 한를 프로그래밍할 때 PaintEventHandler PrintPage PrintDocument 그래픽 개체는 또는의 속성 중 하나로 제공 됩니다 PaintEventArgs PrintPageEventArgs .

Paint 이벤트의 PaintEventArgs에서 그래픽 개체에 대 한 참조를 가져오려면

  1. 개체를 선언 Graphics 합니다.
  2. 의 일부로 전달 된 개체를 참조 하는 변수를 할당 합니다 Graphics PaintEventArgs .
  3. 폼 이나 컨트롤을 그리는 코드를 삽입 합니다.C#복사
    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs pe) { // Declares the Graphics object and sets it to the Graphics object // supplied in the PaintEventArgs. Graphics g = pe.Graphics; // Insert code to paint the form here. }
  4. 다음 예제에서는 이벤트의에서 개체를 참조 하는 방법을 보여 줍니다 Graphics PaintEventArgs Paint .

CreateGraphics 메서드

CreateGraphics컨트롤이 나 폼의 메서드를 사용 하 여 Graphics 해당 컨트롤이 나 폼의 그리기 화면을 나타내는 개체에 대 한 참조를 가져올 수도 있습니다.

CreateGraphics 메서드를 사용 하 여 그래픽 개체를 만들려면

  • CreateGraphics그래픽을 렌더링 하려는 폼 이나 컨트롤의 메서드를 호출 합니다.Graphics g; // Sets g to a graphics object representing the drawing surface of the // control or form g is a member of. g = this.CreateGraphics();
  • C#복사

이미지 개체에서 만들기

또한 클래스에서 파생 되는 모든 개체에서 그래픽 개체를 만들 수 있습니다 Image .

이미지에서 그래픽 개체를 만들려면

  • 개체를 Graphics.FromImage 만들려는 이미지 변수의 이름을 제공 하 여 메서드를 호출 합니다 Graphics .C#복사
    Bitmap myBitmap = new Bitmap(@"C:\Documents and Settings\Joe\Pics\myPic.bmp"); Graphics g = Graphics.FromImage(myBitmap);
  • 다음 예제에서는 개체를 사용 하는 방법을 보여 줍니다 Bitmap .

 참고

Graphics16 비트, 24 비트 및 32 비트 .bmp 파일과 같은 인덱싱되지 않은 .bmp 파일의 개체만 만들 수 있습니다. 비인덱스 .bmp 파일의 각 픽셀은 색 테이블에 대 한 인덱스를 포함 하는 인덱싱된 .bmp 파일의 픽셀과 달리 색을 포함 합니다.

모양 및 이미지 그리기 및 조작

개체를 만든 후에 Graphics 는 개체를 사용 하 여 선과 셰이프를 그리거나, 텍스트를 렌더링 하거나, 이미지를 표시 하 고 조작할 수 있습니다. 개체와 함께 사용 되는 보안 주체 개체는 Graphics 다음과 같습니다.

  • Pen클래스-선 그리기, 모양 개요 또는 다른 기하학적 표현 렌더링에 사용 됩니다.
  • Brush클래스-채워진 도형, 이미지 또는 텍스트와 같은 그래픽 영역을 채우는 데 사용 됩니다.
  • Font클래스-텍스트를 렌더링할 때 사용할 도형에 대 한 설명을 제공 합니다.
  • Color구조는 표시할 여러 색을 나타냅니다.

만든 그래픽 개체를 사용 하려면

C# 콘솔프로그램에서 콘솔창 숨기기
C# 콘솔프로그램에서 콘솔창 숨기기
C# 콘솔프로그램에서 콘솔창 숨기기

C# 콘솔프로그램에서 실행되는 콘솔창을 숨기기 위한 방법이다.

class안에 아래와 같이 선언한다.
[DllImport(“kernel32.dll”)]
static extern IntPtr GetConsoleWindow();

[DllImport(“user32.dll”)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_HIDE = 0; // 숨기기
const int SW_SHOW = 1; // 보이기

2.  main 함수 안에 아래의 코드를 입력한다.

var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE); // 숨기기
ShowWindow(handle, SW_SHOW); // 보이기

3. 실행

요약 
모든 데이터를 오브젝트(object;물체)로 취급하여 프로그래밍 하는 방법으로, 처리 요구를 받은 객체가 자기 자신의 안에 있는 내용을 가지고 처리하는 방식이다.


이 개념은 1960년 중엽에 유행한 시뮬레이션 언어의 SIMURA에서 유래한 것이다. 모든 데이터를 오브젝트(object:물체)로 취급하며, 이 오브젝트에는 클래스(class:類)의 개념이 있어서 상위(上位)와 하위(下位)의 관계가 있다. 클래스의 구체적인 예가 인스턴스(instance)이다. 오브젝트 사이는 메시지의 송신(送信)으로 상호 통신한다. 가장 특징적인 것은 각 클래스에 그 메시지를 처리하기 위한 방식이 있다는 것이다. 어떤 인스턴스에 메시지가 도래하면 그 상위 클래스가 그것을 처리한다. 현재 오브젝트지향개념은 프레임 표현형식과 융합하여 인공지능을 위한 소프트웨어 기법(技法)의 하나로 되어 있다.

객체지향프로그램은 C, Pascal, BASIC 등과 같은 절차형 언어(procedure-oriented programming)가 크고 복잡한 프로그램을 구축하기 어렵다는 문제점을 해결하기 위해 탄생된 것이다. 절차형 언어에서는 코드 전체를 여러 개의 기능부분 즉, 인쇄하는 기능부분과 유저로부터의 입력을 받는 기능부분 등으로 분할하는데, 이와 같이 각 기능부분을 구성하는 코드를 모쥴이라고 한다. 절차형 언어에서는 프로그램을 여러 기능으로 나누고 이들 모쥴을 편성하여 프로그램을 작성할 경우, 각 모쥴이 처리하는 데이터에 대해서는 전혀 고려하지 않는다. 다시 말하면 데이터 취급이 완전하지 않고 현실 세계의 문제를 프로그램으로서 표현하는 것이 곤란하다.

이러한 절차형 프로그래밍이 가지는 문제를 해결하기 위해 탄생된 객체지향프로그래밍은 객체라는 작은 단위로서 모든 처리를 기술하는 프로그래밍 방법으로서, 모든 처리는 객체에 대한 요구의 형태로 표현되며, 요구를 받은 객체는 자기 자신 내에 기술되어 있는 처리를 실행한다. 이 방법으로 프로그램을 작성할 경우 프로그램이 단순화되고, 생산성과 신뢰성이 높은 시스템을 구축할 수 있다.

#C# 에서의 [STAThread] 는 왜 붙이는가? (Why STAThread is attached above C# ?)

C# 코드에서 [STAThread] 가 의미하는 바는 기본적으로, VS .NET에 의해 만들어진 응용 프로그램의 Main()메소드에는 [STAThread] 라는 속성으로 되어 있다. 
하지만 COM 형식을 이용하는 경우엔 [STAThread]  라는 것으로  해당 응용 프로그램이 COM형식을 이용하는 경우에 (단지 이 경우에만 해당하는 것인데) 해당 응용 프로그램이 단일 스레드 아파트(single threaded apartment, STA) 모델로 설정되어야 한다는 것을 런타임에게 알려주는 역할을 한다. 
즉 다중쓰레드로 동작하지 않는다는 것을 알려주는것이다. 
해당 응용 프로그램에서 COM 형식을 이용하지 않는다면, [STAThread] 어트리뷰트는 무시되기 때문에 삭제해도 무방하다.

    /*
    protected override void WndProc(ref Message m)
    {
       base.WndProc(ref m);
       switch(m.Msg)
       {
           case WM_KEYDOWN :
           {
                int ____keyCode=m.WParam.ToInt32();
                if(____keyCode==VK_RIGHT) { // }
           }
        }
     }
     */

private const int WM_ACTIVATE           = 0x0006;
        private const int WM_ACTIVATEAPP        = 0x001C;
        private const int WM_AFXFIRST           = 0x0360;
        private const int WM_AFXLAST            = 0x037F;
        private const int WM_APP                = 0x8000;
        private const int WM_ASKCBFORMATNAME    = 0x030C;
        private const int WM_CANCELJOURNAL      = 0x004B;
        private const int WM_CANCELMODE         = 0x001F;
        private const int WM_CAPTURECHANGED     = 0x0215;
        private const int WM_CHANGECBCHAIN      = 0x030D;
        private const int WM_CHANGEUISTATE      = 0x0127;
        private const int WM_CHAR               = 0x0102;
        private const int WM_CHARTOITEM         = 0x002F;
        private const int WM_CHILDACTIVATE      = 0x0022;
        private const int WM_CLEAR              = 0x0303;
        private const int WM_CLOSE              = 0x0010;
        private const int WM_COMMAND            = 0x0111;
        private const int WM_COMPACTING         = 0x0041;
        private const int WM_COMPAREITEM        = 0x0039;
        private const int WM_CONTEXTMENU        = 0x007B;
        private const int WM_COPY               = 0x0301;
        //private const int WM_COPYDATA           = 0x004A;
        private const int WM_CREATE             = 0x0001;
        private const int WM_CTLCOLORBTN        = 0x0135;
        private const int WM_CTLCOLORDLG        = 0x0136;
        private const int WM_CTLCOLOREDIT       = 0x0133;
        private const int WM_CTLCOLORLISTBOX    = 0x0134;
        private const int WM_CTLCOLORMSGBOX     = 0x0132;
        private const int WM_CTLCOLORSCROLLBAR  = 0x0137;
        private const int WM_CTLCOLORSTATIC     = 0x0138;
        private const int WM_CUT                = 0x0300;
        private const int WM_DEADCHAR           = 0x0103;
        private const int WM_DELETEITEM         = 0x002D;
        private const int WM_DESTROY            = 0x0002;
        private const int WM_DESTROYCLIPBOARD   = 0x0307;
        private const int WM_DEVICECHANGE       = 0x0219;
        private const int WM_DEVMODECHANGE      = 0x001B;
        private const int WM_DISPLAYCHANGE      = 0x007E;
        private const int WM_DRAWCLIPBOARD      = 0x0308;
        private const int WM_DRAWITEM           = 0x002B;
        private const int WM_DROPFILES          = 0x0233;
        private const int WM_ENABLE             = 0x000A;
        private const int WM_ENDSESSION         = 0x0016;
        private const int WM_ENTERIDLE          = 0x0121;
        private const int WM_ENTERMENULOOP      = 0x0211;
        private const int WM_ENTERSIZEMOVE      = 0x0231;
        private const int WM_ERASEBKGND         = 0x0014;
        private const int WM_EXITMENULOOP       = 0x0212;
        private const int WM_EXITSIZEMOVE       = 0x0232;
        private const int WM_FONTCHANGE         = 0x001D;
        private const int WM_GETDLGCODE         = 0x0087;
        private const int WM_GETFONT            = 0x0031;
        private const int WM_GETHOTKEY          = 0x0033;
        private const int WM_GETICON            = 0x007F;
        private const int WM_GETMINMAXINFO      = 0x0024;
        private const int WM_GETOBJECT          = 0x003D;
        private const int WM_GETTEXT            = 0x000D;
        private const int WM_GETTEXTLENGTH      = 0x000E;
        private const int WM_HANDHELDFIRST      = 0x0358;
        private const int WM_HANDHELDLAST       = 0x035F;
        private const int WM_HELP               = 0x0053;
        private const int WM_HOTKEY             = 0x0312;
        private const int WM_HSCROLL            = 0x0114;
        private const int WM_HSCROLLCLIPBOARD   = 0x030E;
        private const int WM_ICONERASEBKGND     = 0x0027;
        private const int WM_IME_CHAR           = 0x0286;
        private const int WM_IME_COMPOSITION    = 0x010F;
        private const int WM_IME_COMPOSITIONFULL= 0x0284;
        private const int WM_IME_CONTROL        = 0x0283;
        private const int WM_IME_ENDCOMPOSITION = 0x010E;
        private const int WM_IME_KEYDOWN        = 0x0290;
        private const int WM_IME_KEYLAST        = 0x010F;
        private const int WM_IME_KEYUP          = 0x0291;
        private const int WM_IME_NOTIFY         = 0x0282;
        private const int WM_IME_REQUEST        = 0x0288;
        private const int WM_IME_SELECT         = 0x0285;
        private const int WM_IME_SETCONTEXT     = 0x0281;
        private const int WM_IME_STARTCOMPOSITION   = 0x010D;
        private const int WM_INITDIALOG         = 0x0110;
        private const int WM_INITMENU           = 0x0116;
        private const int WM_INITMENUPOPUP      = 0x0117;
        private const int WM_INPUTLANGCHANGE    = 0x0051;
        private const int WM_INPUTLANGCHANGEREQUEST = 0x0050;
        private const int WM_KEYDOWN        = 0x0100;
        private const int WM_KEYFIRST           = 0x0100;
        private const int WM_KEYLAST        = 0x0108;
        private const int WM_KEYUP          = 0x0101;
        private const int WM_KILLFOCUS          = 0x0008;
        private const int WM_LBUTTONDBLCLK      = 0x0203;
        private const int WM_LBUTTONDOWN        = 0x0201;
        private const int WM_LBUTTONUP          = 0x0202;
        private const int WM_MBUTTONDBLCLK      = 0x0209;
        private const int WM_MBUTTONDOWN        = 0x0207;
        private const int WM_MBUTTONUP          = 0x0208;
        private const int WM_MDIACTIVATE        = 0x0222;
        private const int WM_MDICASCADE         = 0x0227;
        private const int WM_MDICREATE          = 0x0220;
        private const int WM_MDIDESTROY         = 0x0221;
        private const int WM_MDIGETACTIVE       = 0x0229;
        private const int WM_MDIICONARRANGE     = 0x0228;
        private const int WM_MDIMAXIMIZE        = 0x0225;
        private const int WM_MDINEXT        = 0x0224;
        private const int WM_MDIREFRESHMENU     = 0x0234;
        private const int WM_MDIRESTORE         = 0x0223;
        private const int WM_MDISETMENU         = 0x0230;
        private const int WM_MDITILE        = 0x0226;
        private const int WM_MEASUREITEM        = 0x002C;
        private const int WM_MENUCHAR           = 0x0120;
        private const int WM_MENUCOMMAND        = 0x0126;
        private const int WM_MENUDRAG           = 0x0123;
        private const int WM_MENUGETOBJECT      = 0x0124;
        private const int WM_MENURBUTTONUP      = 0x0122;
        private const int WM_MENUSELECT         = 0x011F;
        private const int WM_MOUSEACTIVATE      = 0x0021;
        private const int WM_MOUSEFIRST         = 0x0200;
        private const int WM_MOUSEHOVER         = 0x02A1;
        private const int WM_MOUSELAST          = 0x020D;
        private const int WM_MOUSELEAVE         = 0x02A3;
        private const int WM_MOUSEMOVE          = 0x0200;
        private const int WM_MOUSEWHEEL         = 0x020A;
        private const int WM_MOUSEHWHEEL        = 0x020E;
        private const int WM_MOVE           = 0x0003;
        private const int WM_MOVING         = 0x0216;
        private const int WM_NCACTIVATE         = 0x0086;
        private const int WM_NCCALCSIZE         = 0x0083;
        private const int WM_NCCREATE           = 0x0081;
        private const int WM_NCDESTROY          = 0x0082;
        private const int WM_NCHITTEST          = 0x0084;
        private const int WM_NCLBUTTONDBLCLK    = 0x00A3;
        private const int WM_NCLBUTTONDOWN      = 0x00A1;
        private const int WM_NCLBUTTONUP        = 0x00A2;
        private const int WM_NCMBUTTONDBLCLK    = 0x00A9;
        private const int WM_NCMBUTTONDOWN      = 0x00A7;
        private const int WM_NCMBUTTONUP        = 0x00A8;
        private const int WM_NCMOUSEHOVER       = 0x02A0;
        private const int WM_NCMOUSELEAVE       = 0x02A2;
        private const int WM_NCMOUSEMOVE        = 0x00A0;
        private const int WM_NCPAINT        = 0x0085;
        private const int WM_NCRBUTTONDBLCLK    = 0x00A6;
        private const int WM_NCRBUTTONDOWN      = 0x00A4;
        private const int WM_NCRBUTTONUP        = 0x00A5;
        private const int WM_NCXBUTTONDBLCLK    = 0x00AD;
        private const int WM_NCXBUTTONDOWN      = 0x00AB;
        private const int WM_NCXBUTTONUP        = 0x00AC;
        private const int WM_NCUAHDRAWCAPTION       = 0x00AE;
        private const int WM_NCUAHDRAWFRAME     = 0x00AF;
        private const int WM_NEXTDLGCTL         = 0x0028;
        private const int WM_NEXTMENU           = 0x0213;
        private const int WM_NOTIFY         = 0x004E;
        private const int WM_NOTIFYFORMAT       = 0x0055;
        private const int WM_NULL           = 0x0000;
        private const int WM_PAINT          = 0x000F;
        private const int WM_PAINTCLIPBOARD     = 0x0309;
        private const int WM_PAINTICON          = 0x0026;
        private const int WM_PALETTECHANGED     = 0x0311;
        private const int WM_PALETTEISCHANGING      = 0x0310;
        private const int WM_PARENTNOTIFY       = 0x0210;
        private const int WM_PASTE          = 0x0302;
        private const int WM_PENWINFIRST        = 0x0380;
        private const int WM_PENWINLAST         = 0x038F;
        private const int WM_POWER          = 0x0048;
        private const int WM_POWERBROADCAST     = 0x0218;
        private const int WM_PRINT          = 0x0317;
        private const int WM_PRINTCLIENT        = 0x0318;
        private const int WM_QUERYDRAGICON      = 0x0037;
        private const int WM_QUERYENDSESSION    = 0x0011;
        private const int WM_QUERYNEWPALETTE    = 0x030F;
        private const int WM_QUERYOPEN          = 0x0013;
        private const int WM_QUEUESYNC          = 0x0023;
        private const int WM_QUIT           = 0x0012;
        private const int WM_RBUTTONDBLCLK      = 0x0206;
        private const int WM_RBUTTONDOWN        = 0x0204;
        private const int WM_RBUTTONUP          = 0x0205;
        private const int WM_RENDERALLFORMATS       = 0x0306;
        private const int WM_RENDERFORMAT       = 0x0305;
        private const int WM_SETCURSOR          = 0x0020;
        private const int WM_SETFOCUS           = 0x0007;
        private const int WM_SETFONT        = 0x0030;
        private const int WM_SETHOTKEY          = 0x0032;
        private const int WM_SETICON        = 0x0080;
        private const int WM_SETREDRAW          = 0x000B;
        private const int WM_SETTEXT        = 0x000C;
        private const int WM_SETTINGCHANGE      = 0x001A;
        private const int WM_SHOWWINDOW         = 0x0018;
        private const int WM_SIZE           = 0x0005;
        private const int WM_SIZECLIPBOARD      = 0x030B;
        private const int WM_SIZING         = 0x0214;
        private const int WM_SPOOLERSTATUS      = 0x002A;
        private const int WM_STYLECHANGED       = 0x007D;
        private const int WM_STYLECHANGING      = 0x007C;
        private const int WM_SYNCPAINT          = 0x0088;
        private const int WM_SYSCHAR        = 0x0106;
        private const int WM_SYSCOLORCHANGE     = 0x0015;
        private const int WM_SYSCOMMAND         = 0x0112;
        private const int WM_SYSDEADCHAR        = 0x0107;
        private const int WM_SYSKEYDOWN         = 0x0104;
        private const int WM_SYSKEYUP           = 0x0105;
        private const int WM_TCARD          = 0x0052;
        private const int WM_TIMECHANGE         = 0x001E;
        private const int WM_TIMER          = 0x0113;
        private const int WM_UNDO           = 0x0304;
        private const int WM_UNINITMENUPOPUP    = 0x0125;
        private const int WM_USER           = 0x0400;
        private const int WM_USERCHANGED        = 0x0054;
        private const int WM_VKEYTOITEM         = 0x002E;
        private const int WM_VSCROLL        = 0x0115;
        private const int WM_VSCROLLCLIPBOARD       = 0x030A;
        private const int WM_WINDOWPOSCHANGED       = 0x0047;
        private const int WM_WINDOWPOSCHANGING      = 0x0046;
        private const int WM_WININICHANGE       = 0x001A;
        private const int WM_XBUTTONDBLCLK      = 0x020D;
        private const int WM_XBUTTONDOWN        = 0x020B;
        private const int WM_XBUTTONUP          = 0x020C;

    /*
    protected override void WndProc(ref Message m)
    {
       base.WndProc(ref m);
       switch(m.Msg)
       {
           case WM_KEYDOWN :
           {
                int ____keyCode=m.WParam.ToInt32();
                if(____keyCode==VK_RIGHT) { // }
           }
        }
     }
     */

    public const int VK_0            = 0x30;
    public const int VK_1            = 0x31;
    public const int VK_2            = 0x32;
    public const int VK_3            = 0x33;
    public const int VK_4            = 0x34;
    public const int VK_5            = 0x35;
    public const int VK_6            = 0x36;
    public const int VK_7            = 0x37;
    public const int VK_8            = 0x38;
    public const int VK_9            = 0x39;
    public const int VK_A            = 0x41;
    public const int VK_B            = 0x42;
    public const int VK_C            = 0x43;
    public const int VK_D            = 0x44;
    public const int VK_E            = 0x45;
    public const int VK_F            = 0x46;
    public const int VK_G            = 0x47;
    public const int VK_H            = 0x48;
    public const int VK_I            = 0x49;
    public const int VK_J            = 0x4A;
    public const int VK_K            = 0x4B;
    public const int VK_L            = 0x4C;
    public const int VK_M            = 0x4D;
    public const int VK_N            = 0x4E;
    public const int VK_O            = 0x4F;
    public const int VK_P            = 0x50;
    public const int VK_Q            = 0x51;
    public const int VK_R            = 0x52;
    public const int VK_S            = 0x53;
    public const int VK_T            = 0x54;
    public const int VK_U            = 0x55;
    public const int VK_V            = 0x56;
    public const int VK_W            = 0x57;
    public const int VK_X            = 0x58;
    public const int VK_Y            = 0x59;
    public const int VK_Z            = 0x5A;
    public const int VK_BACK      =    0x08;
    public const int VK_TAB       =    0x09;
    public const int VK_CLEAR     =    0x0C;
    public const int VK_RETURN    =    0x0D;
    public const int VK_SHIFT     =    0x10;
    public const int VK_CONTROL   =    0x11;
    public const int VK_MENU      =    0x12;
    public const int VK_PAUSE     =    0x13;
    public const int VK_CAPITAL   =    0x14;
    public const int VK_KANA      =    0x15;
    public const int VK_HANGEUL   =    0x15;
    public const int VK_HANGUL    =    0x15;
    public const int VK_JUNJA     =    0x17;
    public const int VK_FINAL     =    0x18;
    public const int VK_HANJA     =    0x19;
    public const int VK_KANJI     =    0x19;
    public const int VK_ESCAPE    =    0x1B;
public const int VK_SPACE     =    0x20;
    public const int VK_CONVERT   =    0x1C;
    public const int VK_NONCONVERT=    0x1D;
    public const int VK_ACCEPT    =    0x1E;
    public const int VK_MODECHANGE=    0x1F;
    public const int VK_PRIOR     =    0x21;
    public const int VK_NEXT      =    0x22;
    public const int VK_END       =    0x23;
    public const int VK_HOME      =    0x24;
    public const int VK_LEFT      =    0x25;
    public const int VK_UP        =    0x26;
    public const int VK_RIGHT     =    0x27;
    public const int VK_DOWN      =    0x28;
    public const int VK_SELECT    =    0x29;
    public const int VK_PRINT     =    0x2A;
    public const int VK_EXECUTE   =    0x2B;
    public const int VK_SNAPSHOT  =    0x2C;
    public const int VK_INSERT    =    0x2D;
    public const int VK_DELETE    =    0x2E;
    public const int VK_HELP      =    0x2F;
    public const int VK_LWIN      =    0x5B;
    public const int VK_RWIN      =    0x5C;
    public const int VK_APPS      =    0x5D;
    public const int VK_SLEEP     =    0x5F;
    public const int VK_NUMPAD0   =    0x60;
    public const int VK_NUMPAD1   =    0x61;
    public const int VK_NUMPAD2   =    0x62;
    public const int VK_NUMPAD3   =    0x63;
    public const int VK_NUMPAD4   =    0x64;
    public const int VK_NUMPAD5   =    0x65;
    public const int VK_NUMPAD6   =    0x66;
    public const int VK_NUMPAD7   =    0x67;
    public const int VK_NUMPAD8   =    0x68;
    public const int VK_NUMPAD9   =    0x69;
    public const int VK_MULTIPLY  =    0x6A;
    public const int VK_ADD       =    0x6B;
    public const int VK_SEPARATOR =    0x6C;
    public const int VK_SUBTRACT  =    0x6D;
    public const int VK_DECIMAL   =    0x6E;
    public const int VK_DIVIDE    =    0x6F;
    public const int VK_F1        =    0x70;
    public const int VK_F2        =    0x71;
    public const int VK_F3        =    0x72;
    public const int VK_F4        =    0x73;
    public const int VK_F5        =    0x74;
    public const int VK_F6        =    0x75;
    public const int VK_F7        =    0x76;
    public const int VK_F8        =    0x77;
    public const int VK_F9        =    0x78;
    public const int VK_F10       =    0x79;
    public const int VK_F11       =    0x7A;
    public const int VK_F12       =    0x7B;
    public const int VK_F13       =    0x7C;
    public const int VK_F14       =    0x7D;
    public const int VK_F15       =    0x7E;
    public const int VK_F16       =    0x7F;
    public const int VK_F17       =    0x80;
    public const int VK_F18       =    0x81;
    public const int VK_F19       =    0x82;
    public const int VK_F20       =    0x83;
    public const int VK_F21       =    0x84;
    public const int VK_F22       =    0x85;
    public const int VK_F23       =    0x86;
    public const int VK_F24       =    0x87;
    public const int VK_NUMLOCK   =    0x90;
    public const int VK_SCROLL    =    0x91;

#In Form Draw & In WndProc Event
#In Form Draw & In WndProc Event
#In Form Draw & In WndProc Event

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace ConsoleForm
{
    public class ____ConsoleDraw : Form
    {
        private const int WM_KEYDOWN = 0x0100;
        private const int WM_PAINT = 0x000F;

        static int toggle=0;
        static int index=0;

        public ____ConsoleDraw()
        {
            //
        }
        protected override void WndProc(ref Message m) //해당 overrride 메소드에서 그래픽관련 핸들을 얻어야 합니다.
        {
            base.WndProc(ref m); 

            index++;
            Console.Write("Window Message Event:" + index.ToString("000000") + "/" + m.Msg + "/");
            Console.WriteLine("0x"+Convert.ToString(m.Msg, 16) + "/");

            switch(m.Msg)
            {
                case WM_PAINT:
                if(toggle==0)
                {
                    this.Size = new Size(800,600);
                    this.Text = "HatchStyle Window Information";
                    toggle=100;
                }
                break;
                case WM_KEYDOWN : 
                    Console.WriteLine("WM_KEYDOWN"); 

                    if (m.Msg == WM_KEYDOWN)
                    {
                        Keys keyCode = (Keys)m.WParam & Keys.KeyCode;

                        switch (keyCode)
                        {
                        case Keys.F1:
                        case Keys.F2:

                        MessageBox.Show("Control.PreProcessMessage: '" +
                          keyCode.ToString() + "' pressed.");
                        break;
                        }

                        if(Keys.F1 == keyCode)
                        {
                            Application.Exit();
                        }
                        if(Keys.F2 == keyCode)
                        {
                            Console.WriteLine("F2 Key Pressed!!");

                            Graphics graphics = CreateGraphics();
                            Pen pen = new Pen(Color.Black);
                            graphics.DrawLine(pen,10,10,50,10);
                            graphics.DrawLine(pen,50,10,50,50);

                            graphics.Dispose(); // Graphics에서 사용하는 리소스를 모두 해제합니다.
                        }
                        if(Keys.F3 == keyCode)
                        {
                            Graphics graphics = CreateGraphics();
                            Font font = new Font("고딕", 12, FontStyle.Bold);

                            //1.
                            for (int h = 0; h <= 52; h++)
                            {
                                HatchStyle hs = (HatchStyle)h;
                                Brush hb = new HatchBrush(hs, Color.White);
                                graphics.FillRectangle(hb, new Rectangle((h/26)*250, (h%26)*20, 50, 20));
                                graphics.DrawString(hs.ToString(), font, Brushes.DarkGreen, (h/26)*250+50, (h%26)*20);
                            }
 
                            //2.
                            Brush brush = new SolidBrush(Color.Green);
                            graphics.FillRectangle(brush, new Rectangle(500, 20, 50, 20));
                            graphics.DrawString("SolidBrush - Green", font, Brushes.Green, 550, 20);
 
                            //3.
                            Brush tb = new TextureBrush(image);
                            graphics.FillRectangle(tb, new Rectangle(500, 40, 50, 20));
                            graphics.DrawString("TextureBrush - myimage", font, Brushes.Green, 550, 40);
                        }
                    }
                    break;
                }
            }

            [STAThread]
            static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ____ConsoleDraw());
            }
      }//end of class
}//end of namespace 

 

#form hexa created by console(WndProc)
#form hexa created by console(WndProc)

#IDE 필요없음, Windows10 csc로 개발가능(메모장으로 개발)
#IDE 필요없음, Windows10 csc로 개발가능(메모장으로 개발)
#IDE 필요없음, Windows10 csc로 개발가능(메모장으로 개발)


Caution)Semaphor Needed, Duplicate DrawHexa Execution Error!!!!
Caution)Semaphor Needed, Duplicate DrawHexa Execution Error!!!!
Caution)Semaphor Needed, Duplicate DrawHexa Execution Error!!!!

DrawStyle 1)
DrawStyle 2)


#기본 sample(base sample code)

namespace WindowForm
{
public class ____KingDom : Form
{
private const int WM_KEYDOWN = 0x0100;
private const int WM_PAINT = 0x000F;
static int toggle=0;

static System.Timers.Timer timer;

static Graphics graphics;
static Font font;

public ____KingDom()
{
//
}
// 윈도우 메시지 처리 함수
protected override void WndProc(ref Message m)
{
  base.WndProc(ref m);
  // 메시지 콘솔 출력
  Console.Write(m.Msg + "/");
  Console.Write("0x"+Convert.ToString(m.Msg, 16) + "/");

  switch(m.Msg)
  {
    case WM_PAINT:
    if(toggle==0)
    {
      this.Size = new Size(800,800);
      this.Text = "HEXA BY CONSOLE FORM";

      graphics = CreateGraphics();
      font = new Font("바탕체", 17, FontStyle.Bold);

      toggle=100;

      timer = new System.Timers.Timer();
      timer.Interval = 1000;
      timer.Elapsed += new ElapsedEventHandler(__time_tick);
      timer.Start();

      MessageBox.Show("HEXA START, Time Interval:" + timer.Interval);

      init(ref hexa, ref xpos, ref ypos, ref __design);
      DrawHexa(hexa);
    }
    break;
    case 0x0100 :
    Console.WriteLine("WM_KEYDOWN");

    if (m.Msg == WM_KEYDOWN)
    {
      int ____keyCode=m.WParam.ToInt32();
      if(____keyCode == VK_RIGHT) //RIGHT
      {
        kk = f_rightkey(ref hexa, ref xpos, ref ypos, ref __design);
      }
      if(____keyCode == VK_LEFT) //LEFT
      {
        kk = f_leftkey(ref hexa, ref xpos, ref ypos, ref __design);
      }
      if(____keyCode == VK_SPACE) //SPACE
      {
        kk = f_spacekey(ref hexa, ref xpos, ref ypos, ref __design);
      }
      }
      break;
      }
    }

    [STAThread]
    static void Main(string[] args)
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new ____KingDom());
    }
  }
}

f13.cs
0.03MB

#include<limits.h> 선언후에 사용되는 정의값

stdio.h 와 마찬가지로 limits.h 도 헤더파일입니다.
다만 틀린 것이 있다면 limits.h 는 매크로 상수처럼 그 값과 변수명이 이미 정해져 있다는 것이죠. 
따라서 유효범위를 알아야 하기위해서는 변수명또한 알아두셔야합니다.

limits.h 헤더파일 내용.

#include<limits.h> 선언후에 사용되는 정의값

CHAR_BIT char의 비트 수
SCHAR_MIN signed char의 최소값
SCHAR_MAX signed char의 최대값
UCHAR_MAX unsigned char의 최대값
CHAR_MIN char의 최소값
CHAR_MAX char의 최대값
MB_LEN_MAX 멀티바이트 문자의 최대 바이트 수
SHRT_MIN short int의 최소값
SHRT_MAX short int의 최대값
USHRT_MAX unsigned short int의 최대값
INT_MIN int의 최소값
INT_MAX int의 최대값
UINT_MAX unsigned int의 최대값
LONG_MIN long int의 최소값
LONG_MAX long int의 최대값
ULONG_MAX unsigned long int의 최대값

ex)

#include<stdio.h>
#include<limits.h>

int main(void)
{
    short min = SHRT_MIN;
    short max = SHRT_MAX;

    printf("MAX:[%d],MIN[%d]\n", max, min);
    return(0);
}


#SendMessage by User Forced & When F1 KeyDown, Process example
#SendMessage by User Forced & When F1 KeyDown, Process example
#SendMessage by User Forced & When F1 KeyDown, Process example


KEY_DOWN시에, 강제로 Message를 Send 한다.
WM_KEYDOWN시에, F1이 눌리면 F1이 눌렸다고 표시한다.

private const int WM_KEYDOWN        = 0x0100;

protected override void WndProc(ref Message m)
{
  base.WndProc(ref m);

  Console.WriteLine(m.Msg); //10진수로 표시
  Console.WriteLine("0x"+Convert.ToString(m.Msg, 16)); //16진수로 표시

  switch(m.Msg)
  {
    case 0x0203 : 
      Console.WriteLine("WM_LBUTTONDBLCLK      "); 
      Console.WriteLine("QUIT--------------------------------"); 
      Application.Exit(); //강제종료
      break;
    case 0x0100 : 
    Console.WriteLine("WM_KEYDOWN ####           ---------------"); 
    ____KingDom.SendMessage(this.Handle, WM_COPYDATA, 1, 2);

    if (m.Msg == WM_KEYDOWN)
    {
      Keys keyCode = (Keys)m.WParam & Keys.KeyCode;

      if(Keys.F1 == keyCode)
      {
        Console.WriteLine("F1 Key Pressed!!");
      }
    }
    break;
  }
}

 

send_msg.cs
0.03MB

+ Recent posts