Exemple #1
0
/*
INT_PTR CALLBACK DialogProc(          HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
);
*/
INT_PTR CALLBACK TrayIcon::InjectDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
	switch (uMsg) 
	{
	case WM_INITDIALOG:
		{
			SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_NSCP)));
			SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_NSCP)));
			SetDlgItemText(hwndDlg, IDC_CMD_BOX, TrayIcon::defaultCommand.c_str());
			SetDlgItemText(hwndDlg, IDC_DESCRIPTION, _T("Loading commands, please wait..."));

			SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_RESETCONTENT, 0, 0); 
			std::wstring result = _T("");
			/*
			TODO! re-implement this!
			try {
				std::list<std::wstring> lst = NSCModuleHelper::getAllCommandNames();
				for (std::list<std::wstring>::const_iterator cit = lst.begin(); cit != lst.end(); ++cit) {
					SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>( (*cit).c_str() ));
				}
			} catch (NSCModuleHelper::NSCMHExcpetion &e) {
				result = _T("Error: ") + e.msg_;
			} catch (...) {
				result = _T("Unknown error!");
			}
			*/
			SetDlgItemText(hwndDlg, IDC_DESCRIPTION, result.c_str());
		}
		break;
	case WM_COMMAND: 
		switch (LOWORD(wParam))
		{
		case IDC_CMD_BOX: 
			switch(HIWORD(wParam)) 
			{
			case CBN_SELCHANGE:
				{
					std::wstring cmd;
					unsigned int id = SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_GETCURSEL, 0, 0); 
					unsigned int len = SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_GETLBTEXTLEN, id, 0);
					TCHAR *buf = new TCHAR[len+2];
					LRESULT ret;
					ret = SendDlgItemMessage(hwndDlg, IDC_CMD_BOX, CB_GETLBTEXT, id, reinterpret_cast<LPARAM>(buf));
					if (ret > 0 && ret <= len) {
						cmd = buf;
						updateDescFromCmd(hwndDlg, cmd);
					}
					delete [] buf;
				}
				break;
			case CBN_KILLFOCUS:
				updateDescFromCmd(hwndDlg, getDlgItemText(hwndDlg, IDC_CMD_BOX));
				break;
			}
			break;
		case IDC_INJECT:
			worker_thread::injectDialog(hwndDlg);
			/*
			{
				std::wstring result = _T("");
				std::wstring cmd = getDlgItemText(hwndDlg, IDC_CMD_BOX);
				std::wstring args = getDlgItemText(hwndDlg, IDC_ARG_BOX);
				std::wstring msg;
				std::wstring perf;
				try {
					int ret = gTrayInstance->inject(cmd, args, _T(" "), true, msg, perf);
					//NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd, args, ' ', msg, perf);
					/ *
					if (ret == NSCAPI::returnIgnored) {
						result = _T("Command not found!");
					} else {
						result = NSCHelper::translateReturn(ret);
					}
					* /
					result = _T("TODO: re-implement this: ") + strEx::itos(ret);
				//} catch (NSCModuleHelper::NSCMHExcpetion &e) {
				//	result = _T("Error: ") + e.msg_;
				} catch (...) {
					result = _T("Unknown error!");
				}
				SetDlgItemText(hwndDlg, IDC_DESCRIPTION, result.c_str());
				SetDlgItemText(hwndDlg, IDC_MSG, msg.c_str());
				SetDlgItemText(hwndDlg, IDC_PERF, perf.c_str());
			}
	*/
			break;
		case IDOK: 
			{
				TCHAR *c=new TCHAR[1024];
				if (GetDlgItemText(hwndDlg, IDC_COMMAND, c, 1023))
					TrayIcon::defaultCommand = c;
				delete [] c;
			}

		case IDCANCEL: 
			EndDialog(hwndDlg, wParam); 
			return TRUE; 
		} 
	}
	return FALSE;
}
BOOL AP_Win32Dialog_MailMerge::_onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	WORD wNotifyCode = HIWORD(wParam);
	WORD wId = LOWORD(wParam);
	HWND hWndCtrl = (HWND)lParam;

	switch (wId)
	{
		case AP_RID_DIALOG_MAILMERGE_LISTBOX:
		if (HIWORD(wParam)==LBN_DBLCLK)
		{
			UT_Win32LocaleString str;
			int nItem = SendMessageW(GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX), LB_GETCURSEL, 0, 0);
			
			if (nItem!=LB_ERR)
			{	
				// get the mail merge field from the listbox
				HWND lBox = GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX);
				UT_sint32 len = SendMessageW(lBox, LB_GETTEXTLEN, nItem, (LPARAM)0);
				wchar_t* szBuff = (wchar_t*)g_malloc(sizeof(wchar_t) * (len + 1));
				SendMessageW(lBox, LB_GETTEXT, nItem, (LPARAM)szBuff);
				str.fromLocale(szBuff);
				FREEP(szBuff);

				setMergeField(str.utf8_str());			
				addClicked();
			}
			return 1;
		}
		else
		{
			return 0;
		}
		
		case AP_RID_DIALOG_MAILMERGE_BTN_INSERT:		
		{	
			UT_Win32LocaleString str;	
			int nChars = getDlgItemText(AP_RID_DIALOG_MAILMERGE_EDIT_FIELD, str);
			if (nChars > 0)
			{
				setMergeField(str.utf8_str ());
				addClicked();
			} 
			else
			{
				int nItem = SendMessageW(GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX), LB_GETCURSEL, 0, 0);
			
				if (nItem!=LB_ERR)
				{	
					// get the mail merge field from the listbox
					HWND lBox = GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX);
					UT_sint32 len = SendMessageW(lBox, LB_GETTEXTLEN, nItem, (LPARAM)0);
					wchar_t* szBuff = (wchar_t*)g_malloc(sizeof(wchar_t) * (len + 1));
					SendMessageW(lBox, LB_GETTEXT, nItem, (LPARAM)szBuff);
					str.fromLocale(szBuff);
					FREEP(szBuff);

					setMergeField(str.utf8_str());
					addClicked();
				}				 
			}

			return 1;
		}
		
		case AP_RID_DIALOG_MAILMERGE_BTN_OPEN:		
		{			
			eventOpen();
			SetFocus(m_hDlg);
			return 1;
		}	
				
		case AP_RID_DIALOG_MAILMERGE_BTN_CLOSE:		
		case IDCANCEL:		// We want to close button work
		{			
			destroy();
			return 1;
		}	
		
		default:							// we did not handle this notification
			UT_DEBUGMSG(("WM_Command for id %ld\n",wId));
			return 0;						// return zero to let windows take care of it.
	}
}
Exemple #3
0
	DWORD threadProc(LPVOID lpParameter) {
		start_block* param = static_cast<start_block*>(lpParameter);
		std::wstring cmd = param->cmd;
		HMENU hMenu = param->hMenu;
		HWND hWnd = param->hWnd;
		delete param;
		if (cmd == _T("update-status")) {
			update(hMenu, ID_SERVICE_STATUS, _T("getting..."));
			try {
				if (serviceControll::isStarted(SZSERVICENAME)) {
					update(hMenu, ID_SERVICE_STATUS, _T("Started"));
				} else {
					update(hMenu, ID_SERVICE_STATUS, _T("Stopped"));
				}
			} catch (serviceControll::SCException &e) {
				LOG_ERROR_TO_TRAY(_T("Failed to get service information: ") + e.error_);
			} catch (...) {
				LOG_ERROR_TO_TRAY(_T("Failed to get service information: Unknown error"));
			}
		} else if (cmd == _T("start-service")) {
			update(hMenu, ID_SERVICE_STATUS, _T("Starting"));
			try {
				serviceControll::Start(SZSERVICENAME);
				update(hMenu, ID_SERVICE_STATUS, _T("Started"));
			} catch (serviceControll::SCException &e) {
				update(hMenu, ID_SERVICE_STATUS, _T("Unknown (failed to start)"));
				LOG_ERROR_TO_TRAY(_T("Failed to get service information: ") + e.error_);
			} catch (...) {
				update(hMenu, ID_SERVICE_STATUS, _T("Unknown (failed to start)"));
				LOG_ERROR_TO_TRAY(_T("Failed to get service information: Unknown error"));
			}
		} else if (cmd == _T("stop-service")) {
			update(hMenu, ID_SERVICE_STATUS, _T("Stopped"));
			try {
				serviceControll::Stop(SZSERVICENAME);
				update(hMenu, ID_SERVICE_STATUS, _T("Stopped"));
			} catch (serviceControll::SCException &e) {
				update(hMenu, ID_SERVICE_STATUS, _T("Unknown (failed to stop)"));
				LOG_ERROR_TO_TRAY(_T("Failed to get service information: ") + e.error_);
			} catch (...) {
				update(hMenu, ID_SERVICE_STATUS, _T("Unknown (failed to stop)"));
				LOG_ERROR_TO_TRAY(_T("Failed to get service information: Unknown error"));
			}
		} else if (cmd == _T("inject-button-pressed")) {
			std::wstring result = _T("");
			std::wstring cmd = getDlgItemText(hWnd, IDC_CMD_BOX);
			std::wstring args = getDlgItemText(hWnd, IDC_ARG_BOX);
			std::wstring msg;
			std::wstring perf;
			try {
				int ret = gTrayInstance->inject(cmd, args, L' ', true, msg, perf);
				//NSCAPI::nagiosReturn ret = NSCModuleHelper::InjectSplitAndCommand(cmd, args, ' ', msg, perf);
				/*
				if (ret == NSCAPI::returnIgnored) {
				result = _T("Command not found!");
				} else {
				result = NSCHelper::translateReturn(ret);
				}
				*/
				result = _T("TODO: re-implement this: ") + strEx::itos(ret);
				//} catch (NSCModuleHelper::NSCMHExcpetion &e) {
				//	result = _T("Error: ") + e.msg_;
			} catch (...) {
				result = _T("Unknown error!");
			}
			SetDlgItemText(hWnd, IDC_DESCRIPTION, result.c_str());
			SetDlgItemText(hWnd, IDC_MSG, msg.c_str());
			SetDlgItemText(hWnd, IDC_PERF, perf.c_str());
		} else if (cmd == _T("connect-service")) {
			gTrayInstance->connectService();
		}
		return 0;
	}
void AP_Win32Dialog_Annotation::_get_text(int nID, std::string &text)
{
	UT_Win32LocaleString str;
	getDlgItemText(nID, str);
	text = str.utf8_str().utf8_str();
}