블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2731)
Unity3D (814)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
03-28 00:02

종료버튼 클릭시 최소화 시키기

 

1. 상태 Flag 변수 선언

2. Form_Closing Event에서 if(flag) else 문 처리

3. WndProc함수 재 정의

 

        private bool isExit = false; //선언

 

         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            // 진짜 종료
            if (isExit == true)
            {

                 //...기타작업

                e.Cancel = false;
            }
            // 숨김
            else
            {

                this.hide();
                e.Cancel = true;
            }
        }

 

위처럼 이벤트 처리하면 우선 X버튼 클릭시 종료가 되지 않고 숨어버리게 되고

특정 버튼 클릭시 isExit 값을 변경해 주면 종료가 되게 된다.

 

하지만, 문제점!

윈도우 종료 시킬때 프로그램이 종료되지 않는다!ㅋㅋㅋ

 

그러면 아래처럼 정의해주면 끝~ㅋㅋㅋ

 

        protected override void WndProc(ref Message m)
        {
            UInt32 WM_QUERYENDSESSION = 0x11;   // Logoff or shutdown

            /*----------------------------------------------------*/
            /* 윈도우 종료시에 종료시켜 버린다.                   */
            /*----------------------------------------------------*/
            if (m.Msg == WM_QUERYENDSESSION)
            {
                isExit = true;
            }


            base.WndProc(ref m);
        }

반응형
Posted by blueasa
, |