playlisteditor.cpp

来自「PocketMVP V0.8082503 source for Pocket 的」· C++ 代码 · 共 593 行 · 第 1/2 页

CPP
593
字号
 /***************************************************************************************
 *This program is free software; you can redistribute it and/or modify					*
 * it under the terms of the GNU General Public License as published by					*
 * the Free Software Foundation; either version 2 of the License, or					*
 * (at your option) any later version.													*
 *																						*
 * The GPL can be found at: http://www.gnu.org/copyleft/gpl.html						*
 *																						*
 *																						*	
 ****************************************************************************************
 * Authors:																			  *
 *          Marc Dukette                                                              *
 **************************************************************************************/

#include "stdafx.h"
#include "PlaylistEditor.h"
#include <commctrl.h>
#include <commdlg.h>
#if (_WIN32_WCE >= 300 && !defined(HPC))
#include <aygshell.h>
#include <sipapi.h>
	#define SHCMBM_GETMENU      (WM_USER + 402)
	#define SHGetMenu( hWndMB )  ( HMENU )SendMessage( ( hWndMB ), SHCMBM_GETMENU, ( WPARAM )0, ( LPARAM )0 )
	#define CommandBar_GetMenu( hWndMB, x )		( HMENU )SendMessage( ( hWndMB ), SHCMBM_GETMENU, ( WPARAM )0, ( LPARAM )0 )
	typedef BOOL (CALLBACK* paygshell_SHCreateMenuBar)( SHMENUBARINFO *pmb );
	paygshell_SHCreateMenuBar aygshell_SHCreateMenuBar;
#endif
#ifdef GAPI
	#include "gx.h"
	GXKeyList g_gxk;
#endif

	LPTSTR ToolTips[9]={_T(""),_T("Open Playlist"),_T("Save"),_T("Add Item"),_T("Add Item URL"),_T("Delete Item"),_T("Play"),_T("Move Up"),_T("Move Down")};


#define MAX_LOADSTRING 100
extern int fnGetFileName(HWND Parent,LPTSTR Filter, LPTSTR initialDir, LPTSTR OutFileName, int MaxFilName,LPTSTR* szMultiBuff,unsigned int vk,int URL);

// Global Variables:
HINSTANCE			hInst;			// The current instance
HWND				hwndCB;			// The command bar handle
OPENFILENAME ofn;
HWND hwndList;
// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass	(HINSTANCE, LPTSTR);
BOOL				InitInstance	(HINSTANCE, int);
LRESULT CALLBACK	WndProc			(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About			(HWND, UINT, WPARAM, LPARAM);
//TCHAR file[200]={L"/my documents/untiltled.pdl"};
TCHAR		szFile[MAX_PATH] = TEXT("");
TCHAR		szPDLFile[MAX_PATH] = TEXT(".pdl\0");
TCHAR temp[200];
bool Edited=false;
#define REG_BASE_FMT			L"software\\PocketMVP\\plugins\\format"
TCHAR tfile[MAX_PATH];// = TEXT(".pdl\0");

void AddEntry(LPTSTR FileName, int pos)
{
	LVITEM lv;
	lv.mask=LVIF_TEXT;
	lv.pszText=_T("");
	lv.cchTextMax=1;
	lv.iSubItem=0;
	LPTSTR temp=FileName+wcslen(FileName);
	if (pos<0) lv.iItem=ListView_GetItemCount(hwndList);	
	else lv.iItem=pos;
	ListView_InsertItem(hwndList,&lv);
	while (temp[0]!='.')
	{
		temp--;
	}
	ListView_SetItemText(hwndList,lv.iItem,2,FileName);
	*temp=0;
	temp++;
	ListView_SetItemText(hwndList,lv.iItem,1,temp);
	while (temp[0]!='\\'&&(temp[0]!='/'))
	{
		temp--;
	}
	temp++;
	ListView_SetItemText(hwndList,lv.iItem,0,temp);
}

int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
	MSG msg;
	HACCEL hAccelTable;

	// Perform application initialization:

	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_PLAYLISTEDITOR);
	if (lpCmdLine)
	{
		if (wcscmp(lpCmdLine,_T("")))
		{
			wcscpy(szPDLFile,lpCmdLine);
			if (wcsstr(szPDLFile,_T(".pdl")))
			{
				//wcscpy(file,ofn.lpstrFile);
				HANDLE h=CreateFile((LPCTSTR)szPDLFile,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
				int size=GetFileSize(h,NULL);
				unsigned long t;
				TCHAR* temp=(TCHAR*)malloc(size);
				TCHAR* EndPos=0;
				TCHAR* BeginPos=0;
				ReadFile(h,temp,size,&t,NULL);
				CloseHandle(h);
				BeginPos=temp;
				ListView_DeleteAllItems(hwndList);
				while(BeginPos<(temp+size) &&((EndPos=wcsstr(BeginPos,_T("\r")))!=NULL))
				{
					*EndPos=0;
					//SendMessage(hwndList,LB_ADDSTRING,0,(LPARAM)BeginPos);
					AddEntry(BeginPos,-1);
					BeginPos=EndPos+2;
				}
				free(temp);
			}
		}
	}

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
#ifdef GAPI
GXCloseInput();
#endif
	return msg.wParam;
}

//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    It is important to call this function so that the application 
//    will get 'well formed' small icons associated with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
	WNDCLASS	wc;

    wc.style			= CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc		= (WNDPROC) WndProc;
    wc.cbClsExtra		= 0;
    wc.cbWndExtra		= 0;
    wc.hInstance		= hInstance;
    wc.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PLAYLISTEDITOR));
    wc.hCursor			= 0;
    wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName		= 0;
    wc.lpszClassName	= szWindowClass;

	return RegisterClass(&wc);
}

//
//  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;
	TCHAR	szTitle[MAX_LOADSTRING];			// The title bar text
	TCHAR	szWindowClass[MAX_LOADSTRING];		// The window class name

	hInst = hInstance;		// Store instance handle in our global variable
	// Initialize global strings
	LoadString(hInstance, IDC_PLAYLISTEDITOR, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance, szWindowClass);

	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	if (FindWindow(szWindowClass, szTitle))
	{
	   SetForegroundWindow(FindWindow(szWindowClass, szTitle));
	   return FALSE;
	}
	hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

	if (!hWnd)
	{	
		return FALSE;
	}
	RECT rc;
	GetClientRect(hWnd,&rc);
#if (_WIN32_WCE < 300 || defined(HPC))
	rc.top+=23;
	rc.bottom-=23;
#else
	rc.bottom-=26;
#endif

	
	hwndList=CreateWindow(_T("SysListView32"), _T(""), WS_VISIBLE|WS_CHILD|WS_VSCROLL|LVS_REPORT|LVS_SHOWSELALWAYS,
		rc.left, rc.top, rc.right, rc.bottom, hWnd, NULL, hInstance, NULL);
	if (!hwndList)
	{	
		return FALSE;
	}
	ListView_SetExtendedListViewStyle(hwndList,LVS_EX_FULLROWSELECT);
	LVCOLUMN lv;
	lv.mask=LVCF_TEXT | LVCF_WIDTH ;
	lv.fmt=LVCFMT_LEFT ;
	lv.cx=120;
	lv.pszText=_T("File");
	lv.cchTextMax=5;
	ListView_InsertColumn(hwndList,0,&lv);
	lv.cx=40;
	lv.pszText=_T("Type");
	ListView_InsertColumn(hwndList,1,&lv);
	lv.cx=80;
	lv.mask=LVCF_TEXT | LVCF_WIDTH | LVCF_FMT ;
	lv.fmt=LVCFMT_LEFT ;
	lv.pszText=_T("Path");
	ListView_InsertColumn(hwndList,2,&lv);

	SetFocus(hwndList);	
	
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	if (hwndCB)
		CommandBar_Show(hwndCB, TRUE);
#ifdef GAPI	
	GXOpenInput();
	// Get the Display properties
	//g_gxdp = GXGetDisplayProperties();
	g_gxk=GXGetDefaultKeys(GX_NORMALKEYS);
#endif
	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
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	int URL=0;
	TCHAR szHello[MAX_LOADSTRING];
	TCHAR* temp;
	HKEY hKey = 0;
	DWORD dwSize = 0;
	DWORD dwType = 0;
	DWORD dwTmp;
	TCHAR value[200];
//	TCHAR path[200];
//	LPTSTR t;
//	HANDLE h;
	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
			case IDM_OPEN:
//				h=GetModuleHandle(_T("PlaylistEditor.exe"));
//				GetModuleFileName((HMODULE)h,path,200);
//				t=wcsstr(path,_T("PlaylistEditor."));
//				*t=0;
//				wcscat(path,_T("playlists\\"));
#ifdef GAPI
					if (fnGetFileName(hWnd,_T("*.pdl"), NULL,szPDLFile, 200,NULL,g_gxk.vkStart,0))
#else

⌨️ 快捷键说明

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