|
In OnSize , I wrote like:
m_btn.MoveWindow(&rc,TRUE);
...
Invalidate();
|
|
|
|
|
followait wrote: Invalidate();
Try RedrawWindow() specifying the RDW_ALLCHILDREN flag.
|
|
|
|
|
|
Hi all,
I am making this pauseresume downloader http version:
hOpen = InternetOpen("PauseResumeDemo",INTERNET_OPEN_TYPE_PRECONFIG ,NULL, NULL, NULL);
if(!hOpen)
{
return false;
}
DWORD dwContext = 123;
strStaus.Format("Connecting to server..");
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);
if ( !(hConnect = InternetConnect ( hOpen, "10.5.1.4/downloads/managepoint" , INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0 , 0) ) )
{
CString strMsg;
string strReposeFromServer;
GetLastResponse(strReposeFromServer);
strMsg.Format("Error:%d\nDescription:%s", GetLastError(), strReposeFromServer.c_str());
AfxMessageBox(strMsg, MB_OK);
return false;
}
strStaus.Format("Finding out if this server supoprts Pause & Resume..");
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);
now this works fine up to this point
LPCTSTR lpszVerb = "GET";
LPCTSTR lpszObjectName = "/";
LPCTSTR lpszVersion = NULL;
LPCTSTR lpszReferrer = NULL;
LPCTSTR *lplpszAcceptTypes = NULL;
DWORD dwOpenRequestFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP |
INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS |
INTERNET_FLAG_KEEP_CONNECTION |
INTERNET_FLAG_NO_AUTH |
INTERNET_FLAG_NO_AUTO_REDIRECT |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_RELOAD;
DWORD dwOpenRequestContext = 0;
HINTERNET hRequest = HttpOpenRequest(hConnect, lpszVerb, lpszObjectName, lpszVersion,
lpszReferrer, lplpszAcceptTypes,
dwOpenRequestFlags, dwOpenRequestContext);
sendReq = HttpSendRequest(hRequest, NULL, 0, NULL, 0);
HttpSendRequest returns falls however if i change the url to just 10.5.1.4 it returns true however the file that should be downloaded isnt there.
What can i do and what should i do after?
Thanks
Jayjay
|
|
|
|
|
monsieur_jj wrote: What can i do and what should i do after?
HttpSendRequest will set an error that is accessable via GetLastError[^]. You can add something like this to get an error description:
DWORD dwErr = GetLastError();
LPTSTR lpMsgBuf = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,dwErr,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL);
TRACE(_T("ERROR: %s\n"),lpMsgBuf);
LocalFree(lpMsgBuf);
Note that you must place the code immediately following the call to HttpSendRequest().
Best Wishes,
-David Delaune
|
|
|
|
|
David,
Actually there is no error it just returns false.
Thanks
|
|
|
|
|
monsieur_jj wrote: Actually there is no error it just returns false.
Strange.
The only other thing that stands out to me is the line:
LPCTSTR *lplpszAcceptTypes = NULL;
I am not sure if NULL is compliant with the W3C [^]standards. Try changing it to
Accept: text
or
Accept: *
If I am incorrect and NULL is a valid header value then I can only recommend taking a look at the MFC sample code TEAR[^] provided by Microsoft. I have successfully modified and used that sample in projects in the past.
Best Wishes,
-David Delaune
|
|
|
|
|
This is my new code, I believe the code finally locates the zip file however the download is incomplete and i cant open the zip file. The zip file should be around 500mb i only get 2kb.
<br />
hOpen = InternetOpen("PauseResumeDemo",INTERNET_OPEN_TYPE_PRECONFIG ,NULL, NULL, NULL);<br />
if(!hOpen)<br />
{<br />
return false;<br />
}<br />
<br />
DWORD dwContext = 123;<br />
<br />
strStaus.Format("Connecting to server..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
<br />
if ( !(hConnect = InternetConnect ( hOpen, "10.5.1.4" , INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0 , 0) ) )<br />
{<br />
CString strMsg;<br />
string strReposeFromServer;<br />
GetLastResponse(strReposeFromServer);<br />
strMsg.Format("Error:%d\nDescription:%s", GetLastError(), strReposeFromServer.c_str());<br />
AfxMessageBox(strMsg, MB_OK);<br />
return false;<br />
}<br />
<br />
strStaus.Format("Finding out if this server supoprts Pause & Resume..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
<br />
hHttpRequest = HttpOpenRequest( hConnect, "GET", "downloads/", NULL, NULL, NULL, 0, 0);<br />
hHttpRequest = HttpOpenRequest( hConnect, "GET", "Managepoint/", NULL, NULL, NULL, 0, 0);<br />
hHttpRequest = HttpOpenRequest( hConnect, "GET", strFileNameAtServer.c_str(), NULL, NULL, NULL, 0, 0);<br />
<br />
if(FindPauseResumeSupported(hHttpRequest))<br />
{<br />
strStaus.Format("Pause & Resume Supported..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
}<br />
else<br />
{<br />
strStaus.Format("Pause & Resume not Supported..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
}<br />
<br />
<br />
double dCurrentFileSize;<br />
<br />
if(IfLocalFileExist(strTmpFileName.c_str(), &dCurrentFileSize)) <br />
{<br />
dOffsetToSeek = dCurrentFileSize;<br />
}<br />
<br />
<br />
if ( !(pFile = fopen (strTmpFileName.c_str(), "ab" ) ) )<br />
{<br />
CString strMsg;<br />
strMsg.Format("Error:%d", GetLastError());<br />
AfxMessageBox(strMsg, MB_OK); <br />
return false;<br />
}<br />
<br />
if(dOffsetToSeek >=0)<br />
{<br />
strStaus.Format("Seeking to local file...");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
<br />
int n = fseek(pFile, dOffsetToSeek, SEEK_SET);<br />
}<br />
<br />
<br />
dwBytesWrrittenToFile = dOffsetToSeek;<br />
GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);<br />
<br />
do<br />
{<br />
PUMPMESSAGE();<br />
<br />
Sleep(100);<br />
<br />
strStaus.Format("Sending RETRIVE..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
<br />
if(m_bStopped)<br />
{<br />
strStaus.Format("Stopped..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
<br />
AfxMessageBox("Download aborted\nThere is an incomplete temp file 'Temp_ManagePoint431InstallerBuild_47.zip' at current directory. Don't delete it just check it out. It has useful data downloaded so far...\nOnce you are done click Start again, now download will start from exact location where it left off");<br />
<br />
m_bStopped = FALSE;<br />
bInComplete = TRUE;<br />
GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);<br />
GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);<br />
break;<br />
}<br />
<br />
if (!InternetReadFile (hHttpRequest, (LPVOID)pBuffer, dwToRead, &dwSize) )<br />
{<br />
fclose (pFile);<br />
CString strMsg;<br />
string strReposeFromServer;<br />
GetLastResponse(strReposeFromServer);<br />
strMsg.Format("Error:%d\nDescription:%s", GetLastError(), strReposeFromServer.c_str());<br />
AfxMessageBox(strMsg, MB_OK); <br />
return false;<br />
}<br />
if (!dwSize)<br />
{<br />
m_ProgressCtl.SetPos(100);<br />
CString strTmpPercentage;<br />
strTmpPercentage.Format("Percentage Completed:%d%%", 100);<br />
GetDlgItem(IDC_STATIC_PERCENTAGE)->SetWindowText(strTmpPercentage);<br />
break;
}<br />
else<br />
{<br />
fwrite(pBuffer, sizeof (char), dwSize , pFile);<br />
<br />
dwBytesWrrittenToFile = dwBytesWrrittenToFile + dwSize;<br />
<br />
int nPercentageComplete = (int)floor(((dwBytesWrrittenToFile) * 100)/dFileSize);<br />
<br />
CString strTmpPercentage;<br />
strTmpPercentage.Format("Percentage Completed:%d%%", nPercentageComplete);<br />
GetDlgItem(IDC_STATIC_PERCENTAGE)->SetWindowText(strTmpPercentage);<br />
<br />
int nLower, nUpper;<br />
m_ProgressCtl.GetRange(nLower, nUpper );<br />
<br />
m_ProgressCtl.SetPos(((nUpper-nLower)/100) * nPercentageComplete);<br />
}<br />
}
while (TRUE);<br />
<br />
fflush (pFile);<br />
fclose (pFile);<br />
delete [] pBuffer;<br />
<br />
<br />
if(!bInComplete)<br />
{<br />
strStaus.Format("Renaming file at local machine..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
<br />
if(!MoveFile(strTmpFileName.c_str(), strFileNameAtLocalMachine.c_str() ))<br />
{<br />
CString strMsg;<br />
strMsg.Format("Error:%d", GetLastError());<br />
AfxMessageBox(strMsg, MB_OK); <br />
<br />
}<br />
strStaus.Format("Done..");<br />
GetDlgItem(IDC_STATIC_STATUSNEW)->SetWindowText(strStaus);<br />
}<br />
<br />
if(!bInComplete)<br />
{<br />
AfxMessageBox("File has downloaded..");<br />
GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);<br />
GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);<br />
}<br />
<br />
if(hConnect)<br />
InternetCloseHandle(hConnect);<br />
if(hOpen)<br />
InternetCloseHandle(hOpen);<br />
if(hOpenFile)<br />
InternetCloseHandle(hOpenFile);<br />
<br />
return TRUE;<br />
|
|
|
|
|
Hello!
Its very difficult to debug your code remotely. To better format your code postings in the future I would recommend wrapping the text in the CODE then the PRE tags. Makes it much easier to read when its formatted correctly.
If your goal is to simply download a remote file then perhaps you can use CInternetSession[^] rather than the WinInet classes.
Here is a sample of how to read a remote file over HTTP and write it locally. Much easier!
I pulled this code snippit from an old project. It was inside a CWinThread derived class for multi-threaded downloads.
char httpbuff[512];
CInternetSession Session;
CStdioFile *remotefile = Session.OpenURL(_T("http://www.somewhere.com/somepath/somefile.zip") ,1,INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD);
CFile myfile(_T("\\Path\\To\\Somewhere\\Local"), CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
int iBytes;
while (iBytes = remotefile->Read(httpbuff, 512))
{
myfile.Write(httpbuff, iBytes);
}
If you also need the filesize for a progress bar then you can use CHttpFile::QueryInfo() to get that information. CHttpConnection::OpenRequest() returns CHttpFile.
Best Wishes,
-David Delaune
|
|
|
|
|
Does CInternetSession have pause resume capability?
Thanks,
David
|
|
|
|
|
My program is:
#include "stdafx.h"
#include "stdio.h"
#include "windows.h"
#include "string.h"
#define SERVICENAME "test"
int InstallService();
int main(int argc, char* argv[])
{
InstallService();
return 0;
}
int InstallService()
{
SC_HANDLE sh = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if(!sh)
{
exit(1);
}
SC_HANDLE rh = CreateService(
sh,
SERVICENAME,
SERVICENAME,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
"c:\windows\notepad.exe",
NULL,
NULL,
NULL,
NULL,
NULL);
if(!rh)
{
if (GetLastError() == ERROR_SERVICE_EXISTS)
{
exit(1);
}
else
{
puts("error CreateService");
CloseServiceHandle(sh);
exit(1);
}
}
return 1;
}
when i use "sc start test",something wrong:"[sc] StartService FAILED 1053",Why?????
|
|
|
|
|
Definition of Error 1053: ERROR_SERVICE_REQUEST_TIMEOUT: The service did not respond to the start or control request in a timely fashion.
Best Wishes,
-David Delaune
|
|
|
|
|
After restart ,the program open notepad.exe,then the notepad.exe closed automatically.
Why???
How to resolve the program????
|
|
|
|
|
Assuming that you installed notepad.exe as a service I would recommend opening command prompt and issuing the following command:
sc delete test
Or you can navigate to HKLM\SYSTEM\CurrentControlSet\Services and manually delete it. However taking into account the history of your prior actions, I would recommend the previous suggestion as the first course of action.
Best Wishes,
-David Delaune
|
|
|
|
|
I want to start a program as a service;
How to realize it??
Can you tell me some document about this??
Thank you very much!
|
|
|
|
|
A gentleman named Xiangyang Liu wrote a very popular article about how to start a program as a service. I suggest that you read the article and take a look at the sample source code.
Start Your Windows Programs From An NT Service[^]
Best Wishes,
-David Delaune
|
|
|
|
|
You can't just throw any old executable at the Service Control Manager and expect the SCM to do all the work to handle it as a "true" service. The executable has to contain the code to communicate back to the SCM. Notepad does not contain that stuff. I'd wager your original test program did not either ... therfore, the SCM started it but your program didn't tell the SCM that it was started, therefore the SCM reported the error that the program didn't start.
Check this article for service basics [^]
Judy
|
|
|
|
|
CachedBitmap *pCB;
void func ()
{
g(hdc);
Bitmap bm(path);
pCB=new CachedBitmap(&bm,&g);
}
...
</pre>
|
|
|
|
|
Yes, the bitmap bits are copied into the CachedBitmap object. You can test it yourself with something like:
void YourClass::OnPaint()
{
CPaintDC dc(this);
Graphics g(dc.m_hDC);
if(NULL != pCB)
{
g.DrawCachedBitmap(pCB,0,0);
}
else
{
CRect rect;
GetClientRect(&rect);
Bitmap buf(rect.Width(), rect.Height());
g.DrawImage(&buf, 0, 0);
if(NULL == pCB)
{
pCB = new CachedBitmap(&buf,&g);
}
}
}
|
|
|
|
|
|
hi
i have a dialog based application with edit box control...i know how to save the data from the edit box to a certain file.and open it again (but i need to open the dialog and press the open button and choose the file then ok).
my question is...when i double click the file .... i want
to restore the data and display it in the edit box as i save it before.ps:
i have my own file type association....that works fine..
i would appreciate any kind of help
thank u
lahom
|
|
|
|
|
Can you more explain,do you need to SetWindowText?
|
|
|
|
|
You need to get the filename from args, open the file, read the file and set text of your textbox control.
|
|
|
|
|
ok
thank u for your reply....
but pleease can u show me how to do this.
i reealy need thisthank u
|
|
|
|
|
dehseth wrote: You need to get the filename from args, open the file, read the file and set text of your textbox control.
actually i had something like that .... but couldnot understand it ....
so pleease can u bear with me and help me through this
i reealy need it
thank u in advance
|
|
|
|
|