| 1 |
/** |
| 2 |
* @file ui.cpp |
| 3 |
* @brief ユーザーインターフェース |
| 4 |
* @author BananaJinn |
| 5 |
* @version $Id: ui.h,v 1.5 2010/11/01 14:34:11 bananajinn Exp $ |
| 6 |
* 円盤複写屋 |
| 7 |
* Copyright (C) 2004-2010 BananaJinn<banana@mxh.mesh.ne.jp> |
| 8 |
*/ |
| 9 |
#include "stdafx.h" |
| 10 |
#include <Shlobj.h> |
| 11 |
#include "ui.h" |
| 12 |
#include "ThemeMessageDlg.h" |
| 13 |
#include "RemoteDlg.h" |
| 14 |
#include "EnbanFukusya.h" |
| 15 |
|
| 16 |
static BOOL g_bAbort=FALSE; |
| 17 |
static HWND g_hWnd=NULL; |
| 18 |
|
| 19 |
static void UIFlushMessage() |
| 20 |
{ |
| 21 |
MSG msg; |
| 22 |
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) != 0 ){ |
| 23 |
TranslateMessage( &msg ); |
| 24 |
DispatchMessage( &msg ); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
void UISetHWND(HWND hWnd) |
| 29 |
{ |
| 30 |
g_hWnd = hWnd; |
| 31 |
} |
| 32 |
|
| 33 |
BOOL UICheckAbort() |
| 34 |
{ |
| 35 |
UIFlushMessage(); |
| 36 |
return g_bAbort; |
| 37 |
} |
| 38 |
|
| 39 |
void UISetAbort() |
| 40 |
{ |
| 41 |
g_bAbort=TRUE; |
| 42 |
} |
| 43 |
|
| 44 |
void UIClearAbort() |
| 45 |
{ |
| 46 |
g_bAbort=FALSE; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
int UIDispMessage(const char *message, int type) |
| 51 |
{ |
| 52 |
CThemeSet *pThemeClass = ((CEnbanFukusyaApp *)AfxGetApp())->GetThemeClass(); |
| 53 |
CThemeMessageDlg *pDlg; |
| 54 |
UINT nFlags=0; |
| 55 |
int ret; |
| 56 |
|
| 57 |
switch(type){ |
| 58 |
case UIDMT_ERROR: |
| 59 |
nFlags = MB_ICONSTOP|MB_OK; |
| 60 |
break; |
| 61 |
case UIDMT_QUESTION: |
| 62 |
nFlags = MB_ICONQUESTION|MB_YESNO; |
| 63 |
break; |
| 64 |
default: |
| 65 |
nFlags = MB_OK; |
| 66 |
} |
| 67 |
pDlg = new CThemeMessageDlg; |
| 68 |
pDlg->SetTheme(pThemeClass); |
| 69 |
ret = pDlg->Disp(message, NULL, nFlags); |
| 70 |
|
| 71 |
delete pDlg; |
| 72 |
|
| 73 |
return (ret==IDOK||ret==IDYES) ? UIDMRET_OK : UIDMRET_CANCEL; |
| 74 |
} |
| 75 |
|
| 76 |
void UIMeter1Initialize(const char *message) |
| 77 |
{ |
| 78 |
::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_METER1INIT, (LPARAM)message); |
| 79 |
} |
| 80 |
|
| 81 |
void UIMeter2Initialize(const char *message) |
| 82 |
{ |
| 83 |
::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_METER2INIT, (LPARAM)message); |
| 84 |
} |
| 85 |
|
| 86 |
void UIMeter1Update(float percentage) |
| 87 |
{ |
| 88 |
::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_METER1SETPOS, |
| 89 |
(LPARAM)(percentage*10)); |
| 90 |
} |
| 91 |
|
| 92 |
void UIMeter2Update(float percentage) |
| 93 |
{ |
| 94 |
::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_METER2SETPOS, |
| 95 |
(LPARAM)(percentage*10)); |
| 96 |
} |
| 97 |
|
| 98 |
void UIDispInfo(const char *message) |
| 99 |
{ |
| 100 |
::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_DISPINFO, (LPARAM)message); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
int UISetting(OPTIONS *option) |
| 105 |
{ |
| 106 |
return ::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_SETTING, (LPARAM)option); |
| 107 |
} |
| 108 |
|
| 109 |
int UIFileDialog(BOOL bOpen, char *filename, int size, const char *suffix) |
| 110 |
{ |
| 111 |
LPCTSTR lpszArg = NULL; |
| 112 |
|
| 113 |
/* |
| 114 |
* コマンドライン引数での指定を確認 |
| 115 |
*/ |
| 116 |
if(bOpen){ |
| 117 |
lpszArg = (LPCTSTR)::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_GETARGREADER, 0); |
| 118 |
} |
| 119 |
else{ |
| 120 |
lpszArg = (LPCTSTR)::SendMessage(g_hWnd, WM_USER_UICTL, UICTL_GETARGWRITER, 0); |
| 121 |
} |
| 122 |
if(lpszArg != NULL){ |
| 123 |
if(strlen(lpszArg) > 0){ |
| 124 |
/* 指定されていればそれをファイル名として返す */ |
| 125 |
strncpy(filename, lpszArg, size); |
| 126 |
filename[size-1] = '\0'; |
| 127 |
return UIDMRET_OK; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
CString csFilter; |
| 132 |
if(suffix != NULL){ |
| 133 |
csFilter.Format("%s files (*.%s)|*.%s|All Files (*.*)|*.*||", suffix, suffix, suffix); |
| 134 |
} |
| 135 |
else{ |
| 136 |
csFilter = "All Files (*.*)|*.*||"; |
| 137 |
} |
| 138 |
CFileDialog dlg(bOpen, suffix, filename, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, |
| 139 |
csFilter, NULL); |
| 140 |
if(dlg.DoModal()==IDOK){ |
| 141 |
CString csFullPath = dlg.GetPathName(); |
| 142 |
strncpy(filename, (LPCTSTR)csFullPath, size); |
| 143 |
filename[size-1] = '\0'; |
| 144 |
return UIDMRET_OK; |
| 145 |
} |
| 146 |
return UIDMRET_CANCEL; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
int UIFolderDialog(char *filename, int size) |
| 151 |
{ |
| 152 |
BROWSEINFO bi; |
| 153 |
char buff[MAX_PATH]; |
| 154 |
LPITEMIDLIST idList; |
| 155 |
BOOL bRet; |
| 156 |
|
| 157 |
ZeroMemory(&bi, sizeof(bi)); |
| 158 |
bi.hwndOwner = AfxGetMainWnd()->m_hWnd; |
| 159 |
bi.pszDisplayName = buff; |
| 160 |
bi.lpszTitle = "フォルダ選択"; |
| 161 |
bi.ulFlags = BIF_RETURNONLYFSDIRS; |
| 162 |
idList = SHBrowseForFolder(&bi); |
| 163 |
if(idList != NULL){ |
| 164 |
bRet = SHGetPathFromIDList(idList, buff); |
| 165 |
if(bRet != FALSE){ |
| 166 |
strncpy(filename, buff, size); |
| 167 |
filename[size-1] = '\0'; |
| 168 |
return UIDMRET_OK; |
| 169 |
} |
| 170 |
} |
| 171 |
return UIDMRET_CANCEL; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
int UINetDialog(BOOL bServer, char *remote, int size, int *port_number) |
| 176 |
{ |
| 177 |
int nRetValue = UIDMRET_CANCEL; |
| 178 |
CThemeSet *pThemeClass = ((CEnbanFukusyaApp *)AfxGetApp())->GetThemeClass(); |
| 179 |
CRemoteDlg *pDlg = new CRemoteDlg(); |
| 180 |
pDlg->SetTheme(pThemeClass); |
| 181 |
pDlg->SetServerMode(bServer); |
| 182 |
int nRet = pDlg->DoModal(); |
| 183 |
if(nRet == IDOK){ |
| 184 |
nRetValue = UIDMRET_OK; |
| 185 |
if(bServer){ |
| 186 |
*port_number = pDlg->GetPortNumber(); |
| 187 |
} |
| 188 |
else{ |
| 189 |
strncpy(remote, pDlg->GetRemoteAddress(), size); |
| 190 |
remote[size-1] = '\0'; |
| 191 |
*port_number = pDlg->GetPortNumber(); |
| 192 |
} |
| 193 |
} |
| 194 |
delete pDlg; |
| 195 |
return nRetValue; |
| 196 |
} |