OSDN Git Service

59a035b29ef5ee8e873211ab7db108ebfbcd4236
[dokopop/dokopop.git] / DCHookTest / DCHookTest.cpp
1 //---------------------------------------------------------------------------
2 #include <vcl.h>
3 #pragma hdrstop
4 USERES("DCHookTest.res");
5 USEFORM("DCHookMain.cpp", DCHookMainForm);
6 USEUNIT("StringLib.cpp");
7 USEFORM("PopupConfig.cpp", PopupConfigDlg);
8 USEUNIT("Util.cpp");
9 USEFORM("Notify.cpp", NotifyForm);
10 USERC("icon.rc");
11 USEUNIT("mustr.cpp");
12 USEUNIT("HookDLl.cpp");
13 USEUNIT("HookLoader.cpp");
14 USEUNIT("DCHookLoader.cpp");
15 USE("..\Diary.txt", File);
16 USEUNIT("prgprof.cpp");
17 USEFORM("MODINotifyDlg.cpp", MODINotifyDialog);
18 USEUNIT("prgconfig.cpp");
19 USEFORM("OCRTextFrm.cpp", OCRTextForm);
20 USEUNIT("MonitorScale.cpp");
21 //---------------------------------------------------------------------------
22 #include "prgconfig.h"
23 #include "DCHookMain.h"
24 //---------------------------------------------------------------------------
25
26 void SetDpiAware();
27
28 WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
29 {
30         SetDpiAware();
31 #if __PROTO
32         SYSTEMTIME st;
33         GetSystemTime(&st);
34         if ( (st.wYear>=2017 && st.wMonth>=2) || st.wYear>=2018){
35                 int ret = MessageBox(NULL, "\8e\8e\8dì\94Å\82Ì\8eg\97p\8aú\8cÀ\82ª\90Ø\82ê\82Ü\82µ\82½\81B\90V\82µ\82¢DokoPop!\82ð\93ü\8eè\82µ\82Ä\82­\82¾\82³\82¢", APPNAME, MB_YESNO);
36                 if (ret != IDNO){
37                         ShowLatestVersion();
38                         return 0;
39                 }
40         }
41 #endif
42
43         HWND hwnd = FindPrev();
44         if ( hwnd ){
45                 if (CheckVersion(hwnd)<0){
46                         // The older version already lauched.
47                         MessageBox(NULL, "DokoPop!\82ª\82·\82Å\82É\8bN\93®\82µ\82Ä\82¢\82Ü\82·\81B\r\8cÃ\82¢\83o\81[\83W\83\87\83\93\82ÌDokoPop!\82ð\83A\83\93\83C\83\93\83X\83g\81[\83\8b\82µ\82Ä\82­\82¾\82³\82¢", APPNAME, MB_OK);
48                         return 0;
49                 }
50                 MoveToTop( hwnd );
51                 return 0;
52         }
53         try
54         {
55                 Application->Initialize();
56                 Application->Title = "DokoPop";
57                 Application->CreateForm(__classid(TDCHookMainForm), &DCHookMainForm);
58                 Application->Run();
59         }
60         catch (Exception &exception)
61         {
62                 Application->ShowException(&exception);
63         }
64         if (Reboot){
65                 _WinExec(Application->ExeName.c_str(), SW_SHOW, 0);
66         }
67         return 0;
68 }
69 //---------------------------------------------------------------------------
70
71 typedef WINUSERAPI BOOL (WINAPI *FNSetProcessDpiAwarenessContext)(UINT_PTR vaule);
72 #define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2      ((UINT_PTR)-4)
73 void SetDpiAware()
74 {
75         HINSTANCE hDll = LoadLibrary( _T("user32") );
76         if (!hDll)
77                 return;
78         FNSetProcessDpiAwarenessContext fnSetProcessDpiAwarenessContext = (FNSetProcessDpiAwarenessContext)GetProcAddress(hDll, "SetProcessDpiAwarenessContext");
79         if (fnSetProcessDpiAwarenessContext){
80                 if (fnSetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)){
81                 } else {
82                         DBW("SetDpiAware failed: %d", GetLastError());
83                 }
84         }
85         FreeLibrary(hDll);
86 }
87
88