JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
MFCTool.cpp
Go to the documentation of this file.
1//
2// MFCTool.cpp : 実装ファイル
3//
4
5#include "MFCTool.h"
6
7
8using namespace jbxwl;
9
10
12// MENU Tool
13//
14
18CMenu* jbxwl::GetMenu_byID(CMenu* pMenu, UINT id)
19{
20 if (pMenu==NULL) return NULL;
21
22 UINT n = pMenu->GetMenuItemCount();
23 for (UINT i=0; i<n; i++){
24 if (pMenu->GetMenuItemID(i)==id) return pMenu;
25
26 CMenu* pSub = GetMenu_byID(pMenu->GetSubMenu(i), id);
27 if (pSub!=NULL) return pSub;
28 }
29 return NULL;
30}
31
32
33
34CMenu* jbxwl::GetMenu_byStringID(CMenu* pMenu, UINT id)
35{
36 if (pMenu==NULL) return NULL;
37
38 CString str = LoadString_byID(id);
39 if (str=="" || str.IsEmpty()) return NULL;
40
41 return GetMenu_byName(pMenu, str);
42}
43
44
45
46CMenu* jbxwl::GetMenu_byName(CMenu* pMenu, LPCTSTR name)
47{
48 if (pMenu==NULL) return NULL;
49 CString str;
50
51 UINT n = pMenu->GetMenuItemCount();
52 for (UINT i=0; i<n; i++){
53 pMenu->GetMenuString(i, str, MF_BYPOSITION);
54 if (str==(CString)name) return pMenu->GetSubMenu(i);
55
56 CMenu* pSub = GetMenu_byName(pMenu->GetSubMenu(i), name);
57 if (pSub!=NULL) return pSub;
58 }
59 return NULL;
60}
61
62
63
64
66// プログラムの再起動
67//
68
70{
71 TCHAR path[LDATA];
72 GetModuleFileName(NULL, (LPTSTR)path, (DWORD)LDATA);
73
74 CString arg;
75 arg.Format(_T("/waitpid %u"), GetCurrentProcessId());
76 ShellExecute(NULL, NULL, (LPCTSTR)path, (LPCTSTR)arg, NULL, SW_SHOWNORMAL);
77
78 SendWinMessage(WM_CLOSE);
79}
80
81
82
84{
85 DWORD pid = 0;
86
87 for (int i=1; i<__argc; i++) {
88 if (!tcscmp(__targv[i], _T("/waitpid"))) {
89 if (i+1<__argc) {
90 pid = ttoi(__targv[i+1]);
91 break;
92 }
93 }
94 }
95 if (pid==0) return TRUE;
96
97 HANDLE hdl = OpenProcess(SYNCHRONIZE, FALSE, pid);
98 if (hdl!=NULL) {
99 if (WaitForSingleObject(hdl, tm*1000)==WAIT_TIMEOUT) return FALSE;
100 }
101
102 return TRUE;
103}
104
CMenu * GetMenu_byID(CMenu *pMenu, UINT id)
Definition MFCTool.cpp:18
CMenu * GetMenu_byName(CMenu *pMenu, LPCTSTR name)
Definition MFCTool.cpp:46
void RebootProgram(void)
Definition MFCTool.cpp:69
BOOL WaitPidTerm(int tm)
Definition MFCTool.cpp:83
void SendWinMessage(UINT mesg, WPARAM wparam=NULL, LPARAM lparam=NULL)
Definition WinTools.cpp:561
CMenu * GetMenu_byStringID(CMenu *pMenu, UINT id)
Definition MFCTool.cpp:34
CString LoadString_byID(UINT id)
Definition WinTools.h:174