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

#WndProc & Message(WM_MOVE) 예제




        // 윈도우 메시지 처리 함수
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            // 메시지 콘솔 출력
            Console.WriteLine(m.Msg);
            Console.WriteLine("----------------------0x"+Convert.ToString(m.Msg, 16));
            switch(m.Msg)
            {
                case WM_MOVE : 
                    Console.WriteLine("WM_MOVE Message Occured!!");
                    break;
            }
        }

 

message_sh.cs
0.03MB

#console tcp server ,client

 

f_ser.cs
0.00MB
f_cli.cs
0.00MB

using System;
using System.Net;
using System.IO;

namespace NetKingdom
{
    class Program    
    {
        static WebRequest request;
        static WebResponse response;
        static Stream dataStream;
        static StreamReader reader;

        static void Main(string[] args)
        {
            request = WebRequest.Create("https://news.naver.com");//URL ADDRESS
            request.Method = "GET";
                
            response = request.GetResponse();
            dataStream = response.GetResponseStream();
            reader = new StreamReader(dataStream);
 
            string responseFromServer = reader.ReadToEnd();
 
            Console.WriteLine(responseFromServer); // response 출력
 
            reader.Close();
            dataStream.Close();
            response.Close();
        }
    }
}

#메시지 처리 함수 (WndProc)
메시지 처리 함수(WndProc) 란 WinMain에 메시지 루프에서 전달된 메시지를 처리해주는 함수입니다. 
이 WndProc 함수는 WinMain에서 호출하는것이 아닌 운영체제에서 호출합니다. 
이렇게 운영체제에서 호출하는 함수를 콜백 함수라고 합니다.
WinMain 내에 메시지 루프는 메시지를 전달하는 역활만 하고 
메시지 처리는 모두 이 WndProc 함수에서 처리가 됩니다.

DOS에서는 main 함수만 있으면 프로그램을 작성할 수 있지만
WINAPI에서는 특별한 경우를 제외하고는 메인 함수와 메시지 처리 함수 이 두 함수가 있어야 한다.

protected override void WndProc(ref Message m)
{
    base.WndProc(ref m);
    switch(m.Msg)
    {
        case APMApiPublic.UWM_CHANGE_HANDLE:,,,,,,,
        case APMApiPublic.WM_COPYDATA:,,,,,,
    }
}

이렇게 전달된 메시지를 프록시함수는 스위치 문으로 처리합니다.
WM_PAINT , WM_KEYDOWN 등등 전달된 메시지의 종류에 따라 다르게 처리를 합니다.
프로그램 종료 버튼을 누르면 WM_DESTROY 메시지가 실행이 되고
PostQuitMessage(0) 함수가 호출되는데 이 함수는 WM_QUIT 메시지를 생성시켜
프로그램을 종료하게됩니다.

스위치 문을 통과한 뒤 DefWindowProc() 함수를 리턴하게 되는데
이 함수는 메뉴 최소화, 최대화 ,윈도우 이동, 등을 프로그래머가 집적 손대지 않아도
운영체제가 알아서 처리해주는 함수입니다.

비고) Window c를 이용하는 프로그램에서 자주 다루어 졌던 내용입니다.

#region을 사용하면 #endregion으로 지시문을 종료해야 합니다. Visual Studio에서 #region에서 바로 다음으로 나오는 #endregion까지의 코드를 확대, 축소하며 작업을 할 수 있습니다. 

 

아래의 그림 1이 위 설명을 코드로 나타낸 것 입니다. 

[그림 1]

 

[그림 2]



비고)
#region을 쓰면 안될 때..
짜임새 있게 짜여지지 못한 코드의 경우 region으로 더 복잡해 질 수 있습니다.

 

 

/*------------------------------------------------------------------------
 double value;

 value = 123;
 Console.WriteLine(value.ToString("00000"));
 Console.WriteLine(String.Format("{0:00000}", value));
 // Displays 00123

 value = 1.2;
 Console.WriteLine(value.ToString("0.00", CultureInfo.InvariantCulture));
 Console.WriteLine(String.Format(CultureInfo.InvariantCulture,
                   "{0:0.00}", value));
 // Displays 1.20

 Console.WriteLine(value.ToString("00.00", CultureInfo.InvariantCulture));
 Console.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                 "{0:00.00}", value));
 // Displays 01.20

 CultureInfo daDK = CultureInfo.CreateSpecificCulture("da-DK");
 Console.WriteLine(value.ToString("00.00", daDK));
 Console.WriteLine(String.Format(daDK, "{0:00.00}", value));
 // Displays 01,20

 value = .56;
 Console.WriteLine(value.ToString("0.0", CultureInfo.InvariantCulture));
 Console.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                 "{0:0.0}", value));
 // Displays 0.6

 value = 1234567890;
 Console.WriteLine(value.ToString("0,0", CultureInfo.InvariantCulture));
 Console.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                 "{0:0,0}", value));
 // Displays 1,234,567,890

 CultureInfo elGR = CultureInfo.CreateSpecificCulture("el-GR");
 Console.WriteLine(value.ToString("0,0", elGR));
Console.WriteLine(String.Format(elGR, "{0:0,0}", value));
 // Displays 1.234.567.890

 value = 1234567890.123456;
 Console.WriteLine(value.ToString("0,0.0", CultureInfo.InvariantCulture));
 Console.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                 "{0:0,0.0}", value));
 // Displays 1,234,567,890.1

 value = 1234.567890;
 Console.WriteLine(value.ToString("0,0.00", CultureInfo.InvariantCulture));
 Console.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                 "{0:0,0.00}", value));
 // Displays 1,234.57

------------------------------------------------------------------------*/
usnig System;
usnig System.IO;
usnig System.Timers;
usnig Kingdom;

namespace Kingdom
{
  class Program
  {
    static void Main(string[] args)
    {
      Episode pro=new Episode();
      pro.running();
    }
  }

  class Episode
  {
    DateTime now;
    ConsoleKey key;
    ConsoleKeyInfo keyinfo;
    Timer timer;
    int xpos,ypos;

    public void elapsed_time_func(object sender, ElapsedEventArgs e)
    {
      ypos++;
      Logging("Time");
    }

    public void running()
    {
      timer=new Timer();
      timer.Interval=1000;
      timer.Elapsed += new ElapsedEventHandler(elapsed_time_func);
      timer.Start();

      Logging("Start");

      while(true)
      {
        key=Console.ReadKey(true).Key;
        //keyinfo=Console.ReadKey(true);

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

        /*if(keyinfo.KeyChar=='+')
        {
          timer.Stop();
          timer.Interval += 10;
          timer.Start();
        }
        else if(keyinfo.Key==ConsoleKey.RightArrow) xpos++*/
        Logging("Key");
      }
      timer.Stop();
      Logging("Stop");
   }

   public void Logging(string msg)
   {
      now=DateTime.Now;
      Console.WriteLine("Debug>>" + "Pos[" + ypos.ToString("0000") + "," + xpos.ToString("0000") + "]   Time:" + now.ToString("yyyy-MM-dd hh:mm:ss") + "    Event:" + msg);
   }
  }
}

원장관리시스템이란 증권사가 고객계좌 관리 및 매매, 거래내역 등을 관리할 수 있는 프로그램. 주시거래에 관한 증권사용 시스템을 의미한다.

증권사 - 원장관리시스템처리, 정보분배시스템처리(수신), 매매지원시스템(거래소연계) - HTS,MTS,WTS

거래소 - 매매지원시스템(채널,매매,매칭), 청산관련시스템, 정보분배시스템(송신)


(1)
1. BackupFileToMemory - 하루동안 쌓여진 데이타를 한번에 메모리에 로딩
2. http://192.168.0.37:8080 확인

(2)
1. 마스터배치실행
2. 실시간 tcp 데이타 송신 & 수신
3. http://192.168.0.37:8080 확인

 


#include <stdio.h>
#include <unistd.h>

int main() 
{
  int i;

  for (i=10;i>=0;i--)
  {
    printf ("Count Down : %02d\r", i);
    fflush(stdout);
    sleep(1);
  }

  return(0);
}

 

#참조(mysql 삭제)
https://velog.io/@michael00987/MYSQL-%EC%84%A4%EC%B9%98-%EC%9E%AC%EC%84%A4%EC%B9%98

 

 

 


#MySQL innoDB 에서 INSERT 하는 속도를 MyISAM 과 유사하게 변경하는 방법은 다음과 같다.

* innodb_flush_log_at_trx_commit 설정값을 확인한다.
mysql> show variables like 'innodb_flush_log_at_trx_commit';
+--------------------------------+-------+
| Variable_name                  | Value |
+--------------------------------+-------+
| innodb_flush_log_at_trx_commit | 1     | 
+--------------------------------+-------+
1 row in set (0.00 sec)

* innodb_flush_log_at_trx_commit 설정값이 1 이면 아래와 같이 실행하여서 0 으로 수정한다.
  - 아래와 같이 설정하면 INSERT 할 때에 로그 파일에 기록하지 않기 때문에 INSERT 속도가 향상된다. 
단, 서버 비정상 종료 또는 정전과 같은 상황에서 INSERT 한 데이터를 잃어버릴 수 있다.

mysql> set global innodb_flush_log_at_trx_commit=0;

innodb_flush_log_at_trx_commit 옵션 설명은 다음과 같다.
이 옵션은 commit 을 하였을 경우 
그 즉시 commit된 데이타를 log file 에 기록할 것인지 아닌지를 설정하는 옵션입니다.  
즉시 로그 파일에 기록할 경우 급작스런 정전 같은 경우 데이타 손실을 막을 수 있지만 매번 로그를 기록해야 하므로 속도가 상당히 저하됩니다. 
0 으로 설정할 경우 매 트랜잭션 마다 데이타를 로그에 기록하지 않으므로 I/O부하를 줄일 수 있으며 여러 트랜잭션을 모아서 한번의 디스크 I/O로 기록하므로 I/O횟수 자체도 줄어듭니다. 



/*
 * namespace(c#) & package(java)
 * java에서 package는 c#에서 namespace와 같은 keyword이다.
 * direct make class에서 direct make class를 호출(public,static 주의)
 */

/* ConsoleKeyInfo 클래스를 사용할경우
   ConsoleKeyInfo keyInfo;

   keyInfo=Console.ReadKey(true);

   if(keyInfo.Key==ConsoleKey.RightArrow) xpos++;
   if(keyInfo.KeyChar=='+') timer.Interval += 10;
   if(keyInfo.KeyChar=='-') timer.Interval -= 10;
*/


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

namespace Kingdom
{
  class Program
  {
    static void Main(string[] args)
    {
      episode pro = new episode();
      pro.running();
    }
  }

  class episode
  {
    DateTime now;
    ConsoleKey key;
    Timer timer;
    int xpos,ypos;

    public void running()
    {

      int toggle=0;

      timer=new Timer();
      timer.Interval=1000; /*1 Second*/
      timer.Elapsed += new ElapsedEventHandler(time_elapsed_func);
      timer.Start();

      xpos=ypos=0;

      WriteLog("Start");
      while(true)
      {
        key=Console.ReadKey(true).Key;
        if(key==ConsoleKey.RightArrow) xpos++;
        else if(key==ConsoleKey.LeftArrow) xpos--;
        else if(key==ConsoleKey.UpArrow) ypos++;
        else if(key==ConsoleKey.DownArrow) ypos--;
        else if(key==ConsoleKey.Escape) break;
        else if(key==ConsoleKey.Enter)
        {
          if(toggle==0)
          {
             timer.Stop();
             toggle=100;
             WriteLog("Time stop");
         }
         else
         {
             timer.Start();
             toggle=0;
             WriteLog("Time restart");
         }
       }
       WriteLog("Key");
      }//end of while
      WriteLog("Stop");
      timer.Stop();
    }

    public void time_elapsed_func(object sender, ElapsedEventArgs e)
    {
        ypos++;
        WriteLog("Time");
    }

    public void WriteLog(string msg)
    {
      now=DateTime.Now;
      Console.Write(now.ToString("yyyy-mm-dd hh:mm:ss") + "  Event:" + msg + "----------------");
      Console.WriteLine("Index;["+ypos+","+xpos + "]");
    }
  }
}//end of namespace;

+ Recent posts