C++ (Qt)#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <windows.h>#include <QMainWindow> DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData ); namespace Ui {class MainWindow;} class MainWindow : public QMainWindow{ Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void pb(LARGE_INTEGER,LARGE_INTEGER); LPPROGRESS_ROUTINE progre; private slots:void on_pushButton_clicked(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
C++ (Qt)#include "mainwindow.h"#include "ui_mainwindow.h"#include <QMessageBox>#include <iostream>#include <cstring>//#include <winbase.h> using namespace std; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); ui->progressBar->setMaximum(100); // DWORD CALLBACK(*Test)(LARGE_INTEGER,LARGE_INTEGER,LARGE_INTEGER,LARGE_INTEGER,DWORD,DWORD,HANDLE,HANDLE,LPVOID); // Test=&MyCopyProgressRoutine; } MainWindow::~MainWindow(){ delete ui;} DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) {// switch(dwCallbackReason)// {// case CALLBACK_CHUNK_FINISHED://ui->progressBar->setValue((StreamSize.QuadPart*100)/TotalFileSize.QuadPart); //string w=QString("скопировано ").toStdString().data() MainWindow *s; s->pb(StreamSize,TotalFileSize); return PROGRESS_CONTINUE; //StreamSize. // } } void MainWindow::on_pushButton_clicked(){ LPCSTR q=QString("D:\\NBA 2K15\\1I").toLocal8Bit().data();// LARGE_INTEGER s(1);// LARGE_INTEGER q(2);// pb(1,2); LPCSTR a=QString("D:\\qw\\123").toLocal8Bit().data();LPVOID lpData;QApplication::processEvents(); CopyFileExA(q,a,(LPPROGRESS_ROUTINE)&MyCopyProgressRoutine,NULL,FALSE,COPY_FILE_FAIL_IF_EXISTS);// DWORD p=GetLastError(); // cout<<p<<endl;}void MainWindow::pb(LARGE_INTEGER StreamSize, LARGE_INTEGER TotalFileSize){ ui->progressBar->setValue((StreamSize.QuadPart*100)/TotalFileSize.QuadPart);}
C++ (Qt)MainWindow *s; s->pb(StreamSize,TotalFileSize);
C++ (Qt)ui->progressBar->setValue((StreamSize.QuadPart*100)/TotalFileSize.QuadPart);
C++ (Qt) static DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) { ui->progressBar->setValue((StreamSize.QuadPart*100)/TotalFileSize.QuadPart); cout<<(StreamSize.QuadPart*100)/TotalFileSize.QuadPart<<endl; return PROGRESS_CONTINUE; //StreamSize.}
C++ (Qt)ui->progressBar->setValue
C++ (Qt) static DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) { return PROGRESS_CONTINUE; }
C++ (Qt)void MainWindow::pb(LARGE_INTEGER StreamSize, LARGE_INTEGER TotalFileSize){ ui->progressBar->setValue((StreamSize.QuadPart*100)/TotalFileSize.QuadPart);}
C++ (Qt)#include <QDebug>.....void MainWindow::on_pushButton_clicked(){ static char q[] = "D:\\NBA 2K15\\1" ; //правильное имя файла static char a[] = "D:\\qw\\123"; //куда копировать CopyFileExA(q,a,(LPPROGRESS_ROUTINE)&MyCopyProgressRoutine,NULL,FALSE,COPY_FILE_FAIL_IF_EXISTS); }.....DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) { qDebug() << "progress:" << TotalBytesTransferred ; return PROGRESS_CONTINUE; //StreamSize.}
CONFIG+=console
C++ (Qt)DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) { qDebug() << "progress:" << TotalBytesTransferred.QuadPart ; return PROGRESS_CONTINUE; //StreamSize.} void MainWindow::on_pushButton_clicked(){ static char q[] = "D:\\game.dat" ; //правильное имя файла static char a[] = "D:\\qw\\123"; //куда копировать CopyFileExA(q,a,(LPPROGRESS_ROUTINE)&MyCopyProgressRoutine,NULL,FALSE,COPY_FILE_FAIL_IF_EXISTS);}
C++ (Qt)DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) { MainWindow s; s.pb(TotalBytesTransferred,TotalFileSize); qDebug() << "progress:" << TotalBytesTransferred.QuadPart ; return PROGRESS_CONTINUE; //StreamSize.} void MainWindow::pb(LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER TotalFileSize){ QApplication::processEvents(); ui->progressBar->setValue((TotalBytesTransferred.QuadPart*100)/TotalFileSize.QuadPart);}
C++ (Qt)//*.hppclass MainWindow : public QMainWindow{ Q_OBJECT static MainWindow* instance_;public: static MainWindow* instance() {return instance_;}public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); .....};........... // *.cpp MainWindow* MainWindow::instance_ = 0; ..... MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ instance_ = this; ui->setupUi(this); .......} void MainWindow::pb(LARGE_INTEGER StreamSize, LARGE_INTEGER TotalFileSize){ ui->progressBar->setValue((StreamSize.QuadPart*100)/TotalFileSize.QuadPart); qApp->processEvents();} DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) { qDebug() << "progress:" << TotalBytesTransferred ; MainWindow::instance()->pb(TotalBytesTransferred, TotalFileSize) return PROGRESS_CONTINUE; //StreamSize.}
C++ (Qt)#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <windows.h>#include <QMainWindow> static DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData ); namespace Ui {class MainWindow;} class MainWindow : public QMainWindow{ Q_OBJECT static MainWindow* instance_;public: static MainWindow* instance() { return instance_; } public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); LPPROGRESS_ROUTINE progre; private slots:void on_pushButton_clicked();public slots:void pb(LARGE_INTEGER,LARGE_INTEGER); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
C++ (Qt)#include "mainwindow.h"#include "ui_mainwindow.h"#include <QMessageBox>#include <iostream>#include <cstring>#include <QDebug>#include <commctrl.h>//#include <winbase.h> using namespace std; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ instance_ = this; ui->setupUi(this); ui->progressBar->setMaximum(100); ui->progressBar->setValue(3); } MainWindow::~MainWindow(){ delete ui;}void MainWindow::on_pushButton_clicked(){ char q[] = "D:\\Error.log" ; //правильное имя файла char a[] = "D:\\qw\\123"; //куда копировать CopyFileExA(q,a,(LPPROGRESS_ROUTINE)&MyCopyProgressRoutine,NULL,FALSE,COPY_FILE_FAIL_IF_EXISTS);}void MainWindow::pb(LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER TotalFileSize){ QApplication::processEvents(); // ui->progressBar->setValue((TotalBytesTransferred.QuadPart*100)/TotalFileSize.QuadPart); ui->progressBar->setValue(7);} DWORD CALLBACK MyCopyProgressRoutine( LARGE_INTEGER TotalFileSize, // размер файла в байтах LARGE_INTEGER TotalBytesTransferred, //байтов скопировано LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) { MainWindow::instance()->pb(TotalBytesTransferred, TotalFileSize); qDebug() << "progress:" << TotalBytesTransferred.QuadPart ; return PROGRESS_CONTINUE; //StreamSize.}
C++ (Qt)instance_ = this;
C++ (Qt)public: static MainWindow* instance() { return instance_; -- на эту строчкуD:\423423\copy\mainwindow.cpp:16: ошибка: undefined reference to `MainWindow::instance_' }
C++ (Qt)MainWindow* MainWindow::instance_ = 0;
C++ (Qt)MainWindow* MainWindow::instance_ = 0; instance_ = this; ui->setupUi(this);
C++ (Qt)#include "mainwindow.h"#include "ui_mainwindow.h"#include <QMessageBox>#include <iostream>#include <cstring>#include <QDebug>#include <commctrl.h>//#include <winbase.h> using namespace std; MainWindow* MainWindow::instance_ = 0; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ // MainWindow* MainWindow::instance_ = 0; instance_ = this; ui->setupUi(this); ui->progressBar->setMaximum(100); ui->progressBar->setValue(0);}