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

📄 toolbar.cpp

📁 一个avi格式文件的播放。 c++源码 只有文件的播放暂停等功能
💻 CPP
字号:
/**
 * Toolbar.cpp		Copyright _ 2001 Li Zhaoming. All rights reserved.
 * Handles general routines for the Toolbar control
 */

#include "stdafx.h"
#include "resource.h"

#define IDC_TOOLBAR		500
#define IDC_TRACK		600

// Global Variable for the toolbar control.
HWND	hwndRebar;
HWND	hwndToolbar;
HWND	hwndTrack;

/**
 * TO DO: Change the following values to match your toolbar bitmap
 *
 * NUMIMAGES	= Number of images in toolbar.bmp. Note that this is not
 *		the same as the number of elements on the toolbar.
 * IMAGEWIDTH	= Width of a single button image in toolbar.bmp
 * IMAGEHEIGHT	= Height of a single button image in toolbar.bmp
 */
#define NUMIMAGES		6
#define IMAGEWIDTH		12
#define IMAGEHEIGHT		12

/**
 * TO DO: Add/remove entries in the following array to define the 
 *		toolbar buttons (see documentation for TBBUTTON).
 */
TBBUTTON tbButton[] =
{
	0,	IDM_PLAY,		TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0,  0,
	1,	IDM_PAUSE,		TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0,  1,
	2,	IDM_STOP,		TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0,  2,	
	3,	IDM_REWIND,		TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0,  3,
	4,	IDM_FORWARD,	TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0,  4,
	5,	IDM_OPEN,		TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0,  5,
};

/**
 * Calls CreateToolBarEx()
 *
 * PARAMETERS:
 *	hwnd - Window handle : Used for the hWndParent parameter of the control.
 *
 * RETURN VALUE:
 *	If toolbar control was created successfully Return true,
 *	else returns false.
 */
BOOL createToolbar(HWND hwndParent)
{
	// Create the REBAR control.
	hwndRebar = CreateWindowEx( 
		WS_EX_TOOLWINDOW,
		REBARCLASSNAME,
		NULL, 
		WS_VISIBLE | 
		WS_BORDER |
		WS_CHILD | 
		WS_CLIPCHILDREN | 
		WS_CLIPSIBLINGS |
		CCS_NODIVIDER |
		CCS_NOPARENTALIGN | 
		RBS_VARHEIGHT |
		RBS_BANDBORDERS, 
		0, 0, 0, 0, 
		hwndParent, 
		(HMENU)0x2000, 
		g_hinstance, 
		NULL); 

	if (!hwndRebar) 
		return false;	

	// Create toolbar without button on it.
	hwndToolbar = CreateToolbarEx(hwndRebar,
		WS_VISIBLE| WS_CHILD | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | WS_CLIPCHILDREN | 
		WS_CLIPSIBLINGS | CCS_NODIVIDER | TBSTYLE_AUTOSIZE | CCS_NORESIZE , 
					IDC_TOOLBAR,
					NUMIMAGES,
					g_hinstance,
					IDB_TOOLBAR,
					tbButton,
					sizeof(tbButton)/sizeof(TBBUTTON),
					0, 0,
					IMAGEWIDTH,
					IMAGEHEIGHT,
					sizeof(TBBUTTON));

	if (!hwndToolbar) 
		return false;	

	SendMessage(hwndToolbar, TB_AUTOSIZE, 0, 0L);

	DWORD nSize;
	nSize = SendMessage(hwndToolbar, TB_GETBUTTONSIZE, 0, 0L);

	REBARBANDINFO rbBand;
	ZeroMemory(&rbBand, sizeof(rbBand));
	rbBand.cbSize = sizeof(REBARBANDINFO); 
	rbBand.fMask = RBBIM_SIZE |
		RBBIM_CHILD | // hwndChild is valid 
		RBBIM_CHILDSIZE | // cxMinChild and cyMinChild are valid 
		RBBIM_ID | // wID is valid 
		RBBIM_STYLE | // fStyle is valid 
		0;
	rbBand.fStyle = RBBS_NOVERT | // do not display in vertical orientation
		RBBS_GRIPPERALWAYS |
		RBBS_FIXEDBMP; 
	rbBand.hwndChild = hwndToolbar; 
	rbBand.wID = IDC_TOOLBAR;
	rbBand.cxMinChild = LOWORD(nSize);
	rbBand.cyMinChild = HIWORD(nSize);

	// Insert band into rebar
	SendMessage(hwndRebar, RB_INSERTBAND, (UINT) -1, (LPARAM) (LPREBARBANDINFO) &rbBand);

	hwndTrack = CreateWindow("STATIC", "", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
		0, 0, 0, 0, hwndRebar, (HMENU) IDC_TRACK, g_hinstance, NULL);


	rbBand.hwndChild = hwndTrack; 
	rbBand.wID = IDC_TRACK;
	rbBand.cxMinChild = LOWORD(nSize);
	
	SendMessage(hwndRebar, RB_INSERTBAND, (UINT) -1, (LPARAM) (LPREBARBANDINFO) &rbBand);	

	return true; 
}

/**
 *
 */
LRESULT msgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) 
{
	LPNMHDR lpnmhdr;
	lpnmhdr = (LPNMHDR)lparam;

	switch (lpnmhdr->code)
	{
	// Sent by a rebar control when its height has changed.
	case RBN_HEIGHTCHANGE:
		RECT rc;
		GetClientRect(hwnd, &rc);
		SendMessage(hwnd, WM_SIZE, 0, MAKELONG(rc.right - rc.left, rc.bottom - rc.top));
		break;
	}
	return 0;

}

/**
 *
 */
void updateStatusBar(LPCTSTR szBuf, double ratio)
{
	RECT rc;
	HDC hdc;
	HFONT hfont, hfontOld;
	GetClientRect(hwndTrack, &rc);
	hdc = GetDC(hwndTrack);
	hfont = CreateFont(-13, 0, 0, 0, 0, false, false, false,
		DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
		PROOF_QUALITY, DEFAULT_PITCH, "Arial");
	hfontOld = (HFONT) SelectObject(hdc, hfont);
	DrawStatusText(hdc, &rc, szBuf, SBT_NOBORDERS);
	rc.right = rc.left + int((rc.right-rc.left)*ratio);
	if (rc.right == rc.left) rc.right++;
	DrawStatusText(hdc, &rc, szBuf, SBT_POPOUT);
	SelectObject(hdc, hfontOld);
	ReleaseDC(hwndTrack, hdc);
	DeleteObject(hfont);
}

⌨️ 快捷键说明

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