'자석효과'에 해당되는 글 1건

  1. 2012.10.05 윈도우 자석효과

윈도우 자석효과

MFC 2012. 10. 5. 19:06

int m_nYOffset, m_nXOffset;

 

//자석효과 세팅(pixel)

m_nYOffset = 20;

m_nXOffset = 20;

 

void CMyDlg::OnWindowPosChanging(WINDOWPOS* lpwndpos)

{

//CDialog::OnWindowPosChanging(lpwndpos);

 

CRectwndRect, trayRect;

intleftTaskbar = 0, rightTaskbar = 0, topTaskbar = 0, bottomTaskbar = 0;

 

GetWindowRect(&wndRect);


// Screen resolution

int screenWidth =GetSystemMetrics(SM_CXSCREEN); 

int screenHeight =GetSystemMetrics(SM_CYSCREEN);

 

// Find the taskbar

CWnd* pWnd = FindWindow(_T("Shell_TrayWnd"), _T(""));

pWnd->GetWindowRect(&trayRect);

int wndWidth = wndRect.right - wndRect.left;

int wndHeight = wndRect.bottom - wndRect.top;


if(trayRect.top <= 0 && trayRect.left <= 0 && trayRect.right >= screenWidth) {

// top taskbar

topTaskbar = trayRect.bottom - trayRect.top;

}

else if(trayRect.top > 0 && trayRect.left <= 0) {

// bottom taskbar

bottomTaskbar = trayRect.bottom - trayRect.top;

}

else if(trayRect.top <= 0 && trayRect.left > 0) {

// right taskbar

rightTaskbar = trayRect.right - trayRect.left;

}

else {

// left taskbar

leftTaskbar = trayRect.right - trayRect.left;

}

 

// Snap to screen border

// Left border

if(lpwndpos->x >= -m_nXOffset + leftTaskbar && lpwndpos->x <= leftTaskbar + m_nXOffset) {

lpwndpos->x = leftTaskbar;

}


// Top border

if(lpwndpos->y >= -m_nYOffset && lpwndpos->y <= topTaskbar + m_nYOffset) {

lpwndpos->y = topTaskbar;

}

 

// Right border

if(lpwndpos->x + wndWidth <= screenWidth - rightTaskbar + m_nXOffset && lpwndpos->x + wndWidth >= screenWidth - rightTaskbar - m_nXOffset) {

lpwndpos->x = screenWidth - rightTaskbar - wndWidth;

}

 

// Bottom border

if( lpwndpos->y + wndHeight <= screenHeight - bottomTaskbar + m_nYOffset && lpwndpos->y + wndHeight >= screenHeight - bottomTaskbar - m_nYOffset) {

lpwndpos->y = screenHeight - bottomTaskbar - wndHeight;

}

}

'MFC' 카테고리의 다른 글

트레이아이콘 잔상 없애기  (0) 2012.10.05
윈도우 자르기  (0) 2012.10.05
실행중인 프로세스ID로 HWND구하기  (0) 2012.10.05
뮤텍스로 중복실행 방지  (0) 2012.10.05
문자열 파싱  (0) 2012.10.05
Posted by 떡공이
,