Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OpenDirHelper.cpp « mplayerc « apps « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 170565e2ce1a60458dcee21879a22c98355df6cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * $Id$
 *
 * (C) 2003-2006 Gabest
 * (C) 2006-2010 see AUTHORS
 *
 * This file is part of mplayerc.
 *
 * Mplayerc 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 3 of the License, or
 * (at your option) any later version.
 *
 * Mplayerc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "stdafx.h"
#include "MainFrm.h"
#include "OpenDirHelper.h"

WNDPROC COpenDirHelper::CBProc;
bool COpenDirHelper::m_incl_subdir;
CString COpenDirHelper::strLastOpenDir;

void COpenDirHelper::SetFont(HWND hwnd,LPTSTR FontName,int FontSize)
{
	HFONT hf, hfOld;
	LOGFONT lf= {0};
	HDC hdc=GetDC(hwnd);

	GetObject(GetWindowFont(hwnd),sizeof(lf),&lf);
	lf.lfWeight = FW_REGULAR;
	lf.lfHeight = (LONG)FontSize;
	lstrcpy( lf.lfFaceName, FontName );
	hf=CreateFontIndirect(&lf);
	SetBkMode(hdc,OPAQUE);

	hfOld = (HFONT)SendMessage(hwnd,WM_GETFONT,NULL,NULL); //get old font
	SendMessage(hwnd,WM_SETFONT,(WPARAM)hf,TRUE); // set new font

	if(!hfOld && (hfOld!=hf)) {
		DeleteObject(hfOld);    //if the old font is not system font or the same as newfont, release it.
	}
	ReleaseDC(hwnd,hdc);

}

// Subclass procedure
LRESULT APIENTRY COpenDirHelper::CheckBoxSubclassProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
	if(uMsg==WM_LBUTTONUP) {
		if((SendMessage(hwnd,BM_GETCHECK,0,0))==1) {
			m_incl_subdir = FALSE;
		} else {
			m_incl_subdir = TRUE;
		}
	}
	return CallWindowProc(CBProc, hwnd, uMsg, wParam, lParam);
}

int __stdcall COpenDirHelper::BrowseCallbackProcDIR(HWND  hwnd,UINT  uMsg,LPARAM  lParam,LPARAM  lpData)
{
	HWND checkbox;

	//Initialization callback message
	if(uMsg==BFFM_INITIALIZED) {
		SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)strLastOpenDir);

		RECT ListViewRect;
		RECT Dialog;
		RECT ClientArea;
		RECT ButtonRect;

		checkbox = CreateWindowEx(0, _T("BUTTON"), ResStr(IDS_MAINFRM_DIR_CHECK),
								  WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | BS_AUTOCHECKBOX | BS_MULTILINE, 0, 100, 100,
								  50, hwnd, 0, AfxGetApp()->m_hInstance, NULL);

		HWND ListView=FindWindowEx(hwnd,NULL,_T("SysTreeView32"),NULL);

		HWND id_ok = GetDlgItem(hwnd, IDOK);
		HWND id_cancel = GetDlgItem(hwnd, IDCANCEL);

		GetWindowRect(hwnd,&Dialog);
		MoveWindow(hwnd, Dialog.left, Dialog.top, Dialog.right-Dialog.left+50, Dialog.bottom-Dialog.top+70, TRUE);
		GetWindowRect(hwnd,&Dialog);

		GetClientRect(hwnd,&ClientArea);

		GetWindowRect(ListView,&ListViewRect);
		MoveWindow(ListView, ListViewRect.left-Dialog.left-3, ListViewRect.top-Dialog.top-55, ListViewRect.right-ListViewRect.left+49, ListViewRect.bottom-ListViewRect.top+115, TRUE);
		GetWindowRect(ListView,&ListViewRect);

		GetWindowRect(id_ok,&ButtonRect);
		MoveWindow(id_ok, ButtonRect.left-Dialog.left+49, ButtonRect.top-Dialog.top+50, ButtonRect.right-ButtonRect.left, ButtonRect.bottom-ButtonRect.top, TRUE);

		GetWindowRect(id_cancel,&ButtonRect);
		MoveWindow(id_cancel, ButtonRect.left-Dialog.left+49, ButtonRect.top-Dialog.top+50, ButtonRect.right-ButtonRect.left, ButtonRect.bottom-ButtonRect.top, TRUE);

		SetWindowPos(checkbox, HWND_BOTTOM, (ListViewRect.left-Dialog.left-3), ClientArea.bottom - 35, 120, 27, SWP_SHOWWINDOW);
		SetFont(checkbox,_T("Tahoma"),13);

		CBProc = (WNDPROC) SetWindowLongPtr(checkbox, GWLP_WNDPROC, (LONG_PTR) CheckBoxSubclassProc);
		SendMessage(checkbox,BM_SETCHECK,(WPARAM)m_incl_subdir,0);
	}
	return 0;
}

void COpenDirHelper::RecurseAddDir(CString path, CAtlList<CString>* sl)
{
	WIN32_FIND_DATA fd = {0};

	HANDLE hFind = FindFirstFile(path + _T("*.*"), &fd);
	if(hFind != INVALID_HANDLE_VALUE) {
		do {
			CString f_name = fd.cFileName;
			if((fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) && (f_name!=_T(".")) && (f_name!=_T(".."))) {
				CString fullpath = path + f_name;
				if(fullpath[fullpath.GetLength()-1] != '\\') {
					fullpath += '\\';
				}
				sl->AddTail(fullpath);
				RecurseAddDir(fullpath, sl);
			} else {
				continue;
			}
		} while(FindNextFile(hFind, &fd));
		FindClose(hFind);
	}
}