@@ -99,7 +99,7 @@ unsigned long getlogodatasize();
9999}
100100#endif
101101
102- DWORD WINAPI messageloopthread (LPVOID lpParameter);
102+ DWORD WINAPI messageLoopThread (LPVOID lpParameter);
103103
104104_graph_setting::_graph_setting ()
105105{
@@ -285,10 +285,12 @@ void guiupdate(_graph_setting* pg, egeControlBase* root)
285285 root->update ();
286286}
287287
288- /* private function*/
289288int waitdealmessage (_graph_setting* pg)
290289{
291- // MSG msg;
290+ if (pg->init_option & INIT_EVENTLOOP ) {
291+ messageHandle ();
292+ }
293+
292294 if (pg->update_mark_count < UPDATE_MAX_CALL ) {
293295 egeControlBase* root = pg->egectrl_root ;
294296 root->draw (NULL );
@@ -857,6 +859,7 @@ void initgraph(int* gdriver, int* gmode, const char* path)
857859{
858860 struct _graph_setting * pg = &graph_setting;
859861
862+ pg->init_option = getinitmode ();
860863 pg->exit_flag = 0 ;
861864 pg->exit_window = 0 ;
862865
@@ -886,17 +889,22 @@ void initgraph(int* gdriver, int* gmode, const char* path)
886889 register_classW (pg, pg->instance );
887890
888891 // SECURITY_ATTRIBUTES sa = {0};
889- DWORD pid;
890- pg->threadui_handle = CreateThread (NULL , 0 , messageloopthread, pg, CREATE_SUSPENDED , &pid);
891- ResumeThread (pg->threadui_handle );
892892
893- while (!pg->has_init ) {
894- ::Sleep (1 );
893+ if (pg->init_option & INIT_EVENTLOOP ) {
894+ initWindow (pg);
895+ } else {
896+ DWORD pid;
897+ pg->threadui_handle = CreateThread (NULL , 0 , messageLoopThread, pg, CREATE_SUSPENDED , &pid);
898+ ResumeThread (pg->threadui_handle );
899+
900+ while (!pg->has_init ) {
901+ ::Sleep (1 );
902+ }
895903 }
896904
897905 UpdateWindow (pg->hwnd );
898906
899- if (!(g_initoption & INIT_HIDE )) {
907+ if (!(pg-> init_option & INIT_HIDE )) {
900908 ShowWindow (pg->hwnd , SW_SHOWNORMAL );
901909 BringWindowToTop (pg->hwnd );
902910 SetForegroundWindow (pg->hwnd );
@@ -914,11 +922,11 @@ void initgraph(int* gdriver, int* gmode, const char* path)
914922
915923 static egeControlBase _egeControlBase;
916924
917- if ((g_initoption & INIT_WITHLOGO ) && !(g_initoption & INIT_HIDE )) {
925+ if ((pg-> init_option & INIT_WITHLOGO ) && !(pg-> init_option & INIT_HIDE )) {
918926 logoscene ();
919927 }
920928
921- if (g_initoption & INIT_RENDERMANUAL ) {
929+ if (pg-> init_option & INIT_RENDERMANUAL ) {
922930 setrendermode (RENDER_MANUAL );
923931 }
924932
@@ -945,12 +953,8 @@ void closegraph()
945953 ShowWindow (pg->hwnd , SW_HIDE );
946954}
947955
948- /* private function*/
949- DWORD WINAPI messageloopthread (LPVOID lpParameter)
956+ int initWindow (_graph_setting* pg)
950957{
951- _graph_setting* pg = (_graph_setting*)lpParameter;
952- MSG msg;
953-
954958 /* 执行应用程序初始化: */
955959 if (!init_instance (pg->instance )) {
956960 return 0xFFFFFFFF ;
@@ -963,25 +967,50 @@ DWORD WINAPI messageloopthread(LPVOID lpParameter)
963967
964968 pg->mouse_show = 0 ;
965969 pg->exit_flag = 0 ;
966- pg->use_force_exit = (g_initoption & INIT_NOFORCEEXIT ? false : true );
970+ pg->use_force_exit = (pg-> init_option & INIT_NOFORCEEXIT ? false : true );
967971
968- if (g_initoption & INIT_NOFORCEEXIT ) {
972+ if (pg-> init_option & INIT_NOFORCEEXIT ) {
969973 SetCloseHandler (DefCloseHandler);
970974 }
971975
972976 pg->close_manually = true ;
973- pg->skip_timer_mark = false ;
974- SetTimer (pg->hwnd , RENDER_TIMER_ID , 50 , NULL );
977+
978+ /* 仅在 INIT_EVENTLOOP 模式下设置定时器(INIT_EVENTLOOP 模式下事件在主线程中处理,固定为手动渲染模式,无需设置定时器。 */
979+ if (pg->init_option & INIT_EVENTLOOP ) {
980+ pg->lock_window = true ;
981+ pg->skip_timer_mark = true ;
982+ } else {
983+ pg->skip_timer_mark = false ;
984+ SetTimer (pg->hwnd , RENDER_TIMER_ID , 50 , NULL );
985+ }
975986
976987 pg->has_init = true ;
988+ }
977989
978- while (!pg->exit_window ) {
979- if (GetMessageW (&msg, NULL , 0 , 0 )) {
980- TranslateMessage (&msg);
981- DispatchMessageW (&msg);
982- } else {
983- Sleep (1 );
990+ int messageHandle ()
991+ {
992+ MSG msg;
993+ int handleCount = 0 ;
994+ while (PeekMessageW (&msg, NULL , 0 , 0 , PM_REMOVE )) {
995+ if (msg.message == WM_QUIT ) {
996+ return -1 ;
984997 }
998+
999+ TranslateMessage (&msg);
1000+ DispatchMessageW (&msg);
1001+ handleCount++;
1002+ }
1003+
1004+ return handleCount;
1005+ }
1006+
1007+ /* private function*/
1008+ DWORD WINAPI messageLoopThread (LPVOID lpParameter)
1009+ {
1010+ _graph_setting* pg = (_graph_setting*)lpParameter;
1011+ initWindow (pg);
1012+ while (messageHandle () != -1 ) {
1013+ Sleep (1 );
9851014 }
9861015
9871016 return 0 ;
@@ -1054,7 +1083,7 @@ BOOL init_instance(HINSTANCE hInstance)
10541083 //DeleteObject(hfont);
10551084 } //*/
10561085
1057- if (!(g_initoption & INIT_HIDE )) {
1086+ if (!(pg-> init_option & INIT_HIDE )) {
10581087 SetActiveWindow (pg->hwnd );
10591088 }
10601089
0 commit comments