Knowledge Base Nr: 00295 wmpslider.cpp - http://www.swe-kaiser.de

Downloads:

win32: Windows Media Player Sliderposition setzen und auslesen

  
int CMySocketServer::DoWMPPos(int nNewPosX) //ACHTUNG funzt nur für Windows Media Player!!!!
{
#ifdef _DEBUG //mediaplayer 10
HWND hwnd = ::FindWindow(NULL, "Windows Media Player");
#else //mediaplayer 9
HWND hwnd = ::FindWindow("WMP Skin Host", "Windows Media Player");
#endif
TRACE("FindWindow = 0x%p\n", hwnd);
if (!hwnd)
{
ASSERT(FALSE);
return -1;
}

//falls noch nicht geschehen und kein anderes fenster (z.b. debugger):
HWND hwndOrg = ::GetForegroundWindow();

BOOL bSucc = ::SetForegroundWindow(hwnd);
TRACE("SetForegroundWindow = %d\n", bSucc);

RECT rect;
bSucc = ::GetWindowRect(hwnd, &rect);
if (!bSucc)
{
ASSERT(FALSE);
return -5;
}

//slider-offsets für beliebige fensterdarstellung mit spy++ ermittelt!
#ifdef _DEBUG //mediaplayer 10
int nStartPosX = rect.left + 41;
int nMaxPosX = rect.right - 51;
int nStartPosY = rect.bottom - 60;
int nMaxPosY = rect.bottom - 50;
#else //mediaplayer 9
int nStartPosX = rect.left + 304;
int nMaxPosX = rect.right - 305;
int nStartPosY = rect.bottom - 180;
int nMaxPosY = rect.bottom - 174;
#endif

int nWidthX = nMaxPosX-nStartPosX;
int nPosY = nStartPosY + ((nMaxPosY-nStartPosY)/2);

int nNewWidth = ((0.0+nWidthX)/100.0) * nNewPosX;
int nPosX = nStartPosX + nNewWidth;
if (nPosX >= nMaxPosX)
nPosX = nMaxPosX-1;

POINT ptOrg;
::GetCursorPos(&ptOrg);

TRACE("SetCursorPos(%d, %d", nPosX, nPosY);
::SetCursorPos(nPosX, nPosY);

mouse_event(MOUSEEVENTF_LEFTDOWN, // motion and click options
0, // horizontal position or change
0, // vertical position or change
0, // wheel movement
NULL // application-defined information
);

Sleep(100);

mouse_event(MOUSEEVENTF_LEFTUP, // motion and click options
0, // horizontal position or change
0, // vertical position or change
0, // wheel movement
NULL // application-defined information
);
Sleep(100);

//alten zustand wiederherstellen
::SetForegroundWindow(hwndOrg);
::SetCursorPos(ptOrg.x, ptOrg.y);

///////////
HWND hWndDesktop = HWND_DESKTOP;
HDC hdc = ::GetDC(hWndDesktop);

CImageSupport img;

int nErr = img.Screenshot(hdc, nStartPosX, nStartPosY, nMaxPosX-nStartPosX, nMaxPosY-nStartPosY);
if (nErr)
{
ASSERT(FALSE);
::ReleaseDC(hwnd, hdc);
return -6;
}

nErr = img.SavePNG("e:\\projects\\internet\\my_home\\kaiserreich\\images\\k_images\\dvdpos.png");
if (nErr)
{
ASSERT(FALSE);
::ReleaseDC(hwnd, hdc);
return -7;
}

::ReleaseDC(hwnd, hdc);
///////////

return 0;
}