Beispiel #1
0
LRESULT WINAPI DoAppSwitch( WPARAM wParam, LPARAM lParam )
{
   HWND hwnd;
   MSG msg;
   BOOL Esc = FALSE;
   INT Count = 0;
   WCHAR Text[1024];

   switchdialog = NULL;

   switch (lParam)
   {
      case VK_TAB:
         if( !CreateSwitcherWindow(User32Instance) ) return 0;
         if( !GetDialogFont() ) return 0;
         ProcessHotKey();
         break;

      case VK_ESCAPE:
         windowCount = 0;
         Count = 0;
         EnumWindowsZOrder(EnumerateCallback, 0);
         if (windowCount < 2) return 0;
         if (wParam == SC_NEXTWINDOW)
            Count = 1;
         else
         {
            if (windowCount == 2)
               Count = 0;
            else
               Count = windowCount - 1;
         }
         TRACE("DoAppSwitch VK_ESCAPE 1 Count %d windowCount %d\n",Count,windowCount);
         hwnd = windowList[Count];
         GetWindowTextW(hwnd, Text, 1023);
         TRACE("[ATbot] Switching to 0x%08x (%ls)\n", hwnd, Text);
         MakeWindowActive(hwnd);
         Esc = TRUE;
         break;

      default:
         return 0;
   }
   // Main message loop:
   while (1)
   {
      for (;;)
      {
         if (PeekMessageW( &msg, 0, 0, 0, PM_NOREMOVE ))
         {
             if (!CallMsgFilterW( &msg, MSGF_NEXTWINDOW )) break;
             /* remove the message from the queue */
             PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE );
         }
         else
             WaitMessage();
      }

      switch (msg.message)
      {
        case WM_KEYUP:
        {
          PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE );
          if (msg.wParam == VK_MENU)
          {
             CompleteSwitch(TRUE);
          }
          else if (msg.wParam == VK_RETURN)
          {
             CompleteSwitch(TRUE);
          }
          else if (msg.wParam == VK_ESCAPE)
          {
             TRACE("DoAppSwitch VK_ESCAPE 2\n");
             CompleteSwitch(FALSE);
          }
          goto Exit; //break;
        }

        case WM_SYSKEYDOWN:
        {
          PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE );
          if (HIWORD(msg.lParam) & KF_ALTDOWN)
          {
             INT Shift;
             if ( msg.wParam == VK_TAB )
             {
                if (Esc) break;
                Shift = GetKeyState(VK_SHIFT) & 0x8000 ? SC_PREVWINDOW : SC_NEXTWINDOW;
                if (Shift == SC_NEXTWINDOW)
                {
                   selectedWindow = (selectedWindow + 1)%windowCount;
                }
                else
                {
                   selectedWindow = selectedWindow - 1;
                   if (selectedWindow < 0)
                      selectedWindow = windowCount - 1;
                }
                InvalidateRect(switchdialog, NULL, TRUE);
             }
             else if ( msg.wParam == VK_ESCAPE )
             {
                if (!Esc) break;
                if (windowCount < 2)
                   goto Exit;
                if (wParam == SC_NEXTWINDOW)
                {
                   Count = (Count + 1)%windowCount;
                }
                else
                {
                   Count--;
                   if (Count < 0)
                      Count = windowCount - 1;
                }
                hwnd = windowList[Count];
                GetWindowTextW(hwnd, Text, 1023);
                MakeWindowActive(hwnd);
             }
          }
          break;
        }

        case WM_LBUTTONUP:
          PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE );
          ProcessMouseMessage(msg.message, msg.lParam);
          goto Exit;

        default:
          if (PeekMessageW( &msg, 0, msg.message, msg.message, PM_REMOVE ))
          {
             TranslateMessage(&msg);
             DispatchMessageW(&msg);
          }
          break;
      }
   }
Exit:
   if (switchdialog) DestroyWindow(switchdialog);
   switchdialog = NULL;
   selectedWindow = 0;
   windowCount = 0;
   return 0;
}
Beispiel #2
0
/*
  Window procedure for autocompletion
 */
static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
    LPOLESTR strs;
    HRESULT hr;
    WCHAR hwndText[255];
    WCHAR *hwndQCText;
    RECT r;
    BOOL control, filled, displayall = FALSE;
    int cpt, height, sel;

    if (!This->enabled) return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);

    switch (uMsg)
    {
	case CB_SHOWDROPDOWN:
	    ShowWindow(This->hwndListBox, SW_HIDE);
	    break;
	case WM_KILLFOCUS:
	    if ((This->options && ACO_AUTOSUGGEST) && 
		((HWND)wParam != This->hwndListBox))
	    {
		ShowWindow(This->hwndListBox, SW_HIDE);
	    }
	    break;
	case WM_KEYUP:
	    
	    GetWindowTextW( hwnd, (LPWSTR)hwndText, 255);
      
	    switch(wParam) {
		case VK_RETURN:
		    /* If quickComplete is set and control is pressed, replace the string */
		    control = GetKeyState(VK_CONTROL) & 0x8000;		    
		    if (control && This->quickComplete) {
			hwndQCText = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
						       (lstrlenW(This->quickComplete)+lstrlenW(hwndText))*sizeof(WCHAR));
			sel = sprintfW(hwndQCText, This->quickComplete, hwndText);
			SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)hwndQCText);
			SendMessageW(hwnd, EM_SETSEL, 0, sel);
			HeapFree(GetProcessHeap(), 0, hwndQCText);
		    }

		    ShowWindow(This->hwndListBox, SW_HIDE);
		    return 0;
		case VK_LEFT:
		case VK_RIGHT:
		    return 0;
		case VK_UP:	      
		case VK_DOWN:
		    /* Two cases here : 
		       - if the listbox is not visible, displays it 
		       with all the entries if the style ACO_UPDOWNKEYDROPSLIST
		       is present but does not select anything.
		       - if the listbox is visible, change the selection
		    */
		    if ( (This->options & (ACO_AUTOSUGGEST | ACO_UPDOWNKEYDROPSLIST)) 
			 && (!IsWindowVisible(This->hwndListBox) && (! *hwndText)) )
		    {
			 /* We must display all the entries */
			 displayall = TRUE;
		    } else {
			if (IsWindowVisible(This->hwndListBox)) {
			    int count;

			    count = SendMessageW(This->hwndListBox, LB_GETCOUNT, 0, 0);
			    /* Change the selection */
			    sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
			    if (wParam == VK_UP)
				sel = ((sel-1)<0)?count-1:sel-1;
			    else
				sel = ((sel+1)>= count)?-1:sel+1;
			    SendMessageW(This->hwndListBox, LB_SETCURSEL, sel, 0);
			    if (sel != -1) {
				WCHAR *msg;
				int len;
				
				len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, (LPARAM)NULL);
				msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
				SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
				SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
				SendMessageW(hwnd, EM_SETSEL, lstrlenW(msg), lstrlenW(msg));
				HeapFree(GetProcessHeap(), 0, msg);
			    } else {
				SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)This->txtbackup);
				SendMessageW(hwnd, EM_SETSEL, lstrlenW(This->txtbackup), lstrlenW(This->txtbackup));
			    }			
			} 		
			return 0;
		    }
		    break;
		case VK_BACK:
		case VK_DELETE:
		    if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) {
			ShowWindow(This->hwndListBox, SW_HIDE);
			return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
		    }
		    if (This->options & ACO_AUTOAPPEND) {
			DWORD b;
			SendMessageW(hwnd, EM_GETSEL, (WPARAM)&b, (LPARAM)NULL);
			if (b>1) {
			    hwndText[b-1] = '\0';
			} else {
			    hwndText[0] = '\0';
			    SetWindowTextW(hwnd, hwndText); 
			}			
		    }
		    break;
		default:		    
		    ;
	    }
      
	    SendMessageW(This->hwndListBox, LB_RESETCONTENT, 0, 0);

	    HeapFree(GetProcessHeap(), 0, This->txtbackup);
	    This->txtbackup = HeapAlloc(GetProcessHeap(),
						 HEAP_ZERO_MEMORY, (lstrlenW(hwndText)+1)*sizeof(WCHAR));							      
	    lstrcpyW(This->txtbackup, hwndText);

	    /* Returns if there is no text to search and we doesn't want to display all the entries */
	    if ((!displayall) && (! *hwndText) )
		break;
	    
	    IEnumString_Reset(This->enumstr);
	    filled = FALSE;
	    for(cpt = 0;;) {
		hr = IEnumString_Next(This->enumstr, 1, &strs, NULL);
		if (hr != S_OK)
		    break;

		if (strstrW(strs, hwndText) == strs) {
		    if (This->options & ACO_AUTOAPPEND) {
			SetWindowTextW(hwnd, strs);
			SendMessageW(hwnd, EM_SETSEL, lstrlenW(hwndText), lstrlenW(strs));
			break;
		    }		

		    if (This->options & ACO_AUTOSUGGEST) {
			SendMessageW(This->hwndListBox, LB_ADDSTRING, 0, (LPARAM)strs);
			filled = TRUE;
			cpt++;
		    }
		}		
	    }
	    
	    if (This->options & ACO_AUTOSUGGEST) {
		if (filled) {
		    height = SendMessageW(This->hwndListBox, LB_GETITEMHEIGHT, 0, 0);
		    SendMessageW(This->hwndListBox, LB_CARETOFF, 0, 0);
		    GetWindowRect(hwnd, &r);
		    SetParent(This->hwndListBox, HWND_DESKTOP);
		    /* It seems that Windows XP displays 7 lines at most 
		       and otherwise displays a vertical scroll bar */
		    SetWindowPos(This->hwndListBox, HWND_TOP, 
				 r.left, r.bottom + 1, r.right - r.left, min(height * 7, height*(cpt+1)), 
				 SWP_SHOWWINDOW );
		} else {
		    ShowWindow(This->hwndListBox, SW_HIDE);
		}
	    }
	    
	    break; 
	default:
	    return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
	    
    }

    return 0;
}
Beispiel #3
0
BOOL CALLBACK MsdDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	int port;
	static wchar_t buff[4096] = { 0 };

	switch (uMsg) {
	case WM_INITDIALOG:
	{
		memset(buff, 0, sizeof(buff));
		port = (int)lParam;
		SetWindowLong(hW, GWL_USERDATA, (LONG)lParam);
		CONFIGVARIANT var(N_CONFIG_PATH, CONFIG_TYPE_WCHAR);
		if (LoadSetting(port, APINAME, var))
			wcsncpy_s(buff, var.wstrValue.c_str(), ARRAYSIZE(buff));
		SetWindowTextW(GetDlgItem(hW, IDC_EDIT1), buff);
		return TRUE;
	}
	case WM_CREATE:
		SetWindowLong(hW, GWL_USERDATA, (LONG)lParam);
		break;
	case WM_COMMAND:

		if (HIWORD(wParam) == BN_CLICKED) {
			switch (LOWORD(wParam)) {
			case IDC_BUTTON1:
				ZeroMemory(&ofn, sizeof(ofn));
				ofn.lStructSize = sizeof(ofn);
				ofn.hwndOwner = hW;
				ofn.lpstrTitle = L"USB image file";
				ofn.lpstrFile = buff;
				ofn.nMaxFile = ARRAYSIZE(buff);
				ofn.lpstrFilter = L"All\0*.*\0";
				ofn.nFilterIndex = 1;
				ofn.lpstrFileTitle = NULL;
				ofn.nMaxFileTitle = 0;
				ofn.lpstrInitialDir = NULL;
				ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;

				if (GetOpenFileName(&ofn) == TRUE) {
					SetWindowText(GetDlgItem(hW, IDC_EDIT1), ofn.lpstrFile);
				}
				break;
			case IDOK:
			{
				INT_PTR res = RESULT_OK;
				GetWindowTextW(GetDlgItem(hW, IDC_EDIT1), buff, ARRAYSIZE(buff));
				port = (int)GetWindowLong(hW, GWL_USERDATA);
				CONFIGVARIANT var(N_CONFIG_PATH, CONFIG_TYPE_WCHAR);
				var.wstrValue = buff;
				if (!SaveSetting(port, APINAME, var))
					res = RESULT_FAILED;
				//strcpy_s(conf.usb_img, ofn.lpstrFile);
				EndDialog(hW, res);
				return TRUE;
			}
			case IDCANCEL:
				EndDialog(hW, FALSE);
				return TRUE;
			}
		}
	}
	return FALSE;
}
Beispiel #4
0
static
INT_PTR CALLBACK
SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch (Msg)
    {
        case WM_INITDIALOG:
        {
            NewSettingsInfo = SettingsInfo;
            InitSettingsControls(hDlg, SettingsInfo);
        }
        break;

        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDC_CHOOSE:
                    ChooseFolder(hDlg);
                    break;

                case IDC_SAVE_WINDOW_POS:
                    IS_CHECKED(NewSettingsInfo.bSaveWndPos, IDC_SAVE_WINDOW_POS);
                    break;

                case IDC_UPDATE_AVLIST:
                    IS_CHECKED(NewSettingsInfo.bUpdateAtStart, IDC_UPDATE_AVLIST);
                    break;

                case IDC_LOG_ENABLED:
                    IS_CHECKED(NewSettingsInfo.bLogEnabled, IDC_LOG_ENABLED);
                    break;

                case IDC_DEL_AFTER_INSTALL:
                    IS_CHECKED(NewSettingsInfo.bDelInstaller, IDC_DEL_AFTER_INSTALL);
                    break;

                case IDC_DEFAULT_SETTINGS:
                    FillDefaultSettings(&NewSettingsInfo);
                    InitSettingsControls(hDlg, NewSettingsInfo);
                    break;

                case IDOK:
                {
                    WCHAR szDir[MAX_PATH];
                    DWORD dwAttr;

                    GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
                                   szDir, MAX_PATH);

                    dwAttr = GetFileAttributesW(szDir);
                    if (dwAttr != INVALID_FILE_ATTRIBUTES &&
                        (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
                    {
                        StringCbCopyW(NewSettingsInfo.szDownloadDir,
                                      sizeof(NewSettingsInfo.szDownloadDir),
                                      szDir);
                    }
                    else
                    {
                        WCHAR szMsgText[MAX_STR_LEN];

                        LoadStringW(hInst,
                                    IDS_CHOOSE_FOLDER_ERROR,
                                    szMsgText, sizeof(szMsgText) / sizeof(WCHAR));

                        if (MessageBoxW(hDlg, szMsgText, NULL, MB_YESNO) == IDYES)
                        {
                            if (CreateDirectoryW(szDir, NULL))
                            {
                                EndDialog(hDlg, LOWORD(wParam));
                            }
                        }

                        SetFocus(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT));
                        break;
                    }

                    SettingsInfo = NewSettingsInfo;
                    SaveSettings(GetParent(hDlg));
                    EndDialog(hDlg, LOWORD(wParam));
                }
                break;

                case IDCANCEL:
                    EndDialog(hDlg, LOWORD(wParam));
                    break;
            }
        }
        break;
    }

    return FALSE;
}
Beispiel #5
0
VOID
MainWndOnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
    WORD wCommand = LOWORD(wParam);

    if (lParam == (LPARAM)hSearchBar)
    {
        WCHAR szBuf[MAX_STR_LEN];

        switch (HIWORD(wParam))
        {
            case EN_SETFOCUS:
            {
                WCHAR szWndText[MAX_STR_LEN];

                LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, _countof(szBuf));
                GetWindowTextW(hSearchBar, szWndText, MAX_STR_LEN);
                if (wcscmp(szBuf, szWndText) == 0)
                {
                    SearchEnabled = FALSE;
                    SetWindowTextW(hSearchBar, L"");
                }
            }
            break;

            case EN_KILLFOCUS:
            {
                GetWindowTextW(hSearchBar, szBuf, MAX_STR_LEN);
                if (wcslen(szBuf) < 1)
                {
                    LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, _countof(szBuf));
                    SearchEnabled = FALSE;
                    SetWindowTextW(hSearchBar, szBuf);
                }
            }
            break;

            case EN_CHANGE:
            {
                WCHAR szWndText[MAX_STR_LEN];

                if (!SearchEnabled)
                {
                    SearchEnabled = TRUE;
                    break;
                }

                LoadStringW(hInst, IDS_SEARCH_TEXT, szBuf, _countof(szBuf));
                GetWindowTextW(hSearchBar, szWndText, MAX_STR_LEN);
                if (wcscmp(szBuf, szWndText) != 0)
                {
                    StringCbCopy(szSearchPattern, sizeof(szSearchPattern),
                                 szWndText);
                }
                else
                {
                    szSearchPattern[0] = UNICODE_NULL;
                }

                SetTimer(hwnd, SEARCH_TIMER_ID, 250, SearchTimerProc);
            }
            break;
        }

        return;
    }

    switch (wCommand)
    {
        case ID_OPEN_LINK:
            ShellExecuteW(hwnd, L"open", pLink, NULL, NULL, SW_SHOWNOACTIVATE);
            HeapFree(GetProcessHeap(), 0, pLink);
            break;

        case ID_COPY_LINK:
            CopyTextToClipboard(pLink);
            HeapFree(GetProcessHeap(), 0, pLink);
            break;

        case ID_SETTINGS:
            CreateSettingsDlg(hwnd);
            break;

        case ID_EXIT:
            PostMessageW(hwnd, WM_CLOSE, 0, 0);
            break;

        case ID_INSTALL:
            if (DownloadApplication(-1))
            /* TODO: Implement install dialog
             *   if (InstallApplication(-1))
             */
                UpdateApplicationsList(-1);
            break;

        case ID_UNINSTALL:
            if (UninstallApplication(-1, FALSE))
                UpdateApplicationsList(-1);
            break;

        case ID_MODIFY:
            if (UninstallApplication(-1, TRUE))
                UpdateApplicationsList(-1);
            break;

        case ID_REGREMOVE:
            RemoveAppFromRegistry(-1);
            break;

        case ID_REFRESH:
            UpdateApplicationsList(-1);
            break;

        case ID_RESETDB:
            UpdateAppsDB();
            UpdateApplicationsList(-1);
            break;

        case ID_HELP:
            MessageBoxW(hwnd, L"Help not implemented yet", NULL, MB_OK);
            break;

        case ID_ABOUT:
            ShowAboutDialog();
            break;
    }
}
Beispiel #6
0
/*
  Window procedure for autocompletion
 */
LRESULT APIENTRY CAutoComplete::ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    CAutoComplete *pThis = static_cast<CAutoComplete *>(GetPropW(hwnd, autocomplete_propertyW));
    HRESULT hr;
    WCHAR hwndText[255];
    WCHAR *hwndQCText;
    RECT r;
    BOOL control, filled, displayall = FALSE;
    int cpt, height, sel;
    ULONG fetched;

    if (!pThis->enabled)
    {
        return CallWindowProcW(pThis->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
    }

    switch (uMsg)
    {
        case CB_SHOWDROPDOWN:
        {
            ShowWindow(pThis->hwndListBox, SW_HIDE);
        }; break;

        case WM_KILLFOCUS:
        {
            if ((pThis->options & ACO_AUTOSUGGEST) && ((HWND)wParam != pThis->hwndListBox))
            {
                ShowWindow(pThis->hwndListBox, SW_HIDE);
            }
            return CallWindowProcW(pThis->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
        }; break;

        case WM_KEYUP:
        {
            GetWindowTextW(hwnd, (LPWSTR)hwndText, 255);

            switch(wParam)
            {
                case VK_RETURN:
                {
                    /* If quickComplete is set and control is pressed, replace the string */
                    control = GetKeyState(VK_CONTROL) & 0x8000;
                    if (control && pThis->quickComplete)
                    {
                        hwndQCText = (WCHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                                           (wcslen(pThis->quickComplete)+wcslen(hwndText))*sizeof(WCHAR));
                        sel = swprintf(hwndQCText, pThis->quickComplete, hwndText);
                        SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)hwndQCText);
                        SendMessageW(hwnd, EM_SETSEL, 0, sel);
                        HeapFree(GetProcessHeap(), 0, hwndQCText);
                    }

                    ShowWindow(pThis->hwndListBox, SW_HIDE);
                    return 0;
                }; break;

                case VK_LEFT:
                case VK_RIGHT:
                {
                    return 0;
                }; break;

                case VK_UP:
                case VK_DOWN:
                {
                    /* Two cases here :
                       - if the listbox is not visible, displays it
                       with all the entries if the style ACO_UPDOWNKEYDROPSLIST
                       is present but does not select anything.
                       - if the listbox is visible, change the selection
                    */
                    if ( (pThis->options & (ACO_AUTOSUGGEST | ACO_UPDOWNKEYDROPSLIST))
                     && (!IsWindowVisible(pThis->hwndListBox) && (! *hwndText)) )
                    {
                        /* We must display all the entries */
                        displayall = TRUE;
                    }
                    else
                    {
                        if (IsWindowVisible(pThis->hwndListBox))
                        {
                            int count;

                            count = SendMessageW(pThis->hwndListBox, LB_GETCOUNT, 0, 0);
                            /* Change the selection */
                            sel = SendMessageW(pThis->hwndListBox, LB_GETCURSEL, 0, 0);
                            if (wParam == VK_UP)
                                sel = ((sel-1) < 0) ? count-1 : sel-1;
                            else
                                sel = ((sel+1) >= count) ? -1 : sel+1;
                            
                            SendMessageW(pThis->hwndListBox, LB_SETCURSEL, sel, 0);
                            
                            if (sel != -1)
                            {
                                WCHAR *msg;
                                int len;

                                len = SendMessageW(pThis->hwndListBox, LB_GETTEXTLEN, sel, (LPARAM)NULL);
                                msg = (WCHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len + 1) * sizeof(WCHAR));
                                
                                if (msg)
                                {
                                    SendMessageW(pThis->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
                                    SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
                                    SendMessageW(hwnd, EM_SETSEL, wcslen(msg), wcslen(msg));
                                
                                    HeapFree(GetProcessHeap(), 0, msg);
                                }
                                else
                                {
                                    TRACE("HeapAlloc failed to allocate %d bytes\n", (len + 1) * sizeof(WCHAR));
                                }
                            }
                            else
                            {
                                SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)pThis->txtbackup);
                                SendMessageW(hwnd, EM_SETSEL, wcslen(pThis->txtbackup), wcslen(pThis->txtbackup));
                            }
                        }
                        return 0;
                    }
                }; break;
                
                case VK_BACK:
                case VK_DELETE:
                {
                    if ((! *hwndText) && (pThis->options & ACO_AUTOSUGGEST))
                    {
                        ShowWindow(pThis->hwndListBox, SW_HIDE);
                        return CallWindowProcW(pThis->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
                    }
                    
                    if (pThis->options & ACO_AUTOAPPEND)
                    {
                        DWORD b;
                        SendMessageW(hwnd, EM_GETSEL, (WPARAM)&b, (LPARAM)NULL);
                        if (b>1)
                        {
                            hwndText[b-1] = '\0';
                        }
                        else
                        {
                            hwndText[0] = '\0';
                            SetWindowTextW(hwnd, hwndText);
                        }
                    }
                }; break;
                
                default:
                    ;
            }

            SendMessageW(pThis->hwndListBox, LB_RESETCONTENT, 0, 0);

            HeapFree(GetProcessHeap(), 0, pThis->txtbackup);

            pThis->txtbackup = (WCHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (wcslen(hwndText)+1)*sizeof(WCHAR));

            if (pThis->txtbackup)
            {
                wcscpy(pThis->txtbackup, hwndText);
            }
            else
            {
                TRACE("HeapAlloc failed to allocate %d bytes\n", (wcslen(hwndText)+1)*sizeof(WCHAR));
            }

            /* Returns if there is no text to search and we doesn't want to display all the entries */
            if ((!displayall) && (! *hwndText) )
                break;

            pThis->enumstr->Reset();
            filled = FALSE;
            size_t curlen = wcslen(hwndText);

            for(cpt = 0;;)
            {
                CComHeapPtr<OLECHAR> strs;
                hr = pThis->enumstr->Next(1, &strs, &fetched);
                if (hr != S_OK)
                    break;

                if (!_wcsnicmp(hwndText, strs, curlen))
                {

                    if (pThis->options & ACO_AUTOAPPEND && *hwndText)
                    {
                        CComBSTR str((PCWSTR)strs);
                        memcpy(str.m_str, hwndText, curlen * sizeof(WCHAR));
                        SetWindowTextW(hwnd, str);
                        SendMessageW(hwnd, EM_SETSEL, curlen, str.Length());
                        if (!(pThis->options & ACO_AUTOSUGGEST))
                            break;
                    }

                    if (pThis->options & ACO_AUTOSUGGEST)
                    {
                        SendMessageW(pThis->hwndListBox, LB_ADDSTRING, 0, (LPARAM)(LPOLESTR)strs);
                        filled = TRUE;
                        cpt++;
                    }
                }
            }

            if (pThis->options & ACO_AUTOSUGGEST)
            {
                if (filled)
                {
                    height = SendMessageW(pThis->hwndListBox, LB_GETITEMHEIGHT, 0, 0);
                    SendMessageW(pThis->hwndListBox, LB_CARETOFF, 0, 0);
                    GetWindowRect(hwnd, &r);
                    SetParent(pThis->hwndListBox, HWND_DESKTOP);
                    /* It seems that Windows XP displays 7 lines at most
                       and otherwise displays a vertical scroll bar */
                    SetWindowPos(pThis->hwndListBox, HWND_TOP,
                         r.left, r.bottom + 1, r.right - r.left, min(height * 7, height * (cpt + 1)),
                         SWP_SHOWWINDOW );
                }
                else
                {
                    ShowWindow(pThis->hwndListBox, SW_HIDE);
                }
            }

        }; break;

        case WM_DESTROY:
        {
            /* Release our reference that we had since ->Init() */
            pThis->Release();
            return 0;
        }


        default:
        {
            return CallWindowProcW(pThis->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
        }

    }

    return 0;
}
Beispiel #7
0
static VOID MessageBoxTextToClipboard(HWND DialogWindow)
{
    HWND hwndText;
    PMSGBOXINFO mbi;
    int cchTotal, cchTitle, cchText, cchButton, i, n, cchBuffer;
    LPWSTR pszBuffer, pszBufferPos, pMessageBoxText, pszTitle, pszText, pszButton;
    WCHAR szButton[MSGBOXEX_MAXBTNSTR];
    HGLOBAL hGlobal;

    static const WCHAR szLine[] = L"---------------------------\r\n";

    mbi = (PMSGBOXINFO)GetPropW(DialogWindow, L"ROS_MSGBOX");
    hwndText = GetDlgItem(DialogWindow, MSGBOX_IDTEXT);
    cchTitle = GetWindowTextLengthW(DialogWindow) + 1;
    cchText = GetWindowTextLengthW(hwndText) + 1;

    if (!mbi)
        return;

    pMessageBoxText = (LPWSTR)RtlAllocateHeap(GetProcessHeap(), 0, (cchTitle + cchText) * sizeof(WCHAR));

    if (pMessageBoxText == NULL)
    {
        RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText);
        return;
    }

    pszTitle = pMessageBoxText;
    pszText = pMessageBoxText + cchTitle;

    if (GetWindowTextW(DialogWindow, pszTitle, cchTitle) == 0 ||
        GetWindowTextW(hwndText, pszText, cchText) == 0)
    {
        RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText);
        return;
    }

    /*
     * Calculate the total buffer size.
     */
    cchTotal = 6 + cchTitle + cchText + (lstrlenW(szLine) * 4) + (mbi->nButtons * MSGBOXEX_MAXBTNSTR + 3);

    hGlobal = GlobalAlloc(GHND, cchTotal * sizeof(WCHAR));

    pszBuffer = (LPWSTR)GlobalLock(hGlobal);

    if (pszBuffer == NULL)
    {
        RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText);
        GlobalFree(hGlobal);
        return;
    }

    /*
     * First format title and text.
     * ------------------
     * Title
     * ------------------
     * Text
     * ------------------
     */
    cchBuffer = wsprintfW(pszBuffer, L"%s%s\r\n%s%s\r\n%s", szLine, pszTitle, szLine, pszText, szLine);
    pszBufferPos = pszBuffer + cchBuffer;

    for (i = 0; i < mbi->nButtons; i++)
    {
        GetDlgItemTextW(DialogWindow, mbi->Btns[i], szButton, MSGBOXEX_MAXBTNSTR);

        cchButton = strlenW(szButton);
        pszButton = szButton;

        /* Skip '&' character. */
        if (szButton[0] == '&')
        {
            pszButton = pszButton + 1;
            cchButton = cchButton - 1;
        }

        for (n = 0; n < cchButton; n++)
            *(pszBufferPos++) = pszButton[n];

        /* Add spaces. */
        *(pszBufferPos++) = L' ';
        *(pszBufferPos++) = L' ';
        *(pszBufferPos++) = L' ';
    }

    wsprintfW(pszBufferPos, L"\r\n%s", szLine);

    GlobalUnlock(hGlobal);

    if (OpenClipboard(DialogWindow))
    {
        EmptyClipboard();
        SetClipboardData(CF_UNICODETEXT, hGlobal);
        CloseClipboard();
    }
    else
    {
        GlobalFree(hGlobal);
    }
    RtlFreeHeap(GetProcessHeap(), 0, pMessageBoxText);
}
Beispiel #8
0
/*
 * period: move and select the text in the next field to the right if
 *         the current field is not empty(l!=0), we are not in the
 *         left most position, and nothing is selected(startsel==endsel)
 *
 * spacebar: same behavior as period
 *
 * alpha characters: completely ignored
 *
 * digits: accepted when field text length < 2 ignored otherwise.
 *         when 3 numbers have been entered into the field the value
 *         of the field is checked, if the field value exceeds the
 *         maximum value and is changed the field remains the current
 *         field, otherwise focus moves to the field to the right
 *
 * tab: change focus from the current ipaddress control to the next
 *      control in the tab order
 *
 * right arrow: move to the field on the right to the left most
 *              position in that field if no text is selected,
 *              we are in the right most position in the field,
 *              we are not in the right most field
 *
 * left arrow: move to the field on the left to the right most
 *             position in that field if no text is selected,
 *             we are in the left most position in the current field
 *             and we are not in the left most field
 *
 * backspace: delete the character to the left of the cursor position,
 *            if none are present move to the field on the left if
 *            we are not in the left most field and delete the right
 *            most digit in that field while keeping the cursor
 *            on the right side of the field
 */
LRESULT CALLBACK
IPADDRESS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    HWND Self = GetPropW (hwnd, IP_SUBCLASS_PROP);
    IPADDRESS_INFO *infoPtr = (IPADDRESS_INFO *)GetWindowLongPtrW (Self, 0);
    CHAR c = (CHAR)wParam;
    INT index, len = 0, startsel, endsel;
    IPPART_INFO *part;

    TRACE("(hwnd=%p msg=0x%x wparam=0x%lx lparam=0x%lx)\n", hwnd, uMsg, wParam, lParam);

    if ( (index = IPADDRESS_GetPartIndex(infoPtr, hwnd)) < 0) return 0;
    part = &infoPtr->Part[index];

    if (uMsg == WM_CHAR || uMsg == WM_KEYDOWN) {
	len = GetWindowTextLengthW (hwnd);
	SendMessageW(hwnd, EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
    }
    switch (uMsg) {
 	case WM_CHAR:
 	    if(isdigit(c)) {
		if(len == 2 && startsel==endsel && endsel==len) {
		    /* process the digit press before we check the field */
		    int return_val = CallWindowProcW (part->OrigProc, hwnd, uMsg, wParam, lParam);

		    /* if the field value was changed stay at the current field */
		    if(!IPADDRESS_ConstrainField(infoPtr, index))
			IPADDRESS_GotoNextField (infoPtr, index, POS_DEFAULT);

		    return return_val;
		} else if (len == 3 && startsel==endsel && endsel==len)
		    IPADDRESS_GotoNextField (infoPtr, index, POS_SELALL);
		else if (len < 3 || startsel != endsel) break;
	    } else if(c == '.' || c == ' ') {
		if(len && startsel==endsel && startsel != 0) {
		    IPADDRESS_GotoNextField(infoPtr, index, POS_SELALL);
		}
 	    } else if (c == VK_BACK) break;
	    return 0;

	case WM_KEYDOWN:
	    switch(c) {
		case VK_RIGHT:
		    if(startsel==endsel && startsel==len) {
			IPADDRESS_GotoNextField(infoPtr, index, POS_LEFT);
			return 0;
		    }
		    break;
		case VK_LEFT:
		    if(startsel==0 && startsel==endsel && index > 0) {
			IPADDRESS_GotoNextField(infoPtr, index - 2, POS_RIGHT);
			return 0;
		    }
		    break;
		case VK_BACK:
		    if(startsel==endsel && startsel==0 && index > 0) {
			IPPART_INFO *prev = &infoPtr->Part[index-1];
			WCHAR val[10];

			if(GetWindowTextW(prev->EditHwnd, val, 5)) {
			    val[lstrlenW(val) - 1] = 0;
			    SetWindowTextW(prev->EditHwnd, val);
			}

			IPADDRESS_GotoNextField(infoPtr, index - 2, POS_RIGHT);
			return 0;
		    }
		    break;
	    }
	    break;
	case WM_KILLFOCUS:
	    if (IPADDRESS_GetPartIndex(infoPtr, (HWND)wParam) < 0)
		IPADDRESS_Notify(infoPtr, EN_KILLFOCUS);
	    break;
	case WM_SETFOCUS:
	    if (IPADDRESS_GetPartIndex(infoPtr, (HWND)wParam) < 0)
		IPADDRESS_Notify(infoPtr, EN_SETFOCUS);
	    break;
    }
    return CallWindowProcW (part->OrigProc, hwnd, uMsg, wParam, lParam);
}
Beispiel #9
0
BOOL
EditDefaultDacl(
    HWND    hwndOwner,
    HANDLE  Instance,
    HANDLE  MyToken
    )
{
    NTSTATUS Status;
    BOOL    Success = FALSE;
    DWORD   EditResult;
    HANDLE  Token = NULL;
    PTOKEN_DEFAULT_DACL DefaultDacl = NULL;
    PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
    PTOKEN_OWNER Owner = NULL;
    PTOKEN_PRIMARY_GROUP PrimaryGroup = NULL;
    WCHAR string[MAX_STRING_LENGTH];

    //
    // Get the window text so we can use it as the token name
    //

    GetWindowTextW(((PMYTOKEN)MyToken)->hwnd, string, sizeof(string)/sizeof(*string));


    //
    // Get a handle to the token
    //

    Token = OpenToken(MyToken, TOKEN_QUERY);

    if (Token == NULL) {
        DbgPrint("SECEDIT : Failed to open the token with TOKEN_QUERY access\n");
        goto CleanupAndExit;
    }


    //
    // Read the default DACL from the token
    //

    if (!GetTokenInfo(Token, TokenDefaultDacl, (PPVOID)&DefaultDacl)) {
        DbgPrint("SECEDIT : Failed to read default DACL from token\n");
        goto CleanupAndExit;
    }


    //
    // Get the owner and group of the token
    //

    if (!GetTokenInfo(Token, TokenOwner, (PPVOID)&Owner)) {
        DbgPrint("SECEDIT : Failed to read owner from token\n");
        goto CleanupAndExit;
    }

    if (!GetTokenInfo(Token, TokenPrimaryGroup, (PPVOID)&PrimaryGroup)) {
        DbgPrint("SECEDIT : Failed to read primary group from token\n");
        goto CleanupAndExit;
    }




    //
    // Create a security descriptor
    //

    SecurityDescriptor = Alloc(SECURITY_DESCRIPTOR_MIN_LENGTH);

    if (SecurityDescriptor == NULL) {
        DbgPrint("SECEDIT : Failed to allocate security descriptor\n");
        goto CleanupAndExit;
    }

    Status = RtlCreateSecurityDescriptor(SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
    ASSERT(NT_SUCCESS(Status));




    //
    // Set the DACL on the security descriptor
    //

    Status = RtlSetDaclSecurityDescriptor(
                        SecurityDescriptor,
                        TRUE,   // DACL present
                        DefaultDacl->DefaultDacl,
                        FALSE   // DACL defaulted
                        );
    ASSERT(NT_SUCCESS(Status));

    //
    // Put the owner and group in the security descriptor to keep the
    // ACL editor happy
    //

    Status = RtlSetOwnerSecurityDescriptor(
                        SecurityDescriptor,
                        Owner->Owner,
                        FALSE // Owner defaulted
                        );
    ASSERT(NT_SUCCESS(Status));


    Status = RtlSetGroupSecurityDescriptor(
                        SecurityDescriptor,
                        PrimaryGroup->PrimaryGroup,
                        FALSE // Owner defaulted
                        );
    ASSERT(NT_SUCCESS(Status));



    ASSERT(RtlValidSecurityDescriptor(SecurityDescriptor));

    //
    // Call the ACL editor, it will call our ApplySecurity function
    // to store any ACL changes in the token.
    //

    Success = EditTokenDefaultAcl(
                        hwndOwner,
                        Instance,
                        string,
                        MyToken,
                        SecurityDescriptor,
                        &EditResult
                        );
    if (!Success) {
        DbgPrint("SECEDIT: Failed to edit token DACL\n");
    }

CleanupAndExit:

    if (DefaultDacl != NULL) {
        FreeTokenInfo(DefaultDacl);
    }
    if (SecurityDescriptor != NULL) {
        FreeTokenInfo(SecurityDescriptor);
    }
    if (PrimaryGroup != NULL) {
        FreeTokenInfo(PrimaryGroup);
    }
    if (Owner != NULL) {
        FreeTokenInfo(Owner);
    }

    if (Token != NULL) {
        CloseToken(Token);
    }


    return(Success);
}
Beispiel #10
0
static BOOL CALLBACK
enum_cb(HWND hwnd, LPARAM lparam)
{
	RECT rect;
	unsigned short title[150];
	LONG styles;
	int state;
	HWND parent;
	DWORD pid;
	int flags;

	styles = GetWindowLong(hwnd, GWL_STYLE);

	if (!(styles & WS_VISIBLE))
		return TRUE;

	/* Since WH_CALLWNDPROC is not effective on cmd.exe, make sure
	   we ignore it during enumeration as well. Make sure to
	   remove this when cmd.exe support has been added, though. */
	char classname[32];
	if (GetClassName(hwnd, classname, sizeof(classname))
		&& !strcmp(classname, "ConsoleWindowClass"))
		return TRUE;

	if (styles & WS_POPUP)
		parent = (HWND) GetWindowLongPtr(hwnd, GWLP_HWNDPARENT);
	else
		parent = NULL;

	GetWindowThreadProcessId(hwnd, &pid);

	flags = 0;
	if (styles & DS_MODALFRAME)
		flags |= SEAMLESS_CREATE_MODAL;

	g_vchannel_write_fn("CREATE", "0x%08lx,0x%08lx,0x%08lx,0x%08x",
		hwnd_to_long(hwnd), (long) pid, hwnd_to_long(parent), flags);

	if (!GetWindowRect(hwnd, &rect)) {
		g_vchannel_debug_fn("GetWindowRect failed!");
		return TRUE;
	}

	g_vchannel_write_fn("POSITION", "0x%08lx,%d,%d,%d,%d,0x%08x",
		hwnd,
		rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);

	GetWindowTextW(hwnd, title, sizeof(title) / sizeof(*title));

	g_vchannel_write_fn("TITLE", "0x%08lx,%s,0x%x", hwnd_to_long(hwnd),
		g_vchannel_strfilter_unicode_fn(title), 0);

	if (styles & WS_MAXIMIZE)
		state = 2;
	else if (styles & WS_MINIMIZE)
		state = 1;
	else
		state = 0;

	g_vchannel_write_fn("STATE", "0x%08lx,0x%08x,0x%08x", hwnd, state, 0);

	return TRUE;
}
Beispiel #11
0
std::wstring Window::getTitle() const
{
	std::vector<wchar_t> buffer(GetWindowTextLengthW(m_HWnd));
	GetWindowTextW(m_HWnd, buffer.data(), buffer.size());
	return std::wstring(buffer.begin(), buffer.end());
}
Beispiel #12
0
int _tmain(int argc, _TCHAR* argv[])
{
	printf("*GetWindowInfo*\n");
	printf("You can monitoring the window inforamtion and its process inforamtion that pointed by your mouse cursor\n");
	printf("If you press any key, start monitoring.\n");
	WCHAR wchtemp;
	scanf_s("%c", &wchtemp);

	HMODULE hmodule = GetModuleHandle(L"ntdll.dll");
	if (NULL == hmodule) hmodule = LoadLibraryW(L"ntdll.dll");
	if (NULL == hmodule)
	{
		printf("ntdll load failed with %d", ::GetLastError());
		return -1;
	}

	NtQueryInformationProcess = (PFNtQueryInformationProcess)::GetProcAddress(hmodule, "NtQueryInformationProcess");
	POINT p = { 0, };
	HWND prevhwnd = NULL;
	HWND curhwnd = NULL;
	while (GetCursorPos(&p))
	{
		if ((curhwnd = WindowFromPoint(p)) != prevhwnd)
		{
			WCHAR wchClass[MAX_NAME_LENGTH];
			memset(wchClass, 0, MAX_NAME_LENGTH*sizeof(WCHAR));
			GetClassNameW(curhwnd, wchClass, MAX_NAME_LENGTH);

			WCHAR wchWindow[MAX_NAME_LENGTH];
			memset(wchWindow, 0, MAX_NAME_LENGTH*sizeof(WCHAR));
			GetWindowTextW(curhwnd, wchWindow, MAX_NAME_LENGTH);

			DWORD dwPid = 0;
			DWORD dwTid = 0;
			dwTid = GetWindowThreadProcessId(curhwnd, &dwPid);

			printf("===============================================================================\n");
			printf("GetCursorPos : p.x-%d, p.y-%d\n", p.x, p.y);
			printf("-------------------------------------------------------------------------------\n");
			printf("Window Information\n");
			printf("-------------------------------------------------------------------------------\n");
			printf("Current Hwnd : 0x%x\n", (DWORD)curhwnd);
			printf("ClssName : %ws\n", wchClass);
			printf("WindowTitle : %ws\n", wchWindow);
			printf("-------------------------------------------------------------------------------\n");
			printf("Process Information\n");
			printf("-------------------------------------------------------------------------------\n");
			printf("Pid : %d\n", dwPid);
			printf("Tid : %d\n", dwTid);

			WCHAR wchstr[MAX_COMMANDLINE_LENGTH];
			memset(wchstr, 0, MAX_COMMANDLINE_LENGTH* sizeof(WCHAR));
			if (GetCommandLine(dwPid, wchstr))
			{
				printf("CommandLine : %ws\n", wchstr);
			}
			prevhwnd = curhwnd;
			printf("===============================================================================\n");
			printf("\n\n");
		}
	}

	return 0;
}
Beispiel #13
0
void OnPaint(HWND hWnd)
{
    HDC dialogDC;
    PAINTSTRUCT paint;
    RECT cRC, textRC;
    int i, xPos, yPos, CharCount;
    HFONT dcFont;
    HICON hIcon;
    HPEN hPen;
    COLORREF Color;

    // check
    if (nCols == 0 || nItems == 0)
        return;

    // begin painting
    dialogDC = BeginPaint(hWnd, &paint);
    if (dialogDC == NULL)
        return;

    // fill the client area
    GetClientRect(hWnd, &cRC);
    FillRect(dialogDC, &cRC, (HBRUSH)(COLOR_3DFACE + 1));

    // if the selection index exceeded the display items, then
    // do display item shifting
    if (selectedWindow >= nItems)
        nShift = selectedWindow - nItems + 1;
    else
        nShift = 0;

    for (i = 0; i < nItems; ++i)
    {
        // get the icon to display
        hIcon = iconList[i + nShift];

        // calculate the position where we start drawing
        xPos = DIALOG_MARGIN + CX_ITEM_SPACE * (i % nCols) + ITEM_MARGIN;
        yPos = DIALOG_MARGIN + CY_ITEM_SPACE * (i / nCols) + ITEM_MARGIN;

        // centering
        if (nItems < CoolSwitchColumns)
        {
            xPos += (itemsW - nItems * CX_ITEM_SPACE) / 2;
        }

        // if this position is selected,
        if (selectedWindow == i + nShift)
        {
            // create a solid pen
            Color = GetSysColor(COLOR_HIGHLIGHT);
            hPen = CreatePen(PS_SOLID, 1, Color);

            // draw a rectangle with using the pen
            SelectObject(dialogDC, hPen);
            SelectObject(dialogDC, GetStockObject(NULL_BRUSH));
            Rectangle(dialogDC, xPos, yPos, xPos + CX_ITEM, yPos + CY_ITEM);
            Rectangle(dialogDC, xPos + 1, yPos + 1,
                                xPos + CX_ITEM - 1, yPos + CY_ITEM - 1);

            // delete the pen
            DeleteObject(hPen);
        }

        // draw icon
        DrawIconEx(dialogDC, xPos + ICON_MARGIN, yPos + ICON_MARGIN,
                   hIcon, CX_ICON, CY_ICON, 0, NULL, DI_NORMAL);
    }

    // set the text rectangle
    SetRect(&textRC, DIALOG_MARGIN, DIALOG_MARGIN + itemsH,
            totalW - DIALOG_MARGIN, totalH - DIALOG_MARGIN);

    // draw the sunken button around text
    DrawFrameControl(dialogDC, &textRC, DFC_BUTTON,
                     DFCS_BUTTONPUSH | DFCS_PUSHED);

    // get text
    CharCount = GetWindowTextW(windowList[selectedWindow], windowText,
                               _countof(windowText));

    // draw text
    dcFont = SelectObject(dialogDC, dialogFont);
    SetTextColor(dialogDC, GetSysColor(COLOR_BTNTEXT));
    SetBkMode(dialogDC, TRANSPARENT);
    DrawTextW(dialogDC, windowText, CharCount, &textRC,
              DT_CENTER | DT_VCENTER | DT_END_ELLIPSIS | DT_SINGLELINE);
    SelectObject(dialogDC, dcFont);

    // end painting
    EndPaint(hWnd, &paint);
}
Beispiel #14
0
/***********************************************************************
 *         WININET_PasswordDialog
 */
static INT_PTR WINAPI WININET_PasswordDialog(
    HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    HWND hitem;
    struct WININET_ErrorDlgParams *params;
    WCHAR szRealm[0x80], szServer[0x80];

    if( uMsg == WM_INITDIALOG )
    {
        TRACE("WM_INITDIALOG (%08lx)\n", lParam);

        /* save the parameter list */
        params = (struct WININET_ErrorDlgParams*) lParam;
        SetWindowLongPtrW( hdlg, GWLP_USERDATA, lParam );

        /* extract the Realm from the response and show it */
        if( WININET_GetAuthRealm( params->hRequest,
                                  szRealm, sizeof szRealm/sizeof(WCHAR), FALSE ) )
        {
            hitem = GetDlgItem( hdlg, IDC_REALM );
            SetWindowTextW( hitem, szRealm );
        }

        /* extract the name of the server */
        if( WININET_GetServer( params->hRequest,
                               szServer, sizeof szServer/sizeof(WCHAR)) )
        {
            hitem = GetDlgItem( hdlg, IDC_SERVER );
            SetWindowTextW( hitem, szServer );
        }

        WININET_GetSetPassword( hdlg, szServer, szRealm, FALSE );

        return TRUE;
    }

    params = (struct WININET_ErrorDlgParams*)
                 GetWindowLongPtrW( hdlg, GWLP_USERDATA );

    switch( uMsg )
    {
    case WM_COMMAND:
        if( wParam == IDOK )
        {
            WCHAR username[0x20], password[0x20];

            username[0] = 0;
            hitem = GetDlgItem( hdlg, IDC_USERNAME );
            if( hitem )
                GetWindowTextW( hitem, username, sizeof username/sizeof(WCHAR) );

            password[0] = 0;
            hitem = GetDlgItem( hdlg, IDC_PASSWORD );
            if( hitem )
                GetWindowTextW( hitem, password, sizeof password/sizeof(WCHAR) );

            hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD );
            if( hitem &&
                SendMessageW( hitem, BM_GETSTATE, 0, 0 ) &&
                WININET_GetAuthRealm( params->hRequest,
                                  szRealm, sizeof szRealm/sizeof(WCHAR), FALSE ) &&
                WININET_GetServer( params->hRequest,
                                   szServer, sizeof szServer/sizeof(WCHAR)) )
            {
                WININET_GetSetPassword( hdlg, szServer, szRealm, TRUE );
            }
            WININET_SetAuthorization( params->hRequest, username, password, FALSE );

            EndDialog( hdlg, ERROR_INTERNET_FORCE_RETRY );
            return TRUE;
        }
        if( wParam == IDCANCEL )
        {
            EndDialog( hdlg, 0 );
            return TRUE;
        }
        break;
    }
    return FALSE;
}
Beispiel #15
0
ZuiInt ZuiOsGetWindowTitle(ZuiOsWindow OsWindow, ZuiText out, ZuiInt outlen) {
	if (OsWindow) {
		return GetWindowTextW(OsWindow->hWnd, out, outlen);
	}
	return 0;
}
Beispiel #16
0
/***********************************************************************
 *         WININET_GetSetPassword
 */
static BOOL WININET_GetSetPassword( HWND hdlg, LPCWSTR szServer, 
                                    LPCWSTR szRealm, BOOL bSet )
{
    WCHAR szResource[0x80], szUserPass[0x40];
    LPWSTR p;
    HWND hUserItem, hPassItem;
    DWORD r, dwMagic = 19;
    UINT r_len, u_len;
    WORD sz;
    static const WCHAR szColon[] = { ':',0 };
    static const WCHAR szbs[] = { '/', 0 };

    hUserItem = GetDlgItem( hdlg, IDC_USERNAME );
    hPassItem = GetDlgItem( hdlg, IDC_PASSWORD );

    /* now try fetch the username and password */
    lstrcpyW( szResource, szServer);
    lstrcatW( szResource, szbs);
    lstrcatW( szResource, szRealm);

    /*
     * WNetCachePassword is only concerned with the length
     * of the data stored (which we tell it) and it does
     * not use strlen() internally so we can add WCHAR data
     * instead of ASCII data and get it back the same way.
     */
    if( bSet )
    {
        szUserPass[0] = 0;
        GetWindowTextW( hUserItem, szUserPass, 
                        (sizeof szUserPass-1)/sizeof(WCHAR) );
        lstrcatW(szUserPass, szColon);
        u_len = strlenW( szUserPass );
        GetWindowTextW( hPassItem, szUserPass+u_len, 
                        (sizeof szUserPass)/sizeof(WCHAR)-u_len );

        r_len = (strlenW( szResource ) + 1)*sizeof(WCHAR);
        u_len = (strlenW( szUserPass ) + 1)*sizeof(WCHAR);
        r = WNetCachePassword( (CHAR*)szResource, r_len,
                               (CHAR*)szUserPass, u_len, dwMagic, 0 );

        return ( r == WN_SUCCESS );
    }

    sz = sizeof szUserPass;
    r_len = (strlenW( szResource ) + 1)*sizeof(WCHAR);
    r = WNetGetCachedPassword( (CHAR*)szResource, r_len,
                               (CHAR*)szUserPass, &sz, dwMagic );
    if( r != WN_SUCCESS )
        return FALSE;

    p = strchrW( szUserPass, ':' );
    if( p )
    {
        *p = 0;
        SetWindowTextW( hUserItem, szUserPass );
        SetWindowTextW( hPassItem, p+1 );
    }

    return TRUE;
}
/**
 * name:	PaintThemeButton
 * desc:	Draws the themed button
 * param:	ctl			- BTNCTRL structure for the button
 *			hdcMem		- device context to draw to
 *			rcClient	- rectangle of the whole button
 * return:	nothing
 **/
static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient)
{
	RECT rcText = { 0, 0, 0, 0 };
	WCHAR wszText[MAX_PATH] = { 0 };
	WORD ccText;

	// Draw the flat button
	if ((ctl->dwStyle & MBS_FLAT) && ctl->hThemeToolbar) {
		int state = IsWindowEnabled(ctl->hwnd)
				? (ctl->stateId == PBS_NORMAL && ctl->defbutton 
					? PBS_DEFAULTED
					: ctl->stateId)
				: PBS_DISABLED;
		if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
			if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient)))
				DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient);
		}
		DrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rcClient, rcClient);
	}
	else {
		// draw themed button background
		if (ctl->hThemeButton) {
			int state = IsWindowEnabled(ctl->hwnd)
				? (ctl->stateId == PBS_NORMAL && ctl->defbutton 
					? PBS_DEFAULTED
					: ctl->stateId)
				: PBS_DISABLED;
			if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
				if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient)))
					DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient);
			}
			DrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, rcClient, rcClient);
		}
	}
	
	// calculate text rect
	{
		RECT	sizeText;
		HFONT	hOldFont;

		ccText = GetWindowTextW(ctl->hwnd, wszText, sizeof(wszText) / sizeof(WCHAR));

		if (ccText > 0) {
			hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
			
			GetThemeTextExtent(
				ctl->hThemeButton,
				hdcMem,
				BP_PUSHBUTTON,
				IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED,
				wszText,
				ccText,
				DST_PREFIXTEXT,
				NULL,
				&sizeText);
			
			if (ctl->cHot) {
				RECT rcHot;
				
				GetThemeTextExtent(ctl->hThemeButton,
					hdcMem,
					BP_PUSHBUTTON,
					IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED,
					L"&",
					1,
					DST_PREFIXTEXT,
					NULL,
					&rcHot);
				
				sizeText.right -= (rcHot.right - rcHot.left);
			}
			SelectObject(hdcMem, hOldFont);

			rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - (sizeText.right - sizeText.left)) / 2;
			rcText.top = (rcClient->bottom - rcClient->top - (sizeText.bottom - sizeText.top)) / 2;
			rcText.right = rcText.left + (sizeText.right - sizeText.left);
			rcText.bottom = rcText.top + (sizeText.bottom - sizeText.top);
			if (ctl->stateId == PBS_PRESSED) {
				OffsetRect(&rcText, 1, 1);
			}
		}
	}
	PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText);
	// draw text
	if (ccText > 0 && ctl->hThemeButton) { 
		HFONT hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont);
		DrawThemeText(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, wszText, ccText, DST_PREFIXTEXT, 0, &rcText);
		SelectObject(hdcMem, hOldFont);
	}
}