#include "dlg.h" #ifdef WIN32 #include "resource.h" #include #endif #include #include #include "common.h" #ifdef WIN32 static BOOL CALLBACK StatusDialogFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { STATUSDIALOG *status = NULL; switch(message){ case WM_INITDIALOG: status = (STATUSDIALOG*)lParam; SetWindowLong(hwnd,GWL_USERDATA,(LONG)status); return 1; case WM_DESTROY: PostQuitMessage(0); return 1; case WM_COMMAND: switch(LOWORD(wParam)){ case IDCANCEL: /* EndDialog(hwnd,0); */ /* I cant to call callback how? */ /* DestroyWindow(hwnd);*/ status = (STATUSDIALOG*)GetWindowLong(hwnd,GWL_USERDATA); if(status!=NULL && status->callback !=NULL){ status->callback(status->callbackparam); } return 1; break; } break; } return 0; } static DWORD StatusDialogThread(LPVOID param) { MSG msg; STATUSDIALOG volatile *status = (STATUSDIALOG *)param; HWND hwnd; extern HINSTANCE _hInst; int ret; hwnd = CreateDialogParam(_hInst,MAKEINTRESOURCE(IDD_DIALOG_STATUS),status->hwnd_parent,StatusDialogFunc,(LPARAM)status); if(hwnd==NULL){return 0;} ret = ShowWindow(hwnd,SW_SHOW); ret = UpdateWindow(hwnd); status->hwnd = hwnd; while(GetMessage(&msg,status->hwnd,0,0)){ //if(status->hwnd == NULL){ TranslateMessage(&msg); DispatchMessage(&msg); //} } return 0; } #endif int StatusDialogPuts(STATUSDIALOG *status,char *str) { #ifdef WIN32 { char str1[1000],str2[1000]; /* set return code to "\r\n" */ Substitute(str1,str,"\r",""); Substitute(str2,str1,"\n","\r\n"); if(status==NULL){return 1;} if(status->hwnd == NULL){return 1;} SendDlgItemMessage(status->hwnd,MAKEINTRESOURCE(IDC_EDIT_STATUS),EM_REPLACESEL,1,(LPARAM)str2); if(status->cancelbutton){ return 0; }else{ return 1; } } #else return 1; #endif } int StatusDialogPrintf(STATUSDIALOG *status,const char *format,...) { #ifdef WIN32 va_list vp; char line[1000]; int ret; va_start(vp,format); ret = vsprintf(line,format,vp); va_end(vp); if(ret<0){return -1;} return StatusDialogPuts(status,line); #else return 1; #endif } STATUSDIALOG *OpenStatusDialog(HINSTANCE hInst,HWND hwnd_parent,int (CALLBACK *callback)(void *callbackparam),void *callbackparam) { #ifdef WIN32 /*HWND hwnd;*/ HANDLE hthread; STATUSDIALOG volatile *status; /*DWORD threadid;*/ /*HANDLE hevent;*/ if((status=malloc(sizeof(STATUSDIALOG)))==NULL) goto errorlabel; memset(status,0,sizeof(STATUSDIALOG)); /* status->hwnd_parent = hwnd_parent; */ status->hwnd_parent = NULL; /* I can't set parent window other than NULL,why?? */ status->callback = callback; status->callbackparam = callbackparam; /*ret = EnterCriticalSection(StatusDialogLock); hevent = CreateEvent(NULL,FALSE,FALSE,NULL); hthread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StatusDialogThread,status,0,&threadid); */ hthread = _beginthread(StatusDialogThread,0,status); while(status->hwnd ==NULL){ Sleep(0); } StatusDialogPuts(status,"FTP32.DLL is Executing...\r\n"); /*ret = WaitForSingleObject(hevent,INFINITE); ret = CloseHandle(hevent); ret = LeaveCriticalSection(StatusDialogLock); */ if(hthread==NULL)goto errorlabel; status->hthread = hthread; return status; errorlabel: CloseStatusDialog(status); return NULL; #else return NULL; #endif } int CloseStatusDialog(STATUSDIALOG *status) { #ifdef WIN32 if(status==NULL){return 0;} if(status->hwnd!=NULL){ SendMessage(status->hwnd,WM_DESTROY,0,0); /*DestroyWindow(status->hwnd);*/ status->hwnd = NULL; } if(status->hthread != 0){ WaitForSingleObject(status->hthread,INFINITE); status->hthread = 0; } free(status); return 0; #else return 0; #endif }