Leaderboard
Popular Content
Showing content with the highest reputation on 04/11/2025 in all areas
-
Thanks for help. Modifying accordingly made my code works. Learning is a fascinating thing. Don't be. This is why I created in the collaboration section. It was fun playing with this foundation. I am very happy with the result of this thread. Good work on it. I will update my OP code but refer to your last script as the solution. Next, I will take a look at the capture part of the foundation. If I come up with something I'll post here also. See ya around2 points
-
Microsoft Media Foundation
argumentum and one other reacted to MattyD for a topic
Press space to play/pause in this next example... We also get notified when the pause button becomes available/unavailable, so that mechanism should allow us to create basic transport controls easily enough. Sorry, I've kinda hijacked this thread nine. I'm just playing around a bit now - let me know if you'd like me to focus on anything specific. Next I was going to see if we can get the video to grow/shrink when sizing the window. #AutoIt3Wrapper_UseX64=Y ;test both x86/x64 #include <APIErrorsConstants.au3> #include <StructureConstants.au3> #include <GUIConstants.au3> #include <Array.au3> Opt("MustDeclareVars", True) Local $sTestFile = @ScriptDir & "\relax.mp4" #Region Constants Global Const $S_OK = 0 Global Const $S_FALSE = 1 Global Const $MF_VERSION = 0x00020070 ; 0x00010070 is needed for pre-Win7. Global Enum $MFSTARTUP_FULL, $MFSTARTUP_LITE, $MFSTARTUP_NOSOCKET = $MFSTARTUP_LITE Global Const $MF_RESOLUTION_MEDIASOURCE = 1 Global Enum $MF_OBJECT_MEDIASOURCE, $MF_OBJECT_BYTESTREAM, $MF_OBJECT_INVALID ; MF_TOPOLOGY_TYPE Global Enum $MF_TOPOLOGY_OUTPUT_NODE, _ $MF_TOPOLOGY_SOURCESTREAM_NODE, _ $MF_TOPOLOGY_TRANSFORM_NODE, _ $MF_TOPOLOGY_TEE_NODE, _ $MF_TOPOLOGY_MAX = 0xffffffff ; MFSESSION_SETTOPOLOGY_FLAGS Global Enum $MFSESSION_SETTOPOLOGY_IMMEDIATE = 0x1, _ $MFSESSION_SETTOPOLOGY_NORESOLUTION = 0x2, _ $MFSESSION_SETTOPOLOGY_CLEAR_CURRENT = 0x4 ; _MFCLOCK_STATE Global Enum $MFCLOCK_STATE_INVALID, _ $MFCLOCK_STATE_RUNNING, _ $MFCLOCK_STATE_STOPPED, _ $MFCLOCK_STATE_PAUSED Global Const $MF_EVENT_FLAG_NO_WAIT = 0x00000001 ;VARTYPE Global Enum $VT_EMPTY = 0, _ $VT_NULL = 1, _ $VT_I2 = 2, _ $VT_I4 = 3, _ $VT_R4 = 4, _ $VT_R8 = 5, _ $VT_CY = 6, _ $VT_DATE = 7, _ $VT_BSTR = 8, _ $VT_DISPATCH = 9, _ $VT_ERROR = 10, _ $VT_BOOL = 11, _ $VT_VARIANT = 12, _ $VT_UNKNOWN = 13, _ $VT_DECIMAL = 14, _ $VT_I1 = 16, _ $VT_UI1 = 17, _ $VT_UI2 = 18, _ $VT_UI4 = 19, _ $VT_I8 = 20, _ $VT_UI8 = 21, _ $VT_INT = 22, _ $VT_UINT = 23, _ $VT_VOID = 24, _ $VT_HRESULT = 25, _ $VT_PTR = 26, _ $VT_SAFEARRAY = 27, _ $VT_CARRAY = 28, _ $VT_USERDEFINED = 29, _ $VT_LPSTR = 30, _ $VT_LPWSTR = 31, _ $VT_RECORD = 36, _ $VT_INT_PTR = 37, _ $VT_UINT_PTR = 38, _ $VT_FILETIME = 64, _ $VT_BLOB = 65, _ $VT_STREAM = 66, _ $VT_STORAGE = 67, _ $VT_STREAMED_OBJECT = 68, _ $VT_STORED_OBJECT = 69, _ $VT_BLOB_OBJECT = 70, _ $VT_CF = 71, _ $VT_CLSID = 72, _ $VT_VERSIONED_STREAM = 73, _ $VT_BSTR_BLOB = 0xfff, _ $VT_VECTOR = 0x1000, _ $VT_ARRAY = 0x2000, _ $VT_BYREF = 0x4000, _ $VT_RESERVED = 0x8000, _ $VT_ILLEGAL = 0xffff, _ $VT_ILLEGALMASKED = 0xfff, _ $VT_TYPEMASK = 0xfff ;IMediaEvent Codes Global Enum $MEUnknown = 0, _ $MEError = 1, _ $MEExtendedType = 2, _ $MENonFatalError = 3, _ $MEGenericV1Anchor = $MENonFatalError, _ $MESessionUnknown = 100, _ $MESessionTopologySet = 101, _ $MESessionTopologiesCleared = 102, _ $MESessionStarted = 103, _ $MESessionPaused = 104, _ $MESessionStopped = 105, _ $MESessionClosed = 106, _ $MESessionEnded = 107, _ $MESessionRateChanged = 108, _ $MESessionScrubSampleComplete = 109, _ $MESessionCapabilitiesChanged = 110, _ $MESessionTopologyStatus = 111, _ $MESessionNotifyPresentationTime = 112, _ $MENewPresentation = 113, _ $MELicenseAcquisitionStart = 114, _ $MELicenseAcquisitionCompleted = 115, _ $MEIndividualizationStart = 116, _ $MEIndividualizationCompleted = 117, _ $MEEnablerProgress = 118, _ $MEEnablerCompleted = 119, _ $MEPolicyError = 120, _ $MEPolicyReport = 121, _ $MEBufferingStarted = 122, _ $MEBufferingStopped = 123, _ $MEConnectStart = 124, _ $MEConnectEnd = 125, _ $MEReconnectStart = 126, _ $MEReconnectEnd = 127, _ $MERendererEvent = 128, _ $MESessionStreamSinkFormatChanged = 129, _ $MESessionV1Anchor = $MESessionStreamSinkFormatChanged, _ $MESourceUnknown = 200, _ $MESourceStarted = 201, _ $MEStreamStarted = 202, _ $MESourceSeeked = 203, _ $MEStreamSeeked = 204, _ $MENewStream = 205, _ $MEUpdatedStream = 206, _ $MESourceStopped = 207, _ $MEStreamStopped = 208, _ $MESourcePaused = 209, _ $MEStreamPaused = 210, _ $MEEndOfPresentation = 211, _ $MEEndOfStream = 212, _ $MEMediaSample = 213, _ $MEStreamTick = 214, _ $MEStreamThinMode = 215, _ $MEStreamFormatChanged = 216, _ $MESourceRateChanged = 217, _ $MEEndOfPresentationSegment = 218, _ $MESourceCharacteristicsChanged = 219, _ $MESourceRateChangeRequested = 220, _ $MESourceMetadataChanged = 221, _ $MESequencerSourceTopologyUpdated = 222, _ $MESourceV1Anchor = $MESequencerSourceTopologyUpdated, _ $MESinkUnknown = 300, _ $MEStreamSinkStarted = 301, _ $MEStreamSinkStopped = 302, _ $MEStreamSinkPaused = 303, _ $MEStreamSinkRateChanged = 304, _ $MEStreamSinkRequestSample = 305, _ $MEStreamSinkMarker = 306, _ $MEStreamSinkPrerolled = 307, _ $MEStreamSinkScrubSampleComplete = 308, _ $MEStreamSinkFormatChanged = 309, _ $MEStreamSinkDeviceChanged = 310, _ $MEQualityNotify = 311, _ $MESinkInvalidated = 312, _ $MEAudioSessionNameChanged = 313, _ $MEAudioSessionVolumeChanged = 314, _ $MEAudioSessionDeviceRemoved = 315, _ $MEAudioSessionServerShutdown = 316, _ $MEAudioSessionGroupingParamChanged = 317, _ $MEAudioSessionIconChanged = 318, _ $MEAudioSessionFormatChanged = 319, _ $MEAudioSessionDisconnected = 320, _ $MEAudioSessionExclusiveModeOverride = 321, _ $MESinkV1Anchor = $MEAudioSessionExclusiveModeOverride, _ $METrustUnknown = 400, _ $MEPolicyChanged = 401, _ $MEContentProtectionMessage = 402, _ $MEPolicySet = 403, _ $METrustV1Anchor = $MEPolicySet, _ $MEWMDRMLicenseBackupCompleted = 500, _ $MEWMDRMLicenseBackupProgress = 501, _ $MEWMDRMLicenseRestoreCompleted = 502, _ $MEWMDRMLicenseRestoreProgress = 503, _ $MEWMDRMLicenseAcquisitionCompleted = 506, _ $MEWMDRMIndividualizationCompleted = 508, _ $MEWMDRMIndividualizationProgress = 513, _ $MEWMDRMProximityCompleted = 514, _ $MEWMDRMLicenseStoreCleaned = 515, _ $MEWMDRMRevocationDownloadCompleted = 516, _ $MEWMDRMV1Anchor = $MEWMDRMRevocationDownloadCompleted, _ $MEReservedMax = 10000 Global Const $MFSESSIONCAP_START = 0x00000001 Global Const $MFSESSIONCAP_SEEK = 0x00000002 Global Const $MFSESSIONCAP_PAUSE = 0x00000004 Global Const $MFSESSIONCAP_RATE_FORWARD = 0x00000010 Global Const $MFSESSIONCAP_RATE_REVERSE = 0x00000020 #EndRegion Constants #Region Interface Defs Global Const $sIID_IMFAttributes = "{2cd2d921-c447-44a7-a13c-4adabfc247e3}" Global Const $tag_IMFAttributes = _ "GetItem hresult(struct*; struct*);" & _ "GetItemType hresult(struct*; long*);" & _ "CompareItem hresult(struct*; struct*; bool*);" & _ "Compare hresult(ptr; long; bool*);" & _ "GetUINT32 hresult(struct*; uint*);" & _ "GetUINT64 hresult(struct*; uint64*);" & _ "GetDouble hresult(struct*; double*);" & _ "GetGUID hresult(struct*; struct*);" & _ "GetStringLength hresult(struct*; uint*);" & _ "GetString hresult(struct*; wstr; uint; uint*);" & _ "GetAllocatedString hresult(struct*; wstr*; uint*);" & _ "GetBlobSize hresult(struct*; uint*);" & _ "GetBlob hresult(struct*; struct*; uint; uint*);" & _ "GetAllocatedBlob hresult(struct*; ptr*; uint*);" & _ "GetUnknown hresult(struct*; struct*; ptr*);" & _ "SetItem hresult(struct*; struct*);" & _ "DeleteItem hresult(struct*);" & _ "DeleteAllItems hresult();" & _ "SetUINT32 hresult(struct*; uint);" & _ "SetUINT64 hresult(struct*; uint64);" & _ "SetDouble hresult(struct*; double);" & _ "SetGUID hresult(struct*; struct*);" & _ "SetString hresult(struct*; wstr);" & _ "SetBlob hresult(struct*; struct*; uint);" & _ "SetUnknown hresult(struct*; ptr);" & _ "LockStore hresult();" & _ "UnlockStore hresult();" & _ "GetCount hresult(uint*);" & _ "GetItemByIndex hresult(uint; struct*; struct*);" & _ "CopyAllItems hresult(ptr);" Global Const $tag_IMFClock = _ "GetClockCharacteristics hresult(uint*);" & _ "GetCorrelatedTime hresult(uint; int64*; int64*);" & _ "GetContinuityKey hresult(uint*);" & _ "GetState hresult(uint; long*);" & _ "GetProperties hresult(struct*);" Global Const $sIID_IMFPresentationClock = "{868CE85C-8EA9-4f55-AB82-B009A910A805}" Global Const $tag_IMFPresentationClock = _ $tag_IMFClock & _ "SetTimeSource hresult(ptr);" & _ "GetTimeSource hresult(ptr*);" & _ "GetTime hresult(int64*);" & _ "AddClockStateSink hresult(ptr);" & _ "RemoveClockStateSink hresult(ptr);" & _ "Start hresult(int64);" & _ "Stop hresult();" & _ "Pause hresult();" Global Const $sIID_IMFActivate = "{7FEE9E9A-4A89-47a6-899C-B6A53A70FB67}" Global Const $tag_IMFActivate = $tag_IMFAttributes & _ "ActivateObject hresult(struct*; ptr*);" & _ "ShutdownObject hresult();" & _ "DetachObject hresult();" Global Const $sIID_IMFMediaEvent = "{DF598932-F10C-4E39-BBA2-C308F101DAA3}" Global Const $tag_IMFMediaEvent = $tag_IMFAttributes & _ "GetType hresult(uint*);" & _ "GetExtendedType hresult(struct*);" & _ "GetStatus hresult([*mut HRESULT]);" & _ "GetValue hresult(struct*);" Global Const $sIID_IMFMediaEventGenerator = "{2cd0bd52-bcd5-4b89-b62c-eadc0c031e7d}" Global Const $tag_IMFMediaEventGenerator = _ "GetEvent hresult(long; ptr*);" & _ "BeginGetEvent hresult(ptr; ptr);" & _ "EndGetEvent hresult(ptr; ptr*);" & _ "QueueEvent hresult(uint; struct*; hresult; struct*);" Global Const $sIID_IMFMediaSession = "{90377834-21D0-4dee-8214-BA2E3E6C1127}" Global Const $tag_IMFMediaSession = $tag_IMFMediaEventGenerator & _ "SetTopology hresult(uint; ptr);" & _ "ClearTopologies hresult();" & _ "Start hresult(struct*; struct*);" & _ "Pause hresult();" & _ "Stop hresult();" & _ "Close hresult();" & _ "Shutdown hresult();" & _ "GetClock hresult(ptr*);" & _ "GetSessionCapabilities hresult(uint*);" & _ "GetFullTopology hresult(uint; uint64; ptr*);" Global Const $sIID_IMFMediaSource = "{279a808d-aec7-40c8-9c6b-a6b492c78a66}" Global Const $tag_IMFMediaSource = $tag_IMFMediaEventGenerator & _ "GetCharacteristics hresult(uint*);" & _ "CreatePresentationDescriptor hresult(ptr*);" & _ "Start hresult(ptr; struct*; struct*);" & _ "Stop hresult();" & _ "Pause hresult();" & _ "Shutdown hresult();" Global Const $sIID_IMFSourceResolver = "{FBE5A32D-A497-4b61-BB85-97B1A848A6E3}" Global Const $tag_IMFSourceResolver = _ "CreateObjectFromURL hresult(wstr; uint; ptr; long*; ptr*);" & _ "CreateObjectFromByteStream hresult(ptr; wstr; uint; ptr; long*; ptr*);" & _ "BeginCreateObjectFromURL hresult(wstr; uint; ptr; ptr*; ptr; ptr);" & _ "EndCreateObjectFromURL hresult(ptr; long*; ptr*);" & _ "BeginCreateObjectFromByteStream hresult(ptr; wstr; uint; ptr; ptr*; ptr; ptr);" & _ "EndCreateObjectFromByteStream hresult(ptr; long*; ptr*);" & _ "CancelObjectCreation hresult(ptr);" Global Const $sIID_IMFPresentationDescriptor = "{03cb2711-24d7-4db6-a17f-f3a7a479a536}" Global Const $tag_IMFPresentationDescriptor = $tag_IMFAttributes & _ "GetStreamDescriptorCount hresult(uint*);" & _ "GetStreamDescriptorByIndex hresult(uint; bool*; ptr*);" & _ "SelectStream hresult(uint);" & _ "DeselectStream hresult(uint);" & _ "Clone hresult(ptr*);" Global Const $sIID_IMFTopologyNode = "{83cf873a-f6da-4bc8-823f-bacfd55dc430}" Global Const $tag_IMFTopologyNode = $tag_IMFAttributes & _ "SetObject hresult(ptr);" & _ "GetObject hresult(ptr*);" & _ "GetNodeType hresult(long*);" & _ "GetTopoNodeID hresult(uint64*);" & _ "SetTopoNodeID hresult(uint64);" & _ "GetInputCount hresult(uint*);" & _ "GetOutputCount hresult(uint*);" & _ "ConnectOutput hresult(uint; ptr; uint);" & _ "DisconnectOutput hresult(uint);" & _ "GetInput hresult(uint; ptr*; uint*);" & _ "GetOutput hresult(uint; ptr*; uint*);" & _ "SetOutputPrefType hresult(uint; ptr);" & _ "GetOutputPrefType hresult(uint; ptr*);" & _ "SetInputPrefType hresult(uint; ptr);" & _ "GetInputPrefType hresult(uint; ptr*);" & _ "CloneFrom hresult(ptr);" Global Const $sIID_IMFTopology = "{83cf873a-f6da-4bc8-823f-bacfd55dc433}" Global Const $tag_IMFTopology = $tag_IMFAttributes & _ "GetTopologyID hresult(uint64*);" & _ "AddNode hresult(ptr);" & _ "RemoveNode hresult(ptr);" & _ "GetNodeCount hresult(short*);" & _ "GetNode hresult(short; ptr*);" & _ "Clear hresult();" & _ "CloneFrom hresult(ptr);" & _ "GetNodeByID hresult(uint64; ptr*);" & _ "GetSourceNodeCollection hresult(ptr*);" & _ "GetOutputNodeCollection hresult(ptr*);" Global Const $sIID_IMFStreamDescriptor = "{56c03d9c-9dbb-45f5-ab4b-d80f47c05938}" Global Const $tag_IMFStreamDescriptor = $tag_IMFAttributes & _ "GetStreamIdentifier hresult(uint*);" & _ "GetMediaTypeHandler hresult(ptr*);" Global Const $sIID_IMFMediaTypeHandler = "{e93dcf6c-4b07-4e1e-8123-aa16ed6eadf5}" Global Const $tag_IMFMediaTypeHandler = _ "IsMediaTypeSupported hresult(ptr; ptr*);" & _ "GetMediaTypeCount hresult(uint*);" & _ "GetMediaTypeByIndex hresult(uint; ptr*);" & _ "SetCurrentMediaType hresult(ptr);" & _ "GetCurrentMediaType hresult(ptr*);" & _ "GetMajorType hresult(struct*);" #EndRegion Interface Defs #Region GUIDs Global Const $MF_TOPONODE_ERRORCODE = __COM_CreateGUID("{494bbcee-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_CONNECT_METHOD = __COM_CreateGUID("{494bbcf1-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_LOCKED = __COM_CreateGUID("{494bbcf7-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_WORKQUEUE_ID = __COM_CreateGUID("{494bbcf8-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_WORKQUEUE_MMCSS_CLASS = __COM_CreateGUID("{494bbcf9-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_DECRYPTOR = __COM_CreateGUID("{494bbcfa-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_DISCARDABLE = __COM_CreateGUID("{494bbcfb-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_ERROR_MAJORTYPE = __COM_CreateGUID("{494bbcfd-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_ERROR_SUBTYPE = __COM_CreateGUID("{494bbcfe-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_WORKQUEUE_MMCSS_TASKID = __COM_CreateGUID("{494bbcff-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_MARKIN_HERE = __COM_CreateGUID("{494bbd00-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_MARKOUT_HERE = __COM_CreateGUID("{494bbd01-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_DECODER = __COM_CreateGUID("{494bbd02-b031-4e38-97c4-d5422dd618dc}") Global Const $MF_TOPONODE_MEDIASTART = __COM_CreateGUID("{835c58ea-e075-4bc7-bcba-4de000df9ae6}") Global Const $MF_TOPONODE_MEDIASTOP = __COM_CreateGUID("{835c58eb-e075-4bc7-bcba-4de000df9ae6}") Global Const $MF_TOPONODE_SOURCE = __COM_CreateGUID("{835c58ec-e075-4bc7-bcba-4de000df9ae6}") Global Const $MF_TOPONODE_PRESENTATION_DESCRIPTOR = __COM_CreateGUID("{835c58ed-e075-4bc7-bcba-4de000df9ae6}") Global Const $MF_TOPONODE_STREAM_DESCRIPTOR = __COM_CreateGUID("{835c58ee-e075-4bc7-bcba-4de000df9ae6}") Global Const $MF_TOPONODE_SEQUENCE_ELEMENTID = __COM_CreateGUID("{835c58ef-e075-4bc7-bcba-4de000df9ae6}") Global Const $MF_TOPONODE_TRANSFORM_OBJECTID = __COM_CreateGUID("{88dcc0c9-293e-4e8b-9aeb-0ad64cc016b0}") Global Const $MF_TOPONODE_STREAMID = __COM_CreateGUID("{14932f9b-9087-4bb4-8412-5167145cbe04}") Global Const $MF_TOPONODE_NOSHUTDOWN_ON_REMOVE = __COM_CreateGUID("{14932f9c-9087-4bb4-8412-5167145cbe04}") Global Const $MF_TOPONODE_RATELESS = __COM_CreateGUID("{14932f9d-9087-4bb4-8412-5167145cbe04}") Global Const $MF_TOPONODE_DISABLE_PREROLL = __COM_CreateGUID("{14932f9e-9087-4bb4-8412-5167145cbe04}") Global Const $MF_TOPONODE_PRIMARYOUTPUT = __COM_CreateGUID("{6304ef99-16b2-4ebe-9d67-e4c539b3a259}") Global Const $MFMediaType_Audio = __COM_CreateGUID("{73647561-0000-0010-8000-00aa00389b71}") Global Const $MFMediaType_Binary = __COM_CreateGUID("{72178c25-e45b-11d5-bc2a-00b0d0f3f4ab}") Global Const $MFMediaType_Default = __COM_CreateGUID("{81a412e6-8103-4b06-857f-1862781024ac}") Global Const $MFMediaType_FileTransfer = __COM_CreateGUID("{72178c26-e45b-11d5-bc2a-00b0d0f3f4ab}") Global Const $MFMediaType_HTML = __COM_CreateGUID("{72178c24-e45b-11d5-bc2a-00b0d0f3f4ab}") Global Const $MFMediaType_Image = __COM_CreateGUID("{72178c23-e45b-11d5-bc2a-00b0d0f3f4ab}") Global Const $MFMediaType_MultiplexedFrames = __COM_CreateGUID("{6ea542b0-281f-4231-a464-fe2f5022501c}") Global Const $MFMediaType_Perception = __COM_CreateGUID("{597ff6f9-6ea2-4670-85b4-ea84073fe940}") Global Const $MFMediaType_Protected = __COM_CreateGUID("{7b4b6fe6-9d04-4494-be14-7e0bd076c8e4}") Global Const $MFMediaType_SAMI = __COM_CreateGUID("{e69669a0-3dcd-40cb-9e2e-3708387c0616}") Global Const $MFMediaType_Script = __COM_CreateGUID("{72178c22-e45b-11d5-bc2a-00b0d0f3f4ab}") Global Const $MFMediaType_Stream = __COM_CreateGUID("{e436eb83-524f-11ce-9f53-0020af0ba770}") Global Const $MFMediaType_Subtitle = __COM_CreateGUID("{a6d13581-ed50-4e65-ae08-26065576aacc}") Global Const $MFMediaType_Video = __COM_CreateGUID("{73646976-0000-0010-8000-00aa00389b71}") Global Const $MF_EVENT_DO_THINNING = __COM_CreateGUID("{321ea6fb-dad9-46e4-b31d-d2eae7090e30}") Global Const $MF_EVENT_MFT_CONTEXT = __COM_CreateGUID("{b7cd31f1-899e-4b41-80c9-26a896d32977}") Global Const $MF_EVENT_MFT_INPUT_STREAM_ID = __COM_CreateGUID("{f29c2cca-7ae6-42d2-b284-bf837cc874e2}") Global Const $MF_EVENT_PRESENTATION_TIME_OFFSET = __COM_CreateGUID("{5ad914d1-9b45-4a8d-a2c0-81d1e50bfb07}") Global Const $MF_EVENT_SCRUBSAMPLE_TIME = __COM_CreateGUID("{9ac712b3-dcb8-44d5-8d0c-37455a2782e3}") Global Const $MF_EVENT_SESSIONCAPS = __COM_CreateGUID("{7e5ebcd0-11b8-4abe-afad-10f6599a7f42}") Global Const $MF_EVENT_SESSIONCAPS_DELTA = __COM_CreateGUID("{7e5ebcd1-11b8-4abe-afad-10f6599a7f42}") Global Const $MF_EVENT_SOURCE_ACTUAL_START = __COM_CreateGUID("{a8cc55a9-6b31-419f-845d-ffb351a2434b}") Global Const $MF_EVENT_SOURCE_CHARACTERISTICS = __COM_CreateGUID("{47db8490-8b22-4f52-afda-9ce1b2d3cfa8}") Global Const $MF_EVENT_SOURCE_CHARACTERISTICS_OLD = __COM_CreateGUID("{47db8491-8b22-4f52-afda-9ce1b2d3cfa8}") Global Const $MF_EVENT_SOURCE_FAKE_START = __COM_CreateGUID("{a8cc55a7-6b31-419f-845d-ffb351a2434b}") Global Const $MF_EVENT_SOURCE_PROJECTSTART = __COM_CreateGUID("{a8cc55a8-6b31-419f-845d-ffb351a2434b}") Global Const $MF_EVENT_SOURCE_TOPOLOGY_CANCELED = __COM_CreateGUID("{db62f650-9a5e-4704-acf3-563bc6a73364}") Global Const $MF_EVENT_START_PRESENTATION_TIME = __COM_CreateGUID("{5ad914d0-9b45-4a8d-a2c0-81d1e50bfb07}") Global Const $MF_EVENT_START_PRESENTATION_TIME_AT_OUTPUT = __COM_CreateGUID("{5ad914d2-9b45-4a8d-a2c0-81d1e50bfb07}") Global Const $MF_EVENT_STREAM_METADATA_CONTENT_KEYIDS = __COM_CreateGUID("{5063449d-cc29-4fc6-a75a-d247b35af85c}") Global Const $MF_EVENT_STREAM_METADATA_KEYDATA = __COM_CreateGUID("{cd59a4a1-4a3b-4bbd-8665-72a40fbea776}") Global Const $MF_EVENT_STREAM_METADATA_SYSTEMID = __COM_CreateGUID("{1ea2ef64-ba16-4a36-8719-fe7560ba32ad}") Global Const $MF_EVENT_TOPOLOGY_STATUS = __COM_CreateGUID("{30c5018d-9a53-454b-ad9e-6d5f8fa7c43b}") Global Const $MF_EVENT_OUTPUT_NODE = __COM_CreateGUID("{830f1a8b-c060-46dd-a801-1c95dec9b107}") #EndRegion GUIDs #Region Local $hResult Local $hWnd = GUICreate("Basic Playback", 800, 600, -1, -1, $WS_OVERLAPPEDWINDOW) _MF_Startup() ;Start Session ConsoleWrite(StringFormat("(%d,0) Start Session", @ScriptLineNumber) & @CRLF) Local $pIMFMediaSession = _MF_CreateMediaSession() Local $oIMFMediaSession = ObjCreateInterface($pIMFMediaSession, $sIID_IMFMediaSession, $tag_IMFMediaSession) ConsoleWrite(StringFormat("(%d,0) $oIMFMediaSession = %s\r\n", @ScriptLineNumber, IsObj($oIMFMediaSession)) & @CRLF) ;Create the media source (using source resolver). ConsoleWrite(StringFormat("(%d,0) Load Source", @ScriptLineNumber) & @CRLF) Local $pIMFSourceResolver = _MF_CreateSourceResolver() Local $oIMFSourceResolver = ObjCreateInterface($pIMFSourceResolver, $sIID_IMFSourceResolver, $tag_IMFSourceResolver) Local $iObjType, $pMediaSource ;OUT Params $hResult = $oIMFSourceResolver.CreateObjectFromURL($sTestFile, $MF_RESOLUTION_MEDIASOURCE, 0, $iObjType, $pMediaSource) Local $oIMFMediaSource = ObjCreateInterface($pMediaSource, $sIID_IMFMediaSource, $tag_IMFMediaSource) ;Get the media source's presentation descriptor. Local $pIMFPresentationDescriptor $hResult = $oIMFMediaSource.CreatePresentationDescriptor($pIMFPresentationDescriptor) Local $oIMFPresentationDescriptor = ObjCreateInterface($pIMFPresentationDescriptor, $sIID_IMFPresentationDescriptor, $tag_IMFPresentationDescriptor) ConsoleWrite(StringFormat("(%d,0) $oIMFPresentationDescriptor = %s\r\n", @ScriptLineNumber, IsObj($oIMFPresentationDescriptor)) & @CRLF) ; Create an empty topology. ConsoleWrite(StringFormat("(%d,0) Create playback topology", @ScriptLineNumber) & @CRLF) Local $pIMFTopology = _MF_CreateTopology() Local $oIMFTopology = ObjCreateInterface($pIMFTopology, $sIID_IMFTopology, $tag_IMFTopology) ; Use the presentation descriptor to enumerate the stream descriptors. Local $iCount $hResult = $oIMFPresentationDescriptor.GetStreamDescriptorCount($iCount) ConsoleWrite(StringFormat("(%d,0) Steam Count in media: %d", @ScriptLineNumber, $iCount) & @CRLF) Local $pIMFStreamDescriptor, $oIMFStreamDescriptor, $bSelect Local $pSourceNode, $oSourceNode Local $pOutputNode, $oOutputNode Local $pIMFMediaTypeHandler, $oIMFMediaTypeHandler Local $tGUID = __COM_CreateGUID() Local $pIMFActivate, $oIMFActivate ;For each stream descriptor: For $i = 0 To $iCount - 1 ConsoleWrite(StringFormat("\r\n(%d,0) Stream: %d", @ScriptLineNumber, $i) & @CRLF) $hResult = $oIMFPresentationDescriptor.GetStreamDescriptorByIndex($i, $bSelect, $pIMFStreamDescriptor) $oIMFStreamDescriptor = ObjCreateInterface($pIMFStreamDescriptor, $sIID_IMFStreamDescriptor, $tag_IMFStreamDescriptor) ;~ Get the stream's major media type, such as audio or video. ;~ Check if the stream is currently selected. (Optionally, you can select or deselect a stream, based on the media type.) ;~ If the stream is selected, create an activation object for the media sink, based on the stream's media type. ;~ Add a source node for the stream and an output node for the media sink. ;~ Connect the source node to the output node. If $bSelect Then $hResult = $oIMFStreamDescriptor.GetMediaTypeHandler($pIMFMediaTypeHandler) $oIMFMediaTypeHandler = ObjCreateInterface($pIMFMediaTypeHandler, $sIID_IMFMediaTypeHandler, $tag_IMFMediaTypeHandler) $oIMFMediaTypeHandler.GetMajorType($tGUID) Select Case __COM_CompareGUIDs($tGUID, $MFMediaType_Audio) ConsoleWrite(StringFormat("(%d,0) Stream type Audio", @ScriptLineNumber) & @CRLF) $pIMFActivate = _MF_CreateAudioRendererActivate() Case __COM_CompareGUIDs($tGUID, $MFMediaType_Video) ConsoleWrite(StringFormat("(%d,0) Steam Type Video", @ScriptLineNumber) & @CRLF) $pIMFActivate = _MF_CreateVideoRendererActivate($hWnd) Case Else ConsoleWrite(StringFormat("(%d,0) Steam Type: %s", @ScriptLineNumber, __COM_ReadGUIDAt(DllStructGetPtr($tGUID))) & @CRLF) ContinueLoop EndSelect ; Add a source node for this stream. - If Not $hResult Then ... is just for testing. if any thrown an error it will be written to the console. $pSourceNode = _MF_CreateTopologyNode($MF_TOPOLOGY_SOURCESTREAM_NODE) $oSourceNode = ObjCreateInterface($pSourceNode, $sIID_IMFTopologyNode, $tag_IMFTopologyNode) $hResult = $oSourceNode.SetUnknown($MF_TOPONODE_SOURCE, $pMediaSource) If Not $hResult Then $hResult = $oSourceNode.SetUnknown($MF_TOPONODE_PRESENTATION_DESCRIPTOR, $pIMFPresentationDescriptor) If Not $hResult Then $hResult = $oSourceNode.SetUnknown($MF_TOPONODE_STREAM_DESCRIPTOR, $pIMFStreamDescriptor) If Not $hResult Then $hResult = $oIMFTopology.AddNode($pSourceNode) ConsoleWrite(StringFormat("(%d,0) Add SrcNode for strm %d, hr = 0x%08x", @ScriptLineNumber, $i, $hResult) & @CRLF) ; Create the output node for the renderer. $pOutputNode = _MF_CreateTopologyNode($MF_TOPOLOGY_OUTPUT_NODE) $oOutputNode = ObjCreateInterface($pOutputNode, $sIID_IMFTopologyNode, $tag_IMFTopologyNode) $hResult = $oOutputNode.SetObject($pIMFActivate) If Not $hResult Then $hResult = $oIMFTopology.AddNode($pOutputNode) If Not $hResult Then $hResult = $oOutputNode.SetUINT32($MF_TOPONODE_NOSHUTDOWN_ON_REMOVE, True) ConsoleWrite(StringFormat("(%d,0) Add OutputNode for strm %d, hr = 0x%08x", @ScriptLineNumber, $i, $hResult) & @CRLF) ; Connect the source node to the output node. $hResult = $oSourceNode.ConnectOutput(0, $pOutputNode, 0) ConsoleWrite(StringFormat("(%d,0) Connect Nodes, hr = 0x%08x", @ScriptLineNumber, $hResult) & @CRLF) EndIf Next $hResult = $oIMFMediaSession.SetTopology($MFSESSION_SETTOPOLOGY_IMMEDIATE, $pIMFTopology) ;MF_E_TOPO_MISSING_SOURCE = C00D521A ConsoleWrite(StringFormat("\r\n(%d,0) Set Toplology, hr = 0x%08x\r\n", @ScriptLineNumber, $hResult) & @CRLF) ;~ $oIMFTopology.Release() GUISetState(@SW_SHOW, $hWnd) $tGUID = __COM_CreateGUID() Local $tVtPropEmpty = DllStructCreate("align 2;ushort vt;word Pad[3]") DllStructSetData($tVtPropEmpty, "vt", $VT_EMPTY) $hResult = $oIMFMediaSession.Start($tGUID, $tVtPropEmpty) ConsoleWrite(StringFormat("(%d,0) Start, hr = 0x%08x", @ScriptLineNumber, $hResult) & @CRLF) Local $iSessCaps, $iSessCapsDelta Local $pEvent, $oEvent, $iEvtType Local $hTimer = TimerInit() Local $iTime, $iHour, $iMin, $iSec Local $pClock, $oClock, $iClockState $oIMFMediaSession.GetClock($pClock) $oClock = ObjCreateInterface($pClock, $sIID_IMFPresentationClock, $tag_IMFPresentationClock) Local $idPlayPause = GUICtrlCreateDummy() Local $aAccelKeys[1][2] = [[" ", $idPlayPause]] GUISetAccelerators($aAccelKeys) While True $hResult = $oIMFMediaSession.GetEvent($MF_EVENT_FLAG_NO_WAIT, $pEvent) If $hResult = $S_OK Then $oEvent = ObjCreateInterface($pEvent, $sIID_IMFMediaEvent, $tag_IMFMediaEvent) $oEvent.GetType($iEvtType) Switch $iEvtType Case $MESessionStarted ConsoleWrite(StringFormat("(%d,0) Event Type: %d, %s", @ScriptLineNumber, $iEvtType, "Session Started.") & @CRLF) Case $MESessionPaused ConsoleWrite(StringFormat("(%d,0) Event Type: %d, %s", @ScriptLineNumber, $iEvtType, "Session Paused.") & @CRLF) Case $MESessionCapabilitiesChanged ConsoleWrite(StringFormat("(%d,0) Event Type: %d, %s", @ScriptLineNumber, $iEvtType, "Capabilities Changed.") & @CRLF) $oEvent.GetUINT32($MF_EVENT_SESSIONCAPS, $iSessCaps) $oEvent.GetUINT32($MF_EVENT_SESSIONCAPS_DELTA, $iSessCapsDelta) ConsoleWrite(StringFormat("(%d,0) Caps: %08x CapsDelta: %08x", @ScriptLineNumber, $iSessCaps, $iSessCapsDelta) & @CRLF) If BitAND($iSessCapsDelta, $MFSESSIONCAP_START) Then _ ConsoleWrite(StringFormat("(%d,0) Can Start = %s\r\n", @ScriptLineNumber, _ BitAND($iSessCaps, $MFSESSIONCAP_START) = $MFSESSIONCAP_START)) If BitAND($iSessCapsDelta, $MFSESSIONCAP_SEEK) Then _ ConsoleWrite(StringFormat("(%d,0) Can Seek = %s\r\n", @ScriptLineNumber, _ BitAND($iSessCaps, $MFSESSIONCAP_SEEK) = $MFSESSIONCAP_SEEK)) If BitAND($iSessCapsDelta, $MFSESSIONCAP_PAUSE) Then _ ConsoleWrite(StringFormat("(%d,0) Can Pause = %s\r\n", @ScriptLineNumber, _ BitAND($iSessCaps, $MFSESSIONCAP_PAUSE) = $MFSESSIONCAP_PAUSE)) If BitAND($iSessCapsDelta, $MFSESSIONCAP_RATE_FORWARD) Then _ ConsoleWrite(StringFormat("(%d,0) Can Forward = %s\r\n", @ScriptLineNumber, _ BitAND($iSessCaps, $MFSESSIONCAP_RATE_FORWARD) = $MFSESSIONCAP_RATE_FORWARD)) If BitAND($iSessCapsDelta, $MFSESSIONCAP_RATE_REVERSE) Then _ ConsoleWrite(StringFormat("(%d,0) Can Reverse = %s\r\n", @ScriptLineNumber, _ BitAND($iSessCaps, $MFSESSIONCAP_RATE_REVERSE) = $MFSESSIONCAP_RATE_REVERSE)) Case Else ConsoleWrite(StringFormat("(%d,0) Event Type: %d", @ScriptLineNumber, $iEvtType) & @CRLF) EndSwitch EndIf If TimerDiff($hTimer) >= 1000 Then ; Ticker $oClock.GetState(0, $iClockState) $oClock.GetTime($iTime) ;seconds (100 ns units.) $iSec = Mod(Round($iTime / 10000000), 60) $iMin = Mod(Floor($iTime / 600000000), 60) $iHour = Floor($iTime / 36000000000) If $iClockState = $MFCLOCK_STATE_RUNNING Then ConsoleWrite(StringFormat("> Clock: %d:%02d:%02d", $iHour, $iMin, $iSec) & @CRLF) $hTimer = TimerInit() EndIf Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idPlayPause $oClock.GetState(0, $iClockState) Switch $iClockState Case $MFCLOCK_STATE_PAUSED $oIMFMediaSession.Start($tGUID, $tVtPropEmpty) Case $MFCLOCK_STATE_RUNNING $oIMFMediaSession.Pause() EndSwitch EndSwitch WEnd ConsoleWrite(StringFormat("\r\n(%d,0) Shutdown, hr = 0x%08x", @ScriptLineNumber, $hResult) & @CRLF) $hResult = $oIMFMediaSession.Close() $hResult = $oIMFMediaSource.Shutdown() $hResult = $oIMFMediaSession.Shutdown() _MF_Shutdown() #EndRegion #Region Funcs ;Might replace this func with _WinAPI_GUIDFromString() Func __COM_CreateGUID($sGUID = "{00000000-0000-0000-0000-000000000000}", $pAddress = 0) Local $tGUID = ($pAddress And IsPtr($pAddress)) ? DllStructCreate($tagGUID, $pAddress) : DllStructCreate($tagGUID) Local $aGUID = StringSplit(StringRegExpReplace($sGUID, "[{}]", ""), "-", 2) If UBound($aGUID) <> 5 Then Return SetError($ERROR_INVALID_PARAMETER, 0, False) DllStructSetData($tGUID, 1, Dec($aGUID[0])) DllStructSetData($tGUID, 2, Dec($aGUID[1])) DllStructSetData($tGUID, 3, Dec($aGUID[2])) DllStructSetData($tGUID, 4, Binary("0x" & $aGUID[3] & $aGUID[4])) Return $tGUID EndFunc ;==>__COM_CreateGUID Func __COM_ReadGUIDAt($pGUID) Local $tGUID, $sGUID If (Not $pGUID) Or (Not IsPtr($pGUID)) Then Return SetError($ERROR_INVALID_PARAMETER, 0, "") $tGUID = DllStructCreate($tagGUID, $pGUID) $sGUID = StringFormat("{%s-%s-%s-%s-%s}", _ Hex(DllStructGetData($tGUID, 1), 8), _ Hex(DllStructGetData($tGUID, 2), 4), _ Hex(DllStructGetData($tGUID, 3), 4), _ StringMid(DllStructGetData($tGUID, 4), 3, 4), _ StringMid(DllStructGetData($tGUID, 4), 7, 12)) Return $sGUID EndFunc ;==>__COM_ReadGUIDAt Func __COM_CompareGUIDs($tGUID1, $tGUID2) If DllStructGetSize($tGUID1) < 16 Then Return SetError($ERROR_INVALID_PARAMETER, 0, False) If DllStructGetSize($tGUID2) < 16 Then Return SetError($ERROR_INVALID_PARAMETER, 0, False) Local $tBuff1 = DllStructCreate("byte[16]", DllStructGetPtr($tGUID1)) Local $tBuff2 = DllStructCreate("byte[16]", DllStructGetPtr($tGUID2)) Return DllStructGetData($tBuff1, 1) = DllStructGetData($tBuff2, 1) EndFunc ;==>__COM_CompareGUIDs ;Wrapped funcs generally populate @error with hresult. ;So this ensures we have sensible errors if DllCall() fails.. Func __COM_GetDllError($iError = @error) Switch $iError Case 0 $iError = $ERROR_SUCCESS Case 1 $iError = $ERROR_DLL_INIT_FAILED Case Else $iError = $ERROR_INVALID_PARAMETER EndSwitch Return $iError EndFunc ;==>__COM_GetDllError Func _MF_CreateMediaSession($pConfig = 0) Local $aCall = DllCall("mf.dll", "long", "MFCreateMediaSession", "ptr", $pConfig, "ptr*", 0) If @error Then Return SetError(__COM_GetDllError(), 0, 0) Return SetError($aCall[0], 0, $aCall[2]) EndFunc ;==>_MF_CreateMediaSession Func _MF_CreateTopology() Local $aCall = DllCall("mf.dll", "long", "MFCreateTopology", "ptr*", 0) If @error Then Return SetError(__COM_GetDllError(), 0, 0) Return SetError($aCall[0], 0, $aCall[1]) EndFunc ;==>_MF_CreateTopology Func _MF_CreateTopologyNode($iNodeType) Local $aCall = DllCall("mf.dll", "long", "MFCreateTopologyNode", "long", $iNodeType, "ptr*", 0) If @error Then Return SetError(__COM_GetDllError(), 0, 0) Return SetError($aCall[0], 0, $aCall[2]) EndFunc ;==>_MF_CreateTopologyNode Func _MF_CreateAudioRendererActivate() Local $aCall = DllCall("mf.dll", "long", "MFCreateAudioRendererActivate", "ptr*", 0) If @error Then Return SetError(__COM_GetDllError(), 0, 0) Return SetError($aCall[0], 0, $aCall[1]) EndFunc ;==>_MF_CreateAudioRendererActivate Func _MF_CreateVideoRendererActivate($hVideo) Local $aCall = DllCall("mf.dll", "long", "MFCreateVideoRendererActivate", "hwnd", $hVideo, "ptr*", 0) If @error Then Return SetError(__COM_GetDllError(), 0, 0) Return SetError($aCall[0], 0, $aCall[2]) EndFunc ;==>_MF_CreateVideoRendererActivate Func _MF_Startup($iFlags = $MFSTARTUP_NOSOCKET) Local $aCall = DllCall("mfplat.dll", "long", "MFStartup", "ulong", $MF_VERSION, "dword", $iFlags) If @error Then Return SetError(__COM_GetDllError(), 0, False) Return SetError($aCall[0], 0, $aCall[0] = $S_OK) EndFunc ;==>_MF_Startup Func _MF_Shutdown() Local $aCall = DllCall("mfplat.dll", "long", "MFShutdown") If @error Then Return SetError(__COM_GetDllError(), 0, False) Return SetError($aCall[0], 0, $aCall[0] = $S_OK) EndFunc ;==>_MF_Shutdown Func _MF_CreateSourceResolver() Local $aCall = DllCall("mfplat.dll", "long", "MFCreateSourceResolver", "ptr*", 0) If @error Then Return SetError(__COM_GetDllError(), 0, False) Return SetError($aCall[0], 0, $aCall[1]) EndFunc ;==>_MF_CreateSourceResolver #EndRegion Funcs2 points -
I thought I was done tinkering with the program for the day, but apparently not. I've added an OnTop button and facility. Clicking the main list continues to select a matching title JPG entry on the 'Cover Images - Source' list, if it can find one, but now if Image 'Source' is selected, that image will auto display in the 'Cover Image' preview field. Clicking the black & white 'Author' and 'Title' labels now copies their related input field value to the clipboard. Enable and Disable of controls at startup and loading has been tweaked a bit. See the first post for the latest update.1 point
-
A bit of an update, available via the first post. After a bit of a break, 10 months, I finally played around with the program again, today. I haven't done much, just mainly improved some things to make them clearer. Having not used it for quite a while, I was getting a little lost on figuring out how to use it, so I needed a refresher course, and that has resulted in me adding some helpful tips etc ... to make it all easier next time after any extended break. Anyway, I did actually check if it did what I needed it to ... determine image folder numbers, and create such folders and copy correct image files to them ... and it did the job as expected, which is to say, excellently. So I can now finally claim that it works. I'd put off doing that last, for a few reasons. The biggest one being an incomplete revamp of the program ... which is still the case, but needs must, and I added some helpful information to the program to assist with dealing with some incomplete aspects. It is also the case, that my USB connection to my Kobo device continues to plague me. I have been able to determine, that when my Kobo device isn't fully charged, my USB connection is maintained. But the moment it reaches full charge or is full charge, it keeps losing the connection, though after xx amount of times of auto disconnecting and auto connecting, it finally settles down. Clearly there is some flaw in the hardware and or software. Add to that, the fact the content on my Kobo has continued to grow, and so I had to pick a point where I was ready to update the folder listings etc. I did all that, because I side loaded a big bunch of ebook files yesterday, and I thought it was time, while I was doing that, to check that my fix for missing number folders and cover images, actually worked. I did the first part of that yesterday, but for one reason or another, the second part did not happen until today. Alas, my Kobo device charged up all too soon, and it took me ages to overcome the disconnects to complete cloning the Kobo device on my PC. After that I tested that fix for cover images, and I am very pleased to say that it works as hoped. So my program can now do all the really important things ... create the correct number sub-folders and copy image files to them, converting to the right size image on-the-fly (for three images). I can also replace wrong size image files or black and white with color, but that's something I've been able to do anyway, since the early days of the program's development. As things currently stand, the program is not fully completed, hence no compiled EXE file, but it certainly works well enough to do what is needed. Enjoy! P.S. One new thing I added, was a three state checkbox to the right of the NEXT button. You can now do three things with that button, instead of just one. You can still jump to the next 'marked' row (shown in yellow), when the checkbox is un-selected. But now also you can jump to the next entry with less than three cover image files (when ticked) or jump to the first such entry that hasn't already been marked (when a block ... neither selected or un-selected).1 point
-
Here's my take including auto-hide after 750ms being off the menu 🙂. Maybe someone has a better method to hide the menu again than "WinActivate(_hWnd_under_Mouse(2))"? Couldn't find a message for that task. #NoTrayIcon #include <Array.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> #include <WinAPISysWin.au3> #include <WinAPIGdi.au3> #include <WinAPIShellEx.au3> #pragma compile(AutoItExecuteAllowed, true) Global $hWnd_AutoIt Global $iPID_Parent = @AutoItPID Global Const $WM_NOTIFYICON = $WM_USER + 1 If StringInStr($CmdLineRaw, "Monitor_Tray_Menu") Then If $CmdLine[0] <> 2 Then Exit Sleep(250) $hWnd_AutoIt = HWnd($CmdLine[2]) If Not IsHWnd($hWnd_AutoIt) Then Exit $iPID_Parent = WinGetProcess($hWnd_AutoIt) Local $i_Timer = TimerInit() While Sleep(10) If CheckMouseOverTrayIcon() <> 1 And CheckMouseOverTrayMenu() <> 1 Then If TimerDiff($i_Timer) > 750 Then WinActivate(_hWnd_under_Mouse(2)) ExitLoop EndIf Else $i_Timer = TimerInit() EndIf If Not IsHWnd($hWnd_AutoIt) Then ExitLoop WEnd Exit EndIf $hWnd_AutoIt = WinGetHandle(AutoItWinGetTitle()) Opt("TrayMenuMode", 3) Local $idAbout = TrayCreateItem("About") TrayCreateItem("") Local $idExit = TrayCreateItem("Exit") TraySetState() HotKeySet("{F9}", ShowTrayMenu) While True Switch TrayGetMsg() Case $idExit ExitLoop Case $idAbout MsgBox($MB_SYSTEMMODAL, "About", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) EndSwitch If CheckMouseOverTrayIcon() = 1 And CheckMouseOverTrayMenu() = 0 Then ShowTrayMenu() EndIf WEnd Func ShowTrayMenu() If @Compiled Then Run(@AutoItExe & " Monitor_Tray_Menu " & WinGetHandle(AutoItWinGetTitle()), @ScriptDir, @SW_HIDE) Else Run(@AutoItExe & ' "' & @ScriptFullPath & '" Monitor_Tray_Menu ' & WinGetHandle(AutoItWinGetTitle()), @ScriptDir, @SW_HIDE) EndIf _SendMessage(WinGetHandle(AutoItWinGetTitle()), $WM_NOTIFYICON, 0, $WM_LBUTTONDOWN) EndFunc ;==>ShowTrayMenu Func CheckMouseOverTrayMenu() Local $hWnd = _hWnd_under_Mouse(2) Local $aWinlist = WinList("[CLASS:#32768]") For $i = 1 To $aWinlist[0][0] If $aWinlist[$i][1] = $hWnd And WinGetProcess($hWnd) = $iPID_Parent Then Return 1 EndIf Next Return 0 EndFunc ;==>CheckMouseOverTrayMenu Func CheckMouseOverTrayIcon() Local $hTrayWnd = _WinAPI_GetShellWindow() If $hTrayWnd = 0 Then Return -1 Local $tRECT = _WinAPI_ShellNotifyIconGetRect($hWnd_AutoIt, 1) If @error Then Return -2 Local $aPos = _WinAPI_GetPosFromRect($tRECT) Local $aMousePos = MouseGetPos() If $aMousePos[0] >= $aPos[0] And $aMousePos[0] <= $aPos[0] + $aPos[2] And $aMousePos[1] >= $aPos[1] And $aMousePos[1] <= $aPos[1] + $aPos[3] Then Return 1 EndIf Return 0 EndFunc ;==>CheckMouseOverTrayIcon Func _hWnd_under_Mouse($hWnd_Type = 1) ; $hWnd_Type = 1 > Current Control ; $hWnd_Type = 2 > Parent Window of Current Control Local $tPoint = DllStructCreate("int X;int Y") Local $pMouse = MouseGetPos() DllStructSetData($tPoint, "X", $pMouse[0]) DllStructSetData($tPoint, "Y", $pMouse[1]) Local $hWnd_Current_Control_under_Mouse = _WinAPI_WindowFromPoint($tPoint) If $hWnd_Type = 1 Then Return $hWnd_Current_Control_under_Mouse Else Local $hWnd_Parent_Window_of_Current_Control_under_Mouse = _WinAPI_GetAncestor($hWnd_Current_Control_under_Mouse, $GA_ROOTOWNER) Return $hWnd_Parent_Window_of_Current_Control_under_Mouse EndIf EndFunc ;==>_hWnd_under_Mouse1 point
-
@sydbarrett74 Do you realise your first post is a reply to a 16 years old thread? please try not to resurrect such old threads in the future. 🙂1 point
-
Something like this here: #include <Array.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> #include <WinAPISysWin.au3> #include <WinAPIGdi.au3> #include <WinAPIShellEx.au3> Global Const $WM_NOTIFYICON = $WM_USER + 1 Global Const $sWinTitle = "TrayExample" AutoItWinSetTitle($sWinTitle) Opt("TrayMenuMode", 3) Global $hHWND = WinGetHandle($sWinTitle) Global $hTaskbar = WinGetHandle("[CLASS:Shell_TrayWnd]") Global $hTray Example() Func Example() Local $idAbout = TrayCreateItem("About") TrayCreateItem("") Local $idExit = TrayCreateItem("Exit") HotKeySet("{F9}", ShowTrayMenu) $a = _WinAPI_EnumChildWindows($hTaskbar) $iPos = _ArraySearch($a, "TrayNotifyWnd", 0, 0, 0, 0, 1, 1) If Not @error Then $hTray = $a[$iPos][0] EndIf While True Switch TrayGetMsg() Case $idExit ExitLoop Case $idAbout MsgBox($MB_SYSTEMMODAL, "About", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) EndSwitch If CheckMouseOverTrayIcon() = 1 And WinExists("[CLASS:#32768]") = 0 Then ShowTrayMenu() WEnd EndFunc ;==>Example Func ShowTrayMenu() _SendMessage($hHWND, $WM_NOTIFYICON, 0, $WM_LBUTTONDOWN) EndFunc ;==>ShowTrayMenu Func CheckMouseOverTrayIcon() Local $tNID = DllStructCreate("dword cbSize;hwnd hWnd;uint uID;uint uFlags") Local $hTrayWnd = _WinAPI_GetShellWindow() If $hTrayWnd = 0 Then Return -1 DllStructSetData($tNID, "cbSize", DllStructGetSize($tNID)) DllStructSetData($tNID, "hWnd", $hTray) DllStructSetData($tNID, "uID", 1) Local $tRECT = _WinAPI_ShellNotifyIconGetRect(WinGetHandle(AutoItWinGetTitle()), 1) If @error Then Return -2 Local $aPos = _WinAPI_GetPosFromRect($tRECT) Local $aMousePos = MouseGetPos() If $aMousePos[0] >= $aPos[0] And $aMousePos[0] <= $aPos[0] + $aPos[2] And $aMousePos[1] >= $aPos[1] And $aMousePos[1] <= $aPos[1] + $aPos[3] Then Return 1 EndIf Return 0 EndFunc ;==>CheckMouseOverTrayIcon Will work properly when icon is visible on the taskbar. Tested on Win11 24H2.1 point
-
Another way : #include <Constants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> Global Const $WM_NOTIFYICON = $WM_USER + 1 Global Const $sWinTitle = "TrayExample" AutoItWinSetTitle($sWinTitle) Opt("TrayMenuMode", 3) Example() Func Example() Local $idAbout = TrayCreateItem("About") TrayCreateItem("") Local $idExit = TrayCreateItem("Exit") HotKeySet("{F9}", ShowTrayMenu) While True Switch TrayGetMsg() Case $idExit ExitLoop Case $idAbout MsgBox($MB_SYSTEMMODAL, "About", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) EndSwitch WEnd EndFunc ;==>Example Func ShowTrayMenu() _SendMessage(WinGetHandle($sWinTitle), $WM_NOTIFYICON, 0, $WM_LBUTTONDOWN) EndFunc ;==>ShowTrayMenu1 point
-
1 point
-
Not sure this is helpful to someone other than me ... #include <GUIConstantsEx.au3> #include <GuiIPAddress.au3> #include <WindowsConstants.au3> #include <WinAPISys.au3> Local $hGui = GUICreate("IP Address Control Enable/Disable Example", 400, 300) Local $hIPAddress1 = _GUICtrlIpAddress_Create($hGui, 10, 10) Local $hIPAddress2 = _GUICtrlIpAddress_Create($hGui, 10, 40) Local $hIPAddress3 = _GUICtrlIpAddress_Create($hGui, 10, 70) _GUICtrlIpAddress_Set($hIPAddress1, "192.168.1.10") _GUICtrlIpAddress_Set($hIPAddress2, "255.255.255.0") _GUICtrlIpAddress_Set($hIPAddress3, "192.168.1.1") _GUICtrlIpAddress_Disable($hIPAddress1, 1) _GUICtrlIpAddress_Disable($hIPAddress2, 7) ; 4 + 2 + 1 _GUICtrlIpAddress_Disable($hIPAddress3, 0xf) ; 8 + 4 + 2 + 1 GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlIpAddress_Disable ; Description ...: Disable (grays-out) the specified fields of an IP Address control ; Syntax ........: _GUICtrlIpAddress_Disable($hWnd[, $iFields = 0]) ; Parameters ....: $hWnd - Handle to the control ; $iFields - Fields to enable/disable. Can be a combination of the following : ; 0 : Enable all fields ; 1 : Disable the first field ; 2 : Disable the second field ; 4 : Disable the third field ; 8 : Disable the fourth field ; Return values .: On success1 - 1 ; On failure - 0 and set @error to non zero value ; Author ........: jguinch ; =============================================================================================================================== Func _GUICtrlIpAddress_Disable($hWnd, $iFields = 0) Local $aFields[4], $n = 0, $hEdit If Not IsInt($iFields) Or $iFields < 0 Or $iFields > 15 Then Return SetError(3, 0, 0) Local $hWindow = _WinAPI_GetAncestor($hWnd) If @error Then Return SetError(1, 0, 0) If Not $hWindow Or Not WinExists($hWnd) Then Return SetError(2, 0, 0) Local $aFields = _WinAPI_EnumChildWindows ($hWnd, False) If @error Or $aFields[0][0] <> 4 Then Return SetError(1, 0, 0) If $iFields = 0xf Then Return ControlDisable($hWindow, "", $hWnd) Local $iRet = ControlEnable($hWindow, "", $hWnd) For $i = 0 to 3 $iRet *= ( BitAND($iFields, 2 ^ $i) ? ControlDisable($hWindow, "", $aFields[4 - $i][0]) : ControlEnable($hWindow, "", $aFields[4 - $i][0]) ) Next Return $iRet EndFunc1 point
-
Crash, My personal favourite is this based on some code from Yashied: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Based on code from Yashied #include <GUIConstantsEx.au3> Opt("WinTitleMatchMode", 3) Global Const $WM_COPYDATA = 0x004A Global $sThis_Win_Title, $sThat_Win_Title Global $iY, $hInput, $hButton, $hLabel Global $sMsg_To_Send, $sMsg_Rcvd, $sMsg_Set = "" ; Set GUI title If WinExists("First Instance") Then If WinExists("Second Instance") Then Exit $sThis_Win_Title = "Second Instance" $sThat_Win_Title = "First Instance" $iY = 300 Else $sThis_Win_Title = "First Instance" $sThat_Win_Title = "Second Instance" $iY = 100 EndIf ; Create GUI GUICreate($sThis_Win_Title, 400, 150, 100, $iY) $hInput = GUICtrlCreateInput("", 20, 20, 360, 20) $hButton = GUICtrlCreateButton("Send", 160, 60, 80, 30) $hLabel = GUICtrlCreateLabel("", 20, 100, 360, 20) GUIRegisterMsg($WM_COPYDATA, "_WM_COPYDATA") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Send close message to other window _SendData(WinGetHandle($sThat_Win_Title), "@exit") Exit Case $hButton ; Send message to other window $sMsg_To_Send = GUICtrlRead($hInput) $hWnd = WinGetHandle($sThat_Win_Title) If (Not @error) And ($sMsg_To_Send <> "") Then _SendData($hWnd, $sMsg_To_Send) EndSwitch ; Check messages received If $sMsg_Rcvd = "@exit" Then Exit If $sMsg_Rcvd <> $sMsg_Set Then GUICtrlSetData($hLabel, $sMsg_Rcvd) $sMsg_Set = $sMsg_Rcvd EndIf WEnd Func _SendData($hWnd, $sData) Local $tCOPYDATA, $tMsg $tMsg = DllStructCreate("char[" & StringLen($sData) + 1 & "]") DllStructSetData($tMsg, 1, $sData) $tCOPYDATA = DllStructCreate("dword;dword;ptr") DllStructSetData($tCOPYDATA, 2, StringLen($sData) + 1) DllStructSetData($tCOPYDATA, 3, DllStructGetPtr($tMsg)) $Ret = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hWnd, "int", $WM_COPYDATA, "wparam", 0, "lparam", DllStructGetPtr($tCOPYDATA)) If (@error) Or ($Ret[0] = -1) Then Return 0 Return 1 EndFunc ;==>_SendData Func _WM_COPYDATA($hWnd, $msgID, $wParam, $lParam) Local $tCOPYDATA = DllStructCreate("dword;dword;ptr", $lParam) Local $tMsg = DllStructCreate("char[" & DllStructGetData($tCOPYDATA, 2) & "]", DllStructGetData($tCOPYDATA, 3)) $sMsg_Rcvd = DllStructGetData($tMsg, 1) Return 0 EndFunc ;==>_WM_COPYDATA Just compile it and run it twice. M231 point