📄 player.cpp
字号:
//Player.cpp
#define INC_OLE2
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <commdlg.h>
#include <string.h>
#include <stdlib.h>
#include <direct.h>
#include <digitalv.h>
#include <vfw.h>
#include "player.h"
#include "resource.h"
// Globals
HWND hWndMCI; /* window handle of the movie */
BOOL bIsOpenMovie = FALSE; /* Open flag: TRUE == movie open, FALSE = none */
HMENU hMenuBar = NULL; /* menu bar handle */
char szAppName [] = "Player";
char playfiledir[300];
//char seps[] = "*\t\n";
char seps[] = "*";
#define WM_USER_PLAY 0x00401
const char szFilterVideo4WindowsFormat[] = "%s\0*.avi\0\0";
// function declarations
long FAR PASCAL WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void OpenMCIMovieFile(HWND hWnd);
void OpenMCIMovieFileInit(HWND hWnd);
void UpdateMenubar(HWND hWnd);
void UpdateTitle(HWND hWnd, LPSTR lpstrMovie);
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
/********************************************************************
************************** FUNCTIONS ********************************
********************************************************************/
//InitWindows - initialize stuff
HWND InitWindows(HINSTANCE hInstance, HINSTANCE hPrevInstance, int nCmdShow)
{
HWND hWnd; /* window handle to return */
int iWinHeight;
WORD wVer;
/* first let's make sure we are running on 1.1 */
wVer = HIWORD(VideoForWindowsVersion());
if (wVer < 0x010a){
/* oops, we are too old, blow out of here */
MessageBeep(MB_ICONHAND);
char szBuffer[BUFFER_LENGTH];
::LoadString(NULL, ID_ERROR_VIDEO4WINDOWS_TOO_OLD, szBuffer, sizeof(szBuffer));
MessageBox(NULL, szBuffer,
NULL, MB_OK|MB_ICONSTOP);
return FALSE;
}
if (!hPrevInstance){
WNDCLASS wndclass;
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, "AppIcon");
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass)){
char szBuffer[BUFFER_LENGTH];
::LoadString(NULL, ID_ERROR_REGISTER_CLASS, szBuffer, sizeof(szBuffer));
MessageBox(NULL, szBuffer, szAppName, MB_OK);
return NULL;
}
}
iWinHeight = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYMENU) +
(GetSystemMetrics(SM_CYFRAME) * 2);
/* create the main window for the app */
hWnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW |
WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 180, iWinHeight,
NULL, NULL, hInstance, NULL);
if (hWnd == NULL){
char szBuffer[BUFFER_LENGTH];
::LoadString(NULL, ID_ERROR_CREATE_WINDOW, szBuffer, sizeof(szBuffer));
MessageBox(NULL, szBuffer, szAppName, MB_OK);
return NULL;
}
hMenuBar = GetMenu(hWnd); /* get the menu bar handle */
UpdateMenubar(hWnd); /* update menu bar to disable Movie menu */
/* Show the main window */
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
/* create the movie window using MCIWnd that has no file open initially */
hWndMCI = MCIWndCreate(hWnd, hInstance, WS_CHILD |WS_VISIBLE | MCIWNDF_NOOPEN |
MCIWNDF_NOERRORDLG | MCIWNDF_NOTIFYSIZE | MCIWNDF_SHOWMODE , NULL);
if (!hWndMCI){
/* we didn't get the movie window, destroy the app's window and bail out */
DestroyWindow(hWnd);
return NULL;
}
MCIWndSetInactiveTimer(hWndMCI, 20);
MCIWndSetActiveTimer(hWndMCI, 20);
//MCIWndSetRepeat( hWndMCI, TRUE );
MCIWndSetRepeat( hWndMCI, FALSE );
ShowWindow(hWndMCI, SW_SHOW);
return hWnd;
}
//WinMain - main routine. |
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
MSG msg;
if ((hWnd = InitWindows(hInstance, hPrevInstance,nCmdShow)) == NULL)
return 0; /* died initializing, bail out */
if (strlen(lpszCmdParam)!=0) {
/////////////////////////
/*
token=strtok(lpszCmdParam,seps);
if (token==NULL) {
char szBuffer[BUFFER_LENGTH];
//::LoadString(NULL, "Error in reading parameters. AVI Aborted", szBuffer, sizeof(szBuffer));
//MessageBox(NULL,szBuffer,NULL,MB_OK);
exit(1);
}
strcpy(playfiledir,token);
//playfiledir[strlen(playfiledir)]=0;
PostMessage(hWnd,WM_USER_PLAY,0,0);
*/
strcpy(playfiledir,lpszCmdParam);
PostMessage(hWnd,WM_USER_PLAY,0,0);
}
while (GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//WndProc - window proc for the app
long FAR PASCAL WndProc (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps;
WORD w;
WORD wMenu;
RECT rc;
switch (message){
case WM_USER_PLAY :
OpenMCIMovieFileInit(hWnd);
return 0;
case WM_CREATE:
return 0;
case WM_INITMENUPOPUP:
/* be sure this isn't the system menu */
if (HIWORD(lParam))
return DefWindowProc(hWnd, WM_INITMENUPOPUP,
wParam, lParam);
wMenu = LOWORD(lParam);
switch (wMenu){
case 0: /* file menu */
/* turn on/off CLOSE & PLAY */
if (bIsOpenMovie) w = MF_ENABLED|MF_BYCOMMAND;
else w = MF_GRAYED|MF_BYCOMMAND;
EnableMenuItem((HMENU)wParam, IDM_CLOSE, w);
break;
} /* switch */
break;
case WM_COMMAND:
switch (wParam) {
/* File Menu */
case ID_PLAY:
MCIWndPlay(hWndMCI);
break;
case ID_STOP:
MCIWndStop(hWndMCI);
break;
case IDM_OPEN:
OpenMCIMovieFile(hWnd);
break;
case IDM_CLOSE:
bIsOpenMovie = FALSE;
MCIWndClose(hWndMCI); // close the movie
ShowWindow(hWndMCI, SW_HIDE); //hide the window
UpdateMenubar(hWnd);
UpdateTitle(hWnd, NULL); // title bar back to plain
break;
case IDM_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0L);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -