jeeswg's Media Player Classic tutorial

Helpful script writing tricks and HowTo's
User avatar
Posts: 5750
Joined: 19 Dec 2016, 01:58
Location: UK

jeeswg's Media Player Classic tutorial

21 Dec 2017, 13:28


Some Media Player Classic code:

Code: Select all

;- SendMessage sends a message and waits for a reply (the reply is stored in ErrorLevel)
;- PostMessage sends a message and doesn't wait for a reply
;- often it makes for the last call to be a PostMessage, and for any previous calls to be a SendMessage

;play/pause (see 'View, Options..., Player, Keys' for more ID numbers):
SendMessage, 0x111, 887,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;MEDIA_PLAY
SendMessage, 0x111, 888,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;MEDIA_PAUSE
SendMessage, 0x111, 889,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;MEDIA_PLAY_PAUSE (toggle)

;get current file (2 methods)
WinGetTitle, vWinTitle, ahk_class MediaPlayerClassicW
RegRead, vPath, HKEY_CURRENT_USER, Software\MPC-HC\MPC-HC\Recent File List, File1

;list recent files
vOutput := ""
Loop, 20
	RegRead, vPath, HKEY_CURRENT_USER, Software\MPC-HC\MPC-HC\Recent File List, % "File" A_Index
	if !(vPath = "")
		vOutput .= vPath "`r`n"
Clipboard := vOutput
MsgBox, % vOutput

;get/set Media Player Classic volume
SendMessage, 0x400, 0, 0, msctls_trackbar321, ahk_class MediaPlayerClassicW ;TBM_GETPOS := 0x400
vVolumeMPC := ErrorLevel
SendMessage 0x422, 1, % vVolumeMPC, msctls_trackbar321, ahk_class MediaPlayerClassicW ;TBM_SETPOSNOTIFY := 0x422

;get mute status
SendMessage, 0x40A, 909,, ToolbarWindow321, ahk_class MediaPlayerClassicW ;TB_ISBUTTONCHECKED := 0x40A
vIsMute := ErrorLevel

;toggle mute status
PostMessage, 0x111, 909,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Mute (toggle mute)

;view, presets..., minimal/compact/normal
SendMessage, 0x111, 827,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;View Minimal
SendMessage, 0x111, 828,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;View Compact
SendMessage, 0x111, 829,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;View Normal

;get elapsed time/duration (assuming it's set to elapsed time, not remaining time)
ControlGetText, vTime, Static2, ahk_class MediaPlayerClassicW
vPos := InStr(vTime, "/")
vElapsed := SubStr(vTime, 1, vPos-2)
vDuration := SubStr(vTime, vPos+2)

;rotate 90 degrees (bit of fun) (alt+numpad3)
SendMessage, 0x111, 882,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;PnS Rotate Z- (rotate 90 degrees)

;get/set window position, get/set fullscreen (full screen)
WinGetPos, vPosX, vPosY, vPosW, vPosH, ahk_class MediaPlayerClassicW
WinMove, ahk_class MediaPlayerClassicW,, % vPosX, % vPosY, % vPosW, % vPosH
SendMessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Fullscreen
SendMessage, 0x111, 831,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;Fullscreen (w/o res.change)

;skip to point (if seek bar visible)
ControlGet, hCtl, Hwnd,, #327704, ahk_class MediaPlayerClassicW
ControlGetPos, vCtlX, vCtlY, vCtlW, vCtlH,, % "ahk_id " hCtl
vPosY := 5
vRatioX := 5 / 10
vCtlPos := Format("X{} Y{}", Round(vCtlW*vRatioX), vPosY)
ControlClick, % vCtlPos, % "ahk_id " hCtl

;(generic code that can be used on windows generally)
;set Media Player Classic 'on top' on/off
WinSet, AlwaysOnTop, On, ahk_class MediaPlayerClassicW
WinSet, AlwaysOnTop, Off, ahk_class MediaPlayerClassicW

;(generic code that can be used on windows generally)
;get/set minimised/maximised status (minimized/maximized)
WinMinimize, ahk_class MediaPlayerClassicW
WinMaximize, ahk_class MediaPlayerClassicW
WinRestore, ahk_class MediaPlayerClassicW
WinGet, vWinMinMax, MinMax, ahk_class MediaPlayerClassicW ;-1/0/1 min/neither/max

You can use PostMessage/SendMessage with WM_COMMAND to invoke various bits of functionality.

There is a list of items and WM_COMMAND codes here:
'View, Options...',
in the treeview: 'Player, Keys',
all the numbers in the ID column can be used with WM_COMMAND (0x111).

E.g. it says this about 'Play/Pause' (toggle):
'Play/Pause Space 889'
Thus you can use this code to invoke that:

Code: Select all

SendMessage, 0x111, 889,,, ahk_class MediaPlayerClassicW ;WM_COMMAND := 0x111 ;MEDIA_PLAY_PAUSE (toggle)

[download link for Media Player Classic + K-Lite Codec Pack Mega]
Download K-Lite Codec Pack Mega ... k_mega.htm

Media Player Classic API script I wrote, although generally I prefer to avoid using OnMessage:
winapi - media player classic - jump to point in video/audio programmatically - Stack Overflow ... mmatically

Any mpc-hc/_struct users can take a look at this api? - AutoHotkey Community
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests