📄 filebrowser.cpp
字号:
InflateRect(&rcMyBounds, -1, -1);
FillRect(hDC,&rcMyBounds, GetSysColorBrush(COLOR_WINDOW));
}
rcMyBounds.left = 15;
rcMyBounds.top = 26;
rcMyBounds.right = 165;
rcMyBounds.bottom = 46;
HFONT hfNewFont = CreateCustomFont(hDC, 15);
HFONT hfOldFont = (HFONT)SelectObject(hDC, hfNewFont);
WCHAR message[MAX_PATH];
swprintf(message,L"Progress: %d bytes", dwBytesSent);
//place the text
ExtTextOut(hDC, 5,5,
0, NULL, message, wcslen(message), NULL);
if(dwBytesTotal == 0xFFFFFFFF)
DrawBarGraph(hDC, &rcMyBounds, dwBytesSent,0,dwBytesSent);
else
DrawBarGraph(hDC, &rcMyBounds, dwBytesSent,0,dwBytesTotal);
SelectObject(hDC, hfOldFont);
DeleteObject(hfNewFont);
EndPaint(hWnd, &ps);
fRepaintAll = TRUE;
}
return 0;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
/*************************************************************************************/
/* Draw a horizontal bar graph */
/* */
/* outline_box = the confining portions of the bar graph (the out parameter) */
/* value = the value to graph */
/* min = the minimum value in the graph */
/* max = the maximum value of the graph */
/* */
/* TRUE returned on success */
/* FALSE returned on failure */
/*************************************************************************************/
static BOOL DrawBarGraph(HDC hdc, RECT *rcOutline_box, LONG lvalue, LONG lmin, LONG lmax)
{
RECT rcBar_box;
FLOAT flPercent = (((FLOAT)(lvalue-lmin))/(FLOAT)((lmax-lmin)) * 100);
//get the old font information and set the current one
COLORREF oldColor = GetTextColor(hdc);
HFONT hfNewFont = CreateCustomFont(hdc, 11);
HFONT hfOldFont = (HFONT)SelectObject(hdc, hfNewFont);
SetTextColor(hdc, GetSysColor(COLOR_ACTIVECAPTION));
//define the max width of the bar graph
FLOAT flMax_width = (FLOAT)(rcOutline_box->right - rcOutline_box->left - (INNER_BAR_GAP));
//create the actual bar (the part that displays data)
rcBar_box.top = rcOutline_box->top+INNER_BAR_GAP;
rcBar_box.left = rcOutline_box->left+INNER_BAR_GAP;
rcBar_box.right = rcOutline_box->left + (LONG)(flPercent * ((flMax_width)/100));// - INNER_BAR_GAP;
rcBar_box.bottom = rcOutline_box->bottom-INNER_BAR_GAP;
//draw the background of the bar graph (in gray, with a black outline)
//and then paint over it with a blue bar representing the value
FillRect(hdc,rcOutline_box, GetSysColorBrush(COLOR_WINDOWTEXT));
InflateRect(rcOutline_box, -1, -1);
FillRect(hdc,rcOutline_box, GetSysColorBrush(COLOR_BTNFACE));
FillRect(hdc, &rcBar_box, GetSysColorBrush(COLOR_ACTIVECAPTION));
// Put in min and max values
//attach text for min and max ranges
WCHAR text[10];
SIZE fontDims;
INT istrLen;
FLOAT flBarMiddleY = (FLOAT)rcOutline_box->top+((FLOAT)(rcOutline_box->bottom - rcOutline_box->top) / 2);
//make a string that contains the min value
wsprintf(text, TEXT("%d"), lmin);
istrLen = lstrlen(text);
//get the size of that string
GetTextExtentPoint32(hdc, text, istrLen, &fontDims);
//place the text
ExtTextOut(hdc,
rcOutline_box->left - fontDims.cx - 2,
(LONG)(flBarMiddleY - (FLOAT)(fontDims.cy /2)),
0, NULL, text, istrLen, NULL);
// Repeat the font process for the max value
//make a string that contains the min value
wsprintf(text, TEXT("%d"), lmax);
istrLen = lstrlen(text);
//get the size of that string
GetTextExtentPoint32(hdc, text, istrLen, &fontDims);
//place the text
ExtTextOut(hdc,
rcOutline_box->right + 2,
(LONG)(flBarMiddleY - (FLOAT)(fontDims.cy /2)),
0, NULL, text, istrLen, NULL);
//change the font color back, and delete our font
SetTextColor(hdc, oldColor);
SelectObject(hdc, hfOldFont);
DeleteObject(hfNewFont);
return TRUE;
}
HFONT CreateCustomFont(HDC hdc, UINT point)
{
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = point;
lf.lfWeight = FW_SEMIBOLD;
return CreateFontIndirect(&lf);
}
BOOL CALLBACK ConfigClientDlgProc(HWND hDlg, UINT message ,WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
if(szClientPassword[0] != NULL && 0 == SetDlgItemText(hDlg,
IDC_CLIENT_PASSWORD,
szClientPassword))
{
MessageBox(hDlg, L"Error fetching password", L"Error", MB_OK);
EndDialog(hDlg, FALSE);
}
}
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
if(0 == GetDlgItemText(hDlg, IDC_CLIENT_PASSWORD,szClientPassword,MAX_PATH))
{
MessageBox(hDlg, L"Not using password.", L"Status", MB_OK);
szClientPassword[0] = NULL;
}
//fall through
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
}
return 0;
}
return FALSE;
}
BOOL CALLBACK AddDirectoryDlgProc(HWND hDlg, UINT message ,WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
szNewDirName[0] = NULL;
}
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
if(0 == GetDlgItemText(hDlg, IDC_ADD_DIRECTORY,szNewDirName,MAX_PATH))
{
MessageBox(hDlg, L"Nothing Entered!", L"Error", MB_OK);
szNewDirName[0] = NULL;
return FALSE;
}
//fall through
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
}
return FALSE;
}
return FALSE;
}
BOOL CALLBACK ConfigServerDlgProc(HWND hDlg, UINT message ,WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
HKEY hk;
DWORD dwRes;
DWORD dwType;
if ((ERROR_SUCCESS == (dwRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
OBEX_FTP_BASE_REG, 0, KEY_QUERY_VALUE, &hk))))
{
WCHAR szPassword[_MAX_PATH];
DWORD dwSize = _MAX_PATH;
//get the password (if any)
if ((ERROR_SUCCESS == RegQueryValueEx (hk, L"Password", NULL, &dwType, (LPBYTE)szPassword, &dwSize)) &&
(dwType == REG_SZ))
{
if(0 == SetDlgItemText(hDlg,
IDC_FB_PASSWORD,
szPassword))
{
MessageBox(hDlg, L"Error fetching password", L"Error", MB_OK);
EndDialog(hDlg, FALSE);
}
}
//see if authentication is required
DWORD dwAuthValue = 0;
if ((ERROR_SUCCESS != RegQueryValueEx (hk, L"Authenticate", NULL, &dwType, (LPBYTE)&dwAuthValue, &dwSize)) ||
dwType != REG_DWORD)
{
dwAuthValue = 1; //default on
}
SendMessage(GetDlgItem(hDlg, IDC_FB_OBEX_AUTHENTICATE), BM_SETCHECK, (dwAuthValue==1), 0);
//see if transport authentication is required
if ((ERROR_SUCCESS != RegQueryValueEx (hk, L"TransportAuthenticate", NULL, &dwType, (LPBYTE)&dwAuthValue, &dwSize)) ||
dwType != REG_DWORD)
{
dwAuthValue = 1; //default on
}
SendMessage(GetDlgItem(hDlg, IDC_FB_TRANSPORT_AUTHENTICATE), BM_SETCHECK, (dwAuthValue==1), 0);
//see if the server allows writing
if ((ERROR_SUCCESS != RegQueryValueEx (hk, L"CanWrite", NULL, &dwType, (LPBYTE)&dwAuthValue, &dwSize)) ||
dwType != REG_DWORD)
{
dwAuthValue = 0; //default off
}
SendMessage(GetDlgItem(hDlg, IDC_FB_ALLOW_WRITES), BM_SETCHECK, (dwAuthValue==1), 0);
//close the key
RegCloseKey(hk);
}
}
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_SETINBOX_VCARD:
{
HKEY hk;
TCHAR szFileName[MAX_PATH];
TCHAR szTitleName[MAX_PATH];
DWORD dwDisp;
//fetch a file name
szFileName[0]=TEXT('\0');
szTitleName[0]=TEXT('\0');;
if(0 == PopFileOpenDlg(g_hInst, g_hWnd, szFileName, szTitleName))
break;
//
// Handle vCard key
//
if ((ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, OBEX_VCARD_BASE_REG,
0, NULL, 0, KEY_ALL_ACCESS, NULL, &hk, &dwDisp)))
{
//set the password (if any)
if ((ERROR_SUCCESS != RegSetValueEx (hk, L"DefaultFile", NULL, REG_SZ, (LPBYTE)szFileName, 2*(wcslen(szFileName) + 1))))
{
MessageBox(hDlg, L"Error setting default inbox vCard file", L"Error", MB_OK);
}
//close the key and exit
RegCloseKey(hk);
EndDialog(hDlg, TRUE);
}
}
break;
case IDC_UNINSTALL:
if(IDYES == MessageBox(hDlg, _T("Pressing YES will permanently prevent OBEX from loading"), _T("Are you sure?"), MB_YESNO))
{
RegDeleteKey(HKEY_LOCAL_MACHINE, L"Drivers\\BuiltIn\\Obex");
RegDeleteKey(HKEY_LOCAL_MACHINE, L"Services\\Obex");
MessageBox(hDlg, _T("Obex has been prevented from unloading. Reset and run Add/Remove programs"), _T("Unloaded"), MB_OK);
EndDialog(hDlg, TRUE);
}
break;
case IDOK:
{
HKEY hk;
//
// Handle FileBrowser specific keys
//
if ((ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
OBEX_FTP_BASE_REG, 0, KEY_QUERY_VALUE, &hk)))
{
WCHAR szPWD[_MAX_PATH];
//set the FB password
if(0 != GetDlgItemText(hDlg,
IDC_FB_PASSWORD,
szPWD,
MAX_PATH))
{
DWORD dwSize = _MAX_PATH;
//set the password (if any)
if ((ERROR_SUCCESS != RegSetValueEx (hk, L"Password", NULL, REG_SZ, (LPBYTE)szPWD, 2*(wcslen(szPWD) + 1))))
{
MessageBox(hDlg, L"Error setting password", L"Error", MB_OK);
}
}
//see if authentication is allowed (and set it)
DWORD iAuthValue = (DWORD)SendMessage(GetDlgItem(hDlg, IDC_FB_OBEX_AUTHENTICATE), BM_GETCHECK, 0, 0);
if (ERROR_SUCCESS != RegSetValueEx (hk, L"Authenticate", NULL, REG_DWORD, (LPBYTE)&iAuthValue, sizeof(DWORD)))
{
MessageBox(hDlg, L"Error setting FB OBEX Authentication", L"Error", MB_OK);
}
//see if authentication is allowed (and set it)
iAuthValue = (DWORD)SendMessage(GetDlgItem(hDlg, IDC_FB_TRANSPORT_AUTHENTICATE), BM_GETCHECK, 0, 0);
if (ERROR_SUCCESS != RegSetValueEx (hk, L"TransportAuthenticate", NULL, REG_DWORD, (LPBYTE)&iAuthValue, sizeof(DWORD)))
{
MessageBox(hDlg, L"Error setting FB Transport Authentication", L"Error", MB_OK);
}
//see if authentication is allowed (and set it)
iAuthValue = (DWORD)SendMessage(GetDlgItem(hDlg, IDC_FB_ALLOW_WRITES), BM_GETCHECK, 0, 0);
if (ERROR_SUCCESS != RegSetValueEx (hk, L"CanWrite", NULL, REG_DWORD, (LPBYTE)&iAuthValue, sizeof(DWORD)))
{
MessageBox(hDlg, L"Error setting CanWrite (if the server supports PUT/DELETE)", L"Error", MB_OK);
}
//close the key and exit
RegCloseKey(hk);
EndDialog(hDlg, TRUE);
}
}
break;
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
}
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -