-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathDiskMark.cpp
111 lines (89 loc) · 2.19 KB
/
DiskMark.cpp
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
/*---------------------------------------------------------------------------*/
// Author : hiyohiyo
// Mail : [email protected]
// Web : https://crystalmark.info/
// License : MIT License
/*---------------------------------------------------------------------------*/
#include "stdafx.h"
#include "DiskMark.h"
#include "DiskMarkDlg.h"
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
#include <afxole.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(CDiskMarkApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
CDiskMarkApp::CDiskMarkApp()
{
}
CDiskMarkApp theApp;
//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
static BOOL IsFileExistEx(const TCHAR* path, const TCHAR* fileName);
static BOOL RunAsRestart();
BOOL CDiskMarkApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
#ifndef UWP
if (! IsUserAnAdmin())
{
if (RunAsRestart())
{
return FALSE;
}
}
#endif
// Multimedia Timer Setting
TIMECAPS tc;
timeGetDevCaps(&tc,sizeof(TIMECAPS));
timeBeginPeriod(tc.wPeriodMin);
BOOL flagReExec = FALSE;
CDiskMarkDlg dlg;
m_pMainWnd = &dlg;
if (dlg.DoModal() == RE_EXEC)
{
flagReExec = TRUE;
}
timeEndPeriod(tc.wPeriodMin);
if(flagReExec)
{
TCHAR str[MAX_PATH];
::GetModuleFileName(NULL, str, MAX_PATH);
ShellExecute(NULL, NULL, str, NULL, NULL, SW_SHOWNORMAL);
}
return FALSE;
}
BOOL IsFileExistEx(const TCHAR* path, const TCHAR* fileName)
{
if(! IsFileExist(path))
{
CString cstr;
cstr.Format(L"Not Found \"%s\".", fileName);
AfxMessageBox(cstr);
return FALSE;
}
return TRUE;
}
BOOL RunAsRestart()
{
int count;
TCHAR** cmd = ::CommandLineToArgvW(::GetCommandLine(), &count);
if (count < 2 || _tcscmp(cmd[1], L"runas") != 0)
{
TCHAR path[MAX_PATH];
::GetModuleFileName(NULL, path, MAX_PATH);
if (::ShellExecute(NULL, L"runas", path, L"runas", NULL, SW_SHOWNORMAL) > (HINSTANCE)32)
{
return TRUE;
}
}
return FALSE;
}