다운로드 dialog progress

운영자 | 기사입력 2005/05/16 [08:19]
>
필자의 다른기사 보기 인쇄하기 메일로 보내기 글자 크게 글자 작게
다운로드 dialog progress
 
운영자   기사입력  2005/05/16 [08:19]

=============================================================
#include<windows.h>
#include<wininet.h>
#include<commctrl.h>
#include "resource.h"
BOOL CALLBACK MainDlgProc(HWND hDlg,UINT Messages,WPARAM wParam,LPARAM lParam);
HINSTANCE g_hInst;
HWND  hDlogMain;
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstace,LPSTR lpszCmdParm,int nCmdShow) {
 g_hInst=hInstance;
 DialogBox(g_hInst,MAKEINTRESOURCE(IDD_DIALOG1),HWND_DESKTOP,MainDlgProc);
return 0;
}
BOOL bStopHttpDownLoad,bDownLoading=FALSE;
BOOL HTTPDown(HWND hWnd,char *URL,char *Path)
{
 HINTERNET hInternet,hURL;
 HANDLE hFile;
 DWORD Size;
 DWORD dwRead,dwWritten,Recv=0;
 char buf[500000];
    MSG  Message;
 int Pos=0;
   
  hInternet=InternetOpen("HTTPTEST",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
  if(hInternet==NULL) {
       return FALSE;
  }
   hURL=InternetOpenUrl(hInternet,URL,NULL,0,INTERNET_FLAG_RELOAD,0);
  if(hURL==NULL) {
   InternetCloseHandle(hInternet);
   return FALSE;
  }
  
     bStopHttpDownLoad=FALSE;
  bDownLoading=TRUE;
  hFile=CreateFile(Path,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  do{
   InternetQueryDataAvailable(hURL,&Size,0,0);
       InternetReadFile(hURL,buf,Size,&dwRead);
WriteFile(hFile,buf,dwRead,&dwWritten,NULL);
Recv +=dwWritten;
Pos +=3;
SendMessage(GetDlgItem(hWnd,IDC_PROGRESS1), PBM_SETPOS, Pos,0);
SendMessage(hWnd,WM_USER+10,0,(LPARAM)Recv);
 if(PeekMessage(&Message,NULL,0,0,PM_REMOVE)) {
      TranslateMessage(&Message);
   DispatchMessage(&Message);
}
if(bStopHttpDownLoad==TRUE)  {
 SendMessage(hWnd,WM_USER+12,0,(LPARAM)Recv);
       break;
}
     } while(dwRead !=0);
  InternetCloseHandle(hURL);
  InternetCloseHandle(hInternet);
  CloseHandle(hFile);
  bDownLoading=FALSE;
 
  if(bStopHttpDownLoad==FALSE) {
 SendMessage(hWnd,WM_USER+11,0,(LPARAM)Recv);
 
     
  }

return TRUE;
}
 

BOOL CALLBACK MainDlgProc(HWND hDlg,UINT Messages,WPARAM wParam,LPARAM lParam)
 {
  char szURL[MAX_PATH];
  char szLOCAL[MAX_PATH];
  char szTmp[100];
 // CProgressCtrl myCtrl;

  switch (Messages){
  case WM_INITDIALOG:
     SetDlgItemText(hDlg,IDC_URL,"http://iwav.co.kr/bbs/data/mpaper_linux/zipcode.sql");
     SetDlgItemText(hDlg,IDC_LOCAL,"C:\\aaa.sql");
  hDlogMain=hDlg;
 SendMessage(GetDlgItem(hDlg,IDC_PROGRESS1), PBM_SETRANGE, 0, MAKELONG(0, 100)); // 최소 최대값 0 - 100
 SendMessage(GetDlgItem(hDlg,IDC_PROGRESS1), PBM_SETPOS, 0, 0); // 초기 값 0

 
  return TRUE;
  case WM_COMMAND:
   switch (LOWORD(wParam)) {
   case IDOK:
    if(bDownLoading==FALSE)
     EndDialog(hDlogMain,0);
        return TRUE;
      case IDC_BTNDOWN:
    if(bDownLoading==FALSE) {
          GetDlgItemText(hDlg,IDC_URL,szURL,MAX_PATH);
    GetDlgItemText(hDlg,IDC_LOCAL,szLOCAL,MAX_PATH);
    if(HTTPDown(hDlg,szURL,szLOCAL)==FALSE) {
     MessageBox(hDlg,"다운 완료 ","완료OK ",MB_OK);
    }
    }
        
   case IDC_BTNCANCEL:
    MessageBox(hDlg,"다운 에러 ","에러 ",MB_OK);
        bStopHttpDownLoad=TRUE;
    return TRUE;
  
    case IDC_BUTTON1:
    MessageBox(hDlg,"시럼 ","에러 ",MB_OK);
   
   
       SetDlgItemText(hDlg,IDC_STATUS99,"aa");
       SetDlgItemText(hDlg,IDC_URL,"ㅁㅡㅡㅡㅡㅡㅡㅡㅡㅡ");
//         m_Progress.SetPos(m_nData);
 
  
   }
        return TRUE;
  case  WM_USER+10:
     wsprintf(szTmp,"%d 바이트를 받았습니다.",lParam);
        SetDlgItemText(hDlg,IDC_STATUS98,szTmp);
  
  return TRUE;
   case  WM_USER+11:
     SetDlgItemText(hDlg,IDC_STATUS,"다운완료");
  return TRUE;
   case  WM_USER+12:
     SetDlgItemText(hDlg,IDC_STATUS,"다운 취소");
  return TRUE;
 
  
 
  }
 
 

 return FALSE;
}
 
==============================================================
트위터 트위터 페이스북 페이스북 카카오톡 카카오톡
기사입력: 2005/05/16 [08:19]  최종편집: ⓒ iwav
 
 
많이 본 기사