⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvdsynth.cpp

📁 DVD工具dvdsynth的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void ChangeToDvdsynthDirectory() {
   char buf[MAX_PATH];
   if (Sprint(buf, MAX_PATH, "%1.", 0, g_dvdsynth_directory) >= 0) {
      SetCurrentDirectory(buf);
   }
}


/*******************************************************************\
\*******************************************************************/


DvsBasePluginFunctions* __cdecl VDevice_DvdsynthBasePluginEntry(DvsBasePluginCallbacks* callbacks);


namespace Main {

   HWND hwnd;
   bool busy = false;

   Vector<DvsBasePluginFunctions*> plugins;

   void* GetTaskbarHWND() {
      return hwnd;
   }

   BOOL WINAPI AboutBoxProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
      static HFONT hfont;
      if (msg == WM_INITDIALOG) {
         static const char* font_names[] = {
            "Times New Roman",
//            "Lucida Sans Unicode",
//            "Arial Black",
         };
         for (int f = 0; f < sizeof(font_names)/sizeof(font_names[0]); ++f) {
            hfont = CreateFont(-20, 0, 0, 0, /*FW_BOLD*/ FW_NORMAL,
             FALSE /*italic*/, FALSE, FALSE, DEFAULT_CHARSET,
             OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
             FF_DONTCARE | DEFAULT_PITCH, font_names[f]);
            if (hfont) {
               SendDlgItemMessage(hwnd, IDC_TITLE, WM_SETFONT, (WPARAM)hfont, FALSE);
               break;
            }
         }
         return TRUE;
      } else if (msg == WM_COMMAND) {
         EndDialog(hwnd, 0);
         return TRUE;
      } else if (msg == WM_DESTROY) {
         if (hfont) {
            DeleteObject(hfont);
            hfont = 0;
         }
         return TRUE;
      }
      return FALSE;
   }

   void AboutBox(void*, int) {
      DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutBoxProc);
   }

   void ExitApp(void*, int) {
      int i;
      for (i=0; i<plugins.size(); ++i) {
         if (plugins[i]->QueryExit() != 0)
            return;
      }
      for (i=0; i<plugins.size(); ++i) {
         plugins[i]->NotifyExit();
      }
      PostQuitMessage(0);
   }

   void HandleTrayMenu() {
      PopupMenu popup;

      for (int p=0; p<plugins.size(); ++p) {
         popup.LockSubmenuLevel();
         plugins[p]->AddMainMenuItems(&popup);
         popup.UnlockSubmenuLevel();
      }

      popup.AddSeparator();

      popup.BeginSubmenu("&Options...", false);
      {
         for (int p=0; p<plugins.size(); ++p) {
            popup.LockSubmenuLevel();
            plugins[p]->AddOptionsMenuItems(&popup);
            popup.UnlockSubmenuLevel();
         }
      }
      popup.EndSubmenu();

      popup.BeginSubmenu("About...", false);
      {
         popup.AddItem("DVDSynth", false, AboutBox, 0, 0);
         popup.AddSeparator();
         for (int p=0; p<plugins.size(); ++p) {
            popup.LockSubmenuLevel();
            plugins[p]->AddAboutMenuItems(&popup);
            popup.UnlockSubmenuLevel();
         }
      }
      popup.EndSubmenu();

      popup.AddItem("E&xit", false, ExitApp, 0, 0);

      POINT pt;
      GetCursorPos(&pt);
      SetForegroundWindow(hwnd);
      int cmd = TrackPopupMenu(popup.GetPopup(), TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL);
      PostMessage(hwnd, WM_NULL, 0, 0);
      popup.InvokeCallback(cmd);
   }

   typedef DvsBasePluginFunctions* __cdecl DBPE_func(DvsBasePluginCallbacks*);

   void AddPlugin(DBPE_func* plugin_entry) {
      static DvsBasePluginCallbacks callbacks = {
         Sprint,
         GetDvdsynthDirectory,
         GetTaskbarHWND
      };

      DvsBasePluginFunctions* plugin_functions = plugin_entry(&callbacks);

      if (plugin_functions) {
         plugins.push_back(plugin_functions);
      }
   }

   void LoadPlugins() {
      // Add internal VDevice plugin
      AddPlugin(VDevice_DvdsynthBasePluginEntry);
      // Add external plugins from DLLs in program directory
      WIN32_FIND_DATA wfd;
      HANDLE h = FindFirstFile("*.dll", &wfd);
      if (h != INVALID_HANDLE_VALUE) {
         do {
            HMODULE hmod = LoadLibrary(wfd.cFileName);
            if (hmod != NULL) {
               DBPE_func* plugin_entry = (DBPE_func*)GetProcAddress(hmod, "DvdsynthBasePluginEntry");
               if (plugin_entry) {
                  AddPlugin(plugin_entry);
               } else {
                  FreeLibrary(hmod);
               }
            }
         } while (FindNextFile(h, &wfd));
         FindClose(h);
      }
   }

   BOOL CALLBACK WndEnumProc(HWND hwnd, LPARAM lparam) {
      if (IsWindowVisible(hwnd)) {
         *(HWND*)lparam = hwnd;
         return FALSE;
      } else {
         return TRUE;
      }
   }

   LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
      if (msg == WM_APP) {
         if (lparam == WM_LBUTTONDOWN || lparam == WM_RBUTTONDOWN) {
            if (!busy) {
               busy = true;
               Main::HandleTrayMenu();
               busy = false;
            } else {
               // try to activate the topmost GUI window
               HWND hwnd = 0;
               EnumThreadWindows(GetCurrentThreadId(), WndEnumProc, (LPARAM)&hwnd);
               if (hwnd) {
                  SetForegroundWindow(hwnd);
               }
            }
         }
         return 0;
      } else {
         return DefWindowProc(hwnd, msg, wparam, lparam);
      }
   }

   int main() {

      static WNDCLASS mywndclass = { 0, WndProc, 0, 0, 0, NULL, NULL, NULL, NULL, "DVDSynth tray window" };
      mywndclass.hInstance = GetModuleHandle(0);
      hwnd = CreateWindow((LPTSTR)RegisterClass(&mywndclass), "", WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL, (HINSTANCE)mywndclass.hInstance, NULL);

      LoadPlugins();

      NOTIFYICONDATA nid;
#ifdef NOTIFYICONDATA_V1_SIZE
      nid.cbSize = NOTIFYICONDATA_V1_SIZE;
#else
      nid.cbSize = sizeof(nid);
#endif
      nid.hWnd = hwnd;
      nid.uID = 0;
      nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
      nid.uCallbackMessage = WM_APP;
      nid.hIcon = (HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_TRAY), IMAGE_ICON, 16, 16, 0);
      lstrcpy(nid.szTip, "DVDSynth 0.1");
      Shell_NotifyIcon(NIM_ADD, &nid);

      MSG msg;
      while (GetMessage(&msg, 0, 0, 0)) {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }

      Shell_NotifyIcon(NIM_DELETE, &nid);

      return msg.wParam;
   }
}


/*******************************************************************\
\*******************************************************************/


template<int n>
class SprintBuf {
   char buf[n];
   SprintBuf(SprintBuf<n>&);
public:
   operator const char*() { return buf; }
   SprintBuf(const char* fmt, const char* types) {
      Sprint(buf, n, fmt, types);
   }
   template<class A>
   SprintBuf(const char* fmt, const char* types, A a) {
      Sprint(buf, n, fmt, types, a);
   }
   template<class A, class B>
   SprintBuf(const char* fmt, const char* types, A a, B b) {
      Sprint(buf, n, fmt, types, a, b);
   }
   template<class A, class B, class C>
   SprintBuf(const char* fmt, const char* types, A a, B b, C c) {
      Sprint(buf, n, fmt, types, a, b, c);
   }
   template<class A, class B, class C, class D>
   SprintBuf(const char* fmt, const char* types, A a, B b, C c, D d) {
      Sprint(buf, n, fmt, types, a, b, c, d);
   }
};


/*******************************************************************\
\*******************************************************************/


int main() {
   ExtractDvdsynthDirectory(__argv[0]);
   ChangeToDvdsynthDirectory();
   InitCommonControls();   // someone's gonna need 'em...
   return Main::main();
}

int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
   return main();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -