OSDN Git Service

8872a487970855f3b395e29f3dba68bf3194de1e
[nlite/nlite.git] / nlite / nlite.cpp
1 // nlite.cpp : \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83G\83\93\83g\83\8a \83|\83C\83\93\83g\82ð\92è\8b`\82µ\82Ü\82·\81B
2 //
3
4 #include "stdafx.h"
5 #include "nlite_include.h"
6 using namespace nlite;
7 CAppModule _Module;
8
9
10
11
12
13
14 static WSAData wsaData;                                                 //winsockdata
15 static HINTERNET hInternet = NULL;
16
17 static BOOL InitializeNlite();                                  //\83A\83v\83\8a\83P\81[\83V\83\87\83\93\8f\89\8aú\89»
18 static VOID FinalizeNlite();                                    //\83A\83v\83\8a\83P\81[\83V\83\87\83\93\8fI\97¹\8f\88\97\9d
19 static CNliteMainFrame wnd;                                             //\83\81\83C\83\93\83t\83\8c\81[\83\80\83E\83B\83\93\83h\83E
20
21 //\83\81\83C\83\93\8aÖ\90\94
22 int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE,
23         LPTSTR lpCmdLine, int nCmdShow)
24 {
25         HINSTANCE hRich = LoadLibrary(CRichEditCtrl::GetLibraryName());
26         int nRet = -1;
27         try{
28
29                 //
30                 //\83A\83v\83\8a\83P\83P\81[\83V\83\87\83\93\8f\89\8aú\89»\8f\88\97\9d
31                 //
32                 HRESULT hRes = ::CoInitialize(NULL);
33                 ATLASSERT(SUCCEEDED(hRes));
34                 //InitCommonControls();
35                  AtlInitCommonControls(ICC_COOL_CLASSES | ICC_WIN95_CLASSES);
36                  GUID guid;
37                 if(_Module.Init(NULL, hInstance,&guid) != S_OK){
38                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
39                 }
40
41                 AtlAxWinInit();
42                         
43                 if(InitializeNlite() != TRUE){
44                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
45                 }
46                 
47                 
48
49                 
50                 
51                 //\83\81\83b\83Z\81[\83W\83\8b\81[\83v\93o\98^
52                 CMessageLoop theLoop;
53                 _Module.AddMessageLoop(&theLoop);
54
55
56                 //\83\81\83C\83\93\83E\83B\83\93\83h\83E\8f\89\8aú\89»
57                 wnd.Initialize(localAppDataPath);
58                 wnd.CreateEx(0,0,WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN);
59
60                 //\83\81\83C\83\93\83E\83B\83\93\83h\83E\95\\8e¦
61                 wnd.ShowWindow(nCmdShow);
62                 wnd.UpdateWindow();
63                 
64                 //\97]\95ª\82É\8am\95Û\82µ\82Ä\82¢\82é\83q\81[\83v\82ð\8aJ\95ú
65                 _heapmin();
66
67                 
68                 //\83\81\83b\83Z\81[\83W\83\8b\81[\83v\8aJ\8en
69                 nRet = theLoop.Run();
70
71                 //\8fI\97¹\8cã\83\81\83\82\83\8a\83`\83F\83b\83N
72                 vcassert(_heapchk() == _HEAPOK,TEXT("\83q\81[\83v\83G\83\89\81[\82Å\82·"));
73
74                 goto nliteend;
75                 
76         } catch(nlite::Exception &e){
77                 
78                 UnexpectedErrorMessageShow(TEXT("\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),e.what(),e.getLineNo(),e.getFileName(),e.getFunctionName());
79                 
80
81                 goto nlitefinally;
82         } catch(nlib::Exception &e){
83                 
84                 UnexpectedErrorMessageShow(TEXT("nlib\82Å\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),e.what(),e.getLineNo(),e.getFileName(),e.getFunctionName());
85                 
86                 goto nlitefinally;
87         }catch(std::exception &e){
88                 UnexpectedErrorMessageShow(TEXT("\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),CComBSTR(e.what()),-1,TEXT("\94­\90\83t\83@\83C\83\8b\82ª\93Á\92è\8fo\97\88\82Ü\82¹\82ñ"),TEXT("\94­\90\8aÖ\90\94\82ª\93Á\92è\82Å\82«\82Ü\82¹\82ñ"));
89
90                 
91
92                 goto nlitefinally;
93         } 
94
95 nlitefinally:
96         wnd.OnException();
97         wnd.DestroyWindow();
98         FreeLibrary(hRich);
99
100 nliteend:
101
102         _Module.RemoveMessageLoop();
103         FinalizeNlite();
104         _Module.Term();
105         ::CoUninitialize();
106
107         return nRet;
108 }
109
110 static BOOL InitializeNlite(){
111
112         BOOL rslt = FALSE;
113
114         try{
115                 
116                 nlite::appInfo = &CApplicationInfo::getInstance();
117                 INT_PTR err;
118                 INT_PTR count = 0;
119
120                 //WSAData\82ð\8f\89\8aú\89»
121                 while((err = WSAStartup(MAKEWORD(2,0),&wsaData)) == WSASYSNOTREADY){
122
123                         count++;
124                         if(count >= 5)break;
125                         Sleep(500);
126
127
128
129                 }
130                 
131                 if(err != ERROR_SUCCESS){
132
133                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
134                 }
135
136                 const CApplicationInfo &appInfo = CApplicationInfo::getInstance();
137                 CNLiteString userAgent;
138                 userAgent = appInfo.getProcuctName();
139                 userAgent += TEXT("/");
140                 userAgent += appInfo.getProductVersion();
141
142
143                 hInternet = WinHttpOpen(userAgent,WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,(LPCWSTR)WINHTTP_NO_PROXY_NAME,(LPCWSTR)WINHTTP_NO_PROXY_BYPASS,0);
144
145                 if(hInternet == NULL){
146
147                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
148
149                 }
150
151                 InitializeNLIB(hInternet);
152
153                 if(SHGetFolderPathW(0,CSIDL_LOCAL_APPDATA,0,SHGFP_TYPE_CURRENT,localAppDataPath) != S_OK){
154
155                         throw AppInitException(__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
156                 }
157
158
159                 SystemParametersInfo (SPI_SETLISTBOXSMOOTHSCROLLING,FALSE,FALSE,0);
160
161
162                 
163                 SHGetFolderPathW(0,CSIDL_APPDATA,0,SHGFP_TYPE_CURRENT,appFolderPath);
164                 ncvAppSettingPath = appFolderPath;
165                 ncvAppSettingPath += TEXT("\\posite-c\\NiconamaCommentViewer\\AppSetting.xml");
166         }catch (AppInitException e){
167
168                 return rslt;
169
170         }
171
172
173
174         rslt = TRUE;
175
176
177         return rslt;
178 }
179
180
181  VOID FinalizeNlite(){
182
183          wnd.Finalaize();
184          FinalizeNLIB();
185          WinHttpCloseHandle(hInternet);
186          WSACleanup();
187
188          return;
189  }
190