|
Thanks Jochen And Richard,
Yes I used an OpenSource version of strptime() that I found here: http://plibc.sourceforge.net/doxygen/strptime_8c-source.html[^]- and I have transformef the char(s) into TCHAR, added _T, etc....
and I ave written this:
{
...
CString strFormatCpp = TranslateFormatDate(strFormatVB);
tm timeDate;
memset(&timeDate,0,sizeof(tm ));
TCHAR * pRes = strptime (strMyDate, strFormatCpp, &timeDate);
if ( pRes != NULL )
{
COleDateTime oleDate;
oleDate.SetDateTime(1900 + timeDate.tm_year,timeDate.tm_mon+1,timeDate.tm_mday,timeDate.tm_hour,timeDate.tm_min,timeDate.tm_sec);
}
}
CString TranslateFormatDate(const CString & strFormat)
{
CString strResult;
int nChar = 0;
while ( nChar < strFormat.GetLength() )
{
switch ( strFormat[nChar] )
{
case 'A':
if ( MatchFormatKey(_T("AMPM"),_T("%p"),strFormat, nChar,strResult) )
continue;
break;
case 'a':
if ( MatchFormatKey(_T("ampm"),_T("%p"),strFormat, nChar,strResult) )
continue;
case 'y':
if ( MatchFormatKey(_T("yyyy"),_T("%Y"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("yy"),_T("%y"),strFormat, nChar,strResult) )
continue;
break;
case 'M':
if ( MatchFormatKey(_T("MMMM"),_T("%B"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("MMM"),_T("%b"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("MM"),_T("%m"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("M"),_T("%#m"),strFormat, nChar,strResult) )
continue;
break;
case 'd':
if ( MatchFormatKey(_T("dddd"),_T("%A"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("ddd"),_T("%a"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("dd"),_T("%d"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("d"),_T("%#d"),strFormat, nChar,strResult) )
continue;
break;
case 'h':
if ( MatchFormatKey(_T("hh"),_T("%I"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("h"),_T("%#I"),strFormat, nChar,strResult) )
continue;
break;
case 'H':
if ( MatchFormatKey(_T("HH"),_T("%H"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("H"),_T("%#H"),strFormat, nChar,strResult) )
continue;
break;
case 'm':
if ( MatchFormatKey(_T("mm"),_T("%M"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("m"),_T("%#M"),strFormat, nChar,strResult) )
continue;
break;
case 's':
if ( MatchFormatKey(_T("ss"),_T("%S"),strFormat, nChar,strResult) )
continue;
if ( MatchFormatKey(_T("s"),_T("%#S"),strFormat, nChar,strResult) )
continue;
break;
}
strResult+=strFormat[nChar];
nChar++;
}
return strResult;
}
bool MatchFormatKey(const CString & strKey,const CString & strTransKey,const CString & strFormat, int & nPos,CString & strResult)
{
if ( strFormat.Mid(nPos, strKey.GetLength()) != strKey )
return false;
strResult+=strTransKey;
nPos+=strKey.GetLength();
return true;
}
Thanks every-one!
Jerry
modified 18-Jul-12 9:49am.
|
|
|
|
|
Richard pointed out using strftime( ) . it is standard C.
#include <cstdio>
#include <ctime>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%Y %m %d ",timeinfo);
puts (buffer);
return 0;
}
|
|
|
|
|
Yes but I want to parse not to format!
Thanks!
Jerry
|
|
|
|
|
My apologies, I got mixed up, and cannot for the life of me recall the function that does the parsing.
[edit]
It's strptime() which, unfortunately, is not available in Windows, so you will need to get a copy of an open source version from somewhere.
[/edit]
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard MacCutchan wrote: It's strptime() which, unfortunately, is not available in Windows
Very odd. Far as I can tell strptime is not part of ANSI C. Which makes me wonder why.
|
|
|
|
|
It's POSIX according to the man page[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
My mistake. Didn't notice that CStrings only compile in MFC.
char buffer[256];
CString cs = buffer;
CString Management[^]
|
|
|
|
|
You can still use the ParseDateTime, but you need to set the format first.
Here's what I've done...
First, get the current format using
GetLocaleInfo(m_LCID, LOCALE_SSHORTDATE, m_csOriginalSDateFormat.GetBuffer(MAX_PATH + 1), MAX_PATH);
m_csOriginalSDateFormat.ReleaseBuffer();
(m_csOriginalSDateFormat is a CString)
Next have your own CString with the desired format:
m_csNewSDateFormat = _T("M/d/yyyy");
Now, set the desired format, parse the date/time, and restore the original format:
SetLocaleInfo(m_LCID, LOCALE_SSHORTDATE, m_csNewSDateFormat);
oleStartTime.ParseDateTime(csDateTime);
SetLocaleInfo(m_LCID, LOCALE_SSHORTDATE, m_csOriginalSDateFormat);
Hope this helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
|
|
Thanks again... but this is to return a string with a format...
What I wanted is to parse a string into a date with a format!
Something like
COleDatetime t;
t.IsThisStringADateWithThisFormat(_T("10012012"),"ddMMyyyy");
But I have managed (see my post above)!
Thanks anyway!
Jerry
|
|
|
|
|
hi,
i have developed program where two separate windows, one containing Map and other the dialog form with some controls, are opened. the program is when i click on Map window, its coordinates are displayed in the static text on the dialog form window. what i want is that when i click on Map window (which is at the front at the time of clicking) the dialog form window should appear at the front showing the results of my click, i.e the coordinates.
Regards
Jawad
modified 18-Jul-12 4:00am.
|
|
|
|
|
When you click on the map you can set the dialog's property to WS_EX_TOPMOST as described here[^]. You would then need to reset that value on some other action. Alternatively you could use the SetWindowPos() [^] function to alter its place in the Z-order, i.e. bring it to the front.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
thank you Richard MacCutchan.
|
|
|
|
|
in my app, I use ftp raw commands to upload several files to server,
after sending PASV and STOR from command port, file transfer starts on data port - so far so good.
But, when I send same commands to server again to upload second file before first uploading completed , server answers "unknowing command" - to second PASV and STOR.
So, I have to wait for first uploading completed to upload second file.
Any comments as solution?
Anything wrong in my ftp commands or process?
how to upload 2 or more files at same time?
how to open multiple data sockets (ports) with one command socket (port)?
Thanks.
.
|
|
|
|
|
Just a guess, but wouldn't you need to create a second connection to the server to upload the second file simultaneously?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
The number of simultaneous transfers is under control of the server. When you send PASV, it will respond with none, one or more lines indicating a data port on which it is listening. If you can't work it out from reading manuals (RFC959 is a good start), find a real server that works, and get Wireshark on the job to see what messages go back and forth. (A good server like Filezilla maintains a log so you probably don't need Wireshark, but it'll be useful when you come to debugging your own code.)
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
hi
am looking to move the existing file along with progress control update .
i tried with movefilewithprogrees did not work .
canany body explain the concept
movefilewithprogrees how it work or any alternate way for moving the file with progress update .
this movefilewithprogress will move the file if i get how much this function will transfer the data .
Best
Regards
sarfaraz
|
|
|
|
|
Can you please post your code snipet?
For your conceptual study, you can have a look at this[^].
|
|
|
|
|
sarfaraznawaz wrote: i tried with movefilewithprogrees did not work . You need to explain what it was that did not work, we cannot guess. Have you checked the documentation[^] to ensure that your function call is correct and also checked for any error responses?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
sarfaraznawaz wrote: i tried with movefilewithprogrees did not work . Which is all but totally meaningless without showing how you are using that function, and what GetLastError() is returning. We're not mind readers!
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
see i tried like this but it does not coming in callback function .
so that i use while loop to update the progress
<pre>DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize,LARGE_INTEGER TotalBytesTransferred,LARGE_INTEGER StreamSize,
LARGE_INTEGER StreamBytesTransferred,DWORD dwStreamNumber,DWORD dwCallbackReason,
HANDLE hStoreFile,HANDLE hFinalFile,LPVOID lpData)
{
Temp_TotalBytesTransferred.QuadPart = TotalBytesTransferred.QuadPart;
Temp_TotalFileSize.QuadPart=TotalFileSize.QuadPart;
iNewPercent1 = int(( double(TotalBytesTransferred.QuadPart) /
double(TotalFileSize.QuadPart) ) * 100);
return PROGRESS_CONTINUE;
}</pre><pre lang="cs">while(savingbytetraversed<=m_li64FileSize.QuadPart)
{
::SendMessage(h_wnd,WM_APP + 12, 0,0);
savingbytetraversed+=10;
ullBytesTraversed = savingbytetraversed;
if (bSaveexecution == 0)
{
successForsavingfile == FALSE;
break;
}
}
if (savingbytetraversed >= m_li64FileSize.QuadPart )
{
successForsavingfile =TRUE;
::SendMessage(h_wnd,WM_APP + 12, 0,0);
MoveFileWithProgress(FilePathForSaving,pathforsaving,
CopyProgressRoutine, NULL, MOVEFILE_COPY_ALLOWED);
::MessageBox(h_wnd,_T("File Saved successfully "),_T("Information "),MB_ICONINFORMATION);
successForsavingfile = FALSE;
closefile= FALSE;
}</pre>
|
|
|
|
|
You're calling MoveFileWithProgress() from within the callback function?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
shot.h
#ifndef CTGALOADER_H
#define CTGALOADER_H
class CTGALoader
{
public:
CTGALoader(); ~CTGALoader();
bool LoadTGAFile(char *filename); void SaveTGAScreenShot(char *filename,
int width,
int height); void FreeImage();
unsigned int ID; int imageWidth; int imageHeight;
protected:
void GenerateTexture(); bool LoadTGA(char *filename); bool WriteTGA(char *file, short int width,
short int height,
unsigned char *image);
unsigned char *image; bool textureExist; int type; };
#endif
shot.cpp
#include"shot.h"
#include <windows.h>
#include <./gl/GL.H>
#include <./gl/GLU.H>
#include <STDIO.H>
#pragma comment(lib,"OPENGL32.LIB")
#pragma comment(lib,"Glu32.lib")
CTGALoader::CTGALoader()
{
image = 0;
textureExist = false;
type = 0;
}
CTGALoader::~CTGALoader()
{
FreeImage(); }
bool CTGALoader::LoadTGAFile(char *file)
{
if(textureExist)
FreeImage();
if(!LoadTGA(file))
return false;
if(image == 0)
{
return false;
}
GenerateTexture();
textureExist = true;
return true;
}
void CTGALoader::GenerateTexture()
{
glGenTextures(1, &ID);
glBindTexture(GL_TEXTURE_2D, ID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D, type, imageWidth, imageHeight,
type, GL_UNSIGNED_BYTE, image);
glTexImage2D(GL_TEXTURE_2D, 0, type, imageWidth, imageHeight,
0, type, GL_UNSIGNED_BYTE, image);
}
bool CTGALoader::LoadTGA(char* file)
{
FILE *pfile;
unsigned char tempColor; unsigned char uselessChar; short int uselessInt; int colorMode; long tgaSize; long index; unsigned char imageTypeCode;
unsigned char bitCount;
pfile = fopen(file, "rb");
if (!pfile)
return false;
fread(&uselessChar, sizeof(unsigned char), 1, pfile);
fread(&uselessChar, sizeof(unsigned char), 1, pfile);
fread(&imageTypeCode, sizeof(unsigned char), 1, pfile);
if ((imageTypeCode != 2) && (imageTypeCode != 3))
{
fclose(pfile);
return false;
}
fread(&uselessInt, sizeof(short int), 1, pfile);
fread(&uselessInt, sizeof(short int), 1, pfile);
fread(&uselessChar, sizeof(unsigned char), 1, pfile);
fread(&uselessInt, sizeof(short int), 1, pfile);
fread(&uselessInt, sizeof(short int), 1, pfile);
fread(&imageWidth, sizeof(short int), 1, pfile);
fread(&imageHeight, sizeof(short int), 1, pfile);
fread(&bitCount, sizeof(unsigned char), 1, pfile);
fread(&uselessChar, sizeof(unsigned char), 1, pfile);
colorMode = bitCount / 8;
tgaSize = imageWidth * imageHeight * colorMode;
image = (unsigned char*)malloc(sizeof(unsigned char)*tgaSize);
fread(image, sizeof(unsigned char), tgaSize, pfile);
for (index = 0; index < tgaSize; index += colorMode)
{
tempColor = image[index];
image[index] = image[index + 2];
image[index + 2] = tempColor;
}
fclose(pfile);
if(bitCount == 32)
type = GL_RGBA;
else
type = GL_RGB;
return true;
}
void CTGALoader::FreeImage()
{
if(image)
{
free(image);
image = 0;
textureExist = false;
type = 0;
}
}
bool CTGALoader::WriteTGA(char *file, short int width, short int height, unsigned char *outImage)
{
FILE *pFile; unsigned char uselessChar; short int uselessInt; unsigned char imageType; int index; unsigned char bits; long Size; int colorMode;
unsigned char tempColors;
pFile = fopen(file, "wb");
if(!pFile) { fclose(pFile); return false; }
imageType = 2; colorMode = 3; bits = 24;
uselessChar = 0; uselessInt = 0;
fwrite(&uselessChar, sizeof(unsigned char), 1, pFile);
fwrite(&uselessChar, sizeof(unsigned char), 1, pFile);
fwrite(&imageType, sizeof(unsigned char), 1, pFile);
fwrite(&uselessInt, sizeof(short int), 1, pFile);
fwrite(&uselessInt, sizeof(short int), 1, pFile);
fwrite(&uselessChar, sizeof(unsigned char), 1, pFile);
fwrite(&uselessInt, sizeof(short int), 1, pFile);
fwrite(&uselessInt, sizeof(short int), 1, pFile);
fwrite(&width, sizeof(short int), 1, pFile);
fwrite(&height, sizeof(short int), 1, pFile);
fwrite(&bits, sizeof(unsigned char), 1, pFile);
fwrite(&uselessChar, sizeof(unsigned char), 1, pFile);
Size = width * height * colorMode;
for(index = 0; index < Size; index += colorMode)
{
tempColors = outImage[index];
outImage[index] = outImage[index + 2];
outImage[index + 2] = tempColors;
}
fwrite(outImage, sizeof(unsigned char), Size, pFile);
fclose(pFile);
return true;
}
void CTGALoader::SaveTGAScreenShot(char *filename, int w, int h)
{
unsigned char *outputImage = 0;
outputImage = (unsigned char*)malloc(w * h * 3);
memset(outputImage, 0, w * h * 3);
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, outputImage);
WriteTGA(filename, w, h, (unsigned char*)outputImage);
free(outputImage);
}
main.cpp
#include <windows.h>
#include "shot.h"
void main()
{
CTGALoader tga;
tga.SaveTGAScreenShot("123.TGA",1024,768);
}
the tga is whole black, why is it ?
thanks for your reply !
|
|
|
|
|
Far too much code here and far too few details. Try and narrow the problem down to a specific area of code and explain what is not working.
|
|
|
|
|