Esempio n. 1
0
INT_PTR CALLBACK OptionsDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            HWND toolbarCombo = GetDlgItem(hwndDlg, IDC_DISPLAYSTYLECOMBO);
            HWND searchboxCombo = GetDlgItem(hwndDlg, IDC_SEARCHBOX_DISPLAYSTYLECOMBO);

            ComboBox_AddString(toolbarCombo, L"No Text Labels"); // Displays no text label for the toolbar buttons.
            ComboBox_AddString(toolbarCombo, L"Selective Text"); // (Selective Text On Right) Displays text for just the Refresh, Options, Find Handles and Sysinfo toolbar buttons.
            ComboBox_AddString(toolbarCombo, L"Show Text Labels"); // Displays text labels for the toolbar buttons.
            ComboBox_SetCurSel(toolbarCombo, PhGetIntegerSetting(SETTING_NAME_TOOLBARDISPLAYSTYLE));
            
            ComboBox_AddString(searchboxCombo, L"Always show");
            ComboBox_AddString(searchboxCombo, L"Hide when inactive");
            //ComboBox_AddString(searchboxCombo, L"Auto-hide");
            ComboBox_SetCurSel(searchboxCombo, PhGetIntegerSetting(SETTING_NAME_SEARCHBOXDISPLAYMODE));

            Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLE_TOOLBAR),
                PhGetIntegerSetting(SETTING_NAME_ENABLE_TOOLBAR) ? BST_CHECKED : BST_UNCHECKED);
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLE_SEARCHBOX),
                PhGetIntegerSetting(SETTING_NAME_ENABLE_SEARCHBOX) ? BST_CHECKED : BST_UNCHECKED);
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLE_STATUSBAR),
                PhGetIntegerSetting(SETTING_NAME_ENABLE_STATUSBAR) ? BST_CHECKED : BST_UNCHECKED);
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_RESOLVEGHOSTWINDOWS),
                PhGetIntegerSetting(SETTING_NAME_ENABLE_RESOLVEGHOSTWINDOWS) ? BST_CHECKED : BST_UNCHECKED);
        }
        break;
    case WM_COMMAND:
        {
            switch (GET_WM_COMMAND_ID(wParam, lParam))
            {
            case IDCANCEL:
                EndDialog(hwndDlg, IDCANCEL);
                break;
            case IDC_CUSTOMIZETOOLBAR:
                PostMessage(ToolBarHandle, TB_CUSTOMIZE, 0, 0);
                break;
            case IDOK:
                {
                    PhSetIntegerSetting(SETTING_NAME_TOOLBARDISPLAYSTYLE,
                        (DisplayStyle = (TOOLBAR_DISPLAY_STYLE)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_DISPLAYSTYLECOMBO))));
                    PhSetIntegerSetting(SETTING_NAME_SEARCHBOXDISPLAYMODE,
                        (SearchBoxDisplayMode = (SEARCHBOX_DISPLAY_MODE)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_SEARCHBOX_DISPLAYSTYLECOMBO))));
                    PhSetIntegerSetting(SETTING_NAME_ENABLE_TOOLBAR,
                        (EnableToolBar = Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLE_TOOLBAR)) == BST_CHECKED));
                    PhSetIntegerSetting(SETTING_NAME_ENABLE_SEARCHBOX,
                        (EnableSearchBox = Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLE_SEARCHBOX)) == BST_CHECKED));
                    PhSetIntegerSetting(SETTING_NAME_ENABLE_STATUSBAR,
                        (EnableStatusBar = Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLE_STATUSBAR)) == BST_CHECKED));
                    PhSetIntegerSetting(SETTING_NAME_ENABLE_RESOLVEGHOSTWINDOWS,
                        Button_GetCheck(GetDlgItem(hwndDlg, IDC_RESOLVEGHOSTWINDOWS)) == BST_CHECKED);

                    LoadToolbarSettings();
                    InvalidateRect(ToolBarHandle, NULL, TRUE);

                    EndDialog(hwndDlg, IDOK);
                }
                break;
            }
        }
        break;
    }

    return FALSE;
}
Esempio n. 2
0
//ダイアログボックスのプロシージャ
BOOL CALLBACK MyDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
    static HWND hRadio1, hRadio2, hRadio3, hRadio4;
    static HWND hCheck1, hCombo1, hList1, hEdit1, hScrol1;
    TCHAR szBuf[64];
    TCHAR szList[5][16] = { TEXT("飼っていない"), TEXT("犬"),
                            TEXT("猫"), TEXT("ねずみ"), TEXT("馬")};
    TCHAR szCombo[6][16] = { TEXT("北海道"), TEXT("本州"), TEXT("四国"),
                             TEXT("九州"), TEXT("沖縄"), TEXT("その他") };
    static HWND hMain;
    int id, n;
    BOOL bSuccess;

    switch (msg) {
        case WM_HSCROLL:        // スクロールイベントの処理
            if (lp != (LPARAM)hScrol1)
                return FALSE;
            switch (LOWORD(wp)) {
                case SB_LEFT:
                    nPos = 0;
                    break;
                case SB_RIGHT:
                    nPos = 100;
                    break;
                case SB_LINELEFT:
                    nPos--;
                    if (nPos < 0)   nPos = 0;
                    break;
                case SB_LINERIGHT:
                    nPos++;
                    if (nPos > 100) nPos = 100;
                    break;
                case SB_PAGELEFT:
                    nPos -= 10;
                    if (nPos > 100) nPos = 100;
                    break;
                case SB_PAGERIGHT:
                    nPos += 10;
                    if (nPos < 0)   nPos = 0;
                    break;
                case SB_THUMBTRACK:
                case SB_THUMBPOSITION:
                    nPos = HIWORD(wp);
                    break;
                
            }

            // スクロールつまみを移動させる
            ScrollBar_SetPos(hScrol1, nPos, TRUE);

            wsprintf(szBuf, TEXT("%03d"), nPos);
            Edit_SetText(hEdit1, szBuf);
            wsprintf(szText[5],
                TEXT("スクロールバーの位置=%03d"), nPos);
            InvalidateRect(hMain, NULL, TRUE);
            return TRUE;
        case WM_INITDIALOG:
            //親ウィンドウのハンドル取得
            hMain = GetParent(hDlg);
            //各コントロールのハンドルを取得
            hRadio1 = GetDlgItem(hDlg, IDC_RADIO1);
            hRadio2 = GetDlgItem(hDlg, IDC_RADIO2);
            hRadio3 = GetDlgItem(hDlg, IDC_RADIO3);
            hRadio4 = GetDlgItem(hDlg, IDC_RADIO4);
            hCheck1 = GetDlgItem(hDlg, IDC_CHECK1);
            hCombo1 = GetDlgItem(hDlg, IDC_COMBO1);
            hList1 = GetDlgItem(hDlg, IDC_LIST1);
            hEdit1 = GetDlgItem(hDlg, IDC_EDIT1);
            hScrol1 = GetDlgItem(hDlg, IDC_SCROLLBAR1);
            //スクロールバーの初期設定
            ScrollBar_SetRange(hScrol1, 0, 100, TRUE);
            ScrollBar_SetPos(hScrol1, nPos, TRUE);
            //ラジオグループの初期設定
            if (nSex == 0)
                Button_SetCheck(hRadio1, BST_CHECKED);
            else
                Button_SetCheck(hRadio2, BST_CHECKED);
            if (nNation == 0)
                Button_SetCheck(hRadio3, BST_CHECKED);
            else
                Button_SetCheck(hRadio4, BST_CHECKED);
            //チェックボックスの設定
            if (n20 == 1)
                Button_SetCheck(hCheck1, BST_CHECKED);
            else
                Button_SetCheck(hCheck1, BST_UNCHECKED);
            //コンボボックスに文字列を加える
            for (n = 0; n < 6; n++)
                ComboBox_AddString(hCombo1, szCombo[n]);
            //リストボックスに文字列を加える
            for (n = 0; n < 5; n++)
                ListBox_AddString(hList1, szList[n]);
            //コンボボックスの初期値
            ComboBox_SetCurSel(hCombo1, nAddress);
            ListBox_SetCurSel(hList1, nPet);
            wsprintf(szBuf, TEXT("%03d"), nPos);
            Edit_SetText(hEdit1, szBuf);
            return TRUE;
        case WM_COMMAND:
            switch (LOWORD(wp)) {
                case IDCANCEL:
                    EndDialog(hDlg, IDCANCEL);
                    return TRUE;
                case IDOK:
                    if (nSex == 0)
                        lstrcpy(szText[0], TEXT("男が選択されました"));
                    else
                        lstrcpy(szText[0], TEXT("女が選択されました"));
                    if (nNation == 0)
                        lstrcpy(szText[1], TEXT("日本が選択されました"));
                    else
                        lstrcpy(szText[1], 
                        TEXT("日本以外が選択されました"));
                    if (n20 == 0)
                        lstrcpy(szText[2], TEXT("20歳未満です"));
                    else
                        lstrcpy(szText[2], TEXT("20歳以上です"));
                    wsprintf(szText[3], TEXT("%sが選択されました"),
                             szCombo[nAddress]);
                    wsprintf(szText[4], TEXT("%sが選択されました"),
                             szList[nPet]);
                    wsprintf(szText[5],
                             TEXT("スクロールバーの位置=%03d"), nPos);
                    InvalidateRect(hMain, NULL, TRUE);
                    EndDialog(hDlg, IDOK);
                    return TRUE;
                case IDC_RADIO1:
                    nSex = 0;
                    lstrcpy(szText[0], TEXT("男が選択されました"));
                    InvalidateRect(hMain, NULL, TRUE);
                    return TRUE;
                case IDC_RADIO2:
                    nSex = 1;
                    lstrcpy(szText[0], TEXT("女が選択されました"));
                    InvalidateRect(hMain, NULL, TRUE);
                    return TRUE;
                case IDC_RADIO3:
                    nNation = 0;
                    lstrcpy(szText[1], TEXT("日本が選択されました"));
                    InvalidateRect(hMain, NULL, TRUE);
                    return TRUE;
                case IDC_RADIO4:
                    nNation = 1;
                    lstrcpy(szText[1], TEXT("日本以外が選択されました"));
                    InvalidateRect(hMain, NULL, TRUE);
                    return TRUE;
                case IDC_CHECK1:
                    if (Button_GetCheck(hCheck1) == BST_CHECKED) {
                        n20 = 1;
                        lstrcpy(szText[2], TEXT("20歳以上です"));
                    } else {
                        n20 = 0;
                        lstrcpy(szText[2], TEXT("20歳未満です"));
                    }
                    InvalidateRect(hMain, NULL, TRUE);
                    return TRUE;
                case IDC_COMBO1:
                    id = ComboBox_GetCurSel(hCombo1);
                    wsprintf(szText[3],
                             TEXT("%sが選択されました"), szCombo[id]);
                    InvalidateRect(hMain, NULL, TRUE);
                    nAddress = id;
                    return TRUE;
                case IDC_LIST1:
                    id = ListBox_GetCurSel(hList1);
                    wsprintf(szText[4],
                             TEXT("%sが選択されました"), szList[id]);
                    InvalidateRect(hMain, NULL, TRUE);
                    nPet = id;
                    return TRUE;
                case IDC_EDIT1:
                    nPos = GetDlgItemInt(
                        hDlg, IDC_EDIT1, &bSuccess, FALSE);
                    if (nPos > 100)
                        nPos = 100;
                    if (nPos < 0)
                        nPos = 0;
                    ScrollBar_SetPos(hScrol1, nPos, TRUE);
                    wsprintf(szText[5],
                             TEXT("スクロールバーの位置=%03d"), nPos);
                    InvalidateRect(hMain, NULL, TRUE);
                    return TRUE;
            }
            return FALSE;
    }
    return FALSE;
}
Esempio n. 3
0
INT_PTR CALLBACK PhpSessionShadowDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            HWND virtualKeyComboBox;
            PH_INTEGER_PAIR hotkey;
            ULONG i;
            PWSTR stringToSelect;

            SetProp(hwndDlg, L"SessionId", (HANDLE)(ULONG)lParam);
            PhCenterWindow(hwndDlg, GetParent(hwndDlg));

            hotkey = PhGetIntegerPairSetting(L"SessionShadowHotkey");

            // Set up the hotkeys.

            virtualKeyComboBox = GetDlgItem(hwndDlg, IDC_VIRTUALKEY);
            stringToSelect = L"{*}";

            for (i = 0; i < sizeof(VirtualKeyPairs) / sizeof(PH_KEY_VALUE_PAIR); i++)
            {
                ComboBox_AddString(virtualKeyComboBox, VirtualKeyPairs[i].Key);

                if ((ULONG)VirtualKeyPairs[i].Value == (ULONG)hotkey.X)
                {
                    stringToSelect = VirtualKeyPairs[i].Key;
                }
            }

            PhSelectComboBoxString(virtualKeyComboBox, stringToSelect, FALSE);

            // Set up the modifiers.

            Button_SetCheck(GetDlgItem(hwndDlg, IDC_SHIFT), hotkey.Y & KBDSHIFT);
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_CTRL), hotkey.Y & KBDCTRL);
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_ALT), hotkey.Y & KBDALT);
        }
        break;
    case WM_DESTROY:
        {
            RemoveProp(hwndDlg, L"SessionId");
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
                EndDialog(hwndDlg, IDCANCEL);
                break;
            case IDOK:
                {
                    ULONG sessionId = (ULONG)GetProp(hwndDlg, L"SessionId");
                    ULONG virtualKey;
                    ULONG modifiers;
                    WCHAR computerName[64];
                    ULONG computerNameLength = 64;

                    virtualKey = VK_MULTIPLY;
                    PhFindIntegerSiKeyValuePairs(
                        VirtualKeyPairs,
                        sizeof(VirtualKeyPairs),
                        PhaGetDlgItemText(hwndDlg, IDC_VIRTUALKEY)->Buffer,
                        &virtualKey
                        );

                    modifiers = 0;

                    if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_SHIFT)) == BST_CHECKED)
                        modifiers |= KBDSHIFT;
                    if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_CTRL)) == BST_CHECKED)
                        modifiers |= KBDCTRL;
                    if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_ALT)) == BST_CHECKED)
                        modifiers |= KBDALT;

                    if (GetComputerName(computerName, &computerNameLength))
                    {
                        if (WinStationShadow(NULL, computerName, sessionId, (UCHAR)virtualKey, (USHORT)modifiers))
                        {
                            PH_INTEGER_PAIR hotkey;

                            hotkey.X = virtualKey;
                            hotkey.Y = modifiers;
                            PhSetIntegerPairSetting(L"SessionShadowHotkey", hotkey);

                            EndDialog(hwndDlg, IDOK);
                        }
                        else
                        {
                            PhShowStatus(hwndDlg, L"Unable to remote control the session", 0, GetLastError());
                        }
                    }
                    else
                    {
                        PhShowError(hwndDlg, L"The computer name is too long.");
                    }
                }
                break;
            }
        }
        break;
    }

    return FALSE;
}
void 
ConnectionCommunity::OnWmCommandConnDialog(HWND hwnd, WPARAM wparam, LPARAM lparam, ConnectionInfo * dbname)
{
    wyInt32 id;

    if(HIWORD(wparam) == EN_UPDATE)
    {
		id = LOWORD(wparam);
		
		if(id != IDC_DLGCONNECT_PASSWORD ||	(id == IDC_DLGCONNECT_PASSWORD &&
		   Button_GetCheck(GetDlgItem(hwnd, IDC_DLGCONNECT_STOREPASSWORD))== BST_CHECKED))
        {
			EnableWindow(GetDlgItem(hwnd, IDC_SAVE), TRUE);
			EnableWindow(GetDlgItem(hwnd, IDC_CLONECONN), FALSE);
			m_conndetaildirty = wyTrue;
			return;
		}
	}
	//handle connection name combobox
    /*else if(LOWORD(wparam) == IDC_DESC)
    {
		//if different connection is selected, then save the previous one
		 if((HIWORD(wparam)== CBN_DROPDOWN) && (m_conndetaildirty  == wyTrue))
		 {
			 PostMessage(hwnd, SHOW_CONFIRM, 0, 0);
			 m_conndetaildirty = wyFalse;
		 }
		else if((HIWORD(wparam) == CBN_CLOSEUP) || (HIWORD(wparam) == CBN_SELENDOK))
		{
			if((m_conndetaildirty == wyTrue) && (m_isnewconnection == wyTrue))
			{
				SendMessage(GetDlgItem(hwnd, IDC_DESC), CB_DELETESTRING, m_newconnid, 0);
				
				m_conndetaildirty = wyFalse;
				m_isnewconnection = wyFalse;
				m_newconnid = -1;
			}

			//if connection is selected using keyboard or mouse, display the contents
			GetInitialDetails(hwnd);
			
			/* we have to change the tab selection to server also */
			/*TabCtrl_SetCurSel(GetDlgItem(hwnd, IDC_CONNTAB), 0);
			
			ShowServerOptions(hwnd);
			m_conndetaildirty = wyFalse;
			return;
		}
		else if((HIWORD(wparam)== CBN_SELCHANGE))
		{
			SetFocus(GetDlgItem(hwnd, IDC_DESC));
		}
	}*/
	//handle connection color combobox
	else if(LOWORD(wparam)== IDC_COLORCOMBO||LOWORD(wparam)== IDC_COLORCOMBO3)
	{
		if((HIWORD(wparam) == CBN_DROPDOWN) || (HIWORD(wparam)== CBN_SELCHANGE))
		{
			//Command handler for color combo box
			
			OnWmCommandColorCombo(hwnd, wparam, lparam);
			dbname->m_rgbconn = m_rgbconnection;
			dbname->m_rgbfgconn = m_rgbconnectionfg;
			m_rgbobbkcolor = m_rgbconnection;
			m_rgbobfgcolor = m_rgbconnectionfg;

			//if color is changed in combo, then set m_conndetaildirty to true
			if((HIWORD(wparam)== CBN_SELCHANGE) && (m_conndetaildirty == wyFalse))
			{
				if(m_changeobcolor == wyFalse)
					m_conndetaildirty = wyFalse;
				else
					m_conndetaildirty  = wyTrue;
			}
		}
		
		if(m_conndetaildirty == wyTrue)
		{
			EnableWindow(GetDlgItem(hwnd, IDC_SAVE), TRUE);
			EnableWindow(GetDlgItem(hwnd, IDC_CLONECONN), FALSE);
			dbname->m_rgbconn = m_rgbconnection;
			dbname->m_rgbfgconn = m_rgbconnectionfg;
			m_rgbobbkcolor = m_rgbconnection;
			m_rgbobfgcolor = m_rgbconnectionfg;
		}
		
		return;
	}

	//Handles the common option in 'MySQL' tab
	HandleCommonConnectOptions(hwnd, dbname, LOWORD(wparam));
	
	switch(LOWORD(wparam))
	{
	case IDOK:
        OnConnect(hwnd, dbname);
		break;

	case IDCANCEL:
		yog_enddialog(hwnd, 0);
		break;

	case IDC_DELETE:
		DeleteConnDetail(hwnd);
		break;

	case IDC_NEW:
		if(m_conndetaildirty == wyTrue)
		{
			PostMessage(hwnd, SHOW_CONFIRM, 0, 0);
		}
		m_conndetaildirty = wyFalse;
		NewConnection(hwnd);
		break;

	case IDC_SAVE:
		SaveConnection(hwnd);
		m_conndetaildirty = wyFalse;
		EnableWindow(GetDlgItem(hwnd, IDC_SAVE), FALSE);
		//EnableWindow(GetDlgItem(hwnd, IDC_CLONECONN), TRUE);
		break;

	case IDC_TESTCONN:
		OnTestConnection(hwnd);
		break;
	
	case IDC_CLONECONN:
		CloneConnection(hwnd);
		break;

	case IDC_TUNNELHELP:
		ShowHelp("http://sqlyogkb.webyog.com/article/155-connecting-using-http-tunneling");
		break;

    case IDC_INITCOMMANDHELP:
       ShowHelp("http://sqlyogkb.webyog.com/article/158-advanced-connection-settings");
        break;

	case IDC_SSHHELP:
		ShowHelp("http://sqlyogkb.webyog.com/article/154-connecting-using-ssh-tunneling");
		break;

    case IDC_SSLHELP:
        ShowHelp("http://sqlyogkb.webyog.com/article/157-connecting-using-ssl-encryption");
		break;

	case IDC_TIMEOUTHELP:
	case IDC_COMPRESSHELP:
		 ShowHelp("http://sqlyogkb.webyog.com/article/153-direct-connection-using-mysql-c-api");
		 break;
	}
}
BOOL TabPage_6_OnCommand(HWND hDlg,WPARAM wParam,LPARAM lParm)
{
	HWND hEdit;

	hEdit = GetDlgItem(hDlg,EditControlID[0]);

	switch(LOWORD(wParam))
	{
		//开始计算(无文本)
	case PCA_START:
		{
			Exception excption;
			ErrNo err;

			PCA pca(hDlg);
			if(err = pca.GetStart_Calc())
			{
				excption.ErrorReport(hDlg,err);
				return FALSE;
			}
		}
		return TRUE;

		// 清除样本数据
	case PCA_DATA_CLEAR:
		Edit_SetText(hEdit,TEXT(""));
		break;

	case PCA_DRAW:
		{
			PCTSTR pErrInfo;

			int n_samples,n_index;
			double **data = NULL;

			TCHAR seps[] = TEXT(" ,\t");
			TCHAR szBuffer[MAXSIZE];
			int graph_type,*sample_num,ncount = 0,nLength;
			Exception excption;
			ErrNo err;

			//获取样本个数
			if(err = GetLine_Int(GetDlgItem(hDlg,EditControlID[2]),n_samples))
			{
				excption.ErrorReport(hDlg,err);
				return err;
			}
			//获取指标个数
			if(err = GetLine_Int(GetDlgItem(hDlg,EditControlID[3]),n_index))
			{
				excption.ErrorReport(hDlg,err);
				return err;
			}
			//获取画图类型
			graph_type = ComboBox_GetCurSel(GetDlgItem(hDlg,ComboBoxID));

			

			//获取样本数据
			//申请空间
			if(!(data = new double* [n_samples]))
			{
				excption.ErrorReport(hDlg,ALLOCATE_MEMORY_FAIL);
				return ALLOCATE_MEMORY_FAIL;
			}
			for(int i=0;i<n_samples;i++)
			{
				if(!(data[i] = new double [n_index]))
				{
					excption.ErrorReport(hDlg,ALLOCATE_MEMORY_FAIL);
					return ALLOCATE_MEMORY_FAIL;
				}
			}
			if(err = GetMatrix(GetDlgItem(hDlg,EditControlID[0]),data,n_samples,n_index))
			{
				excption.ErrorReport(hDlg,err);
				return err;
			}

			//判断是否要将全部样本画在图上
			if(Button_GetCheck(GetDlgItem(hDlg,CheckBoxID)) == BST_CHECKED)		//全部都画
			{
				if(err = PCA_DrawGraph(hDlg,data,List_Names,n_samples,n_index,graph_type))
				{
					excption.ErrorReport(hDlg,err);
					return err;
				}
				
			}
			else			//部分画
			{
				//获取要画图的样本数据编号
				Edit_GetText(GetDlgItem(hDlg,EditControlID[1]),szBuffer,MAXSIZE);

				ncount = 0;
				//判断有多少个样本数据编号
				nLength = _tcslen(szBuffer);
				for(int i=0;i<nLength;i++)
				{
					if(szBuffer[i] == TEXT(','))
						ncount++;
				}
				ncount++;

				//申请空间保存要画图的样本标号
				if(!(sample_num = new int [ncount]))
				{
					excption.ErrorReport(hDlg,ALLOCATE_MEMORY_FAIL);
					return ALLOCATE_MEMORY_FAIL;
				}
				if(err = StringToNumbericArr(szBuffer,seps,sample_num,ncount))
				{
					excption.ErrorReport(hDlg,err);
					return err;
				}
				//判断样本编号是否有误
				for(int i=0;i<ncount;i++)
				{
					if(sample_num[i] > n_samples)
					{
						pErrInfo = excption.FormatError(INCORRECT_DATA);
						_sntprintf_s(szBuffer,_countof(szBuffer),MAXSIZE,TEXT("错误ID:%d\r\n错误信息:%s\r\n补充信息:%s"),INCORRECT_DATA,pErrInfo,TEXT("样本编号超过样本个数"));
						MessageBox(hDlg,szBuffer,TEXT("错误"),MB_ICONERROR);
						return INCORRECT_DATA;
					}
				}

				QuickSort(sample_num,0,ncount-1);		//从小到大

				if(err = PCA_DrawGraph(hDlg,data,List_Names,n_samples,n_index,graph_type,false,sample_num,ncount))
				{
					excption.ErrorReport(hDlg,err);
					return err;
				}

			}
		}
		return TRUE;

	case PCA_NAME:
		{
			HINSTANCE hInstance;
			//创建模态对话框
			hInstance = GetModuleHandle(NULL);
			DialogBox(hInstance,MAKEINTRESOURCE(IDD_PCA_NAME),hDlg,PCA_AddNames_Proc);
		}
		return TRUE;

	case ALL_CHECK:			//要画图的样本数据要全部画在图上
		{
			if(Button_GetCheck(GetDlgItem(hDlg,CheckBoxID)) == BST_CHECKED)
				Edit_SetReadOnly(GetDlgItem(hDlg,EditControlID[1]),TRUE);
			else
				Edit_SetReadOnly(GetDlgItem(hDlg,EditControlID[1]),FALSE);
		}
		return TRUE;

	case RC_CLEAR:
		Edit_SetText(GetDlgItem(hDlg,OutPut_ResultID),TEXT(""));
		return TRUE;

	case RC_HELP:
		{

		}
		return TRUE;
	}
	return FALSE;
}
void FrameWindow::OnCommand(WPARAM wParam, LPARAM lParam)
{
    switch (HIWORD(wParam))
    {
    case BN_CLICKED: // also includes STN_CLICKED:
        switch (LOWORD(wParam))
        {
        case IDM_COLORPICKER_FILL:
            {
                CHOOSECOLOR chc = {0};
                chc.lStructSize = sizeof(CHOOSECOLOR);
                chc.hwndOwner = hWnd;
                chc.lpCustColors = customColors;
                chc.rgbResult = workspace.drawingOptions.fillColor;
                chc.Flags = CC_RGBINIT | CC_FULLOPEN;
                if (ChooseColor(&chc) == TRUE)
                {
                    workspace.drawingOptions.fillColor = chc.rgbResult;
                    InvalidateRect(fillColorPicker.GetHWND(), NULL, FALSE);
                }
            }
            break;

        case IDM_COLORPICKER_STROKE:
            {
                CHOOSECOLOR chc = {0};
                chc.lStructSize = sizeof(CHOOSECOLOR);
                chc.hwndOwner = hWnd;
                chc.lpCustColors = customColors;
                chc.rgbResult = workspace.drawingOptions.strokeColor;
                chc.Flags = CC_RGBINIT | CC_FULLOPEN;
                if (ChooseColor(&chc) == TRUE)
                {
                    workspace.drawingOptions.strokeColor = chc.rgbResult;
                    InvalidateRect(strokeColorPicker.GetHWND(), NULL, FALSE);
                }
            }
            break;

        case IDM_RADIO_SELECT:
            workspace.drawingOptions.tool = SELECT;
            break;

        case IDM_RADIO_PENCIL:
            workspace.drawingOptions.tool = PENCIL;
            break;

        case IDM_RADIO_ELLIPSE:
            workspace.drawingOptions.tool = ELLIPSE;
            break;

        case IDM_RADIO_RECTANGLE:
            workspace.drawingOptions.tool = RECTANGLE;
            break;

        case IDM_RADIO_ZOOMIN:
            workspace.drawingOptions.tool = ZOOMIN;
            break;

        case IDM_RADIO_ZOOMOUT:
            workspace.drawingOptions.tool = ZOOMOUT;
            break;


        case IDM_CHKBX_FILL:
            if (Button_GetCheck(GetDlgItem(hWnd, IDM_CHKBX_FILL)) == BST_CHECKED)
            {
                workspace.drawingOptions.noFill = false;
            }
            else
            {
                workspace.drawingOptions.noFill = true;
            }
            break;

        case IDM_CHKBX_STROKE:
            if (Button_GetCheck(GetDlgItem(hWnd, IDM_CHKBX_STROKE)) == BST_CHECKED)
            {
                workspace.drawingOptions.noStroke = false;
            }
            else
            {
                workspace.drawingOptions.noStroke = true;
            }
            break;

        default:
            break;
        }

    default:
        break;
    }
}
Esempio n. 7
0
BOOL CALLBACK selection_properties_config_t::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
	switch (msg)
	{
	case WM_INITDIALOG:
	{
		pfc::vartoggle_t<bool> init(m_initialising, true);

		HWND wnd_fields = m_field_list.create_in_dialog_units(wnd, ui_helpers::window_position_t(21, 17, 226, 150));
		SetWindowPos(wnd_fields, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
		ShowWindow(wnd_fields, SW_SHOWNORMAL);

		HWND wnd_lv = GetDlgItem(wnd, IDC_INFOSECTIONS);
		ListView_SetExtendedListViewStyleEx(wnd_lv, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES);
		g_set_listview_window_explorer_theme(wnd_lv);

		RECT rc;
		GetClientRect(wnd_lv, &rc);
		ListView_InsertColumnText(wnd_lv, 0, L"", RECT_CX(rc));

		t_size i, count = tabsize(g_info_sections);
		for (i = 0; i < count; i++)
		{
			ListView_InsertItemText(wnd_lv, i, 0, g_info_sections[i].name);
			ListView_SetCheckState(wnd_lv, i, (m_info_sections_mask & (1 << g_info_sections[i].id)) ? TRUE : FALSE);
		}

		HWND wnd_combo = GetDlgItem(wnd, IDC_EDGESTYLE);
		ComboBox_AddString(wnd_combo, L"None");
		ComboBox_AddString(wnd_combo, L"Sunken");
		ComboBox_AddString(wnd_combo, L"Grey");
		ComboBox_SetCurSel(wnd_combo, m_edge_style);

		Button_SetCheck(GetDlgItem(wnd, IDC_SHOWCOLUMNS), m_show_columns ? BST_CHECKED : BST_UNCHECKED);
		Button_SetCheck(GetDlgItem(wnd, IDC_SHOWGROUPS), m_show_groups ? BST_CHECKED : BST_UNCHECKED);
	}
	break;
	case WM_DESTROY:
	{
		m_field_list.destroy();
	}
	break;
	case WM_ERASEBKGND:
		SetWindowLongPtr(wnd, DWL_MSGRESULT, TRUE);
		return TRUE;
	case WM_PAINT:
		ui_helpers::innerWMPaintModernBackground(wnd, GetDlgItem(wnd, IDOK));
		return TRUE;
	case WM_CTLCOLORSTATIC:
		SetBkColor((HDC)wp, GetSysColor(COLOR_WINDOW));
		SetTextColor((HDC)wp, GetSysColor(COLOR_WINDOWTEXT));
		return (BOOL)GetSysColorBrush(COLOR_WINDOW);
	case WM_NOTIFY:
	{
		LPNMHDR lpnm = (LPNMHDR)lp;
		switch (lpnm->idFrom)
		{
		case IDC_INFOSECTIONS:
			switch (lpnm->code)
			{
			case LVN_ITEMCHANGED:
			{
				LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lp;
				if (!m_initialising && lpnmlv->iItem < tabsize(g_info_sections) && (lpnmlv->uChanged & LVIF_STATE))
				{
					m_info_sections_mask = m_info_sections_mask & ~(1 << g_info_sections[lpnmlv->iItem].id);

					//if (((((UINT)(lpnmlv->uNewState & LVIS_STATEIMAGEMASK )) >> 12) -1))
					if (ListView_GetCheckState(lpnm->hwndFrom, lpnmlv->iItem))
						m_info_sections_mask = m_info_sections_mask | (1 << g_info_sections[lpnmlv->iItem].id);

				}
			}
			break;
			};
			break;
		};
	}
	break;
	case WM_COMMAND:
		switch (LOWORD(wp))
		{
		case IDOK:
			EndDialog(wnd, 1);
			break;
		case IDCANCEL:
			EndDialog(wnd, 0);
			break;
		case IDC_SHOWCOLUMNS:
			m_show_columns = Button_GetCheck((HWND)lp) != 0;
			break;
		case IDC_SHOWGROUPS:
			m_show_groups = Button_GetCheck((HWND)lp) != 0;
			break;
		case IDC_EDGESTYLE:
			switch (HIWORD(wp))
			{
			case CBN_SELCHANGE:
				m_edge_style = ComboBox_GetCurSel((HWND)lp);
				break;
			}
			break;
		case IDC_UP:
		{
			if (m_field_list.get_selection_count(2) == 1)
			{
				t_size index = 0, count = m_field_list.get_item_count();
				while (!m_field_list.get_item_selected(index) && index < count) index++;
				if (index && m_fields.get_count())
				{
					m_fields.swap_items(index, index - 1);

					pfc::list_t<t_list_view::t_item_insert> items;
					m_field_list.get_insert_items(index - 1, 2, items);
					m_field_list.replace_items(index - 1, items);
					m_field_list.set_item_selected_single(index - 1);
				}
			}
		}
		break;
		case IDC_DOWN:
		{
			if (m_field_list.get_selection_count(2) == 1)
			{
				t_size index = 0, count = m_field_list.get_item_count();
				while (!m_field_list.get_item_selected(index) && index < count) index++;
				if (index + 1 < count && index + 1 < m_fields.get_count())
				{
					m_fields.swap_items(index, index + 1);

					pfc::list_t<t_list_view::t_item_insert> items;
					m_field_list.get_insert_items(index, 2, items);
					m_field_list.replace_items(index, items);
					m_field_list.set_item_selected_single(index + 1);
				}
			}
		}
		break;
		case IDC_NEW:
		{
			field_t temp;
			temp.m_name_friendly = "<enter name here>";
			temp.m_name = "<ENTER FIELD HERE>";
			t_size index = m_fields.add_item(temp);

			pfc::list_t<t_list_view::t_item_insert> items;
			m_field_list.get_insert_items(index, 1, items);
			m_field_list.insert_items(index, 1, items.get_ptr());
			m_field_list.set_item_selected_single(index);
			SetFocus(m_field_list.get_wnd());
			m_field_list.activate_inline_editing();

		}
		break;
		case IDC_REMOVE:
		{
			if (m_field_list.get_selection_count(2) == 1)
			{
				bit_array_bittable mask(m_field_list.get_item_count());
				m_field_list.get_selection_state(mask);
				//bool b_found = false;
				t_size index = 0, count = m_field_list.get_item_count();
				while (index < count)
				{
					if (mask[index]) break;
					index++;
				}
				if (index < count && index < m_fields.get_count())
				{
					m_fields.remove_by_idx(index);
					m_field_list.remove_item(index);
					t_size new_count = m_field_list.get_item_count();
					if (new_count)
					{
						if (index < new_count)
							m_field_list.set_item_selected_single(index);
						else if (index)
							m_field_list.set_item_selected_single(index - 1);
					}
				}
			}
		}
		break;
		}
		break;
	}
	return FALSE;
}
Esempio n. 8
0
INT_PTR CALLBACK HotkeyDialogProc (HWND hwnd, UINT uMsg,
                                   WPARAM wParam, LPARAM lParam) {
	WORD keyControl = 0;
	UINT nFsModifiers=0,nVKey=0;
	switch (uMsg) {
		case WM_INITDIALOG:
			if (fsModifiers & MOD_ALT) {
				SendMessage(GetDlgItem(hwnd,IDC_ALT),BM_SETCHECK,BST_CHECKED,0);
			}
			if (fsModifiers & MOD_CONTROL) {
				SendMessage(GetDlgItem(hwnd,IDC_CTRL),BM_SETCHECK,BST_CHECKED,0);
			}
			if (fsModifiers & MOD_SHIFT) {
				SendMessage(GetDlgItem(hwnd,IDC_SHIFT),BM_SETCHECK,BST_CHECKED,0);
			}
			switch (vKey) {
				case VK_SPACE:
					keyControl = IDC_SPACE;
					break;
				case 'F':
					keyControl = IDC_F;
					break;
				case VK_OEM_3:
					keyControl = IDC_TILDE;
					break;
			}
			if (keyControl != 0) {
				SendMessage(GetDlgItem(hwnd,keyControl),BM_SETCHECK,BST_CHECKED,0);
			}
			return TRUE;
		case WM_COMMAND:
			switch (wParam) {
				case IDOK:
					nFsModifiers |= (MOD_SHIFT   * Button_GetCheck(GetDlgItem(hwnd,IDC_SHIFT)));
					nFsModifiers |= (MOD_ALT     * Button_GetCheck(GetDlgItem(hwnd,IDC_ALT)));
					nFsModifiers |= (MOD_CONTROL * Button_GetCheck(GetDlgItem(hwnd,IDC_CTRL)));

					if (Button_GetCheck(GetDlgItem(hwnd,IDC_F))) {
						nVKey = 'F';
					} else if( (Button_GetCheck(GetDlgItem(hwnd,IDC_SPACE)))) {
						nVKey = VK_SPACE;
					} else if( (Button_GetCheck(GetDlgItem(hwnd,IDC_TILDE)))) {
						nVKey = VK_OEM_3;
					} else {
						nVKey = vKey;
					}

					if (nVKey != vKey || nFsModifiers != fsModifiers) {
						// remove old hotkey
						UnregisterHotKey(mainWindow,1);
						vKey = nVKey;
						fsModifiers = nFsModifiers;

						// place new hotkey
						if (RegisterHotKey(mainWindow,
									    1,
									    fsModifiers,
									    vKey) == FALSE) {
							MessageBox(NULL,"Failed to Create Hotkey!", NULL, NULL);
							return 1;
						}

						// save registry
						if (RegSetValueEx(regKey,
										"fsModifiers",
										NULL,
										REG_DWORD,
										(BYTE*)&fsModifiers,
										sizeofUINT) != ERROR_SUCCESS ||
							RegSetValueEx(regKey,
										"vKey",
										NULL,
										REG_DWORD,
										(BYTE*)&vKey,
										sizeofUINT) != ERROR_SUCCESS) {
							MessageBox(NULL,"Failed to write registry!", NULL,NULL);
							return 1;
						}
					}
				case IDCANCEL:
					EndDialog(hwnd,0);
					return TRUE;
			}
			break;
	}
	return FALSE;
}
void ShareSetupPage::updateDialog()
{
	EnableWindow(m_hEditAutoIndexInterval,Button_GetCheck(m_hCheckAutoIndex));
}
Esempio n. 10
0
INT_PTR CALLBACK ResetDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch (Msg)
	{
		case WM_INITDIALOG:
			CenterWindow(hDlg);
			hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAMEUI_ICON));
			SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
			hBrush = CreateSolidBrush(RGB(240, 240, 240));
			DisableVisualStylesReset(hDlg);
			return true;

		case WM_CTLCOLORDLG:
			return (LRESULT) hBrush;	
		
		case WM_CTLCOLORSTATIC:
		case WM_CTLCOLORBTN:
			hDC = (HDC)wParam;
			SetBkMode(hDC, TRANSPARENT);
			SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
			return (LRESULT) hBrush;

		case WM_COMMAND:
			switch (GET_WM_COMMAND_ID(wParam, lParam))
			{
				case IDOK:
				{
					bool resetFilters = Button_GetCheck(GetDlgItem(hDlg, IDC_RESET_FILTERS));
					bool resetGames = Button_GetCheck(GetDlgItem(hDlg, IDC_RESET_GAMES));
					bool resetDefaults = Button_GetCheck(GetDlgItem(hDlg, IDC_RESET_DEFAULT));
					bool resetUI = Button_GetCheck(GetDlgItem(hDlg, IDC_RESET_UI));
					bool resetInternalUI = Button_GetCheck(GetDlgItem(hDlg, IDC_RESET_MAME_UI));

					if (resetFilters || resetGames || resetUI || resetDefaults || resetInternalUI)
					{
						char temp[512];
						strcpy(temp, MAMEUINAME);
						strcat(temp, " will now reset the following\n");
						strcat(temp, "to the default settings:\n\n");

						if (resetDefaults)
							strcat(temp, "Global games options\n");

						if (resetInternalUI)
							strcat(temp, "Internal MAME interface options\n");

						if (resetGames)
							strcat(temp, "Individual game options\n");

						if (resetFilters)
							strcat(temp, "Custom folder filters\n");

						if (resetUI)
						{
							strcat(temp, "User interface settings\n\n");
							strcat(temp, "Resetting the user interface options\n");
							strcat(temp, "requires exiting ");
							strcat(temp, MAMEUINAME);
							strcat(temp, ".\n");
						}

						strcat(temp, "\nDo you wish to continue?");

						if (win_message_box_utf8(hDlg, temp, "Restore settings", MB_ICONQUESTION | MB_YESNO) == IDYES)
						{
							DestroyIcon(hIcon);
							DeleteObject(hBrush);

							if (resetFilters)
								ResetFilters();

							if (resetGames)
								ResetAllGameOptions();

							if (resetDefaults)
								ResetGameDefaults();

							if (resetInternalUI)
								ResetInternalUI();

							// This is the only case we need to exit and restart for.
							if (resetUI)
							{
								ResetInterface();
								EndDialog(hDlg, 1);
								return true;
							}
							else 
							{
								EndDialog(hDlg, 0);
								return true;
							}
						}
						else 
							// Give the user a chance to change what they want to reset.
							break;
					}
				}
		
				// Nothing was selected but OK, just fall through
				case IDCANCEL:
					DeleteObject(hBrush);
					DestroyIcon(hIcon);
					EndDialog(hDlg, 0);
					return true;
			}

			break;
	}

	return false;
}
Esempio n. 11
0
int BoolConfigControl::GetIntValue()
{
    if( Button_GetCheck( checkbox ) ) return 1;
    else return 0;
}
Esempio n. 12
0
INT_PTR CALLBACK FilterDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch (Msg)
	{
		case WM_INITDIALOG:
		{
			CenterWindow(hDlg);
			hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAMEUI_ICON));
			SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
			hBrush = CreateSolidBrush(RGB(240, 240, 240));
			DisableVisualStylesFilters(hDlg);
			LPTREEFOLDER folder = GetCurrentFolder();
			LPTREEFOLDER lpParent = NULL;
			LPCFILTER_ITEM g_lpFilterList = GetFilterList();
			dwFilters = 0;

			if (folder != NULL)
			{
				char tmp[80];
				win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_EDIT), g_FilterText.c_str());
				Edit_SetSel(GetDlgItem(hDlg, IDC_FILTER_EDIT), 0, -1);
				// Mask out non filter flags
				dwFilters = folder->m_dwFlags & F_MASK;
				// Display current folder name in dialog titlebar
				snprintf(tmp, WINUI_ARRAY_LENGTH(tmp), "Filters for %s folder", folder->m_lpTitle);
				win_set_window_text_utf8(hDlg, tmp);

				if (GetFilterInherit())
				{
					lpParent = GetFolder(folder->m_nParent);
					bool bShowExplanation = false;

					if (lpParent)
					{
						std::string strText;
						/* Check the Parent Filters and inherit them on child,
						* No need to promote all games to parent folder, works as is */
						dwpFilters = lpParent->m_dwFlags & F_MASK;
						/*Check all possible Filters if inherited solely from parent, e.g. not being set explicitly on our folder*/

						if ((dwpFilters & F_CLONES) && !(dwFilters & F_CLONES))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_CLONES));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_CLONES), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_NONWORKING) && !(dwFilters & F_NONWORKING))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_NONWORKING));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_NONWORKING), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_UNAVAILABLE) && !(dwFilters & F_UNAVAILABLE))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_UNAVAILABLE));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_UNAVAILABLE), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_VECTOR) && !(dwFilters & F_VECTOR))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_VECTOR));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_VECTOR), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_RASTER) && !(dwFilters & F_RASTER))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_RASTER));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_RASTER), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_ORIGINALS) && !(dwFilters & F_ORIGINALS))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_ORIGINALS));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_ORIGINALS), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_WORKING) && !(dwFilters & F_WORKING))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_WORKING));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_WORKING), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_AVAILABLE) && !(dwFilters & F_AVAILABLE))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_AVAILABLE));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_AVAILABLE), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_HORIZONTAL) && !(dwFilters & F_HORIZONTAL))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_HORIZONTAL));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_HORIZONTAL), strText.c_str());
							bShowExplanation = true;
						}

						if ((dwpFilters & F_VERTICAL) && !(dwFilters & F_VERTICAL))
						{
							/*Add a Specifier to the Checkbox to show it was inherited from the parent*/
							strText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_VERTICAL));
							strText.append(" (*)");
							win_set_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_VERTICAL), strText.c_str());
							bShowExplanation = true;
						}
						/*Do not or in the Values of the parent, so that the values of the folder still can be set*/
						//dwFilters |= dwpFilters;
					}

					if(bShowExplanation)
					{
						ShowWindow(GetDlgItem(hDlg, IDC_INHERITED), true);
					}
				}
				else
				{
					ShowWindow(GetDlgItem(hDlg, IDC_INHERITED), false);
				}

				// Find the matching filter record if it exists
				lpFilterRecord = FindFilter(folder->m_nFolderId);

				// initialize and disable appropriate controls
				for (int i = 0; g_lpFilterList[i].m_dwFilterType; i++)
				{
					DisableFilterControls(hDlg, lpFilterRecord, &g_lpFilterList[i], dwFilters);
				}
			}

			SetFocus(GetDlgItem(hDlg, IDC_FILTER_EDIT));
			return false;
		}

		case WM_CTLCOLORDLG:
			return (LRESULT) hBrush;	

		case WM_CTLCOLORSTATIC:
		case WM_CTLCOLORBTN:
			hDC = (HDC)wParam;
			SetBkMode(hDC, TRANSPARENT);
			SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
			return (LRESULT) hBrush;

		case WM_COMMAND:
		{
			WORD wID = GET_WM_COMMAND_ID(wParam, lParam);
			WORD wNotifyCode = GET_WM_COMMAND_CMD(wParam, lParam);
			LPTREEFOLDER folder = GetCurrentFolder();
			LPCFILTER_ITEM g_lpFilterList = GetFilterList();

			switch (wID)
			{
				case IDOK:
					dwFilters = 0;
					g_FilterText = win_get_window_text_utf8(GetDlgItem(hDlg, IDC_FILTER_EDIT));

					// see which buttons are checked
					for (int i = 0; g_lpFilterList[i].m_dwFilterType; i++)
					{
						if (Button_GetCheck(GetDlgItem(hDlg, g_lpFilterList[i].m_dwCtrlID)))
							dwFilters |= g_lpFilterList[i].m_dwFilterType;
					}

					// Mask out invalid filters
					dwFilters = ValidateFilters(lpFilterRecord, dwFilters);
					// Keep non filter flags
					folder->m_dwFlags &= ~F_MASK;
					// put in the set filters
					folder->m_dwFlags |= dwFilters;
					DestroyIcon(hIcon);
					DeleteObject(hBrush);
					EndDialog(hDlg, 1);
					return true;

				case IDCANCEL:
					DestroyIcon(hIcon);
					DeleteObject(hBrush);
					EndDialog(hDlg, 0);
					return true;

				default:
					// Handle unchecking mutually exclusive filters
					if (wNotifyCode == BN_CLICKED)
						EnableFilterExclusions(hDlg, wID);
			}

			break;
		}
	}

	return false;
}
Esempio n. 13
0
INT_PTR CALLBACK InterfaceDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{

	switch (Msg)
	{
		case WM_INITDIALOG:
		{
			char buffer[200];
			int value = 0;
			CenterWindow(hDlg);
			hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAMEUI_ICON));
			SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
			hBrush = CreateSolidBrush(RGB(240, 240, 240));
			DisableVisualStylesInterface(hDlg);
			Button_SetCheck(GetDlgItem(hDlg, IDC_JOY_GUI), GetJoyGUI());
			Button_SetCheck(GetDlgItem(hDlg, IDC_DISABLE_TRAY_ICON), GetMinimizeTrayIcon());
			Button_SetCheck(GetDlgItem(hDlg, IDC_DISPLAY_NO_ROMS), GetDisplayNoRomsGames());
			Button_SetCheck(GetDlgItem(hDlg, IDC_EXIT_DIALOG), GetExitDialog());
			Button_SetCheck(GetDlgItem(hDlg, IDC_USE_BROKEN_ICON), GetUseBrokenIcon());
			Button_SetCheck(GetDlgItem(hDlg, IDC_STRETCH_SCREENSHOT_LARGER), GetStretchScreenShotLarger());
			Button_SetCheck(GetDlgItem(hDlg, IDC_FILTER_INHERIT), GetFilterInherit());
			Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLE_FASTAUDIT), GetEnableFastAudit());
			Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLE_SEVENZIP), GetEnableSevenZip());
			Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLE_DATAFILES), GetEnableDatafiles());
			Button_SetCheck(GetDlgItem(hDlg, IDC_SKIP_BIOS), GetSkipBiosMenu());
			// Get the current value of the control
			SendMessage(GetDlgItem(hDlg, IDC_CYCLETIMESEC), TBM_SETRANGE, true, MAKELPARAM(0, 60)); /* [0, 60] */
			SendMessage(GetDlgItem(hDlg, IDC_CYCLETIMESEC), TBM_SETTICFREQ, 5, 0);
			value = GetCycleScreenshot();
			SendMessage(GetDlgItem(hDlg, IDC_CYCLETIMESEC), TBM_SETPOS, true, value);
			snprintf(buffer, WINUI_ARRAY_LENGTH(buffer), "%d", value);		
			win_set_window_text_utf8(GetDlgItem(hDlg, IDC_CYCLETIMESECTXT), buffer);

			for (int i = 0; i < NUMHISTORYTAB; i++)
			{
				(void)ComboBox_InsertString(GetDlgItem(hDlg, IDC_HISTORY_TAB), i, g_ComboBoxHistoryTab[i].m_pText);
				(void)ComboBox_SetItemData(GetDlgItem(hDlg, IDC_HISTORY_TAB), i, g_ComboBoxHistoryTab[i].m_pData);
			}

			if (GetHistoryTab() < MAX_TAB_TYPES) 
				(void)ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_HISTORY_TAB), GetHistoryTab());
			else 
				(void)ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_HISTORY_TAB), GetHistoryTab() - TAB_SUBTRACT);

			SendMessage(GetDlgItem(hDlg, IDC_SCREENSHOT_BORDERSIZE), TBM_SETRANGE, true, MAKELPARAM(0, 50)); /* [0, 50] */
			SendMessage(GetDlgItem(hDlg, IDC_SCREENSHOT_BORDERSIZE), TBM_SETTICFREQ, 5, 0);
			value = GetScreenshotBorderSize();
			SendMessage(GetDlgItem(hDlg, IDC_SCREENSHOT_BORDERSIZE), TBM_SETPOS, true, value);
			snprintf(buffer, WINUI_ARRAY_LENGTH(buffer), "%d", value);		
			win_set_window_text_utf8(GetDlgItem(hDlg, IDC_SCREENSHOT_BORDERSIZETXT), buffer);
			EnableWindow(GetDlgItem(hDlg, IDC_ENABLE_SEVENZIP), GetEnableFastAudit() ? true : false);
			break;
		}

		case WM_CTLCOLORDLG:
			return (LRESULT) hBrush;	

		case WM_CTLCOLORSTATIC:
		case WM_CTLCOLORBTN:
			hDC = (HDC)wParam;
			SetBkMode(hDC, TRANSPARENT);
			SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
			return (LRESULT) hBrush;

		case WM_HSCROLL:
			HANDLE_WM_HSCROLL(hDlg, wParam, lParam, OnHScroll);
			break;

		case WM_COMMAND:
			switch (GET_WM_COMMAND_ID(wParam, lParam))
			{
				case IDC_SCREENSHOT_BORDERCOLOR:
				{
					CHOOSECOLOR cc;
					COLORREF choice_colors[16];			

					for (int i = 0; i < 16; i++)
						choice_colors[i] = GetCustomColor(i);

					cc.lStructSize = sizeof(CHOOSECOLOR);
					cc.hwndOwner = hDlg;
					cc.lpfnHook = &CCHookProc;
					cc.rgbResult = GetScreenshotBorderColor();
					cc.lpCustColors = choice_colors;
					cc.Flags = CC_ANYCOLOR | CC_RGBINIT | CC_FULLOPEN | CC_ENABLEHOOK;

					if (!ChooseColor(&cc))
						return true;

					for (int i = 0; i < 16; i++)
						SetCustomColor(i,choice_colors[i]);

					SetScreenshotBorderColor(cc.rgbResult);
					UpdateScreenShot();
					return true;
				}

				case IDC_ENABLE_FASTAUDIT:
				{
					bool enabled = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_FASTAUDIT));
					EnableWindow(GetDlgItem(hDlg, IDC_ENABLE_SEVENZIP), enabled ? true : false);
					return true;
				}

				case IDOK:
				{
					bool bRedrawList = false;
					bool checked = false;
					int value = 0;

					SetJoyGUI(Button_GetCheck(GetDlgItem(hDlg, IDC_JOY_GUI)));
					SetMinimizeTrayIcon(Button_GetCheck(GetDlgItem(hDlg, IDC_DISABLE_TRAY_ICON)));
					SetExitDialog(Button_GetCheck(GetDlgItem(hDlg, IDC_EXIT_DIALOG)));
					SetEnableFastAudit(Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_FASTAUDIT)));
					SetEnableSevenZip(Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_SEVENZIP)));
					SetEnableDatafiles(Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLE_DATAFILES)));
					SetSkipBiosMenu(Button_GetCheck(GetDlgItem(hDlg, IDC_SKIP_BIOS)));

					if (Button_GetCheck(GetDlgItem(hDlg, IDC_RESET_PLAYCOUNT)))
					{
						for (int i = 0; i < driver_list::total(); i++)
							ResetPlayCount(i);

						bRedrawList = true;
					}

					if (Button_GetCheck(GetDlgItem(hDlg, IDC_RESET_PLAYTIME)))
					{
						for (int i = 0; i < driver_list::total(); i++)
							ResetPlayTime(i);

						bRedrawList = true;
					}

					value = SendDlgItemMessage(hDlg, IDC_CYCLETIMESEC, TBM_GETPOS, 0, 0);

					if (GetCycleScreenshot() != value)
						SetCycleScreenshot(value);

					value = SendDlgItemMessage(hDlg, IDC_SCREENSHOT_BORDERSIZE, TBM_GETPOS, 0, 0);

					if (GetScreenshotBorderSize() != value)
					{
						SetScreenshotBorderSize(value);
						UpdateScreenShot();
					}

					checked = Button_GetCheck(GetDlgItem(hDlg, IDC_STRETCH_SCREENSHOT_LARGER));

					if (checked != GetStretchScreenShotLarger())
					{
						SetStretchScreenShotLarger(checked);
						UpdateScreenShot();
					}

					checked = Button_GetCheck(GetDlgItem(hDlg, IDC_FILTER_INHERIT));

					if (checked != GetFilterInherit())
					{
						SetFilterInherit(checked);
						bRedrawList = true;
					}

					checked = Button_GetCheck(GetDlgItem(hDlg, IDC_USE_BROKEN_ICON));

					if (checked != GetUseBrokenIcon())
					{
						SetUseBrokenIcon(checked);
						bRedrawList = true;
					}

					checked = Button_GetCheck(GetDlgItem(hDlg, IDC_DISPLAY_NO_ROMS));

					if (checked != GetDisplayNoRomsGames())
					{
						SetDisplayNoRomsGames(checked);
						bRedrawList = true;
					}

					int nCurSelection = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_HISTORY_TAB));
					int nHistoryTab = 0;

					if (nCurSelection != CB_ERR)
						nHistoryTab = ComboBox_GetItemData(GetDlgItem(hDlg, IDC_HISTORY_TAB), nCurSelection);

					DestroyIcon(hIcon);
					DeleteObject(hBrush);
					EndDialog(hDlg, 0);

					if(GetHistoryTab() != nHistoryTab)
					{
						SetHistoryTab(nHistoryTab, true);
						ResizePickerControls(GetMainWindow());
						UpdateScreenShot();
					}

					if(bRedrawList)
						UpdateListView();

					SaveInternalUI();
					return true;
				}

				case IDCANCEL:
					DestroyIcon(hIcon);
					DeleteObject(hBrush);
					EndDialog(hDlg, 0);
					return true;
			}

			break;
	}

	return false;
}
Esempio n. 14
0
void
DoMAPISendMail(HWND hWnd)
{
  ULONG (FAR PASCAL *lpfnMAPISendMail) (LHANDLE lhSession, ULONG ulUIParam, 
                  lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved);

#ifdef WIN16		
  (FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISENDMAIL"); 
#else
  (FARPROC&) lpfnMAPISendMail = GetProcAddress(m_hInstMapi, "MAPISendMail"); 
#endif
  
  if (!lpfnMAPISendMail)
  {
    ShowMessage(hWnd, "Unable to locate MAPI function.");
    return;
  }          

  FLAGS   flFlags = 0;
  char    msg[512];
  char    file1[_MAX_PATH] = "";
  char    file2[_MAX_PATH] = "";
  char    file3[_MAX_PATH] = "";
  char    file4[_MAX_PATH] = "";
  char    toAddr[128];
  char    ccAddr[128];
  char    bccAddr[128];
  char    subject[128];
  char    noteText[4096];
  char    dateReceived[128] = "N/A";
  char    threadID[128] = "N/A";
  char    origName[128] = "N/A";
  char    origAddress[128] = "N/A";

  GetDlgItemText(hWnd, ID_EDIT_TOADDRESS, toAddr, sizeof(toAddr));
  GetDlgItemText(hWnd, ID_EDIT_CCADDRESS, ccAddr, sizeof(ccAddr));
  GetDlgItemText(hWnd, ID_EDIT_BCCADDRESS, bccAddr, sizeof(bccAddr));
  GetDlgItemText(hWnd, ID_EDIT_SUBJECT, subject, sizeof(subject));
  GetDlgItemText(hWnd, ID_EDIT_NOTETEXT, noteText, sizeof(noteText));

  // Do the one flag we support for this call...
  if (BST_CHECKED == Button_GetCheck(GetDlgItem(hWnd, ID_CHECK_SHOWDIALOG)))
  {
    flFlags |= MAPI_DIALOG;
  }

  // Build the message to send off...
  lpMapiMessage  msgPtr = (MapiMessage *)malloc(sizeof(MapiMessage));
  if (msgPtr == NULL)
  {
    return;
  }
  
  memset(msgPtr, 0, sizeof(MapiMessage)); 

  //
  // At this point, we need to populate the structure of information
  // we are passing in via the *lppMessage
  //

  // Set all of the general information first!
  msgPtr->lpszSubject = strdup(subject);
  msgPtr->lpszNoteText = strdup(noteText);
  msgPtr->lpszDateReceived = strdup(dateReceived);
  msgPtr->lpszConversationID = strdup(threadID);
  msgPtr->flFlags = flFlags;

  // Now deal with the recipients of this message
  DWORD       realRecips = 0;
  if (toAddr[0] != '\0')    ++realRecips;
  if (ccAddr[0] != '\0')    ++realRecips;
  if (bccAddr[0] != '\0')   ++realRecips;

  msgPtr->lpRecips = (lpMapiRecipDesc) malloc((size_t) (sizeof(MapiRecipDesc) * realRecips));
  if (!msgPtr->lpRecips)
  {
    FreeMAPIMessage(msgPtr);
    return;
  }

  msgPtr->nRecipCount = realRecips;
  memset(msgPtr->lpRecips, 0, (size_t) (sizeof(MapiRecipDesc) * msgPtr->nRecipCount));

  DWORD       rCount = 0;
  if (toAddr[0] != '\0')
  {
    msgPtr->lpRecips[rCount].lpszName = strdup(toAddr);
    msgPtr->lpRecips[rCount].lpszAddress = strdup(toAddr);
    msgPtr->lpRecips[rCount].ulRecipClass = MAPI_TO;
    rCount++;
  }

  if (ccAddr[0] != '\0')
  {
    msgPtr->lpRecips[rCount].lpszName = strdup(ccAddr);
    msgPtr->lpRecips[rCount].lpszAddress = strdup(ccAddr);
    msgPtr->lpRecips[rCount].ulRecipClass = MAPI_CC;    
    rCount++;
  }

  if (bccAddr[0] != '\0')
  {
    msgPtr->lpRecips[rCount].lpszName = strdup(bccAddr);
    msgPtr->lpRecips[rCount].lpszAddress = strdup(bccAddr);
    msgPtr->lpRecips[rCount].ulRecipClass = MAPI_BCC;
    rCount++;
  }

  // Now get the names of the files to attach...
  GetDlgItemText(hWnd, ID_EDIT_ATTACH1, file1, sizeof(file1));
  GetDlgItemText(hWnd, ID_EDIT_ATTACH2, file2, sizeof(file2));
  GetDlgItemText(hWnd, ID_EDIT_ATTACH3, file3, sizeof(file3));
  GetDlgItemText(hWnd, ID_EDIT_ATTACH4, file4, sizeof(file4));

  DWORD       realFiles = 0;
  if (file1[0] != '\0')    ++realFiles;
  if (file2[0] != '\0')    ++realFiles;
  if (file3[0] != '\0')    ++realFiles;
  if (file4[0] != '\0')    ++realFiles;

  // Now deal with the list of attachments! Since the nFileCount should be set
  // correctly, this loop will automagically be correct
  //
  msgPtr->nFileCount = realFiles;
  if (realFiles > 0)
  {
    msgPtr->lpFiles = (lpMapiFileDesc) malloc((size_t) (sizeof(MapiFileDesc) * realFiles));
    if (!msgPtr->lpFiles)
    {
      FreeMAPIMessage(msgPtr);
      return;
    }

    memset(msgPtr->lpFiles, 0, (size_t) (sizeof(MapiFileDesc) * msgPtr->nFileCount));
  }

  rCount = 0;
  if (file1[0] != '\0')
  {
    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file1);
    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file1);
    ++rCount;
  }

  if (file2[0] != '\0')
  {
    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file2);
    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file2);
    ++rCount;
  }

  if (file3[0] != '\0')
  {
    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file3);
    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file3);
    ++rCount;
  }

  if (file4[0] != '\0')
  {
    msgPtr->lpFiles[rCount].lpszPathName = strdup((LPSTR)file4);
    msgPtr->lpFiles[rCount].lpszFileName = strdup((LPSTR)file4);
    ++rCount;
  }

  // Finally, make the call...
  LONG  rc = (*lpfnMAPISendMail)
           (mapiSession, 
           (ULONG) hWnd, 
           msgPtr, 
           flFlags, 
           0);

  if (rc == SUCCESS_SUCCESS)
  {
    ShowMessage(hWnd, "Success with MAPISendMail");
    SetFooter("MAPISendMail success");
  }
  else
  {
    wsprintf(msg, "FAILURE: Return code %d from MAPISendMail\nError=[%s]", 
                      rc, GetMAPIError(rc));
    ShowMessage(hWnd, msg);
    SetFooter("MAPISendMail failed");
  }

  // Now cleanup and move on...
  FreeMAPIMessage(msgPtr);
}
Esempio n. 15
0
INT_PTR CALLBACK RestartComputerDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    PSERVICE_RECOVERY_CONTEXT context;

    if (uMsg == WM_INITDIALOG)
    {
        context = (PSERVICE_RECOVERY_CONTEXT)lParam;
        SetProp(hwndDlg, L"Context", (HANDLE)context);
    }
    else
    {
        context = (PSERVICE_RECOVERY_CONTEXT)GetProp(hwndDlg, L"Context");

        if (uMsg == WM_DESTROY)
            RemoveProp(hwndDlg, L"Context");
    }

    if (!context)
        return FALSE;

    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            SetDlgItemInt(hwndDlg, IDC_RESTARTCOMPAFTER, context->RebootAfter / (1000 * 60), FALSE); // ms to min
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE), context->RebootMessage ? BST_CHECKED : BST_UNCHECKED);
            SetDlgItemText(hwndDlg, IDC_RESTARTMESSAGE, PhGetString(context->RebootMessage));

            SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_RESTARTCOMPAFTER), TRUE);
            Edit_SetSel(GetDlgItem(hwndDlg, IDC_RESTARTCOMPAFTER), 0, -1);
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
                EndDialog(hwndDlg, IDCANCEL);
                break;
            case IDOK:
                {
                    context->RebootAfter = GetDlgItemInt(hwndDlg, IDC_RESTARTCOMPAFTER, NULL, FALSE) * 1000 * 60;

                    if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE)) == BST_CHECKED)
                        PhMoveReference(&context->RebootMessage, PhGetWindowText(GetDlgItem(hwndDlg, IDC_RESTARTMESSAGE)));
                    else
                        PhClearReference(&context->RebootMessage);

                    context->Dirty = TRUE;

                    EndDialog(hwndDlg, IDOK);
                }
                break;
            case IDC_USEDEFAULTMESSAGE:
                {
                    PPH_STRING message;
                    PWSTR computerName;
                    ULONG bufferSize;
                    BOOLEAN allocated = TRUE;

                    // Get the computer name.

                    bufferSize = 64;
                    computerName = PhAllocate((bufferSize + 1) * sizeof(WCHAR));

                    if (!GetComputerName(computerName, &bufferSize))
                    {
                        PhFree(computerName);
                        computerName = PhAllocate((bufferSize + 1) * sizeof(WCHAR));

                        if (!GetComputerName(computerName, &bufferSize))
                        {
                            PhFree(computerName);
                            computerName = L"(unknown)";
                            allocated = FALSE;
                        }
                    }

                    // This message is exactly the same as the one in the Services console,
                    // except the double spaces are replaced by single spaces.
                    message = PhFormatString(
                        L"Your computer is connected to the computer named %s. "
                        L"The %s service on %s has ended unexpectedly. "
                        L"%s will restart automatically, and then you can reestablish the connection.",
                        computerName,
                        context->ServiceItem->Name->Buffer,
                        computerName,
                        computerName
                        );
                    SetDlgItemText(hwndDlg, IDC_RESTARTMESSAGE, message->Buffer);
                    PhDereferenceObject(message);

                    if (allocated)
                        PhFree(computerName);

                    Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE), BST_CHECKED);
                }
                break;
            case IDC_RESTARTMESSAGE:
                {
                    if (HIWORD(wParam) == EN_CHANGE)
                    {
                        // A zero length restart message disables it, so we might as well uncheck the box.
                        Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE),
                            GetWindowTextLength(GetDlgItem(hwndDlg, IDC_RESTARTMESSAGE)) != 0 ? BST_CHECKED : BST_UNCHECKED);
                    }
                }
                break;
            }
        }
        break;
    }

    return FALSE;
}
Esempio n. 16
0
/// <summary>
/// Injection routine
/// </summary>
/// <param name="path">Image path</param>
/// <param name="init">Initizliation routine/param>
/// <param name="arg">Initizliation routine argument</param>
/// <returns>Error code</returns>
DWORD MainDlg::InjectWorker( std::wstring path, std::string init, std::wstring arg )
{
    blackbone::Thread *pThread = nullptr;
    const blackbone::ModuleData* mod = nullptr;
    PROCESS_INFORMATION pi = { 0 };
    wchar_t cmdline[256] = { 0 };
    HWND hCombo = GetDlgItem( _hMainDlg, IDC_THREADS );
    DWORD thdId = (DWORD)ComboBox_GetItemData( hCombo, ComboBox_GetCurSel( hCombo ) );
    bool bManual = ComboBox_GetCurSel( GetDlgItem( _hMainDlg, IDC_OP_TYPE ) ) == 1;
    
    GetDlgItemTextW( _hMainDlg, IDC_CMDLINE, cmdline, ARRAYSIZE( cmdline ) );  

    // Check export
    if (ValidateInit( init.c_str() ) != STATUS_SUCCESS)
        return ERROR_CANCELLED;

    // Create new process
    if (_newProcess)
    {
        STARTUPINFOW si = { 0 };
        si.cb = sizeof(si);

        if (!CreateProcessW( _procPath.c_str(), cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
        {
            MessageBoxW( _hMainDlg, L"Failed to create new process", L"Error", MB_ICONERROR );
            return GetLastError();
        }

        thdId = 0;

        // Wait for process to initialize loader
        Sleep( 1 );

        AttachToProcess( pi.dwProcessId );
    }

    // Final sanity check
    if (ValidateImage( path.c_str(), init.c_str() ) != ERROR_SUCCESS)
    {
        if (_newProcess)
            TerminateProcess( pi.hProcess, 0 );

        return ERROR_CANCELLED;
    }
        
    // Normal inject
    if (bManual == false)
    {
        if (_imagePE.IsPureManaged())
        {
            DWORD code = 0;

            if (!_proc.modules().InjectPureIL( blackbone::ImageNET::GetImageRuntimeVer( path.c_str() ),
                path, blackbone::Utils::AnsiToWstring( init ), arg, code ))
            {
                if (_newProcess)
                    TerminateProcess( pi.hProcess, 0 );

                MessageBoxW( _hMainDlg, L"Failed to inject image", L"Error", MB_ICONERROR );
                return ERROR_FUNCTION_FAILED;
            }
        }
        else if (!_newProcess && thdId != 0)
        {
            pThread = _proc.threads().get( thdId );
            if (pThread == nullptr)
            {
                if (_newProcess)
                    TerminateProcess( pi.hProcess, 0 );

                MessageBoxW( _hMainDlg, L"Selected thread does not exist", L"Error", MB_ICONERROR );
                return ERROR_NOT_FOUND;
            }

            // Load 
            auto pLoadLib = _proc.modules().GetExport( _proc.modules().GetModule( L"kernel32.dll" ), "LoadLibraryW" ).procAddress;
            blackbone::RemoteFunction<decltype(&LoadLibraryW)> pfn( _proc, (decltype(&LoadLibraryW))pLoadLib, path.c_str() );
            decltype(pfn)::ReturnType junk = 0;
            pfn.Call( junk, pThread );

            mod = _proc.modules().GetModule( path );
        }
        else
            mod = _proc.modules().Inject( path );
    }
    // Manual map
    else
    {
        thdId = 0;
        int flags = blackbone::RebaseProcess | blackbone::NoDelayLoad | MmapFlags();

        mod = _proc.mmap().MapImage( path, flags );
    }

    if (mod == 0 && !_imagePE.IsPureManaged())
    {
        if (_newProcess)
            TerminateProcess( pi.hProcess, 0 );

        MessageBoxW( _hMainDlg, L"Failed to inject image", L"Error", MB_ICONERROR );
        return ERROR_NOT_FOUND;
    }

    // Call init for native image
    if (!init.empty() && !_imagePE.IsPureManaged())
    {
        auto fnPtr = _proc.modules().GetExport( mod, init.c_str() ).procAddress;

        if (thdId == 0)
        {
            auto argMem = _proc.memory().Allocate( 0x1000, PAGE_READWRITE );
            argMem.Write( 0, arg.length() * sizeof(wchar_t)+2, arg.c_str() );

            _proc.remote().ExecDirect( fnPtr, argMem.ptr() );
        }
        else
        {
            pThread = _proc.threads().get( thdId );
            if (pThread == nullptr)
            {
                if (_newProcess)
                    TerminateProcess( pi.hProcess, 0 );

                MessageBoxW( _hMainDlg, L"Selected thread does not exist", L"Error", MB_ICONERROR );
                return ERROR_NOT_FOUND;
            }

            blackbone::RemoteFunction<int( _stdcall* )(const wchar_t*)> pfn( _proc, (int( _stdcall* )(const wchar_t*))fnPtr, arg.c_str() );
            int junk = 0;

            pfn.Call( junk, pThread );
        }
    }

    // Unlink module if required
    if (!_imagePE.IsPureManaged() && !bManual && Button_GetCheck( GetDlgItem( _hMainDlg, IDC_UNLINK ) ))
        if (_proc.modules().Unlink( mod ) == false)
            MessageBoxW( _hMainDlg, L"Failed to unlink module", L"Error", MB_ICONERROR );

    // MessageBoxW( _hMainDlg, L"Successfully injected", L"Info", MB_ICONINFORMATION );
    //ResumeThread( pi.hThread );

    return ERROR_SUCCESS;
}
Esempio n. 17
0
INT_PTR CALLBACK MainWndProc(
    __in HWND hwndDlg,
    __in UINT uMsg,
    __in WPARAM wParam,
    __in LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            // Add the Graphics card name to the Window Title.
            //PPH_STRING gpuname = GetDriverName();
            //PPH_STRING title = PhFormatString(L"Graphics Information (%s)", gpuname->Buffer);

            //SetWindowText(hwndDlg, title->Buffer);  

            //PhDereferenceObject(gpuname);
            //PhDereferenceObject(title);

            // We have already set the group boxes to have WS_EX_TRANSPARENT to fix
            // the drawing issue that arises when using WS_CLIPCHILDREN. However
            // in removing the flicker from the graphs the group boxes will now flicker.
            // It's a good tradeoff since no one stares at the group boxes.
            PhSetWindowStyle(hwndDlg, WS_CLIPCHILDREN, WS_CLIPCHILDREN);
         
            PhCenterWindow(hwndDlg, PhMainWndHandle);
            
            PhInitializeLayoutManager(&WindowLayoutManager, hwndDlg);
  
            PhAddLayoutItem(&WindowLayoutManager, GetDlgItem(hwndDlg, IDC_ALWAYSONTOP), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
            PhAddLayoutItem(&WindowLayoutManager, GetDlgItem(hwndDlg, IDOK), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);

            PhLoadWindowPlacementFromSetting(SETTING_NAME_GFX_WINDOW_POSITION, SETTING_NAME_GFX_WINDOW_SIZE, hwndDlg);

            PhInitializeGraphState(&GpuGraphState);
            PhInitializeGraphState(&CoreGraphState);
            PhInitializeGraphState(&MemGraphState);

            // TEMP
            if (GpuHistory.Count == 0)
            {
                PhInitializeCircularBuffer_FLOAT(&GpuHistory, PhGetIntegerSetting(L"SampleCount"));
                PhInitializeCircularBuffer_FLOAT(&CoreHistory, PhGetIntegerSetting(L"SampleCount"));
                PhInitializeCircularBuffer_ULONG(&MemHistory, PhGetIntegerSetting(L"SampleCount"));
            }

            GpuGraphHandle = CreateWindow(
                PH_GRAPH_CLASSNAME,
                NULL,
                WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
                0,
                0,
                3,
                3,
                hwndDlg,
                (HMENU)110,
                PluginInstance->DllBase,
                NULL
                );
            Graph_SetTooltip(GpuGraphHandle, TRUE);
            BringWindowToTop(GpuGraphHandle);
     
            CoreGraphHandle = CreateWindow(
                PH_GRAPH_CLASSNAME,
                NULL,
                WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
                0,
                0,
                3,
                3,
                hwndDlg,
                (HMENU)111,
                PluginInstance->DllBase,
                NULL
                );
            Graph_SetTooltip(CoreGraphHandle, TRUE);
            BringWindowToTop(CoreGraphHandle);

            MemGraphHandle = CreateWindow(
                PH_GRAPH_CLASSNAME,
                NULL,
                WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
                0,
                0,
                3,
                3,
                hwndDlg,
                (HMENU)109,
                PluginInstance->DllBase,
                NULL
                );
            Graph_SetTooltip(MemGraphHandle, TRUE);
            BringWindowToTop(MemGraphHandle);
      
            PhRegisterCallback(
				PhGetGeneralCallback(GeneralCallbackProcessesUpdated),
				GfxUpdateHandler,
				NULL,
				&ProcessesUpdatedRegistration
				);
        }
        break;
    case WM_DESTROY:
        {     
            // Unregister our callbacks.
            PhUnregisterCallback(&PhProcessesUpdatedEvent, &ProcessesUpdatedRegistration);

            // Save our settings.
            PhSetIntegerSetting(SETTING_NAME_GFX_ALWAYS_ON_TOP, AlwaysOnTop);
            PhSaveWindowPlacementToSetting(SETTING_NAME_GFX_WINDOW_POSITION, SETTING_NAME_GFX_WINDOW_SIZE, hwndDlg);

            // Reset our Window Management.
            PhDeleteLayoutManager(&WindowLayoutManager);

            // TEMP commented out.
            // Clear our buffers.
            //PhDeleteCircularBuffer_FLOAT(&GpuHistory);
            //PhDeleteCircularBuffer_ULONG(&MemHistory);

            // Clear our state.
            PhDeleteGraphState(&GpuGraphState);
            PhDeleteGraphState(&MemGraphState);

            // Quit.
            PostQuitMessage(0);
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case GCN_GETDRAWINFO:
                {
                    PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)header;
                    PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;

                    if (header->hwndFrom == GpuGraphHandle)
                    {
                        if (PhGetIntegerSetting(L"GraphShowText"))
                        {
                            HDC hdc;

                            PhSwapReference2(
                                &GpuGraphState.TooltipText,
                                PhFormatString(
                                L"%.0f%%",
                                CurrentGpuUsage * 100
                                ));

                            hdc = Graph_GetBufferedContext(GpuGraphHandle);
                            SelectObject(hdc, PhApplicationFont);
                            PhSetGraphText(hdc, drawInfo, &GpuGraphState.TooltipText->sr,
                                &NormalGraphTextMargin, &NormalGraphTextPadding, PH_ALIGN_TOP | PH_ALIGN_LEFT);
                        }
                        else
                        {
                            drawInfo->Text.Buffer = NULL;
                        }

                        drawInfo->Flags = PH_GRAPH_USE_GRID;
                        drawInfo->LineColor1 = PhGetIntegerSetting(L"ColorCpuKernel");
                        //drawInfo->LineColor2 = PhGetIntegerSetting(L"ColorCpuUser");
                        drawInfo->LineBackColor1 = PhHalveColorBrightness(drawInfo->LineColor1);
                        //drawInfo->LineBackColor2 = PhHalveColorBrightness(drawInfo->LineColor2);

                        PhGraphStateGetDrawInfo(
                            &GpuGraphState,
                            getDrawInfo,
                            GpuHistory.Count
                            );

                        if (!GpuGraphState.Valid)
                        {
                            PhCopyCircularBuffer_FLOAT(
                                &GpuHistory, 
                                getDrawInfo->DrawInfo->LineData1, 
                                getDrawInfo->DrawInfo->LineDataCount
                                );

                            GpuGraphState.Valid = TRUE;
                        }
                    }
                    else if (header->hwndFrom == MemGraphHandle)
                    {
                        if (PhGetIntegerSetting(L"GraphShowText"))
                        {
                            HDC hdc;

                            PhSwapReference2(&MemGraphState.TooltipText,
                                PhFormatString(
                                L"%s / %s (%.2f%%)",
                                PhaFormatSize(UInt32x32To64(CurrentMemUsage, 1024), -1)->Buffer,
                                PhaFormatSize(UInt32x32To64(MaxMemUsage, 1024), -1)->Buffer,
                                (FLOAT)CurrentMemUsage / MaxMemUsage * 100
                                ));

                            hdc = Graph_GetBufferedContext(MemGraphHandle);
                            SelectObject(hdc, PhApplicationFont);
                            PhSetGraphText(
                                hdc, 
                                drawInfo, 
                                &MemGraphState.TooltipText->sr,  
                                &NormalGraphTextMargin, 
                                &NormalGraphTextPadding, 
                                PH_ALIGN_TOP | PH_ALIGN_LEFT
                                );
                        }
                        else
                        {
                            drawInfo->Text.Buffer = NULL;
                        }

                        drawInfo->Flags = PH_GRAPH_USE_GRID;
                        drawInfo->LineColor1 = PhGetIntegerSetting(L"ColorCpuKernel");
                        //drawInfo->LineColor2 = PhGetIntegerSetting(L"ColorCpuUser");
                        drawInfo->LineBackColor1 = PhHalveColorBrightness(drawInfo->LineColor1);
                        //drawInfo->LineBackColor2 = PhHalveColorBrightness(drawInfo->LineColor2);

                        PhGraphStateGetDrawInfo(
                            &MemGraphState,
                            getDrawInfo,
                            MemHistory.Count
                            );

                        if (!MemGraphState.Valid)
                        {
                            ULONG i = 0;

                            for (i = 0; i < drawInfo->LineDataCount; i++)
                            {
                                MemGraphState.Data1[i] =
                                    (FLOAT)PhGetItemCircularBuffer_ULONG(&MemHistory, i);
                            }

                            // Scale the data.
                            PhxfDivideSingle2U(
                                MemGraphState.Data1,
                                (FLOAT)MaxMemUsage,
                                drawInfo->LineDataCount
                                );

                            MemGraphState.Valid = TRUE;
                        }
                    }
                    else if (header->hwndFrom == CoreGraphHandle)
                    {
                        if (PhGetIntegerSetting(L"GraphShowText"))
                        {
                            HDC hdc;

                            PhSwapReference2(
                                &CoreGraphState.TooltipText,
                                PhFormatString(
                                L"%.0f%%",
                                CurrentCoreUsage * 100
                                ));

                            hdc = Graph_GetBufferedContext(CoreGraphHandle);
                            SelectObject(hdc, PhApplicationFont);
                            PhSetGraphText(hdc, drawInfo, &CoreGraphState.TooltipText->sr,
                                &NormalGraphTextMargin, &NormalGraphTextPadding, PH_ALIGN_TOP | PH_ALIGN_LEFT);
                        }
                        else
                        {
                            drawInfo->Text.Buffer = NULL;
                        }

                        drawInfo->Flags = PH_GRAPH_USE_GRID;
                        drawInfo->LineColor1 = PhGetIntegerSetting(L"ColorCpuKernel");
                        //drawInfo->LineColor2 = PhGetIntegerSetting(L"ColorCpuUser");
                        drawInfo->LineBackColor1 = PhHalveColorBrightness(drawInfo->LineColor1);
                        //drawInfo->LineBackColor2 = PhHalveColorBrightness(drawInfo->LineColor2);

                        PhGraphStateGetDrawInfo(
                            &CoreGraphState,
                            getDrawInfo,
                            CoreHistory.Count
                            );

                        if (!CoreGraphState.Valid)
                        {
                            PhCopyCircularBuffer_FLOAT(
                                &CoreHistory, 
                                getDrawInfo->DrawInfo->LineData1, 
                                getDrawInfo->DrawInfo->LineDataCount
                                );

                            CoreGraphState.Valid = TRUE;
                        }
                    }
                }
                break;
            case GCN_GETTOOLTIPTEXT:
                {
                    PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)lParam;

                    if (getTooltipText->Index < getTooltipText->TotalCount)
                    {
                        if (header->hwndFrom == GpuGraphHandle)
                        {
                            if (GpuGraphState.TooltipIndex != getTooltipText->Index)
                            {
                                FLOAT usage;

                                usage = PhGetItemCircularBuffer_FLOAT(&GpuHistory, getTooltipText->Index);

                                PhSwapReference2(&GpuGraphState.TooltipText, PhFormatString(
                                    L"%.0f%%",
                                    usage * 100
                                    ));
                            }

                            getTooltipText->Text = GpuGraphState.TooltipText->sr;
                        }
                        else if (header->hwndFrom == MemGraphHandle)
                        {
                            if (MemGraphState.TooltipIndex != getTooltipText->Index)
                            {
                                ULONG usage;

                                usage = PhGetItemCircularBuffer_ULONG(&MemHistory, getTooltipText->Index);

                                PhSwapReference2(&MemGraphState.TooltipText,
                                    PhFormatString(
                                    L"%s / %s (%.2f%%)",
                                    PhaFormatSize(UInt32x32To64(usage, 1024), -1)->Buffer,
                                    PhaFormatSize(UInt32x32To64(MaxMemUsage, 1024), -1)->Buffer,
                                    (FLOAT)usage / MaxMemUsage * 100
                                    ));
                            }

                            getTooltipText->Text = MemGraphState.TooltipText->sr;
                        }
                        else if (header->hwndFrom == CoreGraphHandle)
                        {
                            if (CoreGraphState.TooltipIndex != getTooltipText->Index)
                            {
                                FLOAT usage;

                                usage = PhGetItemCircularBuffer_FLOAT(&CoreHistory, getTooltipText->Index);

                                PhSwapReference2(&CoreGraphState.TooltipText, 
                                    PhFormatString(
                                    L"%.0f%%",
                                    usage * 100
                                    ));
                            }

                            getTooltipText->Text = CoreGraphState.TooltipText->sr;
                        }
                    }
                }
                break;
            case GCN_MOUSEEVENT:
                {
                    PPH_GRAPH_MOUSEEVENT mouseEvent = (PPH_GRAPH_MOUSEEVENT)lParam;

                    if (mouseEvent->Message == WM_LBUTTONDBLCLK)
                    {
                        if (header->hwndFrom == GpuGraphHandle)
                        {
                            PhShowInformation(hwndDlg, L"Double clicked!");
                        }
                    }
                }
                break;
            }
        }
        break;
    case WM_SHOWWINDOW:
        {
            RECT margin;

            GfxPanelWindowHandle = CreateDialog(
                PluginInstance->DllBase,
                MAKEINTRESOURCE(IDD_SYSGFX_PANEL),
                hwndDlg,
                MainPanelDlgProc
                );

            SetWindowPos(
                GfxPanelWindowHandle, 
                NULL, 
                10, 0, 0, 0,
                SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOSIZE | SWP_NOZORDER
                );

            ShowWindow(GfxPanelWindowHandle, SW_SHOW);

            AlwaysOnTop = (BOOLEAN)PhGetIntegerSetting(SETTING_NAME_GFX_ALWAYS_ON_TOP);
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_ALWAYSONTOP), AlwaysOnTop ? BST_CHECKED : BST_UNCHECKED);
            GfxSetAlwaysOnTop();

            margin.left = 0;
            margin.top = 0;
            margin.right = 0;
            margin.bottom = 25;
            MapDialogRect(hwndDlg, &margin);

            PhAddLayoutItemEx(
                &WindowLayoutManager, 
                GfxPanelWindowHandle, 
                NULL, 
                PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT, 
                margin
                );

            SendMessage(hwndDlg, WM_SIZE, 0, 0);
            SendMessage(hwndDlg, WM_GFX_UPDATE, 0, 0);
        }
        break;
    case WM_SIZE:
        {                      
            HDWP deferHandle;
            HWND cpuGroupBox = GetDlgItem(hwndDlg, IDC_GROUPCONTROLLER);
            HWND diskGroupBox = GetDlgItem(hwndDlg, IDC_GROUPGPU);
            HWND networkGroupBox = GetDlgItem(hwndDlg, IDC_GROUPMEM);
            RECT clientRect;
            RECT panelRect;
            RECT margin = { 13, 13, 13, 13 };
            RECT innerMargin = { 10, 20, 10, 10 };
            LONG between = 3;
            LONG width;
            LONG height;

            PhLayoutManagerLayout(&WindowLayoutManager);

            GpuGraphState.Valid = FALSE;
            MemGraphState.Valid = FALSE;

            GetClientRect(hwndDlg, &clientRect);
            // Limit the rectangle bottom to the top of the panel.
            GetWindowRect(GfxPanelWindowHandle, &panelRect);
            MapWindowPoints(NULL, hwndDlg, (POINT *)&panelRect, 2);
            clientRect.bottom = panelRect.top;

            width = clientRect.right - margin.left - margin.right;
            height = (clientRect.bottom - margin.top - margin.bottom - between * 2) / 3;

            deferHandle = BeginDeferWindowPos(6);

            deferHandle = DeferWindowPos(deferHandle, diskGroupBox, NULL, margin.left, margin.top,  width, height, SWP_NOACTIVATE | SWP_NOZORDER);
            deferHandle = DeferWindowPos(
                deferHandle,
                GpuGraphHandle,
                NULL,
                margin.left + innerMargin.left,
                margin.top + innerMargin.top,
                width - innerMargin.left - innerMargin.right,
                height - innerMargin.top - innerMargin.bottom,
                SWP_NOACTIVATE | SWP_NOZORDER
                );

            deferHandle = DeferWindowPos(deferHandle, networkGroupBox, NULL, margin.left, margin.top + height + between, width, height, SWP_NOACTIVATE | SWP_NOZORDER);
            deferHandle = DeferWindowPos(
                deferHandle,
                MemGraphHandle,
                NULL,
                margin.left + innerMargin.left,
                margin.top + height + between + innerMargin.top,
                width - innerMargin.left - innerMargin.right,
                height - innerMargin.top - innerMargin.bottom,
                SWP_NOACTIVATE | SWP_NOZORDER
                );

            deferHandle = DeferWindowPos(deferHandle, cpuGroupBox, NULL, margin.left, margin.top + (height + between) * 2, width, height, SWP_NOACTIVATE | SWP_NOZORDER);
            deferHandle = DeferWindowPos(
                deferHandle,
                CoreGraphHandle,
                NULL,
                margin.left + innerMargin.left,
                margin.top + (height + between) * 2 + innerMargin.top,
                width - innerMargin.left - innerMargin.right,
                height - innerMargin.top - innerMargin.bottom,
                SWP_NOACTIVATE | SWP_NOZORDER
                );

            EndDeferWindowPos(deferHandle);
        }
        break;

    case WM_SIZING:
        {
            PhResizingMinimumSize((PRECT)lParam, wParam, 500, 400);
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
            case IDOK:
                DestroyWindow(hwndDlg);
                break;
            case IDC_ALWAYSONTOP:
                {
                    AlwaysOnTop = Button_GetCheck(GetDlgItem(hwndDlg, IDC_ALWAYSONTOP)) == BST_CHECKED;
                    GfxSetAlwaysOnTop();
                }
                break;
            }
        }
        break;
    case WM_GFX_ACTIVATE:
        {
            if (IsIconic(hwndDlg))
                ShowWindow(hwndDlg, SW_RESTORE);
            else
                ShowWindow(hwndDlg, SW_SHOW);

            SetForegroundWindow(hwndDlg);
        }
        break;
    case WM_GFX_UPDATE:
        {
            GetGfxUsages();
            GetGfxTemp();
            GetGfxClockSpeeds();

            GpuGraphState.Valid = FALSE;
            GpuGraphState.TooltipIndex = -1;
            Graph_MoveGrid(GpuGraphHandle, 1);
            Graph_Draw(GpuGraphHandle);
            Graph_UpdateTooltip(GpuGraphHandle);
            InvalidateRect(GpuGraphHandle, NULL, FALSE);

            CoreGraphState.Valid = FALSE;
            CoreGraphState.TooltipIndex = -1;
            Graph_MoveGrid(CoreGraphHandle, 1);
            Graph_Draw(CoreGraphHandle);
            Graph_UpdateTooltip(CoreGraphHandle);
            InvalidateRect(CoreGraphHandle, NULL, FALSE);

            MemGraphState.Valid = FALSE;
            MemGraphState.TooltipIndex = -1;
            Graph_MoveGrid(MemGraphHandle, 1);
            Graph_Draw(MemGraphHandle);
            Graph_UpdateTooltip(MemGraphHandle);
            InvalidateRect(MemGraphHandle, NULL, FALSE);

            SendMessage(GfxPanelWindowHandle, WM_GFX_PANEL_UPDATE, 0, 0);
        }
        break;
    }

    return FALSE;
}
Esempio n. 18
0
void CDialogInstall::LaunchInstallProcess()
{
	const bool isProcsesUserAdmin = Util::IsProcessUserAdmin();
	if (!isProcsesUserAdmin && (Platform::IsAtLeastWinVista() && !Util::CanProcessUserElevate()))
	{
		MessageBox(
			m_Window,
			L"Adminstrative privileges are required to install Rainmeter.\n\nClick OK to close setup.",
			L"Rainmeter Setup", MB_OK | MB_ICONERROR);
		PostMessage(m_Window, WM_CLOSE, 0, 0);
		return;
	}

	m_InstallProcessWaitThread = CreateThread(
		nullptr, 0, ElevatedProcessWaitThreadProc, nullptr, CREATE_SUSPENDED, nullptr);
	if (!m_InstallProcessWaitThread)
	{
		// TODO.
	}

	WCHAR exePath[MAX_PATH];
	GetModuleFileName(nullptr, exePath, _countof(exePath));

	HWND item = m_TabContents.GetControl(TabContents::Id_LanguageComboBox); 
	const LCID lcid = (LCID)ComboBox_GetItemData(item, ComboBox_GetCurSel(item));

	item = m_TabContents.GetControl(TabContents::Id_InstallationTypeComboBox); 
	const LPARAM typeData = ComboBox_GetItemData(item, ComboBox_GetCurSel(item));

	WCHAR targetPath[MAX_PATH];
	item = m_TabContents.GetControl(TabContents::Id_DestinationEdit);
	Edit_GetText(item, targetPath, _countof(targetPath));

	item = m_TabContents.GetControl(TabContents::Id_LaunchOnLoginCheckBox);
	const int launchOnLogin = Button_GetCheck(item) == BST_CHECKED ? 1 : 0;

	WCHAR params[512];
	wsprintf(
		params, L"OPT:%s|%ld|%hd|%hd|%d",
		targetPath, lcid, LOWORD(typeData), HIWORD(typeData), launchOnLogin);

	// Launch the installer process and, if needed, request elevation.
	SHELLEXECUTEINFO sei = {sizeof(sei)};
	sei.fMask = SEE_MASK_FLAG_DDEWAIT | SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
	sei.lpVerb = isProcsesUserAdmin ? L"open" : L"runas";
	sei.lpFile = exePath;
	sei.lpParameters = params;
	sei.hwnd = m_Window;
	sei.nShow = SW_NORMAL;

	if (!ShellExecuteEx(&sei) || !sei.hProcess)
	{
		MessageBox(m_Window,
			L"Adminstrative privileges are required to install Rainmeter.\n\nClick OK to close setup.",
			L"Rainmeter Setup", MB_OK | MB_ICONERROR);
		PostMessage(m_Window, WM_CLOSE, 0, 0);
		return;
	}

	m_InstallProcess = sei.hProcess;
	ResumeThread(m_InstallProcessWaitThread);
}
Esempio n. 19
0
//WM_COMMAND:
void TfrmMain::wmCommand(WPARAM wParam, LPARAM lParam) {
    //---------------------------------------------------------------------------
    int IDControl = LOWORD(wParam);
    switch (HIWORD(wParam)) {
    case BN_CLICKED:		//Button controls
        switch(IDControl) {
        case IDCANCEL:
        case IDCLOSE:
            break;
        case ID_chkTimed:
            m_opt_chkTimed = (BYTE)Button_GetCheck((HWND)lParam);
            TfrmMain::chkTimedClick();
            break;
        case ID_chkClientArea:
            m_opt_chkClientArea = (BYTE)Button_GetCheck((HWND)lParam);
            if(m_hTargetWindow)
                edtSizeUpdate(m_hTargetWindow, m_opt_chkClientArea, GetParent((HWND)lParam), ID_edtSize);
            break;
        case ID_chkOpenAgain:
            m_opt_chkOpenAgain = (BYTE)Button_GetCheck((HWND)lParam);
            break;
        case ID_chkEditor:
            m_opt_chkEditor = (BYTE)Button_GetCheck((HWND)lParam);
            break;

        case ID_bvlTarget:
            if(m_opt_tabCapture==0) SetTimer(m_hWnd,ID_bvlTarget,BUTTON_POLLDELAY,NULL);
            break;

        case ID_btnAbout:
            TfrmMain::btnAboutClick();
            break;
        case ID_btnExplore:
            TfrmMain::btnExploreClick();
            break;
        case ID_btnDesc: {
            m_opt_btnDesc=!m_opt_btnDesc;
            HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF);
            SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
            break;
        }
        case ID_btnDeleteAfterSend:
        {
            m_opt_btnDeleteAfterSend = (m_opt_btnDeleteAfterSend == 0);
            HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF);
            SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
            if(m_cSend) m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend;
        }
        break;
        case ID_btnCapture:
            TfrmMain::btnCaptureClick();
            break;
        default:
            break;
        }
        break;
    case CBN_SELCHANGE:		//ComboBox controls
        switch(IDControl) {
        //lParam = Handle to the control
        case ID_cboxFormat:			//not finish
            m_opt_cboxFormat = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
            break;
        case ID_cboxSendBy:
            m_opt_cboxSendBy = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
            cboxSendByChange();
            break;
        case ID_edtCaption:			//cboxDesktopChange
            m_opt_cboxDesktop = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
            m_hTargetWindow = 0;
            if (m_opt_cboxDesktop > 0) {
                edtSizeUpdate(m_Monitors[m_opt_cboxDesktop-1].rcMonitor, GetParent((HWND)lParam), ID_edtSize);
            }
            else {
                edtSizeUpdate(m_VirtualScreen, GetParent((HWND)lParam), ID_edtSize);
            }
            break;
        default:
            break;
        }
        break;
    case EN_CHANGE:			//Edit controls
        switch(IDControl) {
        //lParam = Handle to the control
        case ID_edtQuality:
            m_opt_edtQuality = (BYTE)GetDlgItemInt(m_hWnd, ID_edtQuality, NULL, FALSE);
            break;
        case ID_edtTimed:
            m_opt_edtTimed = (BYTE)GetDlgItemInt(m_hWnd, ID_edtTimed, NULL, FALSE);
            break;
        default:
            break;
        }
        break;
    default:
        break;
    }
}
Esempio n. 20
0
INT_PTR CALLBACK DlgProcPopupGeneral(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static bool bDlgInit = false;	// some controls send WM_COMMAND before or during WM_INITDIALOG

	static OPTTREE_OPTION *statusOptions = NULL;
	static int statusOptionsCount = 0;
	if (statusOptions) {
		int index;
		if (OptTree_ProcessMessage(hwnd, msg, wParam, lParam, &index, IDC_STATUSES, statusOptions, statusOptionsCount))
			return TRUE;
	}

	switch (msg) {
	case WM_INITDIALOG:
		// Seconds of delay
		CheckDlgButton(hwnd, IDC_INFINITEDELAY, PopupOptions.InfiniteDelay ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hwnd, IDC_LEAVEHOVERED, PopupOptions.LeaveHovered ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hwnd, IDC_SECONDS), !PopupOptions.InfiniteDelay);
		EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC1), !PopupOptions.InfiniteDelay);
		EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC2), !PopupOptions.InfiniteDelay);
		EnableWindow(GetDlgItem(hwnd, IDC_LEAVEHOVERED), !PopupOptions.InfiniteDelay);
		SetDlgItemInt(hwnd, IDC_SECONDS, PopupOptions.Seconds, FALSE);
		SendDlgItemMessage(hwnd, IDC_SECONDS_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(SETTING_LIFETIME_MAX, SETTING_LIFETIME_MIN));

		// Dynamic Resize
		CheckDlgButton(hwnd, IDC_DYNAMICRESIZE, PopupOptions.DynamicResize ? BST_CHECKED : BST_UNCHECKED);
		SetDlgItemText(hwnd, IDC_USEMAXIMUMWIDTH, PopupOptions.DynamicResize ? LPGENT("Maximum width") : LPGENT("Width"));
		// Minimum Width
		CheckDlgButton(hwnd, IDC_USEMINIMUMWIDTH, PopupOptions.UseMinimumWidth ? BST_CHECKED : BST_UNCHECKED);
		SendDlgItemMessage(hwnd, IDC_MINIMUMWIDTH_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(SETTING_MAXIMUMWIDTH_MAX, SETTING_MINIMUMWIDTH_MIN));
		SetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, PopupOptions.MinimumWidth, FALSE);
		// Maximum Width
		PopupOptions.UseMaximumWidth = PopupOptions.DynamicResize ? PopupOptions.UseMaximumWidth : TRUE;
		CheckDlgButton(hwnd, IDC_USEMAXIMUMWIDTH, PopupOptions.UseMaximumWidth ? BST_CHECKED : BST_UNCHECKED);
		SendDlgItemMessage(hwnd, IDC_MAXIMUMWIDTH_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(SETTING_MAXIMUMWIDTH_MAX, SETTING_MINIMUMWIDTH_MIN));
		SetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, PopupOptions.MaximumWidth, FALSE);
		// And finally let's enable/disable them.
		EnableWindow(GetDlgItem(hwnd, IDC_USEMINIMUMWIDTH), PopupOptions.DynamicResize);
		EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
		EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH_SPIN), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
		EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH), PopupOptions.UseMaximumWidth);
		EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH_SPIN), PopupOptions.UseMaximumWidth);

		// Position combobox.
		{
			HWND hCtrl = GetDlgItem(hwnd, IDC_WHERE);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upper left corner")), POS_UPPERLEFT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Lower left corner")), POS_LOWERLEFT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Lower right corner")), POS_LOWERRIGHT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upper right corner")), POS_UPPERRIGHT);
			SendDlgItemMessage(hwnd, IDC_WHERE, CB_SETCURSEL, PopupOptions.Position, 0);
		}
		// Configure popup area
		{
			HWND hCtrl = GetDlgItem(hwnd, IDC_CUSTOMPOS);
			SendMessage(hCtrl, BUTTONSETASFLATBTN, TRUE, 0);
			SendMessage(hCtrl, BUTTONADDTOOLTIP, (WPARAM)_T("Popup area"), BATF_TCHAR);
			SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIconEx(IDI_RESIZE));
		}
		// Spreading combobox
		{
			HWND hCtrl = GetDlgItem(hwnd, IDC_LAYOUT);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Horizontal")), SPREADING_HORIZONTAL);
			ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Vertical")), SPREADING_VERTICAL);
			SendDlgItemMessage(hwnd, IDC_LAYOUT, CB_SETCURSEL, PopupOptions.Spreading, 0);
		}
		// miscellaneous
		CheckDlgButton(hwnd, IDC_REORDERPOPUPS, PopupOptions.ReorderPopups ? BST_CHECKED : BST_UNCHECKED);

		// Popup enabled
		CheckDlgButton(hwnd, IDC_POPUPENABLED, PopupOptions.ModuleIsEnabled ? BST_UNCHECKED : BST_CHECKED);
		CheckDlgButton(hwnd, IDC_DISABLEINFS, PopupOptions.DisableWhenFullscreen ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hwnd, IDC_DISABLEINFS), PopupOptions.ModuleIsEnabled);
		EnableWindow(GetDlgItem(hwnd, IDC_STATUSES), PopupOptions.ModuleIsEnabled);

		// new status options
		{
			int protocolCount = 0;
			PROTOACCOUNT **protocols;
			Proto_EnumAccounts(&protocolCount, &protocols);
			DWORD globalFlags = 0;
			for (int i = 0; i < protocolCount; ++i) {
				if (!protocols[i]->bIsVirtual) {
					DWORD protoFlags = CallProtoService(protocols[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0);
					globalFlags |= protoFlags;
					statusOptionsCount += CountStatusModes(protoFlags);
				}
			}
			statusOptionsCount += CountStatusModes(globalFlags);

			statusOptions = new OPTTREE_OPTION[statusOptionsCount];

			int pos = AddStatusModes(statusOptions, 0, LPGENT("Global Status"), globalFlags);
			for (int i = 0; i < protocolCount; ++i) {
				if (!protocols[i]->bIsVirtual) {
					DWORD protoFlags = CallProtoService(protocols[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0);
					if (!CountStatusModes(protoFlags))
						continue;

					TCHAR prefix[128];
					mir_sntprintf(prefix, _countof(prefix), LPGENT("Protocol Status")_T("/%s"), protocols[i]->tszAccountName);
					pos = AddStatusModes(statusOptions, pos, prefix, protoFlags);
				}
			}

			int index;
			OptTree_ProcessMessage(hwnd, msg, wParam, lParam, &index, IDC_STATUSES, statusOptions, statusOptionsCount);

			for (int i = 0; i < protocolCount; ++i) {
				if (!protocols[i]->bIsVirtual) {
					DWORD protoFlags = CallProtoService(protocols[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0);
					if (!CountStatusModes(protoFlags))
						continue;

					char prefix[128];
					mir_snprintf(prefix, _countof(prefix), "Protocol Status/%s", protocols[i]->szModuleName);

					TCHAR pszSettingName[256];
					mir_sntprintf(pszSettingName, _countof(pszSettingName), LPGENT("Protocol Status")_T("/%s"), protocols[i]->tszAccountName);
					OptTree_SetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, db_get_dw(NULL, MODULNAME, prefix, 0), pszSettingName);
				}
			}
			OptTree_SetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, db_get_dw(NULL, MODULNAME, "Global Status", 0), LPGENT("Global Status"));
		}

		TranslateDialogDefault(hwnd);	// do it on end of WM_INITDIALOG
		bDlgInit = true;
		return TRUE;

	case WM_COMMAND:
		switch (HIWORD(wParam)) {
		case BN_CLICKED:	// Button controls
			switch (LOWORD(wParam)) {
			case IDC_INFINITEDELAY:
				PopupOptions.InfiniteDelay = !PopupOptions.InfiniteDelay;
				EnableWindow(GetDlgItem(hwnd, IDC_SECONDS), !PopupOptions.InfiniteDelay);
				EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC1), !PopupOptions.InfiniteDelay);
				EnableWindow(GetDlgItem(hwnd, IDC_SECONDS_STATIC2), !PopupOptions.InfiniteDelay);
				EnableWindow(GetDlgItem(hwnd, IDC_LEAVEHOVERED), !PopupOptions.InfiniteDelay);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_LEAVEHOVERED:
				PopupOptions.LeaveHovered = !PopupOptions.LeaveHovered;
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_DYNAMICRESIZE:
				PopupOptions.DynamicResize = !PopupOptions.DynamicResize;
				EnableWindow(GetDlgItem(hwnd, IDC_USEMINIMUMWIDTH), PopupOptions.DynamicResize);
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH_SPIN), PopupOptions.DynamicResize && PopupOptions.UseMinimumWidth);
				SetDlgItemText(hwnd, IDC_USEMAXIMUMWIDTH, PopupOptions.DynamicResize ? TranslateT("Maximum width") : TranslateT("Width"));
				if (!PopupOptions.DynamicResize) {
					PopupOptions.UseMaximumWidth = TRUE;
					CheckDlgButton(hwnd, IDC_USEMAXIMUMWIDTH, BST_CHECKED);
					EnableWindow(GetDlgItem(hwnd, IDC_USEMAXIMUMWIDTH), TRUE);
					EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH), TRUE);
					EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH_SPIN), TRUE);
				}
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_USEMINIMUMWIDTH:
				PopupOptions.UseMinimumWidth = !PopupOptions.UseMinimumWidth;
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH), PopupOptions.UseMinimumWidth);
				EnableWindow(GetDlgItem(hwnd, IDC_MINIMUMWIDTH_SPIN), PopupOptions.UseMinimumWidth);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_USEMAXIMUMWIDTH:
				PopupOptions.UseMaximumWidth = Button_GetCheck((HWND)lParam);
				if (!PopupOptions.DynamicResize) { // ugly - set always on if DynamicResize = off
					CheckDlgButton(hwnd, LOWORD(wParam), BST_CHECKED);
					PopupOptions.UseMaximumWidth = TRUE;
				}
				EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH), PopupOptions.UseMaximumWidth);
				EnableWindow(GetDlgItem(hwnd, IDC_MAXIMUMWIDTH_SPIN), PopupOptions.UseMaximumWidth);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_CUSTOMPOS:
			{
				RECT rcButton, rcBox;
				HWND hwndBox = CreateDialog(hInst, MAKEINTRESOURCE(IDD_POSITION), NULL, PositionBoxDlgProc);
				GetWindowRect((HWND)lParam, &rcButton);
				GetWindowRect(hwndBox, &rcBox);
				MoveWindow(hwndBox,
					rcButton.right - (rcBox.right - rcBox.left) + 15,
					rcButton.bottom + 3,
					rcBox.right - rcBox.left,
					rcBox.bottom - rcBox.top,
					FALSE);

				SetWindowLongPtr(hwndBox, GWL_EXSTYLE, GetWindowLongPtr(hwndBox, GWL_EXSTYLE) | WS_EX_LAYERED);
				SetLayeredWindowAttributes(hwndBox, NULL, 0, LWA_ALPHA);
				ShowWindow(hwndBox, SW_SHOW);
				for (int i = 0; i <= 255; i += 15) {
					SetLayeredWindowAttributes(hwndBox, NULL, i, LWA_ALPHA);
					UpdateWindow(hwndBox);
					Sleep(1);
				}
				SetWindowLongPtr(hwndBox, GWL_EXSTYLE, GetWindowLongPtr(hwndBox, GWL_EXSTYLE) & ~WS_EX_LAYERED);

				ShowWindow(hwndBox, SW_SHOW);
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			}
			break;

			case IDC_REORDERPOPUPS:
			{
				PopupOptions.ReorderPopups = !PopupOptions.ReorderPopups;
				PopupOptions.ReorderPopupsWarning = PopupOptions.ReorderPopups ? db_get_b(NULL, MODULNAME, "ReorderPopupsWarning", TRUE) : TRUE;
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			}
			break;

			case IDC_POPUPENABLED:
			{
				int chk = IsDlgButtonChecked(hwnd, IDC_POPUPENABLED);
				if (PopupOptions.ModuleIsEnabled&&chk || !PopupOptions.ModuleIsEnabled && !chk)
					svcEnableDisableMenuCommand(0, 0);
				EnableWindow(GetDlgItem(hwnd, IDC_STATUSES), PopupOptions.ModuleIsEnabled);
				EnableWindow(GetDlgItem(hwnd, IDC_DISABLEINFS), PopupOptions.ModuleIsEnabled);
			}
			break;

			case IDC_DISABLEINFS:
				PopupOptions.DisableWhenFullscreen = !PopupOptions.DisableWhenFullscreen;
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;

			case IDC_PREVIEW:
				PopupPreview();
				break;
			}
			break;

		case CBN_SELCHANGE:		// ComboBox controls
			switch (LOWORD(wParam)) {
				// lParam = Handle to the control
			case IDC_WHERE:
				PopupOptions.Position = ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;
			case IDC_LAYOUT:
				PopupOptions.Spreading = ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam));
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				break;
			}
			break;

		case EN_CHANGE:			// Edit controls change
			if (!bDlgInit) break;
			switch (LOWORD(wParam)) {
				// lParam = Handle to the control
			case IDC_SECONDS:
			{
				int seconds = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (seconds >= SETTING_LIFETIME_MIN &&
					seconds <= SETTING_LIFETIME_MAX &&
					seconds != PopupOptions.Seconds) {
					PopupOptions.Seconds = seconds;
					SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				}
			}
			break;
			case IDC_MINIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, NULL, FALSE);
				if (temp >= SETTING_MINIMUMWIDTH_MIN &&
					temp <= SETTING_MAXIMUMWIDTH_MAX &&
					temp != PopupOptions.MinimumWidth) {
					PopupOptions.MinimumWidth = temp;
					SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				}
			}
			break;
			case IDC_MAXIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, NULL, FALSE);
				if (temp >= SETTING_MINIMUMWIDTH_MIN &&
					temp <= SETTING_MAXIMUMWIDTH_MAX &&
					temp != PopupOptions.MaximumWidth) {
					PopupOptions.MaximumWidth = temp;
					SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
				}
			}
			break;
			}// end switch(idCtrl)
			break;

		case EN_KILLFOCUS:		// Edit controls lost fokus
			switch (LOWORD(wParam)) {
				// lParam = Handle to the control
			case IDC_SECONDS:
			{
				int seconds = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (seconds > SETTING_LIFETIME_MAX)
					PopupOptions.Seconds = SETTING_LIFETIME_MAX;
				else if (seconds < SETTING_LIFETIME_MIN)
					PopupOptions.Seconds = SETTING_LIFETIME_MIN;
				if (seconds != PopupOptions.Seconds) {
					SetDlgItemInt(hwnd, LOWORD(wParam), PopupOptions.Seconds, FALSE);
					ErrorMSG(SETTING_LIFETIME_MIN, SETTING_LIFETIME_MAX);
					SetFocus((HWND)lParam);
				}
			}
			break;
			case IDC_MINIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (temp < SETTING_MINIMUMWIDTH_MIN)
					PopupOptions.MinimumWidth = SETTING_MINIMUMWIDTH_MIN;
				else if (temp > SETTING_MAXIMUMWIDTH_MAX)
					PopupOptions.MinimumWidth = SETTING_MAXIMUMWIDTH_MAX;
				if (temp != PopupOptions.MinimumWidth) {
					SetDlgItemInt(hwnd, LOWORD(wParam), PopupOptions.MinimumWidth, FALSE);
					ErrorMSG(SETTING_MINIMUMWIDTH_MIN, SETTING_MAXIMUMWIDTH_MAX);
					SetFocus((HWND)lParam);
					break;
				}
				if (temp > PopupOptions.MaximumWidth) {
					PopupOptions.MaximumWidth = min(temp, SETTING_MAXIMUMWIDTH_MAX);
					SetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, PopupOptions.MaximumWidth, FALSE);
				}
			}
			break;
			case IDC_MAXIMUMWIDTH:
			{
				int temp = GetDlgItemInt(hwnd, LOWORD(wParam), NULL, FALSE);
				if (temp >= SETTING_MAXIMUMWIDTH_MAX)
					PopupOptions.MaximumWidth = SETTING_MAXIMUMWIDTH_MAX;
				else if (temp < SETTING_MINIMUMWIDTH_MIN)
					PopupOptions.MaximumWidth = SETTING_MINIMUMWIDTH_MIN;
				if (temp != PopupOptions.MaximumWidth) {
					SetDlgItemInt(hwnd, LOWORD(wParam), PopupOptions.MaximumWidth, FALSE);
					ErrorMSG(SETTING_MINIMUMWIDTH_MIN, SETTING_MAXIMUMWIDTH_MAX);
					SetFocus((HWND)lParam);
					break;
				}
				if (temp < PopupOptions.MinimumWidth) {
					PopupOptions.MinimumWidth = max(temp, SETTING_MINIMUMWIDTH_MIN);
					SetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, PopupOptions.MinimumWidth, FALSE);
				}
			}
			break;
			}
			break;
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_RESET:
				LoadOption_General();
				return TRUE;

			case PSN_APPLY:
				// Seconds
				db_set_b(NULL, MODULNAME, "InfiniteDelay", PopupOptions.InfiniteDelay);
				db_set_w(NULL, MODULNAME, "Seconds", (WORD)PopupOptions.Seconds);
				db_set_b(NULL, MODULNAME, "LeaveHovered", PopupOptions.LeaveHovered);

				// Dynamic Resize
				db_set_b(NULL, MODULNAME, "DynamicResize", PopupOptions.DynamicResize);
				db_set_b(NULL, MODULNAME, "UseMinimumWidth", PopupOptions.UseMinimumWidth);
				db_set_w(NULL, MODULNAME, "MinimumWidth", PopupOptions.MinimumWidth);
				db_set_b(NULL, MODULNAME, "UseMaximumWidth", PopupOptions.UseMaximumWidth);
				db_set_w(NULL, MODULNAME, "MaximumWidth", PopupOptions.MaximumWidth);

				// Position
				db_set_b(NULL, MODULNAME, "Position", (BYTE)PopupOptions.Position);

				// Configure popup area
				db_set_w(NULL, MODULNAME, "gapTop", (WORD)PopupOptions.gapTop);
				db_set_w(NULL, MODULNAME, "gapBottom", (WORD)PopupOptions.gapBottom);
				db_set_w(NULL, MODULNAME, "gapLeft", (WORD)PopupOptions.gapLeft);
				db_set_w(NULL, MODULNAME, "gapRight", (WORD)PopupOptions.gapRight);
				db_set_w(NULL, MODULNAME, "spacing", (WORD)PopupOptions.spacing);

				// Spreading
				db_set_b(NULL, MODULNAME, "Spreading", (BYTE)PopupOptions.Spreading);

				// miscellaneous
				Check_ReorderPopups(hwnd);	// this save also PopupOptions.ReorderPopups

				// disable When
				db_set_b(NULL, MODULNAME, "DisableWhenFullscreen", PopupOptions.DisableWhenFullscreen);

				// new status options
				{
					int protocolCount;
					PROTOACCOUNT **protocols;
					Proto_EnumAccounts(&protocolCount, &protocols);

					for (int i = 0; i < protocolCount; ++i) {
						if (!protocols[i]->bIsVirtual) {
							char prefix[128];
							mir_snprintf(prefix, _countof(prefix), "Protocol Status/%s", protocols[i]->szModuleName);

							TCHAR pszSettingName[256];
							mir_sntprintf(pszSettingName, _countof(pszSettingName), _T("Protocol Status/%s"), protocols[i]->tszAccountName);
							db_set_dw(NULL, MODULNAME, prefix, OptTree_GetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, pszSettingName));
						}
					}
					db_set_dw(NULL, MODULNAME, "Global Status", OptTree_GetOptions(hwnd, IDC_STATUSES, statusOptions, statusOptionsCount, _T("Global Status")));
				}
				return TRUE;
			}
			break;

		case IDC_MINIMUMWIDTH_SPIN:
		{
			LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
			int temp = lpnmud->iPos + lpnmud->iDelta;
			if (temp > PopupOptions.MaximumWidth) {
				PopupOptions.MaximumWidth = min(temp, SETTING_MAXIMUMWIDTH_MAX);
				SetDlgItemInt(hwnd, IDC_MAXIMUMWIDTH, PopupOptions.MaximumWidth, FALSE);
			}
		}
		break;

		case IDC_MAXIMUMWIDTH_SPIN:
		{
			LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
			int temp = lpnmud->iPos + lpnmud->iDelta;
			if (temp < PopupOptions.MinimumWidth) {
				PopupOptions.MinimumWidth = max(temp, SETTING_MINIMUMWIDTH_MIN);
				SetDlgItemInt(hwnd, IDC_MINIMUMWIDTH, PopupOptions.MinimumWidth, FALSE);
			}
		}
		}
		break;

	case WM_DESTROY:
		if (statusOptions) {
			for (int i = 0; i < statusOptionsCount; ++i) {
				mir_free(statusOptions[i].pszOptionName);
				mir_free(statusOptions[i].pszSettingName);
			}
			delete[] statusOptions;
			statusOptions = NULL;
			statusOptionsCount = 0;
			bDlgInit = false;
		}
		break;
	}
	return FALSE;
}
void
ConnectionCommunity::OnConnect(HWND hwnd, ConnectionInfo * dbname)
{
	Tunnel		*tunnel;
    MYSQL		*mysql;
	HWND		lastfocus = GetFocus();
	wyString	conn, temp, dirnamestr;
	wyWChar		directory[MAX_PATH + 1] = {0}, *lpfileport = 0, pass[MAX_PATH + 1] = {0};
	HWND		hwndcombo;
	wyInt32		count, storepwd, ret;

//	DEBUG_ENTER("clicked ok");

    tunnel = CreateTunnel(wyFalse);

//	DEBUG_LOG("created tunnel");

	// Call ConnectToMySQL function to initialize a new mySQL structure and connect to
	// mySQL server with the connection details. The function will return a valid mysql
	// pointer if connection successful and if not then it will return NULL.
	// If null then show the standard mySQL errors given by the mySQL API.
	/* set correct values for tunnel to use HTTP authentication */
	dbname->m_tunnel = tunnel;

    mysql = ConnectToMySQL(hwnd, dbname);
	if(mysql == NULL)
    {
        delete tunnel;
		SetFocus(lastfocus);
	} 
    else if(dbname->m_db.GetLength() ==0 ||(IsDatabaseValid(dbname->m_db, mysql, tunnel) == wyTrue))
    {
		// Successful so write the current details in connection .ini file 
		// so that when the user uses the software again it will show the same details.
		dbname->m_mysql = mysql;
		dbname->m_tunnel = tunnel;

		WriteConnDetails(hwnd);

		ret = SearchFilePath(L"sqlyog", L".ini", MAX_PATH, directory, &lpfileport);
		if(ret == 0)
        {
		    yog_enddialog(hwnd, (wyInt32)1);
			return;
		}
		
		/* if the user has changed any information then we ask him whether he wants to save */
		if(m_conndetaildirty == wyTrue)
		{
			if(ConfirmAndSaveConnection(hwnd, wyTrue) == wyFalse)
				return;
		}
		else 
        {
			/*	even if he has not selected to save, we need to check for password thing
				as the user might diable on the store_password first and then make
				modification to the password, in that case the state will not be dirty
				and the value will not be stored */
			VERIFY(hwndcombo = GetDlgItem(hwnd, IDC_DESC));

			count  = SendMessage(hwndcombo, CB_GETCOUNT, 0, 0);

			if(!count)
            {
				yog_enddialog(hwnd,(wyInt32)1);
				return;
			}

			VERIFY ((count = SendMessage(hwndcombo, CB_GETCURSEL, 0, 0))!= CB_ERR);
			count = SendMessage(hwndcombo, CB_GETITEMDATA, count, 0);
			conn.Sprintf("Connection %u", count);

			storepwd = Button_GetCheck(GetDlgItem(hwnd, IDC_DLGCONNECT_STOREPASSWORD));

			/* now we only save the password if the user has asked for otherwise we remove it only */
			/* feature implemented in v5.0 */
			dirnamestr.SetAs(directory);
            //WritePrivateProfileStringA(conn.GetString(), "Password01", NULL, dirnamestr.GetString());
			wyIni::IniDeleteKey(conn.GetString(), "Password01", dirnamestr.GetString());
			if(!storepwd)
            {
				//WritePrivateProfileStringA(conn.GetString(), "Password", NULL, dirnamestr.GetString());
				wyIni::IniDeleteKey(conn.GetString(), "Password", dirnamestr.GetString());
            }
            else
            {
                GetWindowText(GetDlgItem(hwnd, IDC_DLGCONNECT_PASSWORD), pass, MAX_PATH);
                temp.SetAs(pass);
                EncodePassword(temp);
                wyIni::IniWriteString(conn.GetString(), "Password", temp.GetString(), dirnamestr.GetString());
            }
			
			/* write the store password value too */
			temp.Sprintf("%d", storepwd);
			ret =	wyIni::IniWriteString (conn.GetString(), "StorePassword", temp.GetString(), dirnamestr.GetString());
		}

		m_rgbobbkcolor = m_rgbconnection;
		m_rgbobfgcolor = m_rgbconnectionfg;

		yog_enddialog(hwnd,(wyInt32)1);
	}
	else
	{
		ShowMySQLError(hwnd, tunnel, &mysql, NULL, wyTrue);

		//fix a bug, database neme was erasing on error
		//SendMessage(GetDlgItem(hwnd, IDC_DLGCONNECT_DATABASE), WM_SETTEXT, 0,(LPARAM)L"");

		SetFocus(GetDlgItem(hwnd,IDC_DLGCONNECT_DATABASE));
		return;
	}
}
Esempio n. 22
0
VOID PhpAdvancedPageSave(
    _In_ HWND hwndDlg
    )
{
    ULONG sampleCount;

    SetSettingForDlgItemCheck(hwndDlg, IDC_ENABLEWARNINGS, L"EnableWarnings");
    SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLEKERNELMODEDRIVER, L"EnableKph");
    SetSettingForDlgItemCheck(hwndDlg, IDC_HIDEUNNAMEDHANDLES, L"HideUnnamedHandles");
    SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLESTAGE2, L"EnableStage2");
    SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLENETWORKRESOLVE, L"EnableNetworkResolve");
    SetSettingForDlgItemCheck(hwndDlg, IDC_PROPAGATECPUUSAGE, L"PropagateCpuUsage");
    SetSettingForDlgItemCheck(hwndDlg, IDC_ENABLEINSTANTTOOLTIPS, L"EnableInstantTooltips");

    if (WindowsVersion >= WINDOWS_7)
        SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLECYCLECPUUSAGE, L"EnableCycleCpuUsage");

    sampleCount = GetDlgItemInt(hwndDlg, IDC_SAMPLECOUNT, NULL, FALSE);
    SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_SAMPLECOUNTAUTOMATIC, L"SampleCountAutomatic");

    if (sampleCount == 0)
        sampleCount = 1;

    if (sampleCount != PhGetIntegerSetting(L"SampleCount"))
        RestartRequired = TRUE;

    PhSetIntegerSetting(L"SampleCount", sampleCount);

    // Replace Task Manager
    if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_REPLACETASKMANAGER)))
    {
        NTSTATUS status;
        HANDLE taskmgrKeyHandle;
        BOOLEAN replaceTaskMgr;
        UNICODE_STRING valueName;

        replaceTaskMgr = Button_GetCheck(GetDlgItem(hwndDlg, IDC_REPLACETASKMANAGER)) == BST_CHECKED;

        if (OldReplaceTaskMgr != replaceTaskMgr)
        {
            // We should have created the key back in PhpAdvancedPageLoad, which is why
            // we're opening the key here.
            if (NT_SUCCESS(PhOpenKey(
                &taskmgrKeyHandle,
                KEY_WRITE,
                PH_KEY_LOCAL_MACHINE,
                &TaskMgrImageOptionsKeyName,
                0
                )))
            {
                RtlInitUnicodeString(&valueName, L"Debugger");

                if (replaceTaskMgr)
                {
                    PPH_STRING quotedFileName;

                    quotedFileName = PhConcatStrings(3, L"\"", PhApplicationFileName->Buffer, L"\"");
                    status = NtSetValueKey(taskmgrKeyHandle, &valueName, 0, REG_SZ, quotedFileName->Buffer, (ULONG)quotedFileName->Length + 2);
                    PhDereferenceObject(quotedFileName);
                }
                else
                {
                    status = NtDeleteValueKey(taskmgrKeyHandle, &valueName);
                }

                if (!NT_SUCCESS(status))
                    PhShowStatus(hwndDlg, L"Unable to replace Task Manager", status, 0);

                NtClose(taskmgrKeyHandle);
            }
        }
    }
}
Esempio n. 23
0
INT_PTR CALLBACK DlgProcSettings(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	static TCHAR customCommand[MAX_PATH] = {0};
	static TCHAR customText[TITLE_SIZE] = {0};
	static TCHAR szKeyTemp[MAX_PATH + GUID_STRING_SIZE];

	static DWORD showMenu = 2;	//0 off, 1 on, 2 unknown
	static DWORD useMenuIcon = 1;	// 0 off, otherwise on

	HKEY settingKey;
	LONG result;
	DWORD size = 0;

	switch(uMsg) {
		case WM_INITDIALOG: {
			wsprintf(szKeyTemp, TEXT("CLSID\\%s\\Settings"), szGUID);
			result = RegOpenKeyEx(HKEY_CLASSES_ROOT, szKeyTemp, 0, KEY_READ, &settingKey);
			if (result == ERROR_SUCCESS) {
				size = sizeof(TCHAR)*TITLE_SIZE;
				result = RegQueryValueEx(settingKey, TEXT("Title"), NULL, NULL, (LPBYTE)(customText), &size);
				if (result != ERROR_SUCCESS) {
					lstrcpyn(customText, szDefaultMenutext, TITLE_SIZE);
				}

				size = sizeof(TCHAR)*MAX_PATH;
				result = RegQueryValueEx(settingKey, TEXT("Custom"), NULL, NULL, (LPBYTE)(customCommand), &size);
				if (result != ERROR_SUCCESS) {
					lstrcpyn(customCommand, TEXT(""), MAX_PATH);
				}

				size = sizeof(DWORD);
				result = RegQueryValueEx(settingKey, TEXT("Dynamic"), NULL, NULL, (BYTE*)(&isDynamic), &size);
				if (result != ERROR_SUCCESS) {
					isDynamic = 1;
				}

				size = sizeof(DWORD);
				result = RegQueryValueEx(settingKey, TEXT("ShowIcon"), NULL, NULL, (BYTE*)(&useMenuIcon), &size);
				if (result != ERROR_SUCCESS) {
					useMenuIcon = 1;
				}

				RegCloseKey(settingKey);
			}

			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_USECONTEXT), BST_INDETERMINATE);
			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_USEICON), BST_INDETERMINATE);

			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_CONTEXTICON), useMenuIcon?BST_CHECKED:BST_UNCHECKED);
			Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_ISDYNAMIC), isDynamic?BST_CHECKED:BST_UNCHECKED);

			SetDlgItemText(hwndDlg, IDC_EDIT_MENU, customText);
			SetDlgItemText(hwndDlg, IDC_EDIT_COMMAND, customCommand);

			return TRUE;
			break; }
		case WM_COMMAND: {
			switch(LOWORD(wParam)) {
				case IDOK: {
					//Store settings
					GetDlgItemText(hwndDlg, IDC_EDIT_MENU, customText, TITLE_SIZE);
					GetDlgItemText(hwndDlg, IDC_EDIT_COMMAND, customCommand, MAX_PATH);
					int textLen = lstrlen(customText);
					int commandLen = lstrlen(customCommand);

					wsprintf(szKeyTemp, TEXT("CLSID\\%s\\Settings"), szGUID);
					result = RegCreateKeyEx(HKEY_CLASSES_ROOT, szKeyTemp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
					if (result == ERROR_SUCCESS) {

						result = RegSetValueEx(settingKey, TEXT("Title"), 0,REG_SZ, (LPBYTE)customText, (textLen+1)*sizeof(TCHAR));
						result = RegSetValueEx(settingKey, TEXT("Custom"), 0,REG_SZ, (LPBYTE)customCommand, (commandLen+1)*sizeof(TCHAR));

						result = RegSetValueEx(settingKey, TEXT("Dynamic"), 0, REG_DWORD, (LPBYTE)&isDynamic, sizeof(DWORD));
						result = RegSetValueEx(settingKey, TEXT("ShowIcon"), 0, REG_DWORD, (LPBYTE)&useMenuIcon, sizeof(DWORD));

						RegCloseKey(settingKey);
					}

					if (showMenu == 1) {
						result = RegCreateKeyEx(HKEY_CLASSES_ROOT, szShellExtensionKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
						if (result == ERROR_SUCCESS) {
							result = RegSetValueEx(settingKey, NULL, 0,REG_SZ, (LPBYTE)szGUID, (lstrlen(szGUID)+1)*sizeof(TCHAR));
							RegCloseKey(settingKey);
						}
					} else if (showMenu == 0) {
						RegDeleteKey(HKEY_CLASSES_ROOT, szShellExtensionKey);
					}

					if (showIcon == 1) {
						result = RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("Notepad++_file\\shellex\\IconHandler"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
						if (result == ERROR_SUCCESS) {
							result = RegSetValueEx(settingKey, NULL, 0,REG_SZ, (LPBYTE)szGUID, (lstrlen(szGUID)+1)*sizeof(TCHAR));
							RegCloseKey(settingKey);
						}
					} else if (showIcon == 0) {
						RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Notepad++_file\\shellex\\IconHandler"));
						RegDeleteKey(HKEY_CLASSES_ROOT, TEXT("Notepad++_file\\shellex"));
					}

					PostMessage(hwndDlg, WM_CLOSE, 0, 0);
					break; }
				case IDC_CHECK_USECONTEXT: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						showMenu = 1;
					else if (state == BST_UNCHECKED)
						showMenu = 0;
					else
						showMenu = 2;
					break; }
				case IDC_CHECK_USEICON: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						showIcon = 1;
					else if (state == BST_UNCHECKED)
						showIcon = 0;
					else
						showIcon = 2;
					break; }
				case IDC_CHECK_CONTEXTICON: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						useMenuIcon = 1;
					else
						useMenuIcon = 0;
					break; }
				case IDC_CHECK_ISDYNAMIC: {
					int state = Button_GetCheck((HWND)lParam);
					if (state == BST_CHECKED)
						isDynamic = 1;
					else
						isDynamic = 0;
					break; }
				default:
					break;
			}

			return TRUE;
			break; }
		case WM_CLOSE: {
			EndDialog(hwndDlg, 0);
			return TRUE;
			break; }
		default:
			break;
	}

	return FALSE;
}
Esempio n. 24
0
INT_PTR CALLBACK PhpOptionsAdvancedDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            PhpPageInit(hwndDlg);
            PhpAdvancedPageLoad(hwndDlg);

            if (PhStartupParameters.ShowOptions)
            {
                // Disable all controls except for Replace Task Manager.
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLEWARNINGS), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLEKERNELMODEDRIVER), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_HIDEUNNAMEDHANDLES), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLESTAGE2), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLENETWORKRESOLVE), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_PROPAGATECPUUSAGE), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLEINSTANTTOOLTIPS), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLECYCLECPUUSAGE), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_SAMPLECOUNTLABEL), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_SAMPLECOUNT), FALSE);
                EnableWindow(GetDlgItem(hwndDlg, IDC_SAMPLECOUNTAUTOMATIC), FALSE);
            }
            else
            {
                if (WindowsVersion < WINDOWS_7)
                    EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLECYCLECPUUSAGE), FALSE); // cycle-based CPU usage not available before Windows 7
            }
        }
        break;
    case WM_DESTROY:
        {
            if (OldTaskMgrDebugger)
                PhDereferenceObject(OldTaskMgrDebugger);
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDC_CHANGE:
                {
                    HANDLE threadHandle;
                    RECT windowRect;

                    // Save the options so they don't get "overwritten" when
                    // WM_PH_CHILD_EXIT gets sent.
                    PhpAdvancedPageSave(hwndDlg);

                    GetWindowRect(GetParent(hwndDlg), &windowRect);
                    WindowHandleForElevate = hwndDlg;
                    threadHandle = PhCreateThread(0, PhpElevateAdvancedThreadStart, PhFormatString(
                        L"-showoptions -hwnd %Ix -point %u,%u",
                        (ULONG_PTR)GetParent(hwndDlg),
                        windowRect.left + 20,
                        windowRect.top + 20
                        ));

                    if (threadHandle)
                        NtClose(threadHandle);
                }
                break;
            case IDC_SAMPLECOUNTAUTOMATIC:
                {
                    EnableWindow(GetDlgItem(hwndDlg, IDC_SAMPLECOUNT), Button_GetCheck(GetDlgItem(hwndDlg, IDC_SAMPLECOUNTAUTOMATIC)) != BST_CHECKED);
                }
                break;
            }
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case PSN_APPLY:
                {
                    PhpAdvancedPageSave(hwndDlg);
                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
                }
                return TRUE;
            }
        }
        break;
    case WM_PH_CHILD_EXIT:
        {
            PhpAdvancedPageLoad(hwndDlg);
        }
        break;
    }

    return FALSE;
}
Esempio n. 25
0
/*
	WM_COMMAND
*/
VOID Application::Cls_OnCommand(HWND hwnd, INT id, HWND hwndCtl, UINT codeNotify)
{
	static BOOL IsStop = FALSE;				//был ли нажат Stop
	switch (id)
	{
		case IDC_BTNPLAY:						//Play
		{
			if (hStream == NULL && playlist.songs.size() == 0)
			{
				BOOL isOpen = openFile_LoadMusic(hwnd);	
				if (isOpen == TRUE)
				{
					play(hStream);
					SetTimer(hwnd, id_timer, 1000, 0);
					SetTimer(hwnd, idTimerBySpectr, 100, 0);
				}
			}
			else if (hStream == NULL && playlist.songs.size() > 0)
			{
				hStream = playlist.songs[0].hStream;
				play(hStream);
				SetTimer(hwnd, id_timer, 1000, 0);
				SetTimer(hwnd, idTimerBySpectr, 100, 0);
			}
			else if (IsStop == FALSE)
			{
				BASS_Start();
				BASS_ChannelPlay(hStream, 0);
				SetTimer(hwnd, id_timer, 1000, 0);
				SetTimer(hwnd, idTimerBySpectr, 100 , 0);
			}
			else
			{
				play(hStream);
				SetTimer(hwnd, id_timer, 1000, 0);
				SetTimer(hwnd, idTimerBySpectr, 100, 0);
			}
			IsStop = FALSE;
			break;
		}
		case IDC_BTNSTOP:									//Stop
		{
			stop(hStream);
			IsStop = TRUE;
			secPlaying = 0;
			KillTimer(hwnd, id_timer);
			KillTimer(hwnd, idTimerBySpectr);
			id_timer = !id_timer;
			idTimerBySpectr = !idTimerBySpectr;
			break;
		}
		case IDC_BTNPAUSE:									//Pause
		{
			pause();
			KillTimer(hwnd, id_timer);
			KillTimer(hwnd, idTimerBySpectr);
			break;
		}
		/*
			Checkbox плейлист
		*/
		case IDC_CHECKPLAYLIST:
		{
			static HWND hCheckPlayList = GetDlgItem(hwnd, IDC_CHECKPLAYLIST);
			BOOL isShow = Button_GetCheck(hCheckPlayList);
			if (isShow)
			{
				SendMessage(hCheckPlayList, BM_SETCHECK, BST_CHECKED, 0);
				playlist.showPlayList(SW_SHOW);
			}
			else
			{
				SendMessage(hCheckPlayList, BM_SETCHECK, BST_UNCHECKED, 0);
				playlist.showPlayList(SW_HIDE);
			}

			break;
		}
		/*
			Checkbox эквалайзер
		*/
		case IDC_CHECKEQUALIZER:
		{
			static HWND hCheckEqualizer = GetDlgItem(hwnd, IDC_CHECKEQUALIZER);
			BOOL isShow = Button_GetCheck(hCheckEqualizer);
			if (isShow)
			{
				isShow = TRUE;
				SendMessage(hCheckEqualizer, BM_SETCHECK, BST_CHECKED, 0);
				equalizer.ShowEqualizer(SW_SHOW);
			}
			else
			{
				isShow = FALSE;
				SendMessage(hCheckEqualizer, BM_SETCHECK, BST_UNCHECKED, 0);
				equalizer.ShowEqualizer(SW_HIDE);
			}
			break;
		}
		case IDC_ADDSONG:									//Добавление песни
		{
			openFile_LoadMusic(hwnd);
			break;
		}
		case IDC_PREVSONG:									//Предыдущая песня
		{
			prev();
			break;
		}
		case IDC_NEXTSONG:									//Следующая песня
		{
			next();
			break;
		}
		case IDC_BTNCLOSE:									//Закрытие программы
		{
			EndDialog(hwnd, 0);
			break;
		}
		case IDC_REPEATSONG:								//Повтор песни
		{
			if (IsRepeatSong == FALSE)
			{
				SendDlgItemMessage(hwnd, IDC_REPEATSONG, WM_SETTEXT, 0, (LPARAM)TEXT("Yes"));
				HBITMAP bmp = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAPREPEAT));
				SendMessage(GetDlgItem(hwnd, IDC_REPEATSONG), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
				IsRepeatSong = TRUE;
			}
			else
			{
				SendDlgItemMessage(hwnd, IDC_REPEATSONG, WM_SETTEXT, 0, (LPARAM)TEXT("No"));
				HBITMAP bmp = LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAPNOREPEAT));
				SendMessage(GetDlgItem(hwnd, IDC_REPEATSONG), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
				IsRepeatSong = FALSE;
			}
			break;
		}
		/*
			Цвета контура
		*/
		case COLOR_CONTOUR_RED:
		{
			UncheckedAllMenuItemContour();
			CheckMenuItem(hColorContour, COLOR_CONTOUR_RED, MF_BYCOMMAND | MF_CHECKED);
			ColorContourSpectrum(255, 0, 0);
			break;
		}
		case COLOR_CONTOUR_GREEN:
		{
			UncheckedAllMenuItemContour();
			CheckMenuItem(hColorContour, COLOR_CONTOUR_GREEN, MF_BYCOMMAND | MF_CHECKED);
			ColorContourSpectrum(0, 255, 0);
			break;
		}
		case COLOR_CONTOUR_BLUE:
		{
			UncheckedAllMenuItemContour();
			CheckMenuItem(hColorContour, COLOR_CONTOUR_BLUE, MF_BYCOMMAND | MF_CHECKED);
			ColorContourSpectrum(0, 0, 255);
			break;
		}
		case COLOR_CONTOUR_WHITE:
		{
			UncheckedAllMenuItemContour();
			CheckMenuItem(hColorContour, COLOR_CONTOUR_WHITE, MF_BYCOMMAND | MF_CHECKED);
			ColorContourSpectrum(255, 255, 255);
			break;
		}
		case COLOR_CONTOUR_BLACK:
		{
			UncheckedAllMenuItemContour();
			CheckMenuItem(hColorContour, COLOR_CONTOUR_BLACK, MF_BYCOMMAND | MF_CHECKED);
			ColorContourSpectrum(0, 0, 0);
			break;
		}
		/*
			Цвета заливки
		*/
		case COLOR_FILL_RED:
		{
			UncheckedAllMenuItemFill();
			CheckMenuItem(hColorFill, COLOR_FILL_RED, MF_BYCOMMAND | MF_CHECKED);
			ColorFillSpectrum(255, 0, 0);
			break;
		}
		case COLOR_FILL_GREEN:
		{
			UncheckedAllMenuItemFill();
			CheckMenuItem(hColorFill, COLOR_FILL_GREEN, MF_BYCOMMAND | MF_CHECKED);
			ColorFillSpectrum(0, 255, 0);
			break;
		}
		case COLOR_FILL_BLUE:
		{
			UncheckedAllMenuItemFill();
			CheckMenuItem(hColorFill, COLOR_FILL_BLUE, MF_BYCOMMAND | MF_CHECKED);
			ColorFillSpectrum(0, 0, 255);
			break;
		}
		case COLOR_FILL_WHITE:
		{
			UncheckedAllMenuItemFill();
			CheckMenuItem(hColorFill, COLOR_FILL_WHITE, MF_BYCOMMAND | MF_CHECKED);
			ColorFillSpectrum(255, 255, 255);
			break;
		}
		case COLOR_FILL_BLACK:
		{
			UncheckedAllMenuItemFill();
			CheckMenuItem(hColorFill, COLOR_FILL_BLACK, MF_BYCOMMAND | MF_CHECKED);
			ColorFillSpectrum(0, 0, 0);
			break;
		}
		/*
			Прозрачность окна
		*/
		case TRANSPARENCY_100:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_100, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 100);
			break;
		}
		case TRANSPARENCY_90:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_90, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 90);
			break;
		}
		case TRANSPARENCY_80:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_80, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 80);
			break;
		}
		case TRANSPARENCY_70:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_70, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 70);
			break;
		}
		case TRANSPARENCY_60:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_60, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 60);
			break;
		}
		case TRANSPARENCY_50:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_50, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 50);
			break;
		}
		case TRANSPARENCY_40:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_40, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 40);
			break;
		}
		case TRANSPARENCY_30:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_30, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 30);
			break;
		}
		case TRANSPARENCY_20:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_20, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 20);
			break;
		}
		case TRANSPARENCY_10:
		{
			UncheckedAllMenuItemTransperency();
			CheckMenuItem(hTranperency, TRANSPARENCY_10, MF_BYCOMMAND | MF_CHECKED);
			TransparencyWindow(hwnd, 10);
			break;
		}
		default:
			break;
	}
}
void Dlg_AchievementsReporter::OnOK(HWND hwnd)
{

	m_hProblem2 = GetDlgItem(hwnd, IDC_RA_PROBLEMTYPE2);





	const auto bProblem1Sel{ Button_GetCheck(m_hProblem1) };
	const auto bProblem2Sel{ Button_GetCheck(m_hProblem2) };

	if ((bProblem1Sel == false) && (bProblem2Sel == false))
	{
		MessageBox(nullptr, TEXT("Please select a problem type."),
			TEXT("Warning"), MB_ICONWARNING);
		return;
	}
	// 0==?
	auto nProblemType{ bProblem1Sel ? 1 : bProblem2Sel ? 2 : 0 };
	auto sProblemTypeNice{ PROBLEM_STR.at(to_unsigned(nProblemType)) };

	std::string sBuggedIDs;
	sBuggedIDs.reserve(1024);

	int nReportCount = 0;

	const size_t nListSize = to_unsigned(ListView_GetItemCount(m_hList));
	for (size_t i = 0; i < nListSize; ++i)
	{
		if (ListView_GetCheckState(m_hList, i) != 0)
		{
			//	NASTY big assumption here...
			auto buffer{
				tfm::format("%d,",
				g_pActiveAchievements->GetAchievement(i).ID())
			};
			sBuggedIDs+=buffer;

			//ListView_GetItem( hList );	
			nReportCount++;
		}
	}

	// Needs another check
	if (sBuggedIDs == "")
	{
		// even with this it might be strange, there has to be a better way to do this...
		// The close button will still close it even though this warning will show up
		MessageBox(GetActiveWindow(),
			_T("You need to to select at least one achievement"),
			_T("Warning"), MB_OK);
		return;
	}

	if (nReportCount > 5)
	{
		if (MessageBox(nullptr,
			TEXT("You have over 5 achievements selected. Is this OK?"),
			TEXT("Warning"), MB_YESNO) == IDNO)
			return;
	}


	m_hComment = GetDlgItem(hwnd, IDC_RA_BROKENACHIEVEMENTREPORTCOMMENT);

	// Now I remember
	auto len{ GetTextLength(m_hComment)};
	std::string sBugReportComment;

	// This ones is extremly important or the capacity will change
	sBugReportComment.reserve(static_cast<std::size_t>(len));
	GetText(m_hComment, len, sBugReportComment.data());


	//	Intentionally MBCS
	auto sBugReportInFull{ tfm::format(
		"--New Bug Report--\n"
		"\n"
		"Game: %s\n"
		"Achievement IDs: %s\n"
		"Problem: %s\n"
		"Reporter: %s\n"
		"ROM Checksum: %s\n"
		"\n"
		"Comment: %s\n"
		"\n"
		"Is this OK?",
		g_pCurrentGameData->GameTitle(),
		sBuggedIDs,
		sProblemTypeNice,
		username(),
		g_sCurrentROMMD5,
		sBugReportComment.c_str()) // strange, it won't show itself as a regular string
	};

	if (MessageBox(nullptr, NativeStr(sBugReportInFull).c_str(),
		TEXT("Summary"), MB_YESNO) == IDNO)
		return;

	PostArgs args
	{
		{ 'u', cusername() },
		{ 't', user_token()},
		{ 'i', sBuggedIDs.c_str() },
		{ 'p', std::to_string(nProblemType) },
		{ 'n', sBugReportComment.c_str() },
		{ 'm', g_sCurrentROMMD5.c_str() }
	};

	Document doc;
	// Something is wrong with this function...
	if (RAWeb::DoBlockingRequest(RequestSubmitTicket, args, doc))
	{

		// really weird, success is in there but it's not
		// really bizzare need to check the contents of JSON and do a new approach

		//for (auto& i : doc.GetObjectA())
		//{
		//	RA_LOG("Type of member %s is %s\n", i.name.GetString(),
		//		i.value.GetType());
		//}




		if (doc["Success"].GetBool())
		{
			auto msg{
				"Submitted OK!\n"
				"\n"
				"Thank you for reporting that bug(s), and sorry it hasn't worked correctly.\n"
				"\n"
				"The development team will investigate this bug as soon as possible\n"
				"and we will send you a message on RetroAchievements.org\n"
				"as soon as we have a solution.\n"
				"\n"
				"Thanks again!"
			};

			MessageBox(hwnd, NativeStr(msg).c_str(), TEXT("Success!"), MB_OK);
			// this is so strange, the achievements get sent over but says it's failing
			IRA_Dialog::OnOK(hwnd);
			return;
		}
		else
		{
			auto buffer{ tfm::format(
				"Failed!\n"
				"\n"
				"Response From Server:\n"
				"\n"
				"Error code: %d", doc.GetParseError())
			};
			MessageBox(hwnd, NativeStr(buffer).c_str(), TEXT("Error from server!"), MB_OK);
			return;
		}
	}
	else
	{
		MessageBox(hwnd,
			TEXT("Failed!\n")
			TEXT("\n")
			TEXT("Cannot reach server... are you online?\n")
			TEXT("\n"),
			TEXT("Error!"), MB_OK);
		return;
	}
}
Esempio n. 27
0
INT_PTR CALLBACK PhpServiceGeneralDlgProc(
    __in HWND hwndDlg,
    __in UINT uMsg,
    __in WPARAM wParam,
    __in LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
            PSERVICE_PROPERTIES_CONTEXT context = (PSERVICE_PROPERTIES_CONTEXT)propSheetPage->lParam;
            PPH_SERVICE_ITEM serviceItem = context->ServiceItem;
            SC_HANDLE serviceHandle;

            // HACK
            PhCenterWindow(GetParent(hwndDlg), GetParent(GetParent(hwndDlg)));

            SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)context);

            PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_TYPE), PhServiceTypeStrings,
                sizeof(PhServiceTypeStrings) / sizeof(WCHAR *));
            PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_STARTTYPE), PhServiceStartTypeStrings,
                sizeof(PhServiceStartTypeStrings) / sizeof(WCHAR *));
            PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_ERRORCONTROL), PhServiceErrorControlStrings,
                sizeof(PhServiceErrorControlStrings) / sizeof(WCHAR *));

            SetDlgItemText(hwndDlg, IDC_DESCRIPTION, serviceItem->DisplayName->Buffer);
            ComboBox_SelectString(GetDlgItem(hwndDlg, IDC_TYPE), -1,
                PhGetServiceTypeString(serviceItem->Type));
            ComboBox_SelectString(GetDlgItem(hwndDlg, IDC_STARTTYPE), -1,
                PhGetServiceStartTypeString(serviceItem->StartType));
            ComboBox_SelectString(GetDlgItem(hwndDlg, IDC_ERRORCONTROL), -1,
                PhGetServiceErrorControlString(serviceItem->ErrorControl));

            serviceHandle = PhOpenService(serviceItem->Name->Buffer, SERVICE_QUERY_CONFIG);

            if (serviceHandle)
            {
                LPQUERY_SERVICE_CONFIG config;
                PPH_STRING description;
                BOOLEAN delayedStart;

                if (config = PhGetServiceConfig(serviceHandle))
                {
                    SetDlgItemText(hwndDlg, IDC_GROUP, config->lpLoadOrderGroup);
                    SetDlgItemText(hwndDlg, IDC_BINARYPATH, config->lpBinaryPathName);
                    SetDlgItemText(hwndDlg, IDC_USERACCOUNT, config->lpServiceStartName);

                    PhFree(config);
                }

                if (description = PhGetServiceDescription(serviceHandle))
                {
                    SetDlgItemText(hwndDlg, IDC_DESCRIPTION, description->Buffer);
                    PhDereferenceObject(description);
                }

                if (PhGetServiceDelayedAutoStart(serviceHandle, &delayedStart))
                {
                    context->OldDelayedStart = delayedStart;

                    if (delayedStart)
                        Button_SetCheck(GetDlgItem(hwndDlg, IDC_DELAYEDSTART), BST_CHECKED);
                }

                CloseServiceHandle(serviceHandle);
            }

            SetDlgItemText(hwndDlg, IDC_PASSWORD, L"password");
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_PASSWORDCHECK), BST_UNCHECKED);

            SetDlgItemText(hwndDlg, IDC_SERVICEDLL, L"N/A");

            {
                HANDLE keyHandle;
                PPH_STRING keyName;

                keyName = PhConcatStrings(
                    3,
                    L"System\\CurrentControlSet\\Services\\",
                    serviceItem->Name->Buffer,
                    L"\\Parameters"
                    );

                if (NT_SUCCESS(PhOpenKey(
                    &keyHandle,
                    KEY_READ,
                    PH_KEY_LOCAL_MACHINE,
                    &keyName->sr,
                    0
                    )))
                {
                    PPH_STRING serviceDllString;

                    if (serviceDllString = PhQueryRegistryString(keyHandle, L"ServiceDll"))
                    {
                        PPH_STRING expandedString;

                        if (expandedString = PhExpandEnvironmentStrings(&serviceDllString->sr))
                        {
                            SetDlgItemText(hwndDlg, IDC_SERVICEDLL, expandedString->Buffer);
                            PhDereferenceObject(expandedString);
                        }

                        PhDereferenceObject(serviceDllString);
                    }

                    NtClose(keyHandle);
                }

                PhDereferenceObject(keyName);
            }

            PhpRefreshControls(hwndDlg);

            context->Ready = TRUE;
        }
        break;
    case WM_DESTROY:
        {
            RemoveProp(hwndDlg, PhMakeContextAtom());
        }
        break;
    case WM_COMMAND:
        {
            PSERVICE_PROPERTIES_CONTEXT context =
                (PSERVICE_PROPERTIES_CONTEXT)GetProp(hwndDlg, PhMakeContextAtom());

            switch (LOWORD(wParam))
            {
            case IDCANCEL:
                {
                    // Workaround for property sheet + multiline edit: http://support.microsoft.com/kb/130765

                    SendMessage(GetParent(hwndDlg), uMsg, wParam, lParam);
                }
                break;
            case IDC_PASSWORD:
                {
                    if (HIWORD(wParam) == EN_CHANGE)
                    {
                        Button_SetCheck(GetDlgItem(hwndDlg, IDC_PASSWORDCHECK), BST_CHECKED);
                    }
                }
                break;
            case IDC_DELAYEDSTART:
                {
                    context->Dirty = TRUE;
                }
                break;
            case IDC_BROWSE:
                {
                    static PH_FILETYPE_FILTER filters[] =
                    {
                        { L"Executable files (*.exe;*.sys)", L"*.exe;*.sys" },
                        { L"All files (*.*)", L"*.*" }
                    };
                    PVOID fileDialog;
                    PPH_STRING fileName;

                    fileDialog = PhCreateOpenFileDialog();
                    PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));

                    fileName = PhGetFileName(PHA_GET_DLGITEM_TEXT(hwndDlg, IDC_BINARYPATH));
                    PhSetFileDialogFileName(fileDialog, fileName->Buffer);
                    PhDereferenceObject(fileName);

                    if (PhShowFileDialog(hwndDlg, fileDialog))
                    {
                        fileName = PhGetFileDialogFileName(fileDialog);
                        SetDlgItemText(hwndDlg, IDC_BINARYPATH, fileName->Buffer);
                        PhDereferenceObject(fileName);
                    }

                    PhFreeFileDialog(fileDialog);
                }
                break;
            }

            switch (HIWORD(wParam))
            {
            case EN_CHANGE:
            case CBN_SELCHANGE:
                {
                    PhpRefreshControls(hwndDlg);

                    if (context->Ready)
                        context->Dirty = TRUE;
                }
                break;
            }
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case PSN_QUERYINITIALFOCUS:
                {
                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)GetDlgItem(hwndDlg, IDC_TYPE));
                }
                return TRUE;
            case PSN_KILLACTIVE:
                {
                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
                }
                return TRUE;
            case PSN_APPLY:
                {
                    NTSTATUS status;
                    PSERVICE_PROPERTIES_CONTEXT context =
                        (PSERVICE_PROPERTIES_CONTEXT)GetProp(hwndDlg, PhMakeContextAtom());
                    PPH_SERVICE_ITEM serviceItem = context->ServiceItem;
                    SC_HANDLE serviceHandle;
                    PPH_STRING newServiceTypeString;
                    PPH_STRING newServiceStartTypeString;
                    PPH_STRING newServiceErrorControlString;
                    ULONG newServiceType;
                    ULONG newServiceStartType;
                    ULONG newServiceErrorControl;
                    PPH_STRING newServiceGroup;
                    PPH_STRING newServiceBinaryPath;
                    PPH_STRING newServiceUserAccount;
                    PPH_STRING newServicePassword;

                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);

                    if (!context->Dirty)
                    {
                        return TRUE;
                    }

                    newServiceTypeString = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_TYPE)));
                    newServiceStartTypeString = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_STARTTYPE)));
                    newServiceErrorControlString = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_ERRORCONTROL)));
                    newServiceType = PhGetServiceTypeInteger(newServiceTypeString->Buffer);
                    newServiceStartType = PhGetServiceStartTypeInteger(newServiceStartTypeString->Buffer);
                    newServiceErrorControl = PhGetServiceErrorControlInteger(newServiceErrorControlString->Buffer);

                    newServiceGroup = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_GROUP)));
                    newServiceBinaryPath = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_BINARYPATH)));
                    newServiceUserAccount = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_USERACCOUNT)));

                    if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_PASSWORDCHECK)) == BST_CHECKED)
                    {
                        newServicePassword = PhGetWindowText(GetDlgItem(hwndDlg, IDC_PASSWORD));
                    }
                    else
                    {
                        newServicePassword = NULL;
                    }

                    if (newServiceType == SERVICE_KERNEL_DRIVER && newServiceUserAccount->Length == 0)
                    {
                        newServiceUserAccount = NULL;
                    }

                    serviceHandle = PhOpenService(serviceItem->Name->Buffer, SERVICE_CHANGE_CONFIG);

                    if (serviceHandle)
                    {
                        if (ChangeServiceConfig(
                            serviceHandle,
                            newServiceType,
                            newServiceStartType,
                            newServiceErrorControl,
                            newServiceBinaryPath->Buffer,
                            newServiceGroup->Buffer,
                            NULL,
                            NULL,
                            PhGetString(newServiceUserAccount),
                            PhGetString(newServicePassword),
                            NULL
                            ))
                        {
                            BOOLEAN newDelayedStart;

                            newDelayedStart = Button_GetCheck(GetDlgItem(hwndDlg, IDC_DELAYEDSTART)) == BST_CHECKED;

                            if (newDelayedStart != context->OldDelayedStart)
                            {
                                PhSetServiceDelayedAutoStart(serviceHandle, newDelayedStart);
                            }

                            PhMarkNeedsConfigUpdateServiceItem(serviceItem);

                            CloseServiceHandle(serviceHandle);
                        }
                        else
                        {
                            CloseServiceHandle(serviceHandle);
                            goto ErrorCase;
                        }
                    }
                    else
                    {
                        if (GetLastError() == ERROR_ACCESS_DENIED && !PhElevated)
                        {
                            // Elevate using phsvc.
                            if (PhUiConnectToPhSvc(hwndDlg, FALSE))
                            {
                                if (NT_SUCCESS(status = PhSvcCallChangeServiceConfig(
                                    serviceItem->Name->Buffer,
                                    newServiceType,
                                    newServiceStartType,
                                    newServiceErrorControl,
                                    newServiceBinaryPath->Buffer,
                                    newServiceGroup->Buffer,
                                    NULL,
                                    NULL,
                                    PhGetString(newServiceUserAccount),
                                    PhGetString(newServicePassword),
                                    NULL
                                    )))
                                {
                                    BOOLEAN newDelayedStart;

                                    newDelayedStart = Button_GetCheck(GetDlgItem(hwndDlg, IDC_DELAYEDSTART)) == BST_CHECKED;

                                    if (newDelayedStart != context->OldDelayedStart)
                                    {
                                        SERVICE_DELAYED_AUTO_START_INFO info;

                                        info.fDelayedAutostart = newDelayedStart;
                                        PhSvcCallChangeServiceConfig2(
                                            serviceItem->Name->Buffer,
                                            SERVICE_CONFIG_DELAYED_AUTO_START_INFO,
                                            &info
                                            );
                                    }

                                    PhMarkNeedsConfigUpdateServiceItem(serviceItem);
                                }

                                PhUiDisconnectFromPhSvc();

                                if (!NT_SUCCESS(status))
                                {
                                    SetLastError(PhNtStatusToDosError(status));
                                    goto ErrorCase;
                                }
                            }
                            else
                            {
                                // User cancelled elevation.
                                SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                            }
                        }
                        else
                        {
                            goto ErrorCase;
                        }
                    }

                    goto Cleanup;
ErrorCase:
                    if (PhShowMessage(
                        hwndDlg,
                        MB_ICONERROR | MB_RETRYCANCEL,
                        L"Unable to change service configuration: %s",
                        ((PPH_STRING)PHA_DEREFERENCE(PhGetWin32Message(GetLastError())))->Buffer
                        ) == IDRETRY)
                    {
                        SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                    }

Cleanup:
                    if (newServicePassword)
                    {
                        RtlSecureZeroMemory(newServicePassword->Buffer, newServicePassword->Length);
                        PhDereferenceObject(newServicePassword);
                    }
                }
                return TRUE;
            }
        }
        break;
    }

    return FALSE;
}
Esempio n. 28
0
INT_PTR CALLBACK EspServiceRecoveryDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    PSERVICE_RECOVERY_CONTEXT context;

    if (uMsg == WM_INITDIALOG)
    {
        context = PhAllocate(sizeof(SERVICE_RECOVERY_CONTEXT));
        memset(context, 0, sizeof(SERVICE_RECOVERY_CONTEXT));

        SetProp(hwndDlg, L"Context", (HANDLE)context);
    }
    else
    {
        context = (PSERVICE_RECOVERY_CONTEXT)GetProp(hwndDlg, L"Context");

        if (uMsg == WM_DESTROY)
            RemoveProp(hwndDlg, L"Context");
    }

    if (!context)
        return FALSE;

    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            NTSTATUS status;
            LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
            PPH_SERVICE_ITEM serviceItem = (PPH_SERVICE_ITEM)propSheetPage->lParam;

            context->ServiceItem = serviceItem;

            EspAddServiceActionStrings(GetDlgItem(hwndDlg, IDC_FIRSTFAILURE));
            EspAddServiceActionStrings(GetDlgItem(hwndDlg, IDC_SECONDFAILURE));
            EspAddServiceActionStrings(GetDlgItem(hwndDlg, IDC_SUBSEQUENTFAILURES));

            status = EspLoadRecoveryInfo(hwndDlg, context);

            if (status == STATUS_SOME_NOT_MAPPED)
            {
                if (context->NumberOfActions > 3)
                {
                    PhShowWarning(
                        hwndDlg,
                        L"The service has %lu failure actions configured, but this program only supports editing 3. "
                        L"If you save the recovery information using this program, the additional failure actions will be lost.",
                        context->NumberOfActions
                        );
                }
            }
            else if (!NT_SUCCESS(status))
            {
                SetDlgItemText(hwndDlg, IDC_RESETFAILCOUNT, L"0");

                if (WindowsVersion >= WINDOWS_VISTA)
                {
                    context->EnableFlagCheckBox = TRUE;
                    EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLEFORERRORSTOPS), TRUE);
                }

                PhShowWarning(hwndDlg, L"Unable to query service recovery information: %s",
                    ((PPH_STRING)PhAutoDereferenceObject(PhGetNtMessage(status)))->Buffer);
            }

            EspFixControls(hwndDlg, context);

            context->Ready = TRUE;
        }
        break;
    case WM_DESTROY:
        {
            PhClearReference(&context->RebootMessage);
            PhFree(context);
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDC_FIRSTFAILURE:
            case IDC_SECONDFAILURE:
            case IDC_SUBSEQUENTFAILURES:
                {
                    if (HIWORD(wParam) == CBN_SELCHANGE)
                    {
                        EspFixControls(hwndDlg, context);
                    }
                }
                break;
            case IDC_RESTARTCOMPUTEROPTIONS:
                {
                    DialogBoxParam(
                        PluginInstance->DllBase,
                        MAKEINTRESOURCE(IDD_RESTARTCOMP),
                        hwndDlg,
                        RestartComputerDlgProc,
                        (LPARAM)context
                        );
                }
                break;
            case IDC_BROWSE:
                {
                    static PH_FILETYPE_FILTER filters[] =
                    {
                        { L"Executable files (*.exe;*.cmd;*.bat)", L"*.exe;*.cmd;*.bat" },
                        { L"All files (*.*)", L"*.*" }
                    };
                    PVOID fileDialog;
                    PPH_STRING fileName;

                    fileDialog = PhCreateOpenFileDialog();
                    PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));

                    fileName = PhaGetDlgItemText(hwndDlg, IDC_RUNPROGRAM);
                    PhSetFileDialogFileName(fileDialog, fileName->Buffer);

                    if (PhShowFileDialog(hwndDlg, fileDialog))
                    {
                        fileName = PhGetFileDialogFileName(fileDialog);
                        SetDlgItemText(hwndDlg, IDC_RUNPROGRAM, fileName->Buffer);
                        PhDereferenceObject(fileName);
                    }

                    PhFreeFileDialog(fileDialog);
                }
                break;
            case IDC_ENABLEFORERRORSTOPS:
                {
                    context->Dirty = TRUE;
                }
                break;
            }

            switch (HIWORD(wParam))
            {
            case EN_CHANGE:
            case CBN_SELCHANGE:
                {
                    if (context->Ready)
                        context->Dirty = TRUE;
                }
                break;
            }
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case PSN_KILLACTIVE:
                {
                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
                }
                return TRUE;
            case PSN_APPLY:
                {
                    NTSTATUS status;
                    PPH_SERVICE_ITEM serviceItem = context->ServiceItem;
                    SC_HANDLE serviceHandle;
                    ULONG restartServiceAfter;
                    SERVICE_FAILURE_ACTIONS failureActions;
                    SC_ACTION actions[3];
                    ULONG i;
                    BOOLEAN enableRestart = FALSE;

                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);

                    if (!context->Dirty)
                    {
                        return TRUE;
                    }

                    // Build the failure actions structure.

                    failureActions.dwResetPeriod = GetDlgItemInt(hwndDlg, IDC_RESETFAILCOUNT, NULL, FALSE) * 60 * 60 * 24;
                    failureActions.lpRebootMsg = PhGetStringOrEmpty(context->RebootMessage);
                    failureActions.lpCommand = PhaGetDlgItemText(hwndDlg, IDC_RUNPROGRAM)->Buffer;
                    failureActions.cActions = 3;
                    failureActions.lpsaActions = actions;

                    actions[0].Type = ComboBoxToServiceAction(GetDlgItem(hwndDlg, IDC_FIRSTFAILURE));
                    actions[1].Type = ComboBoxToServiceAction(GetDlgItem(hwndDlg, IDC_SECONDFAILURE));
                    actions[2].Type = ComboBoxToServiceAction(GetDlgItem(hwndDlg, IDC_SUBSEQUENTFAILURES));

                    restartServiceAfter = GetDlgItemInt(hwndDlg, IDC_RESTARTSERVICEAFTER, NULL, FALSE) * 1000 * 60;

                    for (i = 0; i < 3; i++)
                    {
                        switch (actions[i].Type)
                        {
                        case SC_ACTION_RESTART:
                            actions[i].Delay = restartServiceAfter;
                            enableRestart = TRUE;
                            break;
                        case SC_ACTION_REBOOT:
                            actions[i].Delay = context->RebootAfter;
                            break;
                        case SC_ACTION_RUN_COMMAND:
                            actions[i].Delay = 0;
                            break;
                        }
                    }

                    // Try to save the changes.

                    serviceHandle = PhOpenService(
                        serviceItem->Name->Buffer,
                        SERVICE_CHANGE_CONFIG | (enableRestart ? SERVICE_START : 0) // SC_ACTION_RESTART requires SERVICE_START
                        );

                    if (serviceHandle)
                    {
                        if (ChangeServiceConfig2(
                            serviceHandle,
                            SERVICE_CONFIG_FAILURE_ACTIONS,
                            &failureActions
                            ))
                        {
                            if (context->EnableFlagCheckBox)
                            {
                                SERVICE_FAILURE_ACTIONS_FLAG failureActionsFlag;

                                failureActionsFlag.fFailureActionsOnNonCrashFailures =
                                    Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLEFORERRORSTOPS)) == BST_CHECKED;

                                ChangeServiceConfig2(
                                    serviceHandle,
                                    SERVICE_CONFIG_FAILURE_ACTIONS_FLAG,
                                    &failureActionsFlag
                                    );
                            }

                            CloseServiceHandle(serviceHandle);
                        }
                        else
                        {
                            CloseServiceHandle(serviceHandle);
                            goto ErrorCase;
                        }
                    }
                    else
                    {
                        if (GetLastError() == ERROR_ACCESS_DENIED && !PhElevated)
                        {
                            // Elevate using phsvc.
                            if (PhUiConnectToPhSvc(hwndDlg, FALSE))
                            {
                                if (NT_SUCCESS(status = PhSvcCallChangeServiceConfig2(
                                    serviceItem->Name->Buffer,
                                    SERVICE_CONFIG_FAILURE_ACTIONS,
                                    &failureActions
                                    )))
                                {
                                    if (context->EnableFlagCheckBox)
                                    {
                                        SERVICE_FAILURE_ACTIONS_FLAG failureActionsFlag;

                                        failureActionsFlag.fFailureActionsOnNonCrashFailures =
                                            Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLEFORERRORSTOPS)) == BST_CHECKED;

                                        PhSvcCallChangeServiceConfig2(
                                            serviceItem->Name->Buffer,
                                            SERVICE_CONFIG_FAILURE_ACTIONS_FLAG,
                                            &failureActionsFlag
                                            );
                                    }
                                }

                                PhUiDisconnectFromPhSvc();

                                if (!NT_SUCCESS(status))
                                {
                                    SetLastError(PhNtStatusToDosError(status));
                                    goto ErrorCase;
                                }
                            }
                            else
                            {
                                // User cancelled elevation.
                                SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                            }
                        }
                        else
                        {
                            goto ErrorCase;
                        }
                    }

                    return TRUE;
ErrorCase:
                    if (PhShowMessage(
                        hwndDlg,
                        MB_ICONERROR | MB_RETRYCANCEL,
                        L"Unable to change service recovery information: %s",
                        ((PPH_STRING)PhAutoDereferenceObject(PhGetWin32Message(GetLastError())))->Buffer
                        ) == IDRETRY)
                    {
                        SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                    }
                }
                return TRUE;
            }
        }
        break;
    }

    return FALSE;
}
Esempio n. 29
0
static void read_control(datamap *map, HWND control, windows_options *opts, datamap_entry *entry, const char *option_name)
{
	BOOL bool_value = 0;
	int int_value = 0;
	float float_value = 0;
	const char *string_value;
	int selected_index = 0;
	int trackbar_pos = 0;
	std::string error;
	// use default read value behavior
	switch(get_control_type(control))
	{
		case CT_BUTTON:
			assert(entry->type == DM_BOOL);
			bool_value = Button_GetCheck(control);
			opts->set_value(option_name, bool_value, OPTION_PRIORITY_CMDLINE,error);
			break;

		case CT_COMBOBOX:
			selected_index = ComboBox_GetCurSel(control);
			if (selected_index >= 0)
			{
				switch(entry->type)
				{
					case DM_INT:
						int_value = (int) ComboBox_GetItemData(control, selected_index);
						opts->set_value(option_name, int_value, OPTION_PRIORITY_CMDLINE,error);
						break;

					case DM_STRING:
						string_value = (const char *) ComboBox_GetItemData(control, selected_index);
						opts->set_value(option_name, string_value ? string_value : "", OPTION_PRIORITY_CMDLINE,error);
						break;

					default:
						break;
				}
			}
			break;

		case CT_TRACKBAR:
			trackbar_pos = SendMessage(control, TBM_GETPOS, 0, 0);
			float_value = trackbar_value_from_position(entry, trackbar_pos);
			switch(entry->type)
			{
				case DM_INT:
					int_value = (int) float_value;
					if (int_value != opts->int_value(option_name)) {
						opts->set_value(option_name, int_value, OPTION_PRIORITY_CMDLINE,error);
					}
					break;

				case DM_FLOAT:
					// Use tztrim(float_value) or we get trailing zero's that break options_equal().
					if (float_value != opts->float_value(option_name)) {
						opts->set_value(option_name, tztrim(float_value), OPTION_PRIORITY_CMDLINE,error);
					}
					break;

				default:
					break;
			}
			break;

		case CT_EDIT:
			// NYI
			break;

		case CT_STATIC:
		case CT_LISTVIEW:
		case CT_UNKNOWN:
			// non applicable
			break;
	}
}
Esempio n. 30
0
BOOL CRadioBtn::GetCheck(DWORD num) const
{
	return Button_GetCheck(m_radios[num]);
}