BOOL FormMain_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
	g_hwndDlg = hwnd;
	SetWindowText(hwnd, pCaption);
	//----Everything else must follow the above----//
	btnDetails_Click(hwnd);
	AdjustLayout(hwnd);
	//Get the initial Width and height of the dialog
	//in order to fix the minimum size of dialog

	syncForm(hwnd, pParams);

  /* Disable fields if in prompt mode */
  if (g_isPrompt)
  {
    EnableWindow(GetDlgItem(hwnd, IDC_EDIT_name), FALSE);
    EnableWindow(GetDlgItem(hwnd, IDC_EDIT_description), FALSE);
  }

  /* if prompting without DSN, don't disable OK button */
  /* preserved here old logic + enabled OK if data source
     name is not NULL when not prompting. I don't know why it should be disabled
     when prompting and name is not NULL. */
  if (g_isPrompt == (pParams->name==NULL))
  {
    Button_Enable(GetDlgItem(hwnd,IDOK), 1);
    Button_Enable(GetDlgItem(hwnd,IDC_BUTTON_TEST), 1);
    RedrawWindow(hwnd,NULL,NULL,RDW_INVALIDATE);
  }

	BOOL b = DoCreateDialogTooltip();
	return 0;
}
Ejemplo n.º 2
0
void ClearModelTree()
{
	Button_Enable(GetControl(IDC_START),false);
	Button_Enable(GetControl(IDC_CLEARMODELS),false);
	g_targets.clear();
	TreeView_DeleteAllItems(GetControl(IDC_MODELS));
}
Ejemplo n.º 3
0
void plAnimComponentProc::EnableGlobal(HWND hWnd, bool enable)
{
    ComboBox_Enable(GetDlgItem(hWnd, IDC_ANIM_GLOBAL_LIST), enable);
    ComboBox_Enable(GetDlgItem(hWnd, IDC_ANIM_NAMES), !enable);
    ComboBox_Enable(GetDlgItem(hWnd, IDC_LOOP_NAMES), !enable);
    Button_Enable(GetDlgItem(hWnd, IDC_COMP_ANIM_AUTOSTART_CKBX), !enable);
    Button_Enable(GetDlgItem(hWnd, IDC_COMP_ANIM_LOOP_CKBX), !enable);
}   
Ejemplo n.º 4
0
static void buttons_enable(_Bool enable)
{
    Button_Enable(GetDlgItem(main_window, ID_INSTALL_BUTTON), enable);
    Button_Enable(GetDlgItem(main_window, ID_BROWSE_BUTTON), enable);
    Button_Enable(GetDlgItem(main_window, ID_DESKTOP_SHORTCUT_CHECKBOX), enable);
    Button_Enable(GetDlgItem(main_window, ID_STARTMENU_SHORTCUT_CHECKBOX), enable);
    Button_Enable(GetDlgItem(main_window, ID_TOX_URL_CHECKBOX), enable);
}
Ejemplo n.º 5
0
static void Update_States(int iSelectedItem)
{
    TOOL* tool;
    LVITEM item = {};

    assert(hToolsPage);

    item.mask  = LVIF_PARAM;
    item.iItem = iSelectedItem;

    if (ListView_GetItem(hToolsListCtrl, &item)) // (item.iItem > -1) // TODO: corriger ailleurs ce genre de code...
    {
        LPWSTR lpszCmdLine = NULL;
        size_t numOfChars  = 0;
        tool = reinterpret_cast<TOOL*>(item.lParam);

        ListView_EnsureVisible(hToolsListCtrl, item.iItem, FALSE);

        Button_Enable(GetDlgItem(hToolsPage, IDC_BTN_RUN), TRUE);

        if (!*(wchar_t*)tool->m_AdvParam)
        {
            ShowWindow(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), SW_HIDE);
            Button_Enable(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), FALSE);
        }
        else
        {
            Button_Enable(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), TRUE);
            ShowWindow(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), SW_NORMAL);
        }

        if ( (Button_IsEnabled(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT))) &&
             (Button_GetCheck(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT)) == BST_CHECKED) )
        {
            numOfChars = BuildCommandLine(NULL, tool->m_Command, tool->m_AdvParam, 0);
            lpszCmdLine = (LPWSTR)MemAlloc(0, numOfChars * sizeof(WCHAR));
            BuildCommandLine(lpszCmdLine, tool->m_Command, tool->m_AdvParam, numOfChars);
        }
        else
        {
            numOfChars = BuildCommandLine(NULL, tool->m_Command, tool->m_DefParam, 0);
            lpszCmdLine = (LPWSTR)MemAlloc(0, numOfChars * sizeof(WCHAR));
            BuildCommandLine(lpszCmdLine, tool->m_Command, tool->m_DefParam, numOfChars);
        }

        SendDlgItemMessage(hToolsPage, IDC_TOOLS_CMDLINE, WM_SETTEXT, 0, (LPARAM)lpszCmdLine);

        MemFree(lpszCmdLine);
    }
    else
    {
        ShowWindow(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), SW_HIDE);
        Button_Enable(GetDlgItem(hToolsPage, IDC_CBX_TOOLS_ADVOPT), FALSE);
        Button_Enable(GetDlgItem(hToolsPage, IDC_BTN_RUN), FALSE);
    }
}
Ejemplo n.º 6
0
void SetButtonEnble(HWND hDlg,BOOL B)
{

		//HWND hand = GetDlgItem(hDlg,IDC_EDIT_Type);

		HWND hand = GetDlgItem(hDlg,IDC_BtnNext);
		Button_Enable(hand,B);

		 hand = GetDlgItem(hDlg,IDC_BtnPrev);
		Button_Enable(hand,B);

		 hand = GetDlgItem(hDlg,IDC_BtnPageUp);
		Button_Enable(hand,B);

		 hand = GetDlgItem(hDlg,IDC_BtnPageDown);
		Button_Enable(hand,B);

		 hand = GetDlgItem(hDlg,IDC_BtnSave);
		Button_Enable(hand,B);

		 hand = GetDlgItem(hDlg,IDC_BtnPrint);
		Button_Enable(hand,B);

		 hand = GetDlgItem(hDlg,IDC_BtnStart);
		Button_Enable(hand,B);

		hand = GetDlgItem(hDlg,IDC_BtnOpen);
		Button_Enable(hand,B);

		hand = GetDlgItem(hDlg,IDC_BtnClose);
		Button_Enable(hand,B);
}
Ejemplo n.º 7
0
bool
tzfixcfg_OSD::setup_ui (HWND hDlg)
{
  bool installed = wcslen (TZT_GetRTSSInstallDir ().c_str ()) > 0;

  hWndInstall    = GetDlgItem (hDlg, IDC_RTSS_INSTALL);

  hWndStealth    = GetDlgItem (hDlg, IDC_RTSS_STEALTH);
  hWndCustomD3D  = GetDlgItem (hDlg, IDC_RTSS_CUSTOM3D);
  hWndUseDelay   = GetDlgItem (hDlg, IDC_RTSS_DELAY);
  hWndDelayLabel = GetDlgItem (hDlg, IDC_RTSS_DELAY_LABEL);
  hWndDelayTime  = GetDlgItem (hDlg, IDC_RTSS_DELAY_TIME);

  hWndColorLabel = GetDlgItem (hDlg, IDC_RTSS_COLOR_LABEL);
  hWndColor      = GetDlgItem (hDlg, IDC_RTSS_COLOR);

  ShowWindow (hWndColorLabel, SW_HIDE);
  ShowWindow (hWndColor,      SW_HIDE);

  hWndRTSSGroup  = GetDlgItem (hDlg, IDC_RTSS_GROUP);

  Button_Enable (hWndInstall, (! installed));

  Button_Enable (hWndStealth,   installed);
  Button_Enable (hWndCustomD3D, installed);
  Button_Enable (hWndUseDelay,  installed);
  Button_Enable (hWndColor,     installed);

  if (installed && delay_triggers->get_value ().length ()) {
    EnableWindow    (hWndDelayLabel, installed);
    EnableWindow    (hWndDelayTime,  installed);
    Button_SetCheck (hWndUseDelay,   true);
  } else {
    EnableWindow    (hWndDelayLabel, false);
    EnableWindow    (hWndDelayTime,  false);
    Button_SetCheck (hWndUseDelay,   false);
  }

  EnableWindow (hWndColorLabel, installed);
  EnableWindow (hWndRTSSGroup,  installed);

  stealth_mode->bind_to_control (new tzt::UI::CheckBox (hWndStealth));
  stealth_mode->set_value       (stealth_mode->get_value ());

  custom_d3d->bind_to_control (new tzt::UI::CheckBox (hWndCustomD3D));
  custom_d3d->set_value       (custom_d3d->get_value ());

  delay_ms->bind_to_control (new tzt::UI::EditBox (hWndDelayTime));
  delay_ms->set_value       (delay_ms->get_value () / 1000);

  return true;
}
Ejemplo n.º 8
0
// This has to get called after any change to audio driver/in dev/out dev
void PopulateDriverSpecificControls(HWND hwndDlg)
{
#ifdef OS_WIN
  int dt = (int) SendDlgItemMessage(hwndDlg, IDC_COMBO_AUDIO_DRIVER, CB_GETCURSEL, 0, 0);
  if(dt)   //ASIO
  {
    ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_AUDIO_IN_DEV), FALSE);
    Button_Enable(GetDlgItem(hwndDlg, IDC_BUTTON_ASIO), TRUE);
  }
  else
  {
    ComboBox_Enable(GetDlgItem(hwndDlg, IDC_COMBO_AUDIO_IN_DEV), TRUE);
    Button_Enable(GetDlgItem(hwndDlg, IDC_BUTTON_ASIO), FALSE);
  }
#endif

  int indevidx = 0;
  int outdevidx = 0;

  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_RESETCONTENT,0,0);
  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_RESETCONTENT,0,0);

  for (int i = 0; i<gAudioInputDevs.size(); i++)
  {
    SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_ADDSTRING,0,(LPARAM)GetAudioDeviceName(gAudioInputDevs[i]).c_str());

    if(!strcmp(GetAudioDeviceName(gAudioInputDevs[i]).c_str(), gState->mAudioInDev))
      indevidx = i;
  }

  for (int i = 0; i<gAudioOutputDevs.size(); i++)
  {
    SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_ADDSTRING,0,(LPARAM)GetAudioDeviceName(gAudioOutputDevs[i]).c_str());

    if(!strcmp(GetAudioDeviceName(gAudioOutputDevs[i]).c_str(), gState->mAudioOutDev))
      outdevidx = i;
  }

  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_IN_DEV,CB_SETCURSEL, indevidx, 0);
  SendDlgItemMessage(hwndDlg,IDC_COMBO_AUDIO_OUT_DEV,CB_SETCURSEL, outdevidx, 0);

  RtAudio::DeviceInfo inputDevInfo = gDAC->getDeviceInfo(gAudioInputDevs[indevidx]);
  RtAudio::DeviceInfo outputDevInfo = gDAC->getDeviceInfo(gAudioOutputDevs[outdevidx]);

  PopulateAudioInputList(hwndDlg, &inputDevInfo);
  PopulateAudioOutputList(hwndDlg, &outputDevInfo);
  PopulateSampleRateList(hwndDlg, &inputDevInfo, &outputDevInfo);
}
Ejemplo n.º 9
0
void
ObjectReference::activate( HWND hwndButton )
{
	uiDialog::activate( hwndButton );

	char szObjectName[ 256 ];
	assert( _edit );
	_edit->GetText( szObjectName, sizeof( szObjectName ) );
	INode* pNode = theAttributes.ip->GetINodeByName( szObjectName );

	assert( hwndGoToObjectButton );
	Button_Enable( hwndGoToObjectButton, bool( pNode ) );

	if ( hwndButton == hwndBrowseButton )
	{
		TrackViewPick pick;
		if ( theAttributes.ip->TrackViewPickDlg( _hPanel, &pick ) )
			reset( pick.anim->NodeName() );
	}
	else if ( hwndButton == hwndGoToObjectButton )
	{
		assert( pNode );
		theHold.Begin();
		theAttributes.ip->SelectNode( pNode );
		char szUndoMessage[ 512 ];
		sprintf( szUndoMessage, "Attributes - go to %s", szObjectName );
		theHold.Accept( szUndoMessage );
	}
}
Ejemplo n.º 10
0
INT_PTR CALLBACK Pin2DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {	
	static char *pin2;
	switch(message) {
		case WM_INITDIALOG:
			setLabelText(hwnd, IDC_NAME, ((DialogData *)lParam)->name);
			if(((DialogData *)lParam)->message != NULL) {
				setLabelText(hwnd, IDC_ERROR, ((DialogData *)lParam)->message);
			}
			pin2 = ((DialogData *)lParam)->pin2;
			return true;
		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDOK:
					GetDlgItemText(hwnd, IDC_PIN2, pin2, PIN2_MAX_LEN);
				case IDCANCEL:
					EndDialog(hwnd, LOWORD(wParam));
					break;
			}
			if(HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == IDC_PIN2) {
				Button_Enable(GetDlgItem(hwnd, IDOK), isAcceptableLengthPIN2(hwnd, IDC_PIN2));
			}
			return true;
		case WM_CTLCOLORSTATIC:
			if(GetDlgItem(hwnd, IDC_ERROR) == ((HWND)lParam)){
				SetTextColor((HDC)wParam, RGB(255, 0, 0));
				SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
				return (INT_PTR)GetStockObject(NULL_BRUSH);
			}			
		default:
			return false;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);	
}
Ejemplo n.º 11
0
BOOL CALLBACK PropSheetProc(HWND hwnd, UINT msg, LPARAM lParam) {
  if (msg == PSCB_PRECREATE) {
    DLGTEMPLATE *pDlgTemplate = (DLGTEMPLATE*) lParam;
    pDlgTemplate->style |= WS_THICKFRAME;
  }
  else if (msg == PSCB_INITIALIZED) {
    g_cfgwnd = hwnd;
    SetWindowSubclass(g_cfgwnd, PropSheetWinProc, 0, 0);
    UpdateStrings();

    // Set new icon specifically for the taskbar and Alt+Tab, without changing window icon
    HICON taskbar_icon = LoadImage(g_hinst, L"taskbar_icon", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
    SendMessage(g_cfgwnd, WM_SETICON, ICON_BIG, (LPARAM)taskbar_icon);

    // OK button replaces Cancel button
    SendMessage(g_cfgwnd, PSM_CANCELTOCLOSE, 0, 0);
    HWND cancel = GetDlgItem(g_cfgwnd, IDCANCEL);
    HWND ok = GetDlgItem(g_cfgwnd, IDOK);
    Button_Enable(cancel, TRUE); // Re-enable to enable escape key
    WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
    GetWindowPlacement(cancel, &wndpl);
    SetWindowPlacement(ok, &wndpl);
    ShowWindow(cancel, SW_HIDE);

    HWND apply = GetDlgItem(g_cfgwnd, IDAPPLY);
    Button_SetText(apply, L""); // Remove text to remove it's shortcut (Alt+A in English)
  }
}
Ejemplo n.º 12
0
/////////////////////////////////////////
// Dir window callback
LRESULT CALLBACK ShDirProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static const int tTabs[] = { 90, 125 };
struct S_DirectoryContent *pDir = (struct S_DirectoryContent *) lParam;
HWND hLBWnd = GetDlgItem (hWnd, IDC_LB_SHDIR);
int Ark;

  switch (message)
  {
       case WM_INITDIALOG :
	   	   // Set the window name to either tftpd32 or tftpd64
	       SetWindowText (hWnd, TFTPD_DIR_TITLE);

           ListBox_SetTabStops ( hLBWnd, SizeOfTab(tTabs), tTabs );
           ListBox_ResetContent ( hLBWnd );
           for ( Ark=0 ;  Ark < pDir->nb ;  Ark++ )
                ListBox_AddString ( hLBWnd, pDir->ent[Ark].file_descr );
           CenterChildWindow (hWnd, CCW_INSIDE | CCW_VISIBLE);
           // If GUI is in remote mode, deactivate Explorer Button
           if ( IsGuiConnectedToRemoteService () )
                Button_Enable (GetDlgItem (hWnd, IDC_SD_EXPLORER), FALSE);
           break;

       case WM_COMMAND :
            Handle_VM_Command (hWnd, wParam, lParam);
           break;
       case WM_CLOSE :
       case WM_DESTROY :
            EndDialog (hWnd, 0);
            break;

  } // switch

return FALSE;
} // ShDirProc
Ejemplo n.º 13
0
void FormTagManager::WM_NOTIFY_LIST_Tags(WPARAM & wParam, LPARAM & lParam)
{
	switch (((LPNMHDR) lParam)->code)
	{
	case LVN_GETDISPINFO:
		{
			NMLVDISPINFO* plvdi = (NMLVDISPINFO*)lParam;
			GetListColValue_Tags(plvdi);
			break;
		}
	}

	UINT count = ListView_GetSelectedCount(_hListTags);
	Button_Enable(_hBuEdit,count > 0);
	Button_Enable(_hBuDel,count > 0);
}
Ejemplo n.º 14
0
void FormTagManager::OnNewTagChanged(WPARAM wParam, LPARAM lParam)
{
	auto code = HIWORD(wParam);
	if ( EN_CHANGE == code || EN_SETFOCUS == code)
	{
		// set the button ADD enabled/disabled up to the new tag.
		wchar_t key[MAXLENGTH_EACHTAG];
		UINT keyLength;
		BOOL x = IsNewTagOk(key,keyLength);

		auto bu = GetDlgItem(_hwnd,IDC_TAGMANAGER_BU_ADD);
		Button_Enable(bu,x);

		if ( x == TRUE )
		{
			ShowMsg(::MyLoadString(IDS_MSG_PRESS_ENTER_TO_SUBMIT),COLOR_MY_REMARK);
		}
		else
		{
			if( keyLength == 0 )
			{
				ShowMsg(::MyLoadString(IDS_MSG_PLS_ENTER_TAG),COLOR_MY_NOTE);
			}else{
				ShowMsg(::MyLoadString(IDS_MSG_TAG_UNAVAILABLE),COLOR_MY_ERROR);
			}
		}
	}
	else if ( EN_KILLFOCUS == code )
	{
		ShowMsg(L"");
	}
}
Ejemplo n.º 15
0
bool
ObjectReference::enable( bool bEnabled )
{
	bool ret = false;

	if ( uiDialog::enable( bEnabled ) )
	{
		assert( hwndEdit );
		Edit_Enable( hwndEdit, uiDialog::enable() );
		assert( hwndBrowseButton );
		Button_Enable( hwndBrowseButton, uiDialog::enable() );
		Button_Enable( hwndGoToObjectButton, uiDialog::enable() );
		ret = true;
	}

	eval();
	return ret;
}
Ejemplo n.º 16
0
BOOL plAnimComponentProc::DlgProc(TimeValue t, IParamMap2 *pMap, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    HWND gWnd = GetDlgItem(hWnd, IDC_ANIM_GLOBAL_LIST);
    char buff[512];
    switch (msg)
    {
    case WM_INITDIALOG:
        {
            fPB = pMap->GetParamBlock();
            
            fNoteTrackDlg.Init(GetDlgItem(hWnd, IDC_ANIM_NAMES),
                GetDlgItem(hWnd, IDC_LOOP_NAMES),
                kAnimName,
                kAnimLoopName,
                fPB,
                fPB->GetOwner());
            fNoteTrackDlg.Load();
            
            EnableWindow(GetDlgItem(hWnd, IDC_LOOP_NAMES), fPB->GetInt(kAnimLoop));
            
            FillAgeGlobalComboBox(gWnd, fPB->GetStr(ParamID(kAnimGlobalName)));
            SetBoxToAgeGlobal(gWnd, fPB->GetStr(ParamID(kAnimGlobalName)));
            EnableGlobal(hWnd, fPB->GetInt(ParamID(kAnimUseGlobal)));
            Button_Enable(GetDlgItem(hWnd, IDC_COMP_ANIM_PHYSANIM), 
                HasPhysicalComponent((plComponentBase*)fPB->GetOwner()));
        }
        return TRUE;
    case WM_COMMAND:
        if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_ANIM_NAMES)
        {
            fNoteTrackDlg.AnimChanged();
            return TRUE;
        }
        else if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_LOOP_NAMES)
        {
            // Get the new loop name
            fNoteTrackDlg.LoopChanged();
            return TRUE;
        }
        else if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_ANIM_GLOBAL_LIST)
        {
            ComboBox_GetLBText(gWnd, ComboBox_GetCurSel(gWnd), buff);
            fPB->SetValue(ParamID(kAnimGlobalName), 0, _T(buff));
        }
        // Catch loop button updates
        else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_COMP_ANIM_LOOP_CKBX)
            EnableWindow(GetDlgItem(hWnd, IDC_LOOP_NAMES), fPB->GetInt(kAnimLoop));
        else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_COMP_ANIM_USE_GLOBAL)
        {
            EnableGlobal(hWnd, fPB->GetInt(ParamID(kAnimUseGlobal)));
        }
        break;
    }
    return false;   
}
Ejemplo n.º 17
0
//---------------------------------------------------------------------------
void TfrmMain::cboxSendByChange() {
    BOOL bState;
    HICON hIcon;
    BYTE itemFlag = SS_DLG_DESCRIPTION;		//SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND |
    if (m_cSend && !m_cSend->m_bFreeOnExit) {
        delete m_cSend;
        m_cSend = NULL;
    }
    switch(m_opt_cboxSendBy) {
    case SS_FILESEND:		//"File Transfer"
        m_cSend = new CSendFile(m_hWnd, m_hContact, false);
        break;
    case SS_EMAIL:			//"E-mail"
        m_cSend = new CSendEmail(m_hWnd, m_hContact, false);
        break;
    case SS_HTTPSERVER:		//"HTTP Server"
        m_cSend = new CSendHTTPServer(m_hWnd, m_hContact, false);
        break;
    case SS_FTPFILE:		//"FTP File"
        m_cSend = new CSendFTPFile(m_hWnd, m_hContact, false);
        break;
    case SS_IMAGESHACK:		//"ImageShack"
        m_cSend = new CSendImageShack(m_hWnd, m_hContact, false);
        break;
    default:				//SS_JUSTSAVE - "Just save it "
        m_cSend = NULL;
        break;
    }
    if(m_cSend) {
        itemFlag = m_cSend->GetEnableItem();
        m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend;
    }
    bState = (itemFlag & SS_DLG_DELETEAFTERSSEND);
    hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF);
    SendMessage(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0));
    Button_Enable(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), bState);

    bState = (itemFlag & SS_DLG_DESCRIPTION);
    hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF);
    SendMessage(GetDlgItem(m_hWnd, ID_btnDesc), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0));
    Button_Enable(GetDlgItem(m_hWnd, ID_btnDesc), bState);
}
Ejemplo n.º 18
0
/** opens the file explorer and lets user add a tracking file **/
void AddTargetFile()
{
	pxcCHAR	file[1024] = {0};
	OPENFILENAME ofn;
	memset(&ofn,0,sizeof(ofn));
	ofn.lStructSize=sizeof(ofn);
	ofn.lpstrInitialDir = L"";
	ofn.lpstrFilter=fileFilters[GetTrackingType()];
	ofn.lpstrFile=file;
	ofn.nMaxFile=sizeof(file)/sizeof(pxcCHAR);
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER;
	if (GetOpenFileName(&ofn))
	{	
		g_targets.push_back(Model(file));
		Button_Enable(GetControl(IDC_START), true);
		Button_Enable(GetControl(IDC_CLEARMODELS), true);

		RefreshModelTree();
	}
}
Ejemplo n.º 19
0
bool
CheckBox::enable( bool bEnabled )
{
	if ( uiDialog::enable( bEnabled ) )
	{
		assert( hwndCheckbox );
		Button_Enable( hwndCheckbox, uiDialog::enable() );
		return true;
	}
	else
		return false;
}
Ejemplo n.º 20
0
Archivo: swnd.c Proyecto: goriy/sif
static void on_search_click (void)
{
char buf[256];
  //msgbox ("Seaching...");
  Edit_GetText (GetDlgItem(hMainWindow, IDC_TXT), buf, sizeof(buf));
  ListView_DeleteAllItems (hResult);
  text_set ("");
  Edit_SetText (GetDlgItem(hMainWindow, IDC_LFIND), "");
  Button_Enable (GetDlgItem (hMainWindow, IDC_SAVELF), 0);
  Button_Enable (GetDlgItem (hMainWindow, IDC_SAVECRLF), 0);

  recent_current_reset ();
  get_options ();
  if (strlen(buf) > 0)  {
    recent_add (buf);
    recent_fill_combo (IDC_RECENT);
    search_in_path (buf, CurrentPath, FileMask);
  }
  else  {
    status_bar (1, "Empty search string!");
  }
}
Ejemplo n.º 21
0
bool
ObjectReference::updateGoToObjectButton() const
{
	char szObjectName[ 256 ];
	assert( _edit );
	_edit->GetText( szObjectName, sizeof( szObjectName ) );
	INode* pNode = theAttributes.ip->GetINodeByName( szObjectName );

	assert( hwndGoToObjectButton );
	Button_Enable( hwndGoToObjectButton, bool( pNode ) );

	return bool( pNode );
}
Ejemplo n.º 22
0
void fill_header(HWND hwnd)
{
	Button_SetText(GetDlgItem(hwnd, find_bt_id), utf8_2_ansi(_("Find")));

	Button_Enable(GetDlgItem(hwnd, find_bt_id), FALSE);

	char text[1024];
	HWND hctl = GetDlgItem(hwnd, listview_id);
	LVCOLUMN lvc;

	lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
	lvc.fmt = LVCFMT_LEFT;
	lvc.cx = 90;
	strcpy(text, dgettext_2_ansi("wesnoth-hero", "name"));
	lvc.pszText = text;
	lvc.cchTextMax = 0;
	lvc.iSubItem = 0;
	ListView_InsertColumn(hctl, 0, &lvc);

	lvc.mask= LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
	lvc.cx = 60;
	lvc.iSubItem = 1;
	strcpy(text, dgettext_2_ansi("wesnoth-hero", "catalog"));
	lvc.pszText = text;
	ListView_InsertColumn(hctl, 1, &lvc);

	lvc.cx = 48;
	lvc.iSubItem = 2;
	strcpy(text, dgettext_2_ansi("wesnoth-hero", "feature"));
	lvc.pszText = text;
	ListView_InsertColumn(hctl, 2, &lvc);

	lvc.cx = 40;
	lvc.iSubItem = 3;
	strcpy(text, dgettext_2_ansi("wesnoth-hero", "side feature"));
	lvc.pszText = text;
	ListView_InsertColumn(hctl, 3, &lvc);

	lvc.cx = 40;
	lvc.iSubItem = 4;
	strcpy(text, dgettext_2_ansi("wesnoth-hero", "leadership"));
	lvc.pszText = text;
	ListView_InsertColumn(hctl, 4, &lvc);

	ListView_SetImageList(hctl, NULL, LVSIL_SMALL);
	ListView_SetExtendedListViewStyleEx(hctl, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
}
Ejemplo n.º 23
0
bool on_command(HWND hwnd, int id, UINT codeNotify)
{
	char text[_MAX_PATH];
	if (id == find_et_id) {
		if (codeNotify == EN_CHANGE) {
			Edit_GetText(GetDlgItem(hwnd, find_et_id), text, sizeof(text) / sizeof(text[0]));
			Button_Enable(GetDlgItem(hwnd, find_bt_id), strlen(text));
		}
#ifndef _ROSE_EDITOR
	} else if (id == find_bt_id) {
		listview_find_hero(GetDlgItem(hwnd, listview_id), GetDlgItem(hwnd, find_et_id));
	} else {
#endif
		return false;
	}
	return true;
}
Ejemplo n.º 24
0
INT_PTR CALLBACK CertSelectionDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {	
	static char* selectedCertID;
	switch(message) {
		case WM_INITDIALOG:
			buildCertificatesList(hwnd);
			selectedCertID = (char*)lParam;
			selectedCertID[0] = '\0';
			break;
		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDOK: {
					int index = ListView_GetNextItem(GetDlgItem(hwnd, IDC_CERTIFICATESLIST), -1, LVNI_SELECTED);
					TCHAR unicodeSelectedCertID[256];
					ListView_GetItemText(GetDlgItem(hwnd, IDC_CERTIFICATESLIST), index, 3, (LPTSTR)unicodeSelectedCertID, 33);
					strcpy(selectedCertID, CW2A(unicodeSelectedCertID));
					EstEID_log("selected certificate id in dialog proc: %s", selectedCertID);
				}
				default:
					EndDialog(hwnd, LOWORD(wParam));
			}	
			break;
		case WM_NOTIFY:			
			if(wParam == IDC_CERTIFICATESLIST) {
				switch(((LPNMHDR)lParam)->code) {
					case LVN_ITEMCHANGED:
					case NM_CLICK:
						Button_Enable(GetDlgItem(hwnd, IDOK), ((LPNMITEMACTIVATE)lParam)->iItem != -1);
						break;
					case LVN_ITEMACTIVATE: {
						int selectedCertIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
						TCHAR unicodeSelectedCertID[256];
						ListView_GetItemText(GetDlgItem(hwnd, IDC_CERTIFICATESLIST), selectedCertIndex, 3, (LPTSTR)unicodeSelectedCertID, 33);
						strcpy(selectedCertID, CW2A(unicodeSelectedCertID));
						EstEID_log("dblcklicked certificate id in dialog proc: %s", selectedCertID);
						EndDialog(hwnd, LOWORD(wParam));
					}
				}
			}			
		default:
			return false;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);	
}
Ejemplo n.º 25
0
/*窗口初始化*/
LONG DoOperatorInit(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
	SetWindowPos(hDlg,NULL,0,0,800,480,SWP_SHOWWINDOW);

	//打印机串口通信初始化
	TCHAR STRCOM[20];
	_stprintf_s(STRCOM,10,_T("COM1:"));
	//hPrinterComPort = InitCommunication(STRCOM,hPrinterComPort,NOPARITY);

	//plc控制器串口通信初始化
	_stprintf_s(STRCOM,10,_T("COM4:"));
	hServoComPort = InitCommunication(STRCOM,hServoComPort,NOPARITY);

	hPrinterComPort = hServoComPort;
	//下拉菜单初始化
	 OnInit( hDlg, message, wParam, lParam);

	//开启速度曲线刷新线程
	MapFlag = TRUE;
	if (!GetExitCodeThread (hMapThread, &dwMapThreadID) ||(dwMapThreadID != STILL_ACTIVE)) 
	{
		hMapThread = CreateThread(NULL,0,MapThread,(LPVOID)hDlg,0,&dwMapThreadID);
	}
	//开启伺服控制主线程
	MainFlag = TRUE;
	if (!GetExitCodeThread (hmainThread, &dwMainThreadID) ||(dwMainThreadID != STILL_ACTIVE)) 
	{
		hmainThread = CreateThread(NULL,0,MainThread,(LPVOID)hDlg,0,&dwMainThreadID);
	}

	//线程同步:伺服控制主线程和绘图线程
	m_Event = CreateEvent(NULL,FALSE,TRUE,NULL);

	Button_Enable(GetDlgItem(hDlg,IDC_BtnNext),FALSE);


	return TRUE;
}
Ejemplo n.º 26
0
void Dlg_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify) {

   switch (id) {
      case IDCANCEL:
         EndDialog(hWnd, id);
         break;

      case IDC_BTN_STOP: 
      {
         // StopProcessing can't be called from the UI thread
         // or a deadlock will occur: SendMessage() is used 
         // to fill up the listboxes
         // --> Another thread is required
         DWORD dwThreadID;
         CloseHandle(chBEGINTHREADEX(NULL, 0, StoppingThread, 
            NULL, 0, &dwThreadID));
         
         // This button can't be pushed twice
         Button_Enable(hWndCtl, FALSE);
      }
      break;
   }
}
Ejemplo n.º 27
0
BOOL CALLBACK PropSheetProc(HWND hwnd, UINT msg, LPARAM lParam) {
  if (msg == PSCB_PRECREATE) {
    DLGTEMPLATE *pDlgTemplate = (DLGTEMPLATE*) lParam;
    pDlgTemplate->style |= WS_THICKFRAME;
  }
  else if (msg == PSCB_INITIALIZED) {
    g_cfgwnd = hwnd;
    SetWindowSubclass(g_cfgwnd, PropSheetWinProc, 0, 0);
    UpdateStrings();

    // OK button replaces Cancel button
    SendMessage(g_cfgwnd, PSM_CANCELTOCLOSE, 0, 0);
    HWND cancel = GetDlgItem(g_cfgwnd, IDCANCEL);
    HWND ok = GetDlgItem(g_cfgwnd, IDOK);
    Button_Enable(cancel, TRUE); // Re-enable to enable escape key
    WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
    GetWindowPlacement(cancel, &wndpl);
    SetWindowPlacement(ok, &wndpl);
    ShowWindow(cancel, SW_HIDE);

    HWND apply = GetDlgItem(g_cfgwnd, IDAPPLY);
    Button_SetText(apply, L""); // Remove text to remove it's shortcut (Alt+A in English)
  }
}
Ejemplo n.º 28
0
BOOL SceneViewer::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_INITDIALOG:
        {
            fhDlg = hDlg;

            // Set the exe to use
            HWND hExeCombo = GetDlgItem(hDlg, IDC_EXE);
            ComboBox_AddString(hExeCombo, "Release");
            ComboBox_AddString(hExeCombo, "Debug");
            ComboBox_SetCurSel(hExeCombo, fReleaseExe ? 0 : 1);

            // Set the client path
            const char *path = plMaxConfig::GetClientPath(false, true);
            ICustEdit *edit = GetICustEdit(GetDlgItem(hDlg, IDC_CLIENT_PATH));
            edit->SetText((char*)path);

            // Set the "Load old data" checkbox
            HWND hLoadOld = GetDlgItem(hDlg, IDC_REUSE_DATA);
            Button_SetCheck(hLoadOld, fLoadOld ? BST_CHECKED : BST_UNCHECKED);
            Button_Enable(hLoadOld, SceneSync::Instance().CanLoadOldResMgr());

            // Set the update controls
            float val = float(fUpdateFreq) / 1000.f;
            ISpinnerControl *spin = SetupFloatSpinner(hDlg, IDC_SPINNER, IDC_EDIT, 0.1, 1.f, val);
            spin->Enable(fUpdate);
            CheckDlgButton(hDlg, IDC_UPDATE, fUpdate ? BST_CHECKED : BST_UNCHECKED);

            IEnableSetupControls(!SceneSync::Instance().IsClientRunning());
        }
        return TRUE;

    case WM_COMMAND:
        // Start/Stop SceneViewer
        if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_START)
        {
            IToggleRunning();
            IEnableSetupControls(!SceneSync::Instance().IsClientRunning());
            return TRUE;
        }
        // Close dialog
        else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDCANCEL)
        {
            DestroyWindow(hDlg);
            fhDlg = NULL;
            return TRUE;
        }
        // Browse for directory
        else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_DIR)
        {
            const char *path = plMaxConfig::GetClientPath(true);
            if (path)
            {
                ICustEdit *edit = GetICustEdit(GetDlgItem(hDlg, IDC_CLIENT_PATH));
                edit->SetText((char*)path);
            }

            return TRUE;
        }
        // "Load old data" selection changed
        else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_REUSE_DATA)
        {
            fLoadOld = (Button_GetCheck((HWND)lParam) == BST_CHECKED);
            return TRUE;
        }
        // Release/Debug exe selection changed
        else if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_EXE)
        {
            int sel = ComboBox_GetCurSel((HWND)lParam);
            fReleaseExe = (sel == 0);
            return TRUE;
        }
        else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_UPDATE)
        {
            fUpdate = (SendMessage((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED);

            ISpinnerControl *spin = GetISpinner(GetDlgItem(hDlg, IDC_SPINNER));
            spin->Enable(fUpdate);
            ReleaseISpinner(spin);

            // If update was turned on, send out an update message so any dirty objects
            // will be reconverted right away
            if (fUpdate)
                SceneSync::Instance().SetUpdateFreq(fUpdateFreq);

            return TRUE;
        }
        break;
        
    // Update frequency changed
    case CC_SPINNER_CHANGE:
        if (LOWORD(wParam) == IDC_SPINNER)
        {
            ISpinnerControl *spin = (ISpinnerControl*)lParam;
            float val = spin->GetFVal();
            fUpdateFreq = int(val*1000.f);
            SceneSync::Instance().SetUpdateFreq(fUpdateFreq);
        }
        return TRUE;

    // Type in directory
    case WM_CUSTEDIT_ENTER:
        if (wParam == IDC_CLIENT_PATH)
        {
            ICustEdit *edit = GetICustEdit((HWND)lParam);

            char path[MAX_PATH];
            edit->GetText(path, sizeof(path));
            plMaxConfig::SetClientPath(path);
        }
        return TRUE;
    }

    return FALSE;
}
Ejemplo n.º 29
0
static NTSTATUS DownloadUpdateThreadStart(
    __in PVOID Parameter
    )
{
    PPH_STRING downloadUrlPath = NULL;
    HANDLE tempFileHandle = NULL;
    HINTERNET hInitialize = NULL, hConnection = NULL, hRequest = NULL;
    NTSTATUS status = STATUS_UNSUCCESSFUL;
    HWND hwndDlg = (HWND)Parameter;

    Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), FALSE);
    SetDlgItemText(hwndDlg, IDC_STATUS, L"Initializing");

    // Reset the progress state on Vista and above.
    if (WindowsVersion > WINDOWS_XP)
        SendDlgItemMessage(hwndDlg, IDC_PROGRESS, PBM_SETSTATE, PBST_NORMAL, 0L);

    if (!ConnectionAvailable())
        return status;

    __try
    {
        // Get temp dir.
        WCHAR tempPathString[MAX_PATH];
        DWORD tempPathLength = GetTempPath(MAX_PATH, tempPathString);

        if (tempPathLength == 0 || tempPathLength > MAX_PATH)
        {
            LogEvent(hwndDlg, PhFormatString(L"CreateFile failed (%d)", GetLastError()));
            __leave;
        }

        // create the download path string.
        downloadUrlPath = PhFormatString(
            L"/projects/processhacker/files/processhacker2/processhacker-%u.%u-setup.exe/download?use_mirror=autoselect", /* ?use_mirror=waix" */
            UpdateData.MajorVersion,
            UpdateData.MinorVersion
            );

        // Append the tempath to our string: %TEMP%processhacker-%u.%u-setup.exe
        // Example: C:\\Users\\dmex\\AppData\\Temp\\processhacker-2.10-setup.exe
        SetupFilePath = PhFormatString(
            L"%sprocesshacker-%u.%u-setup.exe",
            tempPathString,
            UpdateData.MajorVersion,
            UpdateData.MinorVersion
            );

        // Create output file
        status = PhCreateFileWin32(
            &tempFileHandle,
            SetupFilePath->Buffer,
            FILE_GENERIC_READ | FILE_GENERIC_WRITE,
            FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | FILE_ATTRIBUTE_TEMPORARY,
            FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
            FILE_OVERWRITE_IF,
            FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
            );

        if (!NT_SUCCESS(status))
        {
            LogEvent(hwndDlg, PhFormatString(L"PhCreateFileWin32 failed (%s)", ((PPH_STRING)PHA_DEREFERENCE(PhGetNtMessage(status)))->Buffer));
            __leave;
        }

        {
            // Create a user agent string.
            PPH_STRING phVersion = PhGetPhVersion();
            PPH_STRING userAgent = PhConcatStrings2(L"PH Updater v", phVersion->Buffer);

            // Initialize the wininet library.
            if (!(hInitialize = InternetOpen(
                userAgent->Buffer,
                INTERNET_OPEN_TYPE_PRECONFIG,
                NULL,
                NULL,
                0
                )))
            {
                LogEvent(hwndDlg, PhFormatString(L"Updater: (InitializeConnection) InternetOpen failed (%d)", GetLastError()));

                PhDereferenceObject(userAgent);
                PhDereferenceObject(phVersion);

                __leave;
            }

            PhDereferenceObject(userAgent);
            PhDereferenceObject(phVersion);
        }

        // Connect to the server.
        if (!(hConnection = InternetConnect(
            hInitialize,
            L"sourceforge.net",
            INTERNET_DEFAULT_HTTP_PORT,
            NULL,
            NULL,
            INTERNET_SERVICE_HTTP,
            0,
            0)))
        {
            LogEvent(hwndDlg, PhFormatString(L"InternetConnect failed (%d)", GetLastError()));
            __leave;
        }

        // Open the HTTP request.
        if (!(hRequest = HttpOpenRequest(
            hConnection,
            NULL,
            downloadUrlPath->Buffer,
            NULL,
            NULL,
            NULL,
            INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RESYNCHRONIZE,
            0
            )))
        {
            LogEvent(hwndDlg, PhFormatString(L"HttpOpenRequest failed (%d)", GetLastError()));
            __leave;
        }

        SetDlgItemText(hwndDlg, IDC_STATUS, L"Connecting");

        // Send the HTTP request.
        if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0))
        {
            LogEvent(hwndDlg, PhFormatString(L"HttpSendRequest failed (%d)", GetLastError()));

            // Enable the 'Retry' button.
            Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), TRUE);
            SetDlgItemText(hwndDlg, IDC_DOWNLOAD, L"Retry");

            // Reset the state and let user retry the download.
            PhUpdaterState = Download;
        }
        else
        {
            BYTE hashBuffer[20]; 
            DWORD contentLengthSize = sizeof(DWORD);
            PH_HASH_CONTEXT hashContext;

            // Initialize hash algorithm.
            PhInitializeHash(&hashContext, Sha1HashAlgorithm);

            if (!HttpQueryInfoW(hRequest, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &contentLength, &contentLengthSize, 0))
            {
                // No content length...impossible to calculate % complete...
                // we can read the data, BUT in this instance Sourceforge always returns the content length
                // so instead we'll exit here instead of downloading the file.
                LogEvent(hwndDlg, PhFormatString(L"HttpQueryInfo failed (%d)", GetLastError()));
                __leave;
            }
            else
            {
                BYTE buffer[PAGE_SIZE];
                DWORD bytesRead = 0, startTick = 0;
                IO_STATUS_BLOCK isb;

                // Zero the buffer.
                ZeroMemory(buffer, PAGE_SIZE);

                // Reset the counters.
                bytesDownloaded = 0, timeTransferred = 0, LastUpdateTime = 0;
                IsUpdating = FALSE;

                // Start the clock.
                startTick = GetTickCount();
                timeTransferred = startTick;

                // Download the data.
                while (InternetReadFile(hRequest, buffer, PAGE_SIZE, &bytesRead))
                {
                    // If we get zero bytes, the file was uploaded or there was an error.
                    if (bytesRead == 0)
                        break;

                    // If window closed and thread handle was closed, just dispose and exit.
                    // (This also skips error checking/prompts and updating the disposed UI)
                    if (!DownloadThreadHandle)
                        __leave;

                    // Update the hash of bytes we downloaded.
                    PhUpdateHash(&hashContext, buffer, bytesRead);

                    // Write the downloaded bytes to disk.
                    status = NtWriteFile(
                        tempFileHandle,
                        NULL,
                        NULL,
                        NULL,
                        &isb,
                        buffer,
                        bytesRead,
                        NULL,
                        NULL
                        );

                    if (!NT_SUCCESS(status))
                    {
                        PPH_STRING message = PhGetNtMessage(status);

                        LogEvent(hwndDlg, PhFormatString(L"NtWriteFile failed (%s)", message->Buffer));

                        PhDereferenceObject(message);
                        break;
                    }

                    // Check dwBytesRead are the same dwBytesWritten length returned by WriteFile.
                    if (bytesRead != isb.Information)
                    {
                        PPH_STRING message = PhGetNtMessage(status);

                        LogEvent(hwndDlg, PhFormatString(L"NtWriteFile failed (%s)", message->Buffer));

                        PhDereferenceObject(message);
                        break;
                    }
                                        
                    // Update our total bytes downloaded
                    PhAcquireQueuedLockExclusive(&Lock);
                    bytesDownloaded += (DWORD)isb.Information;
                    PhReleaseQueuedLockExclusive(&Lock);

                    AsyncUpdate();
                }

                // Check if we downloaded the entire file.
                assert(bytesDownloaded == contentLength);

                // Compute our hash result.
                if (PhFinalHash(&hashContext, &hashBuffer, 20, NULL))
                {
                    // Allocate our hash string, hex the final hash result in our hashBuffer.
                    PPH_STRING hexString = PhBufferToHexString(hashBuffer, 20);

                    if (PhEqualString(hexString, UpdateData.Hash, TRUE))
                    {
                        // If PH is not elevated, set the UAC shield for the install button as the setup requires elevation.
                        if (!PhElevated)
                            SendMessage(GetDlgItem(hwndDlg, IDC_DOWNLOAD), BCM_SETSHIELD, 0, TRUE);

                        // Set the download result, don't include hash status since it succeeded.
                        //SetDlgItemText(hwndDlg, IDC_STATUS, L"Download Complete");
                        // Set button text for next action
                        Button_SetText(GetDlgItem(hwndDlg, IDC_DOWNLOAD), L"Install");
                        // Enable the Install button
                        Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), TRUE);
                        // Hash succeeded, set state as ready to install.
                        PhUpdaterState = Install;
                    }
                    else
                    {
                        if (WindowsVersion > WINDOWS_XP)
                            SendDlgItemMessage(hwndDlg, IDC_PROGRESS, PBM_SETSTATE, PBST_ERROR, 0L);

                        SetDlgItemText(hwndDlg, IDC_STATUS, L"Download complete, SHA1 Hash failed.");

                        // Set button text for next action
                        Button_SetText(GetDlgItem(hwndDlg, IDC_DOWNLOAD), L"Retry");
                        // Enable the Install button
                        Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), TRUE);
                        // Hash failed, reset state to downloading so user can redownload the file.
                        PhUpdaterState = Download;
                    }

                    PhDereferenceObject(hexString);
                }
                else
                {
                    //SetDlgItemText(hwndDlg, IDC_STATUS, L"PhFinalHash failed");

                    // Show fancy Red progressbar if hash failed on Vista and above.
                    if (WindowsVersion > WINDOWS_XP)
                        SendDlgItemMessage(hwndDlg, IDC_PROGRESS, PBM_SETSTATE, PBST_ERROR, 0L);
                }
            }
        }

        status = STATUS_SUCCESS;
    }
    __finally
    {
        if (hInitialize)
        {
            InternetCloseHandle(hInitialize);
            hInitialize = NULL;
        }

        if (hConnection)
        {
            InternetCloseHandle(hConnection);
            hConnection = NULL;
        }

        if (hRequest)
        {
            InternetCloseHandle(hRequest);
            hRequest = NULL;
        }

        if (tempFileHandle)
        {
            NtClose(tempFileHandle);
            tempFileHandle = NULL;
        }

        if (downloadUrlPath)
        {
            PhDereferenceObject(downloadUrlPath);
            downloadUrlPath = NULL;
        }
    }

    return status;
}
Ejemplo n.º 30
0
static NTSTATUS CheckUpdateThreadStart(
    __in PVOID Parameter
    )
{
    HWND hwndDlg = (HWND)Parameter;

    if (ConnectionAvailable())
    {
        if (QueryXmlData())
        {
            INT result = 0;

            PhGetPhVersionNumbers(
                &UpdateData.PhMajorVersion, 
                &UpdateData.PhMinorVersion, 
                NULL, 
                &UpdateData.PhRevisionVersion
                );

            result = 1;/*CompareVersions(
                UpdateData.MajorVersion, 
                UpdateData.MinorVersion, 
                UpdateData.PhMajorVersion, 
                UpdateData.PhMinorVersion
                );*/

            if (result > 0)
            {
                PPH_STRING summaryText = PhFormatString(
                    L"Process Hacker %u.%u",
                    UpdateData.MajorVersion,
                    UpdateData.MinorVersion
                    );

                PPH_STRING releaseDateText = PhFormatString(
                    L"Released: %s",
                    UpdateData.RelDate->Buffer
                    );

                PPH_STRING releaseSizeText = PhFormatString(
                    L"Size: %s",
                    UpdateData.Size->Buffer
                    );

                SetDlgItemText(hwndDlg, IDC_MESSAGE, summaryText->Buffer);
                SetDlgItemText(hwndDlg, IDC_RELDATE, releaseDateText->Buffer);
                SetDlgItemText(hwndDlg, IDC_STATUS, releaseSizeText->Buffer);

                // Set the state for the button to know it can preform the download action.
                PhUpdaterState = Download;

                // Enable the download button.
                Button_Enable(GetDlgItem(hwndDlg, IDC_DOWNLOAD), TRUE);
                // Use the Scrollbar macro to enable the other controls.
                ScrollBar_Show(GetDlgItem(hwndDlg, IDC_PROGRESS), TRUE);
                ScrollBar_Show(GetDlgItem(hwndDlg, IDC_RELDATE), TRUE);
                ScrollBar_Show(GetDlgItem(hwndDlg, IDC_STATUS), TRUE);

                PhDereferenceObject(releaseSizeText);
                PhDereferenceObject(releaseDateText);
                PhDereferenceObject(summaryText);
            }
            else if (result == 0)
            {
                PPH_STRING summaryText = PhCreateString(
                    L"No updates available"
                    );

                PPH_STRING versionText = PhFormatString(
                    L"You're running the latest stable version: v%u.%u",
                    UpdateData.MajorVersion,
                    UpdateData.MinorVersion
                    );

                SetDlgItemText(hwndDlg, IDC_MESSAGE, summaryText->Buffer);
                SetDlgItemText(hwndDlg, IDC_RELDATE, versionText->Buffer);
  
                PhDereferenceObject(versionText);
                PhDereferenceObject(summaryText);
            }
            else if (result < 0)
            {
                PPH_STRING summaryText = PhCreateString(
                    L"No updates available"
                    );

                PPH_STRING versionText = PhFormatString(
                    L"You're running SVN build: v%u.%u (r%u)",
                    UpdateData.PhMajorVersion,
                    UpdateData.PhMinorVersion,
                    UpdateData.PhRevisionVersion
                    );

                //swprintf_s(
                // szReleaseText,
                // _countof(szReleaseText),
                // L"Released: %s",
                // xmlData.RelDate
                // );

                SetDlgItemText(hwndDlg, IDC_RELDATE, versionText->Buffer);
                SetDlgItemText(hwndDlg, IDC_MESSAGE, summaryText->Buffer);
       
                PhDereferenceObject(versionText);
                PhDereferenceObject(summaryText);
            }
        }
    }

    return STATUS_SUCCESS;
}