static VOID NTAPI LoadCallback( _In_opt_ PVOID Parameter, _In_opt_ PVOID Context ) { // Update settings TaskbarIconType = PhGetIntegerSetting(SETTING_NAME_TASKBAR_ICON_TYPE); // Get the TaskbarButtonCreated Id TaskbarButtonCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated"); // Allow the TaskbarButtonCreated message to pass through UIPI. ChangeWindowMessageFilter(TaskbarButtonCreatedMsgId, MSGFLT_ALLOW); // Allow WM_COMMAND messages to pass through UIPI (Required for ThumbBar buttons if elevated...TODO: Review security.) ChangeWindowMessageFilter(WM_COMMAND, MSGFLT_ALLOW); // Set the process-wide AppUserModelID SetCurrentProcessExplicitAppUserModelID(L"ProcessHacker2"); if (SUCCEEDED(CoCreateInstance(&CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, &IID_ITaskbarList3, &TaskbarListClass))) { if (!SUCCEEDED(ITaskbarList3_HrInit(TaskbarListClass))) { ITaskbarList3_Release(TaskbarListClass); TaskbarListClass = NULL; } } PhRegisterCallback(&PhProcessesUpdatedEvent, ProcessesUpdatedCallback, NULL, &ProcessesUpdatedCallbackRegistration); }
LRESULT MetroWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { HICON hIcon = LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDI_ICON_IBURN)); SetIcon(hIcon,FALSE); ModifyStyle(WS_CAPTION, 0, SWP_FRAMECHANGED); ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_DRAWFRAME); ::SetWindowLongPtr(m_hWnd, GWL_EXSTYLE, ::GetWindowLongPtr(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); SetLayeredWindowAttributes(m_hWnd, 0, 255, LWA_ALPHA/*LWA_COLORKEY*/); ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD); ChangeWindowMessageFilter(0x0049, MSGFLT_ADD); HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT logFont = { 0 }; GetObject(hFont, sizeof(logFont), &logFont); DeleteObject(hFont); hFont = NULL; logFont.lfHeight = 19; logFont.lfWeight = FW_NORMAL; wcscpy_s(logFont.lfFaceName, L"Segoe UI"); hFont = CreateFontIndirect(&logFont); InitCommonControls(); //HWND hCob; //HWND hEdit; DWORD dwCobExStyle = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOPARENTNOTIFY; DWORD dwCobStyle = WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_SORT | CBS_HASSTRINGS; DWORD dwEditExSt = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE; DWORD dwEditSt = WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_VISIBLE | WS_TABSTOP | ES_LEFT | ES_AUTOHSCROLL; DWORD dwpgExSt = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOPARENTNOTIFY; DWORD dwpgSt = WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_VISIBLE; //hCob = CreateWindowEx(dwCobExStyle, WC_COMBOBOX, L"Driver", dwCobStyle, 120, 60, 560, 24, m_hWnd, HMENU(IDC_COMBOX_DEVICE), _Module.m_hInst, NULL); RECT cbRect = { 120, 60, 680, 78 }; RECT ceRect = {120,96,561,122}; m_combox.Create(m_hWnd, cbRect, nullptr, dwCobStyle, dwCobExStyle, IDC_COMBOX_DEVICE, nullptr); //hEdit = CreateWindowEx(dwEditExSt, WC_EDIT, L"", dwEditSt, 120, 95, 441, 27, m_hWnd, HMENU(IDC_EDIT_IMAGE), _Module.m_hInst, NULL); m_edit.Create(m_hWnd, ceRect, nullptr, dwEditSt, dwEditExSt, IDC_EDIT_IMAGE, nullptr); RECT rect = {320,290,680,310}; m_proge.Create(m_hWnd, rect, L"Progress Times", dwpgSt, dwpgExSt, HMENU(IDC_PROCESS_TIME), NULL); m_combox.SendMessage(WM_SETFONT, (WPARAM)hFont, lParam); m_edit.SendMessage( WM_SETFONT, (WPARAM)hFont, lParam); UINT usbnub = DiscoverRemoveableDrives(); if (usbnub > 0) { for (UINT i = 0; i < usbnub; i++){ m_combox.SendMessage(CB_ADDSTRING, 0, (LPARAM) (g_DriveList[i].sizeInfo)); } } Initialize(); // HANDLE hThread = CreateThread(NULL, 0, InspectionEnvironmentThread, m_hWnd, 0, &iseThreadID); CloseHandle(hThread); return S_OK; }
bool wxFrame::Create(wxWindow *parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) return false; SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); #if wxUSE_TASKBARBUTTON static bool s_taskbarButtonCreatedMsgRegistered = false; if ( !s_taskbarButtonCreatedMsgRegistered ) { s_taskbarButtonCreatedMsgRegistered = true; wxMsgTaskbarButtonCreated = ::RegisterWindowMessage(wxT("TaskbarButtonCreated")); // In case the application is run elevated, allow the // TaskbarButtonCreated and WM_COMMAND messages through. #if wxUSE_DYNLIB_CLASS typedef BOOL (WINAPI *ChangeWindowMessageFilter_t)(UINT message, DWORD dwFlag); wxDynamicLibrary dllUser32(wxT("user32.dll")); ChangeWindowMessageFilter_t pfnChangeWindowMessageFilter = NULL; wxDL_INIT_FUNC(pfn, ChangeWindowMessageFilter, dllUser32); if ( pfnChangeWindowMessageFilter ) { pfnChangeWindowMessageFilter(wxMsgTaskbarButtonCreated, wxMSGFLT_ADD); pfnChangeWindowMessageFilter(WM_COMMAND, wxMSGFLT_ADD); } #else ChangeWindowMessageFilter(wxMsgTaskbarButtonCreated, wxMSGFLT_ADD); ChangeWindowMessageFilter(WM_COMMAND, wxMSGFLT_ADD); #endif // wxUSE_DYNLIB_CLASS } #endif // wxUSE_TASKBARBUTTON return true; }
/* * Message Action Function */ LRESULT MetroWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandle) { auto hr = Initialize(); if (hr != S_OK) { ::MessageBoxW(nullptr, L"Initialize() failed", L"Fatal error", MB_OK | MB_ICONSTOP); std::terminate(); return S_FALSE; } HICON hIcon = LoadIconW(GetModuleHandleW(nullptr), MAKEINTRESOURCEW(IDI_PEANALYZER)); SetIcon(hIcon, TRUE); ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD); ChangeWindowMessageFilter(0x0049, MSGFLT_ADD); ::DragAcceptFiles(m_hWnd, TRUE); DWORD dwEditEx = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | \ WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE; DWORD dwEdit = WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_VISIBLE | \ WS_TABSTOP | ES_LEFT | ES_AUTOHSCROLL; HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT logFont = { 0 }; GetObject(hFont, sizeof(logFont), &logFont); DeleteObject(hFont); hFont = NULL; logFont.lfHeight = 19; logFont.lfWeight = FW_NORMAL; wcscpy_s(logFont.lfFaceName, L"Segoe UI"); hFont = CreateFontIndirect(&logFont); HWND hEdit = CreateWindowExW(dwEditEx, WC_EDITW, L"", dwEdit, 80, 40, 360, 27, m_hWnd, HMENU(IDC_IMAGE_URI_EDIT), HINST_THISCOMPONENT, NULL); //::SetWindowFont(hEdit, hFont, TRUE); ::SendMessage(hEdit, WM_SETFONT, (WPARAM)hFont, TRUE); return S_OK; }
CRCHostProxy::CRCHostProxy() : CInstanceTracker(_T("CRCHostProxy")), m_instance(NULL), m_unSetHooks(NULL), m_setMouseFilterHook(NULL), m_setKeyboardFilterHook(NULL), m_setHooks(NULL), m_hookinited(false), CThread() { TRY_CATCH /// Registering communication message handlers m_srvCommutator.RegisterMsgHandler(SRVCOMM_SEND_MOUSE_INPUT, boost::bind(&CRCHostProxy::OnSendMouseEventMsg, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_SEND_KBD_INPUT, boost::bind(&CRCHostProxy::OnSendKbdEventMsg, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_SET_VNCHOOKS, boost::bind(&CRCHostProxy::OnSetVNCHooksMsg, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_GET_DESKTOP, boost::bind(&CRCHostProxy::OnGetWinLogonDesktopMsg, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_SEND_CAD, boost::bind(&CRCHostProxy::OnSendCAD, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_RESET_WALLPAPER, boost::bind(&CRCHostProxy::OnResetWallpaper, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_TOGGLE_TASKBAR, boost::bind(&CRCHostProxy::OnToggleTaskBar, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_ALLOW_CONNECTIONS, boost::bind(&CRCHostProxy::OnAllowConnections, this, _1, _2, _3)); m_srvCommutator.RegisterMsgHandler(SRVCOMM_START_BROKER, boost::bind(&CRCHostProxy::OnStartBroker, this, _1, _2, _3)); OSVERSIONINFOEX osInfo; osInfo.dwOSVersionInfoSize=sizeof(osInfo); int osVersion = 0; if(0 == GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&osInfo))) { osVersion = 5; //WinXP by default Log.WinError(_ERROR_,_T("Failed to GetVersionEx")); } else { osVersion = osInfo.dwMajorVersion; } /// Allowing lower integrity applications to communicate with proxy for Vista and higher if (osVersion > 5) { TRY_CATCH CScopedTracker<HMODULE> user32Module; user32Module.reset(LoadLibrary(_T("User32.dll")),FreeLibrary); if (NULL == user32Module) throw MCException_Win("NULL == user32Module"); typedef BOOL (WINAPI* pChangeWindowMessageFilter)(UINT message, DWORD dwFlag); pChangeWindowMessageFilter ChangeWindowMessageFilter = reinterpret_cast<pChangeWindowMessageFilter>(GetProcAddress(user32Module, _T("ChangeWindowMessageFilter"))); if (NULL == ChangeWindowMessageFilter) throw MCException_Win("NULL == ChangeWindowMessageFilter"); if (FALSE == ChangeWindowMessageFilter(m_srvCommutator.m_commMsg, 1)) throw MCException_Win("Failed to ChangeWindowMessageFilter for m_srvCommutator.m_commMsg"); CATCH_LOG() }
//================================================================================================ //--------------------------------------------------==-+++--> Entry Point of Program Using WinMain: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wndclass; HWND hwndMain; MSG msg; int updated; (void)hPrevInstance; (void)nCmdShow; #if defined(__GNUC__) && defined(_DEBUG) # ifdef _WIN64 # define LoadExcHndl() LoadLibraryExA("dbg\\64\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH) # else # define LoadExcHndl() LoadLibraryExA("dbg\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH) # endif #else # define LoadExcHndl() #endif LoadExcHndl(); // LOAD_WITH_ALTERED_SEARCH_PATH works :P At least since Win2k g_instance = hInstance; if(LoadClockAPI("misc/T-Clock" ARCH_SUFFIX, &api)){ MessageBox(NULL, "Error loading: T-Clock" ARCH_SUFFIX ".dll", "API error", MB_OK|MB_ICONERROR); return 2; } chdir(api.root); // make sure we've got the right working directory // Make sure we're running Windows 2000 and above if(!api.OS) { MessageBox(NULL,"T-Clock requires Windows 2000 or newer","old OS",MB_OK|MB_ICONERROR); return 1; } // make sure ObjectBar isn't running -> From Original Code/Unclear if This is Still a Conflict. (test suggested not really.. no crash but no clock either :P) if(FindWindow("ObjectBar Main","ObjectBar")) { MessageBox(NULL,"ObjectBar and T-Clock can't be run together","ObjectBar detected!",MB_OK|MB_ICONERROR); return 1; } // Load ALL of the Global Resources g_hIconTClock = LoadIcon(api.hInstance, MAKEINTRESOURCE(IDI_MAIN)); g_hIconPlay = LoadImage(g_instance, MAKEINTRESOURCE(IDI_PLAY), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); g_hIconStop = LoadImage(g_instance, MAKEINTRESOURCE(IDI_STOP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); g_hIconDel = LoadImage(g_instance, MAKEINTRESOURCE(IDI_DEL), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); // FindTrayServer(hwndMain); // Make sure we're not running 32bit on 64bit OS / start the other one #ifndef _WIN64 if(IsWow64()){ hwndMain = FindWindow(g_szClassName, NULL); if(hwndMain) { // send commands to existing instance ProcessCommandLine(hwndMain,lpCmdLine); }else{ // start new instance char clock64[MAX_PATH]; memcpy(clock64, api.root, api.root_len+1); add_title(clock64,"Clock" ARCH_SUFFIX_64 ".exe"); api.Exec(clock64,lpCmdLine,NULL); } return 0; } #endif // _WIN64 // Do Not Allow the Program to Execute Twice! updated = 25; /**< wait up to 5 sec in 1/5th seconds for other instance */ do{ HANDLE processlock=CreateMutex(NULL,FALSE,g_szClassName); // we leak handle here, but Windows closes on process exit anyway (so why do it manually?) if(processlock && GetLastError()==ERROR_ALREADY_EXISTS){ CloseHandle(processlock); hwndMain = FindWindow(g_szClassName, NULL); if(hwndMain) { // This One Sends Commands to the Instance ProcessCommandLine(hwndMain,lpCmdLine); // That is Currently Running. return 0; } Sleep(200); continue; } break; }while(updated--); // Update settings if required and setup defaults if((updated=CheckSettings())<0){ return 1; } CancelAllTimersOnStartUp(); // Message of the taskbar recreating - Special thanks to Mr.Inuya g_WM_TaskbarCreated = RegisterWindowMessage("TaskbarCreated"); // register a window class wndclass.style = 0; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = g_instance; wndclass.hIcon = g_hIconTClock; wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)(intptr_t)(COLOR_WINDOW+1); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = g_szClassName; g_atomTClock = RegisterClass(&wndclass); if(api.OS >= TOS_VISTA) { // allow non elevated processes to send control messages (eg, App with admin rights, explorer without) #define MSGFLT_ADD 1 #define MSGFLT_REMOVE 2 typedef BOOL (WINAPI* ChangeWindowMessageFilter_t)(UINT message,DWORD dwFlag); ChangeWindowMessageFilter_t ChangeWindowMessageFilter=(ChangeWindowMessageFilter_t)GetProcAddress(GetModuleHandle("user32"), "ChangeWindowMessageFilter"); if(ChangeWindowMessageFilter){ int msgid; ChangeWindowMessageFilter(g_WM_TaskbarCreated,MSGFLT_ADD); ChangeWindowMessageFilter(WM_COMMAND,MSGFLT_ADD); for(msgid=WM_MOUSEFIRST; msgid<=WM_MOUSELAST; ++msgid) ChangeWindowMessageFilter(msgid,MSGFLT_ADD); for(msgid=MAINMFIRST; msgid<=MAINMLAST; ++msgid) ChangeWindowMessageFilter(msgid,MSGFLT_ADD); } } // create a hidden window g_hwndTClockMain = hwndMain = CreateWindowEx(WS_EX_NOACTIVATE, MAKEINTATOM(g_atomTClock),NULL, 0, 0,0,0,0, NULL,NULL,g_instance,NULL); // This Checks for First Instance Startup Options ProcessCommandLine(hwndMain,lpCmdLine); GetHotKeyInfo(hwndMain); if(api.OS > TOS_2000) { if(api.GetInt("Desktop", "MonOffOnLock", 0)) RegisterSession(hwndMain); } if(updated==1){ PostMessage(hwndMain,WM_COMMAND,IDM_SHOWPROP,0); } while(GetMessage(&msg, NULL, 0, 0)) { if(!(g_hwndSheet && IsWindow(g_hwndSheet) && PropSheet_IsDialogMessage(g_hwndSheet,&msg)) && !(g_hDlgTimer && IsWindow(g_hDlgTimer) && IsDialogMessage(g_hDlgTimer,&msg)) && !(g_hDlgTimerWatch && IsWindow(g_hDlgTimerWatch) && IsDialogMessage(g_hDlgTimerWatch,&msg)) && !(g_hDlgStopWatch && IsWindow(g_hDlgStopWatch) && IsDialogStopWatchMessage(g_hDlgStopWatch,&msg))){ TranslateMessage(&msg); DispatchMessage(&msg); } } UnregisterHotKey(hwndMain, HOT_TIMER); UnregisterHotKey(hwndMain, HOT_WATCH); UnregisterHotKey(hwndMain, HOT_STOPW); UnregisterHotKey(hwndMain, HOT_PROPR); UnregisterHotKey(hwndMain, HOT_CALEN); UnregisterHotKey(hwndMain, HOT_TSYNC); UnregisterSession(hwndMain); EndNewAPI(NULL); return (int)msg.wParam; }
ShellServiceWindow::ShellServiceWindow(HINSTANCE pInstance, bool pTopmost) { hInstance = pInstance; TaskbarCreated = RegisterWindowMessage(TEXT("TaskbarCreated")); hUser32 = LoadLibrary(TEXT("user32.dll")); if (hUser32) { ChangeWindowMessageFilter = (BOOL (WINAPI *)(UINT, DWORD))GetProcAddress(hUser32, "ChangeWindowMessageFilter"); if (ChangeWindowMessageFilter) { ChangeWindowMessageFilter(TaskbarCreated, MSGFLT_ADD); } } else ChangeWindowMessageFilter = NULL; HMODULE trayForward = LoadLibrary(TEXT("TrayForwarder.dll")); WCHAR trayForwardName[MAX_PATH]; bool trayInjected = false; DWORD trayProcessId = 0; LPVOID injectName = NULL; LPVOID loadLibraryWAddr = NULL; HANDLE proc = NULL; if (trayForward) { GetModuleFileNameW(trayForward, trayForwardName, MAX_PATH); FreeLibrary(trayForward); OutputDebugStringW(trayForwardName); GetWindowThreadProcessId(FindWindow(TEXT("Shell_TrayWnd"), NULL), &trayProcessId); if (trayProcessId) { proc = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, trayProcessId); if (proc) { loadLibraryWAddr = reinterpret_cast<LPVOID>(GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), TEXT("LoadLibraryW"))); injectName = VirtualAllocEx(proc, NULL, (wcslen(trayForwardName)+1)*sizeof(WCHAR), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); WriteProcessMemory(proc, injectName, reinterpret_cast<LPVOID>(trayForwardName), (wcslen(trayForwardName)+1)*sizeof(WCHAR), NULL); trayInjected = true; } } } WNDCLASSEX wndClass; ZeroMemory(&wndClass, sizeof(wndClass)); wndClass.cbSize = sizeof(wndClass); wndClass.hInstance = hInstance; wndClass.lpfnWndProc = WndProc; wndClass.cbClsExtra = sizeof(this); if (trayInjected) { wndClass.lpszClassName = TEXT("HandlerShell_TrayWnd"); } else { wndClass.lpszClassName = TEXT("Shell_TrayWnd"); } RegisterClassEx(&wndClass); hTrayWnd = CreateWindowEx( WS_EX_TOOLWINDOW | (pTopmost ? WS_EX_TOPMOST : 0), wndClass.lpszClassName, NULL, WS_POPUP | WS_DISABLED | WS_OVERLAPPED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); if (!trayInjected) { HWND tempParent = createChild(hTrayWnd, TEXT("TrayNotifyWnd")); createChild(tempParent, TEXT("TrayClockWClass")); createChild(createChild(tempParent, TEXT("SysPager")), TEXT("ToolbarWindow32"), TEXT("Notification Area")); createChild(createChild(tempParent, TEXT("SysPager")), TEXT("ToolbarWindow32"), TEXT("System Control Area")); } SetClassLongPtr(hTrayWnd, 0, (LONG_PTR)this); if (trayInjected) { m_forwarderModuleMsg = RegisterWindowMessage(TEXT("TRAYFORWARDER_MODULE")); WaitForSingleObject(CreateRemoteThread(proc, NULL, NULL, (LPTHREAD_START_ROUTINE)loadLibraryWAddr, injectName, NULL, NULL), INFINITE); } CloseHandle(proc); announceWindow(); }
// // Windows メイン関数 // int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgs, int nWinMode) { MSG msg; HWND hMain; int err; // 初期化 install_flag = FALSE; uninstall_flag = FALSE; read_ini_flag = FALSE; start_flag = FALSE; no_error_flag = FALSE; question_flag = FALSE; ok_flag = FALSE; h_instance = hInstance; // 実行ディレクトリにある sexe.exe のフルパスを作成 GetModuleFileName(NULL, module_name, sizeof(module_name)); lstrcpy(execute_path, module_name); extract_directory(execute_path); lstrcpy(ini_name, execute_path); lstrcat(ini_name, _T("\\sexe.ini")); // コマンドライン解析 analyze_args(lpszArgs); // サービスで動作しているか? service_flag = check_execute_service(); // WindowsNT/2000 ? if(nt_flag) { // サービスとして動作中? if(service_flag) { // すでに動作中? if(!check_already()) { // サービスとして起動 start_service(); } } else { // 2011/5/31 // コマンドラインパラメータでインストール・アンインストール if(install_flag) { TCHAR *ext; if(service_name[0] == _T('\0')) { if(!no_error_flag) { // サービス名を指定してください MessageBoxResourceText(NULL, IDS_ERROR_NO_SERVICE_NAME, NULL, ERROR_HEADER, MB_OK); } return ERROR_PARAMETER; } ext = extract_ext(exe_name); if(exe_name[0] == _T('\0') || (_tcsicmp(ext, _T("exe")) && _tcsicmp(ext, _T("bat")))) { if(!no_error_flag) { // プログラム名を指定してください MessageBoxResourceText(NULL, IDS_ERROR_NO_PROGRAM_NAME, NULL, ERROR_HEADER, MB_OK); } return ERROR_PARAMETER; } if(question_flag) { // サービス service_name を登録しますか? if(MessageBoxResourceText(NULL, IDS_QUESTION_INSTALL, service_name, ERROR_HEADER, MB_YESNO) != IDYES) { return ERROR_NO_INSTALL; } } if(!read_ini_flag) { // ini ファイルから読み出したのでなければ設定値を保存 set_inifile(); } // インストール if((err = install_service()) == ERROR_SUCCESS) { if(start_flag) { // サービス開始 if(restart_service()) { if(ok_flag) { // サービス service_name を登録し、開始しました。 MessageBoxResourceText(NULL, IDS_INSTALL_START_OK, service_name, HEADER, MB_OK); } } else if(!no_error_flag) { // サービス service_name を登録しましたが、開始に失敗しました。 MessageBoxResourceText(NULL, IDS_ERROR_INSTALL_START, service_name, HEADER, MB_OK); return ERROR_START; } } else if(ok_flag) { // サービス service_name を登録しました。 MessageBoxResourceText(NULL, IDS_INSTALL_OK, service_name, HEADER, MB_OK); } } else { if(!no_error_flag) { if(err == ERROR_SERVICE_EXISTS) { // すでに同名のサービスが登録済みです MessageBoxResourceText(NULL, IDS_ERROR_SAME_SERVICE, NULL, ERROR_HEADER, MB_OK); } else { // サービスに登録できませんでした。\nサービスの権限があるユーザーでログインして実行してください。 MessageBoxResourceText(NULL, IDS_ERROR_INSTALL_SERVICE, NULL, ERROR_HEADER, MB_OK); } } return ERROR_INSTALL; } } else if(uninstall_flag) { if(service_name[0] == _T('\0')) { if(!no_error_flag) { // サービス名を指定してください MessageBoxResourceText(NULL, IDS_ERROR_NO_SERVICE_NAME, NULL, ERROR_HEADER, MB_OK); } return ERROR_PARAMETER; } if(question_flag) { // サービス service_name を削除しますか? if(MessageBoxResourceText(NULL, IDS_QUESTION_UNINSTALL, service_name, HEADER, MB_YESNO) != IDYES) { return ERROR_NO_INSTALL; } } if(service_install_flag) { // サービスから削除 if(remove_service()) { if(ok_flag) { // サービス service_name を削除しました MessageBoxResourceText(NULL, IDS_UNINSTALL_OK, service_name, HEADER, MB_OK); } } else { if(!no_error_flag) { // サービスから削除できませんでした。\nサービスの権限があるユーザーでログインして実行してください。 MessageBoxResourceText(NULL, IDS_ERROR_UNINSTALL_SERVICE, NULL, ERROR_HEADER, MB_OK); } return ERROR_INSTALL; } } else { if(!no_error_flag) { // サービス service_name は登録されていません MessageBoxResourceText(NULL, IDS_ERROR_NOT_INSTALL_SERVICE, service_name, ERROR_HEADER, MB_OK); } return ERROR_INSTALL; } } else { // 2010/6/10 Vista/7 で WM_DROPFILES を受ける funcChangeWindowMessageFilter ChangeWindowMessageFilter; if(ChangeWindowMessageFilter = (funcChangeWindowMessageFilter)GetProcAddress(LoadLibrary(_T("user32.dll")) ,"ChangeWindowMessageFilter")) { ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD); ChangeWindowMessageFilter(0x0049, MSGFLT_ADD); } // 設定ダイアログを表示 hMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG_SETUP), GetDesktopWindow(), (DLGPROC)MainFunc); ShowWindow(hMain, SW_SHOW); // Drag&Drop を受け入れる準備 DragAcceptFiles(hMain, TRUE); while(GetMessage(&msg, NULL, 0, 0)) { if(!IsDialogMessage(hMain, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } } } else { // Windows NT/2000/XP/Vista/7 で起動してください。 MessageBoxResourceText(NULL, IDS_ERROR_OS, NULL, ERROR_HEADER, MB_OK); } return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { Waifu2x::init_liblary(__argc, __argv); // 管理者権限で起動してもファイルのドロップを受け付けるようにする ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD); ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD); ChangeWindowMessageFilter(0x0049, MSGFLT_ADD); // Caffeのエラーでないログを保存しないようにする google::SetLogDestination(google::INFO, ""); google::SetLogDestination(google::WARNING, ""); // Caffeのエラーログを「error_log_〜」に出力 google::SetLogDestination(google::ERROR, "error_log_"); google::SetLogDestination(google::FATAL, "error_log_"); // CDialogクラスでダイアログを作成する CDialog cDialog; CDialog cDialog2; // IDC_EDITのサブクラス CControl cControlInput(IDC_EDIT_INPUT); CControl cControlOutput(IDC_EDIT_OUTPUT); CControl cControlScaleRatio(IDC_EDIT_SCALE_RATIO); CControl cControlScaleWidth(IDC_EDIT_SCALE_WIDTH); CControl cControlScaleHeight(IDC_EDIT_SCALE_HEIGHT); CControl cControlScaleWidthHeight(IDC_EDIT_SCALE_WIDTH_HEIGHT); // 登録する関数がまとめられたクラス // グローバル関数を使えばクラスにまとめる必要はないがこの方法が役立つこともあるはず DialogEvent cDialogEvent; // クラスの関数を登録する場合 // IDC_EDITにWM_DROPFILESが送られてきたときに実行する関数の登録 cControlInput.SetEventCallBack(SetClassCustomFunc(DialogEvent::DropInput, &cDialogEvent), NULL, WM_DROPFILES); cControlOutput.SetEventCallBack(SetClassCustomFunc(DialogEvent::DropOutput, &cDialogEvent), NULL, WM_DROPFILES); cControlScaleRatio.SetEventCallBack(SetClassCustomFunc(DialogEvent::TextInput, &cDialogEvent), NULL, WM_CHAR); cControlScaleWidth.SetEventCallBack(SetClassCustomFunc(DialogEvent::TextInput, &cDialogEvent), NULL, WM_CHAR); cControlScaleHeight.SetEventCallBack(SetClassCustomFunc(DialogEvent::TextInput, &cDialogEvent), NULL, WM_CHAR); cControlScaleWidthHeight.SetEventCallBack(SetClassCustomFunc(DialogEvent::TextInput, &cDialogEvent), NULL, WM_CHAR); // コントロールのサブクラスを登録 cDialog.AddControl(&cControlInput); cDialog.AddControl(&cControlOutput); cDialog.AddControl(&cControlScaleRatio); cDialog.AddControl(&cControlScaleWidth); cDialog.AddControl(&cControlScaleHeight); cDialog.AddControl(&cControlScaleWidthHeight); // 各コントロールのイベントで実行する関数の登録 cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::Exec, &cDialogEvent), NULL, IDC_BUTTON_EXEC); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::Cancel, &cDialogEvent), NULL, IDC_BUTTON_CANCEL); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::InputRef, &cDialogEvent), NULL, IDC_BUTTON_INPUT_REF); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OutputRef, &cDialogEvent), NULL, IDC_BUTTON_OUTPUT_REF); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::ClearOutputDir, &cDialogEvent), NULL, IDC_BUTTON_CLEAR_OUTPUT_DIR); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::AppSetting, &cDialogEvent), NULL, IDC_BUTTON_APP_SETTING); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OnModeChange, &cDialogEvent), NULL, IDC_RADIO_MODE_NOISE); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OnModeChange, &cDialogEvent), NULL, IDC_RADIO_MODE_SCALE); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OnModeChange, &cDialogEvent), NULL, IDC_RADIO_MODE_NOISE_SCALE); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OnModeChange, &cDialogEvent), NULL, IDC_RADIO_AUTO_SCALE); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OnModeChange, &cDialogEvent), NULL, IDC_RADIO_SCALE_WIDTH_HEIGHT); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::UpdateAddString, &cDialogEvent), NULL, IDC_RADIONOISE_LEVEL0); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::UpdateAddString, &cDialogEvent), NULL, IDC_RADIONOISE_LEVEL1); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::UpdateAddString, &cDialogEvent), NULL, IDC_RADIONOISE_LEVEL2); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::UpdateAddString, &cDialogEvent), NULL, IDC_RADIONOISE_LEVEL3); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::UpdateAddString, &cDialogEvent), NULL, IDC_CHECK_TTA); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::UpdateAddString, &cDialogEvent), NULL, IDC_COMBO_OUTPUT_DEPTH); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::ScaleRadio, &cDialogEvent), NULL, IDC_RADIO_SCALE_RATIO); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::ScaleRadio, &cDialogEvent), NULL, IDC_RADIO_SCALE_WIDTH); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::ScaleRadio, &cDialogEvent), NULL, IDC_RADIO_SCALE_HEIGHT); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::CheckCUDNN, &cDialogEvent), NULL, IDC_BUTTON_CHECK_CUDNN); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::LangChange, &cDialogEvent), NULL, IDC_COMBO_LANG); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OutExtChange, &cDialogEvent), NULL, IDC_COMBO_OUT_EXT); cDialog.SetCommandCallBack(SetClassFunc(DialogEvent::OnModelChange, &cDialogEvent), NULL, IDC_COMBO_MODEL); // ダイアログのイベントで実行する関数の登録 cDialog.SetEventCallBack(SetClassFunc(DialogEvent::Create, &cDialogEvent), NULL, WM_INITDIALOG); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnDialogEnd, &cDialogEvent), NULL, WM_CLOSE); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnFaildCreateDir, &cDialogEvent), NULL, WM_FAILD_CREATE_DIR); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnWaifu2xError, &cDialogEvent), NULL, WM_ON_WAIFU2X_ERROR); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnWaifu2xNoOverwrite, &cDialogEvent), NULL, WM_ON_WAIFU2X_NO_OVERWRITE); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::WaitThreadExit, &cDialogEvent), NULL, WM_END_THREAD); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::Timer, &cDialogEvent), NULL, WM_TIMER); // ダイアログを表示 cDialog.DoModal(hInstance, IDD_DIALOG); Waifu2x::quit_liblary(); return 0; }