현상 : MDI 자식폼에서 팝업창을 모달리스로 띄울 경우 불특정 상황에서(파악안됨 --;;)

팝업된 창이 메인 창 뒤로 숨겨져 버림 ㅡ,.ㅜ

 

MDI 인 경우인지 메인폼에 타이머(타이머 없애도 안되더라...)가 있어서 인지는 모르겠으나

API 로 해도 해결이 안되었음

 

결국, 별도스레드로 팝업하게 변경 후 해결

 

아래소스는 CodeProject 에서 검색된것.. 후킹에 관한 좋은 샘플도 되고하니..

일단 펌.. ^^

 

 

 

 

 

 

 

 

 

 

Introduction

In .NET, there are a few functions for working with windows (of other applications). The most part have appeared in .NET 3.0, but they are not enough. So, we have to use the WinAPI functions. I introduce here the CWindow class, which is the wrapper class for the required window API functions.

About

I decided to make CWindow look like the System.Windows.Forms.Form .NET class. So, the description of the majority of the functions/properties is similar to the functions/properties with the same name from the Form class. Sometimes, even the inner construction is the same.

In this article, I wouldn’t describe all the functions/properties, but just those that differ enough from the same of the Form .NET class. The description for others can be obtained from the CWindow code or from MSDN. The code is commented well enough, and most of the descriptions in this article are just short descriptions of the functions in the class code with the explanations. I decided not to throw exceptions in CWindow at all, because mistakes could be very specific, and it is better to catch them in the main code.

The IuSpy program was written first as just an example of using the CWindow class. But then, after getting a working application, I decided to decorate it and make it comfortable for usage. So remember, IuSpy is not the end product. You can see how some CWindow functions/properties work, but don't be sure that it is the best way. For example, in TreeForm and FindWindowForm, I enumerate all windows, but in TreeForm, I did it in a slower fashion. It is just an example. IuSpy is a very simple program. Almost all controls have tooltips. That’s why I wouldn’t describe it in this article. You can see its picture in the top of this page.

CWindow Class

Static Functions/Properties

Properties

  • TopWindow - Gets/sets the window at the top of the window's Z order.
  • StateChangeAnimation - Gets/sets whether windows animation, when minimizing and maximizing, is enabled.
  • ActiveWindow - Gets/sets the currently active window.
  • FocusedWindow - Gets/sets the window that has the keyboard focus.
  • Captured - Gets the window (if any) that has captured the mouse.
  • DesktopWindow - Gets the desktop window.

Functions

  • FromPoint - Retrieves the window at a specified location.
  • FindWindow - Overloaded. Retrieves a window whose class name and window name match the specified values.
  • EnumWindows - Enumerates all top-level windows on the screen. For details, see EnumWindows in MSDN, or the description in the code.
  • EnumThreadWindows - Enumerates all non-child windows associated with the specified thread. For details, see EnumThreadWindows in MSDN, or the description in the code.
  • GetThreadWindows - Retrieves the collection of top-level windows contained within the specified thread.

Object of a Class

The CWindow object is just an IntPtr – a handle to a window.

Implicit Operators

CWindow -> IntPtr; IntPtr -> CWindow; CWindow -> int;

Overloaded Operators

==/!= (CWindow, CWindow), ==/!= (CWindow, IntPtr). So you can use this in such a way:

Collapse Copy Code
IntPtr p;
CWindow w,w2;
w = new CWindow(p);
w = p;
p = w;
w = 0x15864;
if(w == w2)…
if(w != p)…

Window Info

  • TextUnsafe - Gets/sets the text associated with this window. The simple Text property can’t get/set the text of most window types. TextUnsafe sends a message to the specified window, so your application can hang if that window is not responding. Check IsHung before using this property.
  • Exists - Determines whether this object identifies an existing window.
  • Menu - Gets/sets a handle to the menu assigned to the window.
  • ThreadId - Gets the identifier of the thread that created this window.
  • ProcessId - Gets the identifier of the process that created the window.
  • IsUnicodeWindow - Determines whether the specified window is a native Unicode window.
  • IsHung - Determines if Microsoft Windows considers that a specified application is not responding.
  • ClassName - Gets the name of the class to which the specified window belongs to.
  • RealClassName - Gets a string that specifies the window type.

You can get icons with the following properties:

  • Icon
  • SmallIcon
  • ClassIcon
  • SmallClassIcon

Be careful with these properties, check IsHung first. If you want to set your icon, you need to write it to the memory space of the process to which the window belongs to. You can do this with WriteProcessMemory(). But don't forget, that you also need to destroy the old icon. You have to call DestroyIcon() from the space of the window's process. For these operations, you have to inject your Win32 DLL with the help of hooks. I use some of my other classes for this, and I decided not to put them all together.

Styles

  • Styles
  • UpdateStyles()
  • GetStyle()
  • SetStyle()

You can get window styles with the help of GetStyle() and set them with SetStyle(). If you need to get or set styles several times for the same window, you can use the Styles property and an object of the WindowStyle class returned by it. Don’t forget that you not only need to set the styles to a window, but also apply them. You can do this with UpdateStyles(), or specify this in the SetStyle() function.

Extended Styles

  • ExStyles
  • UpdateExStyles()
  • GetExStyle()
  • SetExStyle()

Description is the same as for the simple styles.

State

Properties

  • WindowState - Gets/sets the window's state.
  • WindowVisibleState - Gets/sets the window's visible state. Implemented the same as Form.WindowState. Sometimes it differs from the real window state. For changing the real current state, use WindowState.
  • RestoreToMaximized - Gets/sets a value indicating whether the window is maximized in the restored state.

Functions

  • Minimize - Minimizes the window.
  • Restore - Restores the window from minimized to its previous state.

Window Relations

Properties

  • Children - Gets the collection of windows contained within the window. It contains only the immediate child windows.
  • IsTopWindow - If the current window is a top-level window, checks if it is at the top of the Z order. If the window is a child window, checks if it is at the top of its parent's Z order.
  • ThreadWindows - Gets the collection of the top-level windows contained within the window's thread.
  • TopChild - Gets the child window at the top of the Z order, if this window is a parent window; otherwise, returns null-window.
  • TopLevelWindow - Retrieves the root window by walking the chain of parent windows.

Functions

  • EnumChildWindows - Enumerates the child windows that belong to this window.
  • EnumThreadWindows - Enumerates all non-child windows associated with the current thread.
  • FindChildWindow - Overloaded. Retrieves the window whose class name and window name match the specified values.
  • GetNextWindow - Retrieves a window that has the specified relationship (Z-Order or owner) to this window.
  • InsertAfter - Inserts this window after the specified window in the Z order.

Other

  • Transparent - Gets/sets whether the window is considered to be transparent. Can be used for hit testing or for drawing under-layered windows.
  • ForceActivate() - Activates the window and gives it focus. The Activate() function can’t activate the window in some cases, for example, when a popup window is shown. So you can use the ForceActivate() function, if you want to activate a window in any case.

Namesakes

The description of the following properties/function can be seen in the class code or in MSDN. Remember that their real descriptions may not fully repeat the MSDN description. So, with the MSDN description you can decide whether it is the function that you need, and then see the specification in the class code.

WindowRelations

  • HasChildren
  • Owner
  • Parent
  • TopLevel
  • BringToFront()
  • Contains()
  • GetChildAtPoint()
  • SendToBack()
  • SetTopLevel()

Coordinates

  • Bottom
  • Bounds
  • ClientRectangle
  • ClientSize
  • DesktopBounds
  • DesktopLocation
  • Height
  • Left
  • Location
  • MaximizedBounds
  • MaximumSize
  • MinimumSize
  • RestoreBounds
  • Right
  • Size
  • Top
  • Width
  • PointToClient()
  • PointToScreen()
  • RectangleToClient()
  • RectangleToScreen()

Visibility

  • AllowTransparency
  • Opacity
  • Region
  • TransparencyKey
  • Visible
  • Hide()
  • Invalidate()
  • Refresh()
  • Show()
  • Update()

Window Info

  • Handle
  • Text
  • Enabled
  • Modal
  • CanFocus
  • Focused
  • ContainsFocus
  • Capture
  • ShowInTaskbar

Others

  • Activate()
  • Close()
  • CreateGraphics()
  • Focus()

Additional Classes

CWindowWorker, CWindowsWorker

These classes were not made big. They contain only basic features, with the help of which you can try to implement everything that you need.

CWindowWorker

You can use the CWindowWorker class if you want to change several properties of a window in a single screen-refreshing cycle. The constructor is simple. Just put there the CWindow object or a handle to a window. With this class, you can change the Location, Size, and Visible state of the window, set styles and extended styles, and also set the window order.

You can set the window styles with SetStyle() or SetExStyle() , but they will be applied to a window when you call the Reposition() function.

The overloaded SetOrder() changes the window’s placement in the Z-order. But, remember that you can use this function only once for the current reposition. This is the only function in the Iu.Windows namespace where I throw an exception if this function is called more than once for the current object, because that is an obvious developer mistake.

Call RePosition() at the end to apply everything that you have specified.

CWindowsWorker

Use this class when you want to change properties of several windows in a single screen-refreshing cycle. This class has only the indexer and the Reposition() function.

You can specify a CWindow object or a handle in the indexer, and you will get an object of the CWindowWorker class for a specified window. You can specify everything that you want in the returned object, but don’t call Reposition().

At the end, after changing all the windows, call the Reposition() function of the CWindowsWorker class to apply all the changes.

WindowStyle, WindowExStyle

The Styles and ExStyles properties of the CWindow class returns objects of the aforesaid classes. They were written to check/set the specified styles. They are useful when you need to check/set styles several times for the same window. Both of these classes have the Check() and Set() functions and a lot of implicit operators.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Maxim Berezov


Member

Location: Ukraine Ukraine

Other popular Dialogs and Windows articles:

트랙백 주소 :: http://blog.kkomzi.net/184/trackback/
옵션
댓글 달기

설치 경로 및 참조 정보 url

http://geekswithblogs.net/SoftwareDoneRight/archive/2007/12/12/coolcommands-in-visual-studio-2008.aspx

http://weblogs.asp.net/GMilano/archive/2006/02/27/439208.aspx

http://www.deklarit.com

 

CoolCommands 3.0 인스톨 버전은 Visual Studio 2005 를 위한 것이었음...

 

2008 이 나온 지금 솔루션탐색기에서 해당 소스파일 폴더를 열 수 있는 기능은 추가가 되서 불필요 하겠지만,

 

다른 기능을 사용하겠다면 msi 파일로 설치할게 아니라

 

아래 표의 커맨드라인 명령은 Path 를 고려해서 수정해줘야함

 

 

[Visual Studio 2005]

 

-- Install

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe" CoolCommands.dll /codebase
regpkg CoolCommands.dll /codebase
"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe" /setup

 

-- UnInstall

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe" /u CoolCommands.dll
regpkg /unregister CoolCommands.dll
"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe" /setup

 

[Visual Studio 2008]

 

-- Install

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe" CoolCommands.dll /codebase
regpkg CoolCommands.dll /root:Software\Microsoft\VisualStudio\9.0 /codebase
"C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe" /setup

 

-- UnInstall

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe" /u CoolCommands.dll
regpkg /unregister CoolCommands.dll
"C:\Program Files\Microsoft Visual Studio 9\Common7\IDE\devenv.exe" /setup

 

 

2008 에 설치할 때 regasm 경로를 다른 버전으로 바꿔야 할까??
실제 바뀐 부분이 있는지 여부는 다시 확인해 봐야 할듯함

 

트랙백 주소 :: http://blog.kkomzi.net/181/trackback/
옵션
댓글 달기

 

흠~ 오프라인 매장에서 받아서 긁어보니.. 헉 3등 이네....

 

제세공과금은 96800 원이고 2명이서 사용할 수 있는거군... 흠...

 

왜 하필 백수일 때 이런게 ㅡ,.ㅠ

 

로또나 3등 걸리지 ㅋㅋㅋㅋㅋㅋ

 

  1. kirox 2009/09/16 17:17 답글수정삭제

    오...축하축하..
    나랑가자..
    월차도 많이 남았는데..함쓰지머..ㅋㅋ

트랙백 주소 :: http://blog.kkomzi.net/180/trackback/
옵션
댓글 달기

성능옵션에 대한 설명... 이해하기 쉽게 잘 설명되어 있다는... 구뜨 !!

 

출처 : http://blogs.technet.com/sankim/archive/2009/06/10/windows-vs.aspx

 

> 고급 > 프로세서 사용 계획'에 '프로그램'과 '백그라운드 서비스' 옵션 두 가지 하나를 사용자가 선택할 수 있습니다. 이 두 개의 옵션에 대해서 여러 의견(?)들이 난무하는데요, 이번 포스팅에서는 이 두 가지 옵션이 어떤 의미를 가지는지 그리고 여러분은 어떤 상황에서 두 옵션 중 하나를 선택할 것인지를 설명 드릴까 합니다.

   

[그림 1. Windows 7, 프로세서 사용 계획]

잘못된 오해

많은 분들께서 이 옵션에 대해서 아래와 같이 잘못 이해하고 계십니다.

{'프로그램'은 실제 사용자가 실행하는 응용 프로그램이고 '백그라운드 서비스'는 '서비스 관리자(services.msc)'에서 실행되는 서비스를 의미한다. 그래서 프로세서 사용계획의 설정에 의해 '프로그램'을 선택하면 사용자 프로그램에 더 많은 CPU 사용량을 할당하고 '백그라운드 서비스'를 선택하면 서비스(Service)에 더 많은 CPU 사용량을 할당한다} => NO, NO, NO 이렇게 이해하고 계시면 됩니다.

진실을 말씀 드리겠습니다.

(이 옵션을 이해하기 위해서는 먼저 스레드와 컨텍스트 스위치 두가지 개념을 이해하셔야 합니다 그래서 이 단어의 정의를 설명드리면서 옵션을 이해하도록 하겠습니다)

우리가 사용하는 프로그램이란 것은 알고 보면 실행 파일이 프로세스(Process)로 만들어 진 스레드(Thread)에서 명령이 실행되는 것 입니다, 여기서 스레드란 명령어가 CPU를 사용하여 실행되는 단위로 정의 할 수 있습니다. (그밖에 많은 복잡한 이야기들이 있지만 여기서는 이정도 까지만 이해하시면 되겠습니다)

우리가 컴퓨터를 사용할 때 우리는 모르지만 네트워크 처리, HDD 처리, 커널에서의 작업, 응용프로그램 처리 등등 너무나도 많은 작업들이 동시 다발적으로 이뤄지고 있습니다. 다른 예로, 사용자가 인터넷에서 파일을 다운로드 하면서 Word와 WMP를 함께 사용하는 경우도 생각해 볼 수 있습니다. 이러한 것들은 모두 스레드 단위로 작업이 이뤄지며 작업에 따라 스레드 처리 시간이 길수도 짧을 수도 있습니다.

일상 생활에서도 금방 끝나는 일이 있고 오래 걸리는 일들이 있듯이 스레드도 처리 하는데 시간이 긴 작업과 짧은 작업들이 섞여 있는데 만약 그림처럼 CPU에서 하나의 스레드가 끝날 때까지 다른 스레드들은 기다려야 한다면 스레드 A가 끝날 때 까지는 스레드 B, C는 기다리고만 있어야 할 것 입니다.

[그림 2]

위 그림 2처럼 하나의 스레드가 자신의 명령이 끝날 때가지 계속 CPU 독점해서 사용한다고 하면 오랜 시간 동안 다른 스레드들(프로그램)이 실행되지 못할 것입니다, 그렇게 되면 다른 프로그램의 성능에 영향을 주겠죠? 특히 스레드 B의 입장에서는 잠시 CPU를 사용하면 금방 끝날 일인데 앞에서 스레드 A의 작업이 끝나기를 기다려야 하니 답답한 노릇일 것입니다.

그래서 좀더 효율적으로 동시 작업이 가능 하도록 하나의 스레드가 시작해서 끝날 때까지 무작정 CPU를 사용하는 것이 아니고 그림 3. 처럼 스레드의 실행 시간을 짧은 시간 단위 로 잘라낸 뒤 순서대로 세워 놓고 실행하다 자신에게 할당된 시간이 끝나면 하던 일을 멈추고 다음 스레드에게 CPU를 사용할 수 있도록 한 다시 자기 차례가 돌아오면 자신의 일을 다시 합니다. 스레드가 CPU를 얼마 동안 사용할지를 정의한 시간 단위를 바로 퀀텀(Quantum)이라고 합니다. 그러면 그림에서처럼 스레드 B는 다음 순번에서 바로 작업을 끝낼 수 있습니다. (그림 3의 'A B C A B C A C A C A A A' 순서를 보시면 이해가 좀 쉬우실 것입니다)

[그림 3]

이 퀀텀을 사용자가 길게도 혹은 짧게도 설정 할 수 있는데 이것이 바로 '프로세스 사용 계획 옵션'입니다. 그래서 '프로그램'으로 설정하면 모든 스레드의 퀀텀을 짧게(6, 대략 2 Click) 설정하고 반대로 '백그라운드 서비스'로 설정하면 길게(36, 대략 12 Click) 설정 합니다.

그렇다면 퀀텀(스레드 실행 시간)을 짧게 혹은 길게 설정 하는 것은 어떤 차이가 있을까요?

차이와 그에 따른 장단 점을 이해 하시려면 Context Switch라는 의미를 이해 해야 합니다.

[그림 4, Context Switch]

그림 4.와 같이 퀀텀에 정의된 시간이 끝나 CPU를 떠나야 하는 스레드 A는 CPU를 떠나기 전에 자신이 어디까지 작업을 했는지를 저장합니다, 그래야 다음 차례에 다시 A가 실행될 때 앞에서 마지막으로 진행했던 부분부터 다시 시작 할 수 있기 때문입니다, 또한 B는 자신이 앞에서 실행 했던 부분부터 다시 시작 하기 위해 앞에서 저장했던 실행정보를 불러옵니다, 바로 이런 일련의 작업을 컨텍스트 스위치(Context Switch)라고 합니다.

이 Context Switch 자체는 미약(?)하기는 하지만 전체적으로 보면 성능에 영향을 줄 수 있는 작업입니다. 그래서 만약 다른 작업은 거의 없고 CPU에서 스레드를 처리하는데 긴 시간이 필요한 단일 응용프로그램(SQL Server 혹은 그래픽 랜더링 작업 같은)만 실행하는 환경이라면 '백그라운드 서비스'로 설정해 Context Swith를 최소화하고 해당 프로그램의 스레드가 긴 시간 CPU를 사용 할 있도록 하는 것이 효과적일 것입니다.

반대로 일반 사용자의 컴퓨터 사용 패턴은 아주 소소한 아이콘 클릭 같은 작업을 포함해 IE같은 웹 브라우저 사용과 함께 음악을 듣는 것과 같이 동시에 여러 프로그램을 실행하는 패턴을 보입니다. 이런 경우 스레드에 긴 시간을 주면 스레드가 끝나기를 기다리는 시간이 오래 걸리기 때문에 다른 작업으로 넘어가는데 시간이 걸려 반응속도를 늦출 수 있지만, 일정한 시간 내에 여러 스레드들이 실행 될 수 있도록 퀀텀을 작게 설정하면 사용자 측면에서 반응속도를 높일 수 있습니다..

두 옵션은 아래와 같이 정의 할 수 있습니다

프로그램: 여러 작업을 동시에 수행하는 일반 사용자 환경에서 쾌적한(?) 반응 속도를 보여준다.

백그라운드 서비스: 계속해서 한가지 작업을 실행하는 응용프로그램을 실행 하는 경우 높은 처리 효율을 가진다.

* 이 두 옵션을 그 반대의 환경에 설정하였다면 반드시 나쁘다고는 말할 수 없겠지만 성능 효율면에서는 떨어질 것입니다.

그래서 기본적으로 Windows 2000 Professional, XP, Vista그리고 Windows 7과 같이 일반 사용자를 위한 Windows 클라이언트에서는  '프로그램'으로 설정 되어 있으며 Windows Server 2000, 2003, 2008에서는 '백그라운드 서비스'로 설정 되어 있습니다. 만약 윈도우 클라이언트지만 그래픽 랜더링 작업 같이 CPU를 많이 사용하는 하나의 작업을 주로 사용하는 환경이라면 '백그라운드 서비스'를 선택 할 수 있을 것이고 반대로 윈도우 서버지만 클라이언트 환경같이 사용한다면 '프로그램' 옵션을 선택하면 성능에 효과적일 것입니다.

조금 자세한 추가 설명

'프로그램'으로 설정 되어 있으면 스레드는 2 Clock interval 기간 동안 실행이 가능하며 '백그라운드 서비스'는 12 Clock interval 기간 동안 실행할 수 있습니다.

퀀텀에서는 Clock interval의 3배수로 설정됩니다, 그래서 '프로그램'으로 설정 되어 있으면 Short 값인 6('실제 Clock 2개' x 3배수)을 가지고, '백그라운드 서비스'로 설정 되어 있으면 퀀텀 Long 값인 36('실제 Clock 12개' x 3배수)을 가집니다. 그래서 클럭인터럽트가 걸릴 때마다 퀀텀 값을 3단위로 줄여가 결국 0이 되면 일단 그 스레드가 이번에 실행될 시간은 모두 끝내고 기다리고 있던 다음 스레드가 실행 되도록 합니다.

이해를 돕고자 상당 부분 단순화 썼습니다. 좀더 자세한 정보가 필요하신 분들께서는 아래  Windows Internals의 Thread 부분을 참고 하시기 바랍니다.

[참고문서]

Windows Internals 4'th, Chapter 6, Controlling the Quantum

  1. 강민철 2009/10/21 09:40 답글수정삭제

    좋은내용이네요 ^^ 잘 읽었습니다. 퀀텀.. 클럭.. 쓰레드..

트랙백 주소 :: http://blog.kkomzi.net/179/trackback/
옵션
댓글 달기

출처 : http://www.omypc.co.kr/shopuser/etc/bbsList.html?bbs=data

http://www.ripple.co.kr/mini/support/mininotice_view.asp?code=mininotice&codes=mininotice&num=&no=2025&page=1&keyfield=&keyword=

 

툴 : UFDisk Utility

 

 

 

 

 

트랙백 주소 :: http://blog.kkomzi.net/178/trackback/
옵션
댓글 달기
이전 1 2 3 4 5 ... 31 다음