00001
00002
00003
00004
00005 #include "MFCTool.h"
00006
00007
00008 using namespace jbxwl;
00009
00010
00012
00013
00014
00018 CMenu* jbxwl::GetMenu_byID(CMenu* pMenu, UINT id)
00019 {
00020 if (pMenu==NULL) return NULL;
00021
00022 UINT n = pMenu->GetMenuItemCount();
00023 for (UINT i=0; i<n; i++){
00024 if (pMenu->GetMenuItemID(i)==id) return pMenu;
00025
00026 CMenu* pSub = GetMenu_byID(pMenu->GetSubMenu(i), id);
00027 if (pSub!=NULL) return pSub;
00028 }
00029 return NULL;
00030 }
00031
00032
00033
00034 CMenu* jbxwl::GetMenu_byStringID(CMenu* pMenu, UINT id)
00035 {
00036 if (pMenu==NULL) return NULL;
00037
00038 CString str = LoadString_byID(id);
00039 if (str=="" || str.IsEmpty()) return NULL;
00040
00041 return GetMenu_byName(pMenu, str);
00042 }
00043
00044
00045
00046 CMenu* jbxwl::GetMenu_byName(CMenu* pMenu, LPCTSTR name)
00047 {
00048 if (pMenu==NULL) return NULL;
00049 CString str;
00050
00051 UINT n = pMenu->GetMenuItemCount();
00052 for (UINT i=0; i<n; i++){
00053 pMenu->GetMenuString(i, str, MF_BYPOSITION);
00054 if (str==(CString)name) return pMenu->GetSubMenu(i);
00055
00056 CMenu* pSub = GetMenu_byName(pMenu->GetSubMenu(i), name);
00057 if (pSub!=NULL) return pSub;
00058 }
00059 return NULL;
00060 }
00061
00062
00063
00064
00066
00067
00068
00069 void jbxwl::RebootProgram(void)
00070 {
00071 TCHAR path[LDATA];
00072 GetModuleFileName(NULL, (LPTSTR)path, (DWORD)LDATA);
00073
00074 CString arg;
00075 arg.Format(_T("/waitpid %u"), GetCurrentProcessId());
00076 ShellExecute(NULL, NULL, (LPCTSTR)path, (LPCTSTR)arg, NULL, SW_SHOWNORMAL);
00077
00078 SendWinMessage(WM_CLOSE);
00079 }
00080
00081
00082
00083 BOOL jbxwl::WaitPidTerm(int tm)
00084 {
00085 DWORD pid = 0;
00086
00087 for (int i=1; i<__argc; i++) {
00088 if (!tcscmp(__targv[i], _T("/waitpid"))) {
00089 if (i+1<__argc) {
00090 pid = ttoi(__targv[i+1]);
00091 break;
00092 }
00093 }
00094 }
00095 if (pid==0) return TRUE;
00096
00097 HANDLE hdl = OpenProcess(SYNCHRONIZE, FALSE, pid);
00098 if (hdl!=NULL) {
00099 if (WaitForSingleObject(hdl, tm*1000)==WAIT_TIMEOUT) return FALSE;
00100 }
00101
00102 return TRUE;
00103 }
00104