在对数据库整理时,如何显示进度?

解决方案 »

  1.   

    好哇,做个假的也行,不过,我用TIMER和线程,都不能动态显示,如果能每隔2秒,动一下就好了。
    大家看看有没有办法?
      

  2.   

    http://expert.csdn.net/Expert/topic/1883/1883221.xml?temp=6.893557E-02
    还有一个是网友问得,不过没有时间看,你可以看看,也许有启发
    http://expert.csdn.net/Expert/topic/1897/1897353.xml?temp=8.831203E-03
      

  3.   

    有多少 记录就高MAX为多少, 整理一条加1
      

  4.   

    cow8063(吴七郎) 所言有理,但我是打了一条SQL进去。
      

  5.   

    我先用那个假的应付过去了。。真的到现在也没有搞出来。。我很奇怪。
    方法一:
    我引入了sqldmo.dll,
    生成sqldmo_Tlb.pas编译,安装成控件形式,
    用TBackUp控件,
    就有了OnPercentComplete事件,
    但备份会出错,备份能成功,但总是报地址错,方法二:
    用CreateOleObject方法此方法无论如何不能给控件加上OnPercentComplete事件
    看了MSDN中的源码,VB的源码非常简单,只是一句With Event就OK了。
    VC的看不太懂,引入了EventSink,
    我看了sqldmo_Tlb.pas,里面有BackupSink接口,
    但不知如何用。。慢慢研究吧,总会有解决的一天。
      

  6.   

    这是VC++的例子。#define STRICT // strict type checking
    #define WIN32_LEAN_AND_MEAN // do not include the world
    #define INC_OLE2 // include OLE/COM files
    #define UNICODE
    #define _UNICODE#include <windows.h>
    #include <initguid.h>
    #include <tchar.h>
    #include "C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\include\sqldmoid.h"
    #include "C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\include\sqldmo.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <olectl.h>#include "backupdb.h"// **********************************************************************
    // function declarations
    // **********************************************************************
    int DisplayError();STDMETHODIMP CMyBackupSink::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
    {
    if (riid == IID_IUnknown || riid == IID_ISQLDMOBackupSink) 
    {
    AddRef();
    *ppvObj = this;
    return NOERROR;
    }
    return E_NOINTERFACE;
    }// Backup Sink Methords.
    //
    STDMETHODIMP CMyBackupSink::Complete(THIS_ SQLDMO_LPCSTR Message)
    {
    // Backup object calls us when backup is completed.
    //
    printf("Backup Completed\n");

    return NOERROR;
    }STDMETHODIMP CMyBackupSink::PercentComplete(THIS_ SQLDMO_LPCSTR Message, long Percent)
    {
    // Backup object calls us with new percent complete.
    //
    printf("%ld%s Completed\n", Percent,"%");

    return NOERROR;
    }STDMETHODIMP CMyBackupSink::NextMedia(THIS_ SQLDMO_LPCSTR Message)
    {
    // Backup object calls us when it's ready for next volume.
    //
    printf("Next Volume Message: %s \n", Message);
    return NOERROR;
    }// **********************************************************************
    // main()
    // **********************************************************************
    int main(void)
    {
    HRESULT hr;
    if FAILED(hr = CoInitialize (NULL))
    {
    _tprintf(TEXT("CoInitialize Failed\n"));
    return (0);
    } LPSQLDMOSERVER pSQLServer = NULL; if FAILED(hr = CoCreateInstance(
    CLSID_SQLDMOServer, 
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_ISQLDMOServer, 
    (LPVOID*)&pSQLServer))
    {
    _tprintf(TEXT("CoCreateInstance Failed\n"));
    return (0);
    } pSQLServer->SetLoginTimeout(10);
    pSQLServer->SetLoginSecure(TRUE); if FAILED(hr = pSQLServer->Connect(TEXT(""),TEXT("sa"),TEXT("")))
    {
    return DisplayError();
    } LPSQLDMOBACKUP pSQLBackup = NULL; if FAILED(hr = CoCreateInstance(
    CLSID_SQLDMOBackup, 
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_ISQLDMOBackup, 
    (LPVOID*)&pSQLBackup))
    {
    _tprintf(TEXT("CoCreateInstance Failed\n"));
    return (0);
    } LPCONNECTIONPOINTCONTAINER pMyConnectionPointContainer;
    LPCONNECTIONPOINT pMyConnectionPoint;    CMyBackupSink* pMyBackupSink = new CMyBackupSink();
    pMyBackupSink->AddRef();

    if (!pMyBackupSink)
    {
    return(0);
    } DWORD dwCookie; // ask the connectable object (pSQLBackup) about its outgoing interface,
    // by using QI on IID_IConnectionPointContainer. If fails, this object
    // does not support outgoing interface
    //
    if FAILED(pSQLBackup->QueryInterface(
    IID_IConnectionPointContainer,
    (LPVOID FAR*) &pMyConnectionPointContainer))
    {
    return DisplayError();
    } // find the specific outgoing interface IID_ISQLDMOBackupSink and retrieve
    // a pointer to the connectionpoint object. If fails, the object does not
    // support this outgoing interface
    //
    if FAILED(pMyConnectionPointContainer->FindConnectionPoint(
    IID_ISQLDMOBackupSink, 
    (LPCONNECTIONPOINT FAR*)&pMyConnectionPoint))
    {
    return DisplayError();
    } // establish the connection between the Sink and the ConnectionPoint object.
    // Retrieve a key (cookie) value for terminating the connection later. If
    // this fails, the Sink and ConnectionPoint object do not support the same interface
    //
    if (S_OK != (hr = pMyConnectionPoint->Advise((LPUNKNOWN)pMyBackupSink, &dwCookie)))
    {
    return DisplayError();
    } if FAILED(hr = pSQLBackup->SetFiles(TEXT("c:\\test.dmp") ))
    {
    return DisplayError();
    } if FAILED(hr = pSQLBackup->SetDatabase(TEXT("pubs") ))
    {
    return DisplayError();
    } printf("Backup Start\n");
    if FAILED(hr = pSQLBackup->SQLBackup(pSQLServer))
    {
    return DisplayError();
    } // terminate the connection using the same connection key
    //
    pMyConnectionPoint->Unadvise(dwCookie);
    pMyConnectionPoint->Release ();
    pMyConnectionPointContainer->Release ();
    pSQLBackup->Release ();
    pSQLServer->Release (); CoUninitialize ();
    return (0);
    }// **********************************************************************
    // display error information
    // **********************************************************************
    int DisplayError()
    {
    LPERRORINFO pErrorInfo = NULL;
    BSTR strDescription, strSource; GetErrorInfo(0,&pErrorInfo); pErrorInfo->GetDescription (&strDescription);
    pErrorInfo->GetSource(&strSource); _tprintf(TEXT("%s\n"),strDescription);
    _tprintf(TEXT("%s\n"),strSource); pErrorInfo->Release();

    SysFreeString(strDescription);
    SysFreeString(strSource);

    return(0);
    }
      

  7.   

    还有一个是Delphi的。
    不过是在WebBrosers中加事件。
    这可是在大富翁上花1000分才买到的答案。希望对你有所帮助。
    我看了一下,还是不太懂,呵呵。。如下:
    》》》》》》》这个可能比较麻烦了
    http://www.delphibbs.com/delphibbs/dispq.asp?lid=1142842
    不好办!在Delphi中还没有想到办法!
    MSDN中有VB的例子,用WithEvents声明一个对象就行了
    简单得让人难以想象,可我和大家一样,都不喜欢用vb,微软真是TMD坏透了!  
    来自:manfeel, 时间:2002-6-8 1:20:00, ID:1150181
    黑干两天两夜,终于被我编出来了!// --------------------------------------------------------------- 
    // 在WebBrowser中得到当前鼠标下图片和对象的链接                    
    // Get the element's url under the mouse pointer in WebBrowser     
    // Copyright (c) 2002 Powered by Manfeel                           
    // Manfeel保留版权,转载请保留作者信息!                           
    //                                            [email protected] 
    // --------------------------------------------------------------- unit main;interfaceuses
     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
     OleCtrls, SHDocVw, MSHTML, ActiveX, ComObj, ExtCtrls, StdCtrls;type
     TForm1 = class(TForm)
       Panel1: TPanel;
       Splitter1: TSplitter;
       Panel2: TPanel;
       WebBrowser1: TWebBrowser;
       Memo1: TMemo;
       PanelTop: TPanel;
       Edit1: TEdit;
       procedure FormActivate(Sender: TObject);
       procedure WebBrowser1DocumentComplete(Sender: TObject;
         const pDisp: IDispatch; var URL: OleVariant);
       procedure Edit1KeyDown(Sender: TObject; var Key: Word;
         Shift: TShiftState);
       procedure FormShow(Sender: TObject);
       procedure FormDestroy(Sender: TObject);
     private
       { Private declarations }
     public
       { Public declarations }
     end; TEventSink = class(TObject, IUnknown, IDispatch)
     private
       FRefCount:Longint;
       FControl:TControl;
     protected
       { IUnknown }
       function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
       function _AddRef: Integer; stdcall;
       function _Release: Integer; stdcall;
       { IDispatch }
       function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
       function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
       function GetIDsOfNames(const IID: TGUID; Names: Pointer;
         NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
       function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
         Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
       property Control:TControl read FControl;      
     public
       constructor Create(Control: TControl);
     end;const
     IID_IConnectionPointContainer: TGUID = '{B196B284-BAB4-101A-B69C-00AA00341D07}';
     DISPID_HTMLElement_ONMouseOver  = -2147418104 ;  
    var
     Form1: TForm1;
     CPC:IConnectionPointContainer;
     CP:IConnectionPoint;
     Cookie:Integer;
     EventSink:TEventSink;
    implementation{$R *.DFM}
    constructor TEventSink.Create(Control: TControl);
    begin
     FControl := Control;
    end;function TEventSink.QueryInterface(const IID: TGUID; out Obj): HResult;
    begin
     if GetInterface(IID, Obj) then
       Result := S_OK
     else
       Result := E_NOINTERFACE;
    end;function TEventSink._AddRef: Integer;
    begin
     Inc(FRefCount);
     Result := FRefCount;
    end;function TEventSink._Release: Integer;
    begin
     Dec(FRefCount);
     Result := FRefCount;
    end;{ TEventSink.IDispatch }function TEventSink.GetTypeInfoCount(out Count: Integer): HResult;
    begin
     Count := 0;
     Result := S_OK;
    end;function TEventSink.GetTypeInfo(Index, LocaleID: Integer;
     out TypeInfo): HResult;
    begin
     Pointer(TypeInfo) := nil;
     Result := E_NOTIMPL;
    end;function TEventSink.GetIDsOfNames(const IID: TGUID; Names: Pointer;
     NameCount, LocaleID: Integer; DispIDs: Pointer): HResult;
    begin
     Result := E_NOTIMPL;
    end;
    function TEventSink.Invoke(DispID: integer; const IID: TGUID; LocaleID: Integer;
       Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
    var
     WB:IHTMLDocument2;
     Anchor:IHTMLElement;
    begin
     if (DispID = DISPID_HTMLElement_ONMouseOver) then
     begin
       WB:=(FControl as TForm1).WebBrowser1.Document as IHTMLDocument2;
       Anchor:=WB.parentWindow.event.srcElement;
       if (Anchor.tagName='A') then
       begin
         (Fcontrol as TForm1).Memo1.lines.Add((Anchor as IHTMLAnchorElement).href);
       end;
       if (Anchor.parentElement.tagName='A') then
       begin
         (Fcontrol as TForm1).Memo1.lines.Add((Anchor.parentElement as IHTMLAnchorElement).href);
       end;
     end;
     Result := S_OK;
    end;
    procedure TForm1.FormActivate(Sender: TObject);
    begin
     WebBrowser1.Navigate('about:blank');
    end;procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
     const pDisp: IDispatch; var URL: OleVariant);
    var
     Doc:IHTMLDocument2;
    begin
     Doc:=WebBrowser1.Document as IHTMLDocument2;
     OleCheck(Doc.QueryInterface(IID_IConnectionPointContainer, CPC));
     OleCheck(CPC.FindConnectionPoint(DIID_HTMLDocumentEvents2,CP));
     EventSink:= TEventSink.Create(Self);
     OleCheck(CP.Advise(IUnKnown(EventSink),Cookie));
    end;procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
     Shift: TShiftState);
    begin
     if Key = VK_RETURN then WeBbrowser1.Navigate(Edit1.text);
    end;procedure TForm1.FormShow(Sender: TObject);
    begin
     Edit1.Align := alClient;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
     CP.Unadvise(Cookie);
    end;end.