본문 바로가기

프로그래밍/리서치결과

windows api Dialog Z Order 순서알기

참조 : http://hyacinth.byus.net/moniwiki/wiki.php/C%2B%2B/%28Windows%29Z-Order%20%EC%83%81%EC%9C%84%20%EC%9C%88%EB%8F%84%20%EB%B9%84%EA%B5%90


  1. int GetZIndex(HWND hTarget)  
  2. {  
  3.     int index = 0;  
  4.     HWND hNext = ::GetTopWindow(NULL);  
  5.     do  
  6.     {  
  7.         hNext = ::GetNextWindow(hNext, GW_HWNDNEXT);  
  8.   
  9.         if (hNext == hTarget)  
  10.             break;  
  11.   
  12.         ++index;  
  13.     } while (hNext);  
  14.     return index;  
  15. }  
  16.   
  17. // 예  
  18. HWND hWnd1 = ::FindWindow(NULL, L"Daum - 모으다 잇다 흔들다 - Internet Explorer");  
  19. HWND hWnd2 = ::FindWindow(NULL, L"Google - Internet Explorer");  
  20.   
  21. CString str;  
  22. str.Format(_T("Daum %d; Google %d"), GetZIndex(hWnd1), GetZIndex(hWnd2));  
  23. OutputDebugString(str.GetBuffer(0));  

빠른번호일수록 위라고 한다.