-
-
[原创]Windows动态桌面的实现
-
发表于: 2021-4-7 15:10 4171
-
原理:
所谓的动态桌面就是在桌面窗口上插入播放器,播放视频。
子函数之找到顶层的窗口
实际上桌面是一个特殊的窗口,我们需要先找到它的句柄才能对它进行操作。
1 2 3 4 5 6 7 8 | BOOL CALLBACK EnumWindowProcFindDesktopWindow(HWND hTop, LPARAM lparam) { HWND hWndShl = FindWindowExW( hTop, nullptr, L "SHELLDLL_DefView" , nullptr); if (hWndShl = = nullptr) { return true; } s_hWorkerWnd = FindWindowExW(nullptr, hTop, L "WorkerW" , nullptr); return s_hWorkerWnd = = nullptr; } |
主函数
1 2 3 4 5 | HWND hwnd_pro = FindWindow(L "Progman" , NULL); if (hwnd_pro = = NULL) { std::cout << "can not find the progman" ; return 1 ; } DWORD_PTR result = NULL; SendMessageTimeout(hwnd_pro, 0x052c , 0 , 0 , SMTO_NORMAL, 1000 , &result); EnumWindows(EnumWindowProcFindDesktopWindow, NULL); |
调用开源的vlc播放器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | char * path = new char[MAX_PATH]; WideCharToMultiByte(CP_UTF8, 0 , L "C:\\Users\\user\\Desktop\\1.mp4" , - 1 , path, 128 , NULL, 0 ); libvlc_instance_t * inst = libvlc_new( 0 , 0 ); libvlc_media_t * m = libvlc_media_new_path(inst, path); libvlc_media_list_t * ml = libvlc_media_list_new(inst); libvlc_media_player_t * mp = libvlc_media_player_new_from_media(m); libvlc_media_list_player_t * mlp = libvlc_media_list_player_new(inst); libvlc_media_list_add_media(ml, m); libvlc_media_release(m); libvlc_media_list_player_set_media_list(mlp, ml); libvlc_media_list_player_set_media_player(mlp, mp); libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_loop);; libvlc_media_player_set_hwnd(mp, s_hWorkerWnd); libvlc_audio_set_volume(mp, 100 ); libvlc_media_list_player_play(mlp); std::cin.get(); |
这样我们就简单地实现了动态桌面。
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
最后于 2021-4-7 15:14
被wx_放心我很好编辑
,原因:
赞赏
看原图
赞赏
雪币:
留言: