| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1722 人关注过本帖
标题:[讨论]一个多屏播放器
只看楼主 加入收藏
radcat
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:306
专家分:45
注 册:2006-9-12
收藏
 问题点数:0 回复次数:3 
[讨论]一个多屏播放器
RQ8k138n.rar (44.05 KB) [讨论]一个多屏播放器



一个用单线程实现的多窗口播放器(如上附件).

希望用多线程实现

void Thread (PVOID pvoid)
{
static HWND hmedia;
hmedia=MCIWndCreate(hwnd,hInst,MCIWNDF_NOMENU,TEXT("CLOCK.AVI"));
MoveWindow(hmedia,240,20,200,200,true);
MCIWndPlay(hmedia);
_endthread();
}

但以上代码在线程结束后,主窗口中的MCI窗口也随之消失,讨论如何用多线程实现.
搜索更多相关主题的帖子: 播放器 hmedia 线程 窗口 MCI 
2006-09-25 11:43
radcat
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:306
专家分:45
注 册:2006-9-12
收藏
得分:0 
快沉了,自已顶一下

2006-09-26 11:34
del000
Rank: 1
等 级:新手上路
威 望:1
帖 子:79
专家分:0
注 册:2006-9-8
收藏
得分:0 
大哥,请付上原代码吧,可以吗?
2006-09-30 11:33
radcat
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:306
专家分:45
注 册:2006-9-12
收藏
得分:0 

#include "stdafx.h"
#include "resource.h"
#include "vfw.h"
#define MAX_LOADSTRING 100
#include <commdlg.h>

typedef struct
{
HWND hwnd ;
int cxClient ;
int cyClient ;
int cyChar ;
BOOL bKill ;
}
PARAMS, *PPARAMS ;

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
static HWND hmedia1,hmedia2,hmedia3,hmedia4,hmedia5;

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MY922B, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY922B);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY922B);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(CreateSolidBrush(RGB(180,180,180)));
wcex.lpszMenuName = (LPCSTR)IDC_MY922B;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_POPUP ,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow|SW_MAXIMIZE);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
void re()
{
MoveWindow(hmedia1, 30, 50,757,606,true);
MoveWindow(hmedia2,790, 50,176,144,true);
MoveWindow(hmedia3,790,204,176,144,true);
MoveWindow(hmedia4,790,358,176,144,true);
MoveWindow(hmedia5,790,512,176,144,true);

MCIWndSetVolume(hmedia2,0);
MCIWndSetVolume(hmedia3,0);
MCIWndSetVolume(hmedia4,0);
MCIWndSetVolume(hmedia5,0);

//MCIWndChangeStyles(hmedia1,MCIWNDF_NOMENU,true);
//MCIWndChangeStyles(hmedia2,MCIWNDF_NOMENU,true);
//MCIWndChangeStyles(hmedia3,MCIWNDF_NOMENU,true);
//MCIWndChangeStyles(hmedia4,MCIWNDF_NOMENU,true);
//MCIWndChangeStyles(hmedia5,MCIWNDF_NOMENU,true);

}



TCHAR *OPEN(HWND hWnd)
{
OPENFILENAME ofn;
static TCHAR szFilter[] = TEXT ("All Files (*.*)\0");//打开的路径名
static TCHAR szFile[100];
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = szFilter ;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH ;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

if (GetOpenFileName(&ofn) == TRUE)
{
strcpy(szFile, ofn.lpstrFile );
InvalidateRect(hWnd,NULL,true);
}
return szFile;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
static TCHAR *w1,*w2,*w3,*w4;
static TCHAR *szFile;
HWND bta1,bta2,btb1,btb2,btc1,btc2,btd1,btd2;
static int i1,i2,i3,i4;

switch (message)
{
case WM_CREATE:
hmedia1=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,TEXT("clock.avi"));
hmedia2=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,TEXT("clock.avi"));
hmedia3=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,TEXT("clock.avi"));
hmedia4=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,TEXT("clock.avi"));
hmedia5=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,TEXT("clock.avi"));
bta1=CreateWindow("BUTTON", "打开", WS_VISIBLE|WS_CHILD,970,146,50,20,
hWnd, (HMENU)ID_bta1, hInst, NULL);
bta2=CreateWindow("BUTTON", "放大", WS_VISIBLE|WS_CHILD,970,176,50,20,
hWnd, (HMENU)ID_bta2, hInst, NULL);
btb1=CreateWindow("BUTTON", "打开", WS_VISIBLE|WS_CHILD,970,300,50,20,
hWnd, (HMENU)ID_btb1, hInst, NULL);
btb2=CreateWindow("BUTTON", "放大", WS_VISIBLE|WS_CHILD,970,330,50,20,
hWnd, (HMENU)ID_btb2, hInst, NULL);
btc1=CreateWindow("BUTTON", "打开", WS_VISIBLE|WS_CHILD,970,454,50,20,
hWnd, (HMENU)ID_btc1, hInst, NULL);
btc2=CreateWindow("BUTTON", "放大", WS_VISIBLE|WS_CHILD,970,484,50,20,
hWnd, (HMENU)ID_btc2, hInst, NULL);
btd1=CreateWindow("BUTTON", "打开", WS_VISIBLE|WS_CHILD,970,608,50,20,
hWnd, (HMENU)ID_btd1, hInst, NULL);
btd2=CreateWindow("BUTTON", "放大", WS_VISIBLE|WS_CHILD,970,638,50,20,
hWnd, (HMENU)ID_btd2, hInst, NULL);
re();

break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_bta1:
MCIWndDestroy(hmedia2);
szFile=new TCHAR(sizeof(OPEN(hWnd)));
szFile=OPEN(hWnd);
w1=new TCHAR(sizeof(szFile));
strcpy(w1,szFile);
hmedia2=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w1);
//MCIWndPlay(hmedia2);
re();
break;
case ID_bta2:
MCIWndDestroy(hmedia1);
hmedia1=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w1);
i1=MCIWndGetPosition(hmedia2);
MCIWndPlayFrom(hmedia1,i1);
re();
break;
case ID_btb1:
MCIWndDestroy(hmedia3);
szFile=new TCHAR(sizeof(OPEN(hWnd)));
szFile=OPEN(hWnd);
w2=new TCHAR(sizeof(szFile));
strcpy(w2,szFile);
hmedia3=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w2);
re();
break;
case ID_btb2:
MCIWndDestroy(hmedia1);
hmedia1=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w2);
i2=MCIWndGetPosition(hmedia3);
MCIWndPlayFrom(hmedia1,i2);
re();
break;
case ID_btc1:
MCIWndDestroy(hmedia4);
szFile=new TCHAR(sizeof(OPEN(hWnd)));
szFile=OPEN(hWnd);
w3=new TCHAR(sizeof(szFile));
strcpy(w3,szFile);
hmedia4=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w3);
re();
break;
case ID_btc2:
MCIWndDestroy(hmedia1);
hmedia1=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w3);
i3=MCIWndGetPosition(hmedia4);
MCIWndPlayFrom(hmedia1,i3);
re();
break;
case ID_btd1:
MCIWndDestroy(hmedia5);
szFile=new TCHAR(sizeof(OPEN(hWnd)));
szFile=OPEN(hWnd);
w4=new TCHAR(sizeof(szFile));
strcpy(w4,szFile);
hmedia5=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w4);
re();
break;
case ID_btd2:
MCIWndDestroy(hmedia1);
hmedia1=MCIWndCreate(hWnd,hInst,MCIWNDF_NOMENU,w4);
i4=MCIWndGetPosition(hmedia5);
MCIWndPlayFrom(hmedia1,i4);
re();
break;

case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}


2006-09-30 13:00
快速回复:[讨论]一个多屏播放器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037410 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved