Dateidownload und Progressbar



  • Hi,

    ich habe das Problem, dass ich einen Dateidownload brauche, der in einem eigenen Thread abläuft, abbrechbar sein muss und zu dem ich auch noch eine Progressbar brauche 😉

    Also ihr kennt sicher alle diese Downloaddialoge die auch noch ne kleine Animation mit drin haben... Die haben alle Funktionen die ich brauche nur dass ich noch weiß wie ich das hinbekommen soll - die msdn hilft auch nich weiter aber da das bei fast allen Programmen gleich aussieht muss es doch irgendeinen Weg geben 😕

    Bitte helft mir - ist echt wichitg 🙄

    Vielen Dank schonmal für eure Überlegungen 🙂



  • da gab's hier schon irgendwo nen thread. das sollte wohlin irgendeiner dll liegen..

    Mit dem uploaden, bzw. downloaden kannste doch so machen, dass Du im message-switch auf die Buttons reagierst und im default nicht die DefWindowProc ausführst, sondern deine eigene, die den Upload macht..

    cYa
    DjR



  • mit dem code kanst du alle Animationen, Bilder, Icons und Cursors die in einer DLL gespeichert sind dir angucken bzw. abspielen...
    Der Code ist nicht optimiert, aber er funzt.
    Einfach in der Funktion DllSuchen () die DLL eingeben und los...

    #include <windows.h>
    #include <commctrl.h>
    #include <string.h>
    #include "resource.h"
    
    #define ID_BUTTON_OK        1
    #define ID_BUTTON_CLOSE     2
    #define ID_FUNKTION_ID      3
    #define ID_DLL_NAME         4
    #define ID_ANIMATION_WND    5
    
    #define BUTTON_BREITE       80
    #define BUTTON_HOHE         25
    #define FENSTER_BREITE      800
    #define FENSTER_HOHE        600
    #define MAX_ID              32000
    
    LRESULT CALLBACK    WndProc     (HWND, UINT, WPARAM, LPARAM) ;
    BOOL                Animation   (HWND, HWND, HWND) ;
    BOOL                DllSuchen   (HWND, HWND) ;
    
    NOTIFYICONDATA      nidTrayIcon ;
    TCHAR               szAppName[] = TEXT ("test") ;
    HMODULE             hAvi = NULL ;
    HBITMAP             hBitmap = NULL ;
    HICON               hIcon = NULL ;
    HCURSOR             hCursor = NULL ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow){
        HWND            hwnd ;
        MSG             msg ;
        WNDCLASSEX      wndclassex ;
        wndclassex.cbSize           = sizeof (WNDCLASSEX) ;
        wndclassex.style            = CS_HREDRAW | CS_VREDRAW ;
        wndclassex.lpfnWndProc      = WndProc ;
        wndclassex.cbClsExtra       = 0 ;
        wndclassex.cbWndExtra       = 0 ;
        wndclassex.hInstance        = hInstance ;
        wndclassex.hIcon            = LoadIcon (NULL, IDI_APPLICATION) ;
        wndclassex.hCursor          = LoadCursor (NULL, IDC_ARROW) ;
        wndclassex.hbrBackground    = (HBRUSH) (COLOR_BTNFACE + 1) ;
        wndclassex.lpszMenuName     = NULL ;
        wndclassex.lpszClassName    = szAppName ;
        wndclassex.hIconSm          = NULL ;
        RegisterClassEx (&wndclassex) ;
        hwnd = CreateWindowEx (NULL, szAppName, TEXT ("test"),
                                WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT, CW_USEDEFAULT,
                                FENSTER_BREITE , FENSTER_HOHE,
                                NULL, NULL, hInstance, NULL) ;
        ShowWindow (hwnd, iCmdShow) ;
        UpdateWindow (hwnd) ;
        while (GetMessage (&msg, NULL, 0, 0)){
            TranslateMessage (&msg) ;
            DispatchMessage (&msg) ;
        }
        return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
        static  HINSTANCE   hInstance ;
        HDC                 hdc ;
        PAINTSTRUCT         ps ;
        BITMAP              bm ;
        HDC                 hMemDC ;
        POINT               pt ;
        switch (message){
            case WM_CREATE :
                hInstance = ((LPCREATESTRUCT) lParam) -> hInstance ;
                CoInitialize (0) ;
                CreateWindowEx (NULL, "static",
                                TEXT ("keine"), WS_CHILD | WS_VISIBLE,
                                60, FENSTER_HOHE - 80,
                                300, 20,
                                hwnd, (HMENU) ID_DLL_NAME, hInstance, NULL) ;
                DllSuchen (hwnd, GetDlgItem (hwnd, ID_DLL_NAME)) ;
                CreateWindowEx (NULL, "button",
                                TEXT ("Weiter"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                600,
                                FENSTER_HOHE - (2 * BUTTON_HOHE) - 5,
                                BUTTON_BREITE, BUTTON_HOHE,
                                hwnd, (HMENU) ID_BUTTON_OK, hInstance, NULL) ;
                CreateWindowEx (NULL, "button",
                                TEXT ("Ende"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                605 + BUTTON_BREITE,
                                FENSTER_HOHE - (2 * BUTTON_HOHE) - 5,
                                BUTTON_BREITE, BUTTON_HOHE,
                                hwnd, (HMENU) ID_BUTTON_CLOSE, hInstance, NULL) ;
                CreateWindowEx (0, ANIMATE_CLASS,
                                NULL, WS_CHILD | WS_VISIBLE |
                                ACS_TRANSPARENT | ACS_CENTER,
                                0, 0,
                                300, 60,
                                hwnd, (HMENU) ID_ANIMATION_WND, hInstance, NULL) ;          
                CreateWindowEx (NULL, "static",
                                TEXT ("FunktionID"), WS_CHILD | WS_VISIBLE,
                                5, FENSTER_HOHE - 50,
                                80, 20,
                                hwnd, NULL, hInstance, NULL) ;
                CreateWindowEx (NULL, "static",
                                TEXT ("keine"), WS_CHILD | WS_VISIBLE,
                                95, FENSTER_HOHE - 50,
                                50, 20,
                                hwnd, (HMENU) ID_FUNKTION_ID, hInstance, NULL) ;
                CreateWindowEx (NULL, "static",
                                TEXT ("DLL :"), WS_CHILD | WS_VISIBLE,
                                5, FENSTER_HOHE - 80,
                                50, 20,
                                hwnd, NULL, hInstance, NULL) ;          
                return 0 ;
            case WM_MOUSEMOVE :
                if (hCursor){
                    SetCursor (hCursor) ;
                }
                return 0 ;
            case WM_PAINT :
                hdc = BeginPaint (hwnd, &ps) ;
                if (hBitmap){
                    hMemDC = CreateCompatibleDC (hdc) ;
                    SelectObject (hMemDC, hBitmap) ;
                    GetObject (hBitmap, sizeof (BITMAP), &bm) ;
                    pt.x = bm.bmWidth ;
                    pt.y = bm.bmHeight ;
                    BitBlt (hdc, 50, 300, pt.x, pt.y, hMemDC, 0, 0, SRCCOPY) ;
                    DeleteDC (hMemDC) ;
                    DeleteObject (hBitmap) ;
                }
                else if (hIcon){
                    DrawIcon (hdc, 50, 300, hIcon) ;
                    DeleteObject (hIcon) ;
                }
                else if (hCursor){
                    DrawIcon (hdc, 50, 300, (HICON) hCursor) ;
                    DeleteObject (hCursor) ;
                }
                EndPaint (hwnd, &ps) ;
                return 0 ;
            case WM_COMMAND :
                switch (LOWORD (wParam)){
                    case ID_BUTTON_OK :
                        InvalidateRect (hwnd, NULL, TRUE) ;
                        Animation (hwnd, GetDlgItem (hwnd, ID_ANIMATION_WND), GetDlgItem (hwnd, ID_FUNKTION_ID)) ;
                        break ;
                    case ID_BUTTON_CLOSE :
                        SendMessage (hwnd, WM_DESTROY, 0, 0) ;
                        FreeLibrary (hAvi) ;
                        break ;
                }
                return 0 ;
            case WM_DESTROY :
                PostQuitMessage (0) ;
                return 0 ;
        }
        return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    
    BOOL DllSuchen (HWND hParent, HWND hNameDll){
        TCHAR           szDllName[MAX_PATH] = "C:\\WINDOWS\\system32\\Shell32.dll" ;
        if  ((hAvi = LoadLibrary ((LPTSTR) szDllName)) == NULL){
            MessageBox (hParent, (LPTSTR) szDllName, "Fehler", MB_ICONERROR) ;
            return FALSE ;
        }
        SetWindowText (hNameDll, (LPTSTR) szDllName) ;
        return TRUE ;
    }
    
    BOOL Animation (HWND hParent, HWND AniHwnd, HWND hAnzeige){
        static  long    iZahl = 0 ;
        char            szAnzeige[6] ;
        wsprintf (szAnzeige, "%d", iZahl) ;
        SetWindowText (hAnzeige, szAnzeige) ;
        while (iZahl < MAX_ID){
            wsprintf (szAnzeige, "%d", iZahl) ;
            SetWindowText (hAnzeige, szAnzeige) ;
            if (SendMessage (AniHwnd, ACM_OPEN, (WPARAM) hAvi, (LPARAM)iZahl) != NULL){
                hBitmap = NULL ;
                hIcon = NULL ;
                hCursor = NULL ;
                InvalidateRect (hParent, NULL, TRUE) ;
                SendMessage (AniHwnd, ACM_PLAY, (WPARAM) -1, MAKELONG(0,-1)) ;
                iZahl++ ;
                break ;
            }
            else if ((hBitmap = LoadBitmap (hAvi, MAKEINTRESOURCE (iZahl))) != NULL){
                    hIcon = NULL ;
                    hCursor = NULL ;
                    InvalidateRect (hParent, NULL, TRUE) ;
                    iZahl++ ;
                    break ;
            }
            else if ((hIcon = LoadIcon (hAvi, MAKEINTRESOURCE (iZahl))) != NULL){
                    hBitmap = NULL ;
                    hCursor = NULL ;
                    InvalidateRect (hParent, NULL, TRUE) ;
                    iZahl++ ;
                    break ;
            }
            else if ((hCursor = LoadCursor (hAvi, MAKEINTRESOURCE (iZahl))) != NULL){
                    hBitmap = NULL ;
                    hIcon = NULL ;
                    InvalidateRect (hParent, NULL, TRUE) ;
                    iZahl++ ;
                    break ;
            }
            iZahl++ ;       
        }
        if (iZahl == MAX_ID){
            iZahl = 0 ;
            return FALSE ;
        }
        return TRUE ;
    }
    

    sorry für die Unordnung, aber der code ist auf die Schnelle geschrieben...



  • Hi,

    danke für eure Mühe! Habe das Problem jetzt anders gelöst auch URLDownloadToFile() unterstützt Progress - dachte erst so wie es in der Huilfe steht das würde nur unter win nt gehen funktioniert aber...

    mfg Slater



  • no such file or directory

    #include "resource.h"



  • sorry, #include "resource.h" muss natürlich weg.



  • Das sollte auch helfen....

    'Dieser Source stammt von http://www.activevb.de 
    'und kann frei verwendet werden. Für eventuelle Schäden
    'wird nicht gehaftet.
    
    'Um Fehler oder Fragen zu klären, nutzen Sie bitte unser Forum.
    'Ansonsten viel Spaß und Erfolg mit diesem Source!
    
    '------------- Anfang Projektdatei PROJECT1.VBP -------------
    '--------- Anfang Formular "Form1" alias Form1.frm  ---------
    
    Option Explicit
    
    Private Declare Function DoFileDownload Lib "shdocvw.dll" _
            (ByVal lpszFile As String) As Long
    
    Private Sub Command1_Click()
      Dim Result&, URL$
        URL = StrConv(Text1.Text, vbUnicode)
        Call DoFileDownload(URL)
    End Sub
    '---------- Ende Formular "Form1" alias Form1.frm  ----------
    '-------------- Ende Projektdatei PROJECT1.VBP --------------
    

    Zwar VB aber egal... 😃

    cu para
    😃


Anmelden zum Antworten