|
In my experience, if ur programming language is VC++ and u r using CButton u have to overide DrawItem . I wonder anyboy here to correct me if am wrong?
|
|
|
|
|
ani_ikram wrote: to draw our own button we have to draw circle ?
Of course. That's the purpose of being able to draw controls yourself
Is drawing circles a problem?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, can somebody tell me how to create a plane passing through 3 points and how to project a point onto this plane.Please do help me out.Thnk You.
|
|
|
|
|
If u provide some more details like why u want this plane...it will be better...
|
|
|
|
|
Thnx for the reply.ok, ill explain it clearly.I want this plane as i have to project a set of points that are scattered all over the space.So i am required to project these points on to the plane, so that i get the 2d cordinates of all th points with respect to that plane.Plse do tell me how to do it.
|
|
|
|
|
|
Well, actually i had to develop a c/c++ code for creating a plane n projecting the points on that plane.Thats y i posted it here so that somebody could help me if they had done something similar to what i want.Plse do tell me if you know how to do it.Anyways, thk you for the reply.
|
|
|
|
|
|
Thnx alot for the reply.I'll chk out those links.Thnx once again for your effort.
|
|
|
|
|
Good Morning!
i have a Cstring of this type
str = "%India%#Mumbai#>Address1>Address2>Address3>"
so i want to store "India" in one CString, say str1
"Mumbai" in another, say str2 and
"Address1","Address2","Address3" in an array of Cstring, say str3[3]
so how can i extract a string present in between % and % for India,
# and # for Mumbai etc.
it is easy to check each character, start from '%' to '%'. but is there any function which does this
i tried with str.Tokenize('%', 0)
but output is
India
and
#Mumbai#>Address1>Address2>Address3>
|
|
|
|
|
kapardhi wrote: i tried with str.Tokenize('%', 0)
Try using _tcstok_s...
Some more details here![^]
Pass multiple delimiters to Tokenize function given in above blog post. You can easily change the output parameter from a vector of std::string to a vector of CString 's. Also a test application is provided to test out different cases. I've tried out with files of 1 MB, 2MB and it was quite good.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
kapardhi wrote: i tried with str.Tokenize('%', 0)
You could use CStringT::Tokenize() itself. it accepts a string of delimiters as parameter. For instance see the sample code snippet from msdn.
CAtlString str( "%First Second#Third" );
CAtlString resToken;
int curPos= 0;
resToken= str.Tokenize("% #",curPos);
while (resToken != "")
{
printf("Resulting token: %s\n", resToken);
resToken= str.Tokenize("% #",curPos);
};
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi, I had the same problem, but I also needed the delimiters to be strings. Here's a function I wrote to do this:
std::string FindEnclosedString( const std::string& src, const std::string& left_guard, const std::string& right_guard )
{
int start, stop;
std::string dest;
start = src.find(left_guard);
if (start != std::string::npos)
{
start += left_guard.size();
stop = src.find(right_guard, start);
if (stop != std::string::npos)
stop -= start;
dest = src.substr(start, stop);
}
return dest;
}
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I want to send a Command string to the modem port (COM3).
I have created a file with CreateFile()
then what should be the parameters to the WriteFile() function to send a string to the COM3 port ... ?
Apurv
|
|
|
|
|
Have you tried passing the file name as "COM3" (no extension, no root directory or absolute path required). That must give you direct access to the port.
Besides that, what is attached at COM3 port? Are you aware that some devices might require you to follow a specific text pattern (usually a series of ASCII keywords) if you want to send it a command? For instance, a printer usually follows the EPSON escape code sequences. I think you need to try specifying the file name as "COM3", as I already said and if it doesn't give you the desired results, you will need to provide more details.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
i m configuring the COM3 port as follows ...
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
TCHAR *pcCommPort = TEXT("COM3");
DWORD dwBytesWritten = 0;
hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (hCom == INVALID_HANDLE_VALUE)
{
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}
dcb.DCBlength = sizeof(DCB);
fSuccess = GetCommState(hCom, &dcb);
if (!fSuccess)
{
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}
dcb.BaudRate = CBR_57600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
fSuccess = SetCommState(hCom, &dcb);
if (!fSuccess)
{
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}
_tprintf (TEXT("Serial port %s successfully reconfigured.\n"),pcCommPort);
Apurv
|
|
|
|
|
i m configuring the COM3 port as follows ...
and it is getting configured correctly ....
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
TCHAR *pcCommPort = TEXT("COM3");
DWORD dwBytesWritten = 0;
hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (hCom == INVALID_HANDLE_VALUE)
{
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}
dcb.DCBlength = sizeof(DCB);
fSuccess = GetCommState(hCom, &dcb);
if (!fSuccess)
{
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}
dcb.BaudRate = CBR_57600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
fSuccess = SetCommState(hCom, &dcb);
if (!fSuccess)
{
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}
_tprintf (TEXT("Serial port %s successfully reconfigured.\n"),pcCommPort);
Apurv
|
|
|
|
|
Good. Now, you can treat it as a file and write your commands as if you were writing it into a file. You may use WriteFile[^] for instance. Or you have a trouble somewhere else?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Hi all,
I have this project which is downloading product updates over the internet. What I do first is that before I can go to the second download the first download must be finished. Now I have decided to create a thread so I can download updates simultaneously.
Let me show a bit of the code:
while (m_bIsRunning)
{
Sleep(5000);
if (isUpdateTime())
{
CSiteCode m_CSiteCode;
RMproduct* MPoint = new RMproduct(L"ManagePoint",ManagepointService, ManagepointVersion);
if (isPrdInstalled(MPoint))
{
GetVersion(MPoint);
MPoint->m_SiteCode = m_CSiteCode.GetMPSiteCode(MPoint->m_SerialNo.c_str());
dloadAvailable = DoCheckForProductUpdates(MPoint);
if(dloadAvailable)
{
GetUpdate(MPoint);
}
}
delete MPoint;
RMproduct* ReRite = new RMproduct(L"ReRite",ReriteService, ReriteVersion);
if (isPrdInstalled(ReRite))
{
GetVersion(ReRite);
ReRite->m_SiteCode = m_CSiteCode.GetReRiteSiteCode(ReRite->m_SerialNo.c_str());
dloadAvailable = DoCheckForProductUpdates(ReRite);
if(dloadAvailable)
{
GetUpdate(ReRite);
}
}
delete ReRite;
RMproduct* ReRiteAsian = new RMproduct(L"ReRite",ReriteAsianService, ReriteAsianVersion);
if (isPrdInstalled(ReRiteAsian))
{
GetVersion(ReRiteAsian);
ReRiteAsian->m_SiteCode = m_CSiteCode.GetReRiteAsianSiteCode(ReRiteAsian->m_SerialNo.c_str());
dloadAvailable= DoCheckForProductUpdates(ReRiteAsian);
if(dloadAvailable)
{
GetUpdate(MPoint);
}
}
delete ReRiteAsian;
}
}
This is service btw. Now the function GetUpdate call a function called downloadfile:
bool CUpdateServiceModule::DownloadFile(RMUpdates* prd)
{
bool result = false;
int Data_Of_Thread_1 = 1;
HANDLE Handle_Of_Thread_1 = 0;
HANDLE Array_Of_Thread_Handles[3];
Handle_Of_Thread_1 = CreateThread( NULL, 0, Thread_no_1, ((void*)prd), 0, NULL);
if ( Handle_Of_Thread_1 == NULL) ExitProcess(Data_Of_Thread_1);
Array_Of_Thread_Handles[0] = Handle_Of_Thread_1;
WaitForMultipleObjects( 3, Array_Of_Thread_Handles, TRUE, INFINITE);
CloseHandle(Handle_Of_Thread_1);
Sleep( 100 );
return result;
}
This download file is creating a thread that calls the downloadthread global function which downloads the update. The behavior of this downloadthread function is that even the service stops once it is restored it will start the download where it ended:
DWORD WINAPI Thread_no_1( PVOID PrdPtr )
{
DownloadThread((void*)PrdPtr);
return 0;
}
void DownloadThread(PVOID PrdPtr)
{
RMUpdates *ParamPtr;
ParamPtr = (RMUpdates *) PrdPtr;
FILE * pFile = NULL;
DWORD dwPacketSize =5;
PBYTE pBuffer = new BYTE[dwPacketSize * 1024];
double dOffsetToSeek =0;
std::wstring strTmpFileName = ParamPtr->savePath.c_str();
strTmpFileName.append(L".tmp");
std::wstring strFileNameAtLocalMachine= ParamPtr->savePath.c_str();
int res = DeleteFile(strFileNameAtLocalMachine.c_str());
double dCurrentFileSize;
if(IfLocalFileExist(strTmpFileName.c_str(), &dCurrentFileSize))
{
dOffsetToSeek = dCurrentFileSize;
}
CString strRangeQuest;
if(dCurrentFileSize>0){
strRangeQuest.Format( _T("%sRange: bytes=%d-\r\n"), szHeaders,static_cast<ULONGLONG>(dCurrentFileSize));
}
else
strRangeQuest = szHeaders;
if (!(pFile = _wfopen (strTmpFileName.c_str(), L"a+b" ) ) )
{
return;
}
try
{
CInternetSession Session(_T("UpdateService"));
CHttpConnection Connection1(Session,ParamPtr->link.c_str());
BYTE Buffer[4096];
CHttpFile dFile(Session,ParamPtr->link.c_str());
CInternetFile::CInfo Info(dFile);
dFile.SendRequest(strRangeQuest);
DWORD dwRead;
for (dwRead = 1 ; dwRead; )
{
dFile.Read(Buffer,sizeof(Buffer),dwRead);
if (dwRead>0)
fwrite(Buffer, sizeof (char), dwRead , pFile);
}
fclose (pFile);
BOOL moved = MoveFile(strTmpFileName.c_str(), strFileNameAtLocalMachine.c_str());
if(moved)
{
EmailUser(strFileNameAtLocalMachine.c_str());
}
DeleteFile(strTmpFileName.c_str());
HKEY hkey;
TCHAR szKey[256];
int nValue = 0;
szKey[0] = _T('\0');
_tcscpy(szKey, ServiceRegEntry);
_tcscat(szKey, UPDATEMGR);
_tcscat(szKey, ServiceParam);
_tcscat(szKey, _T("\\"));
_tcscat(szKey,ParamPtr->prdName.c_str());
_tcscat(szKey, _T("\\"));
_tcscat(szKey,ParamPtr->nameVer.c_str());
if (RMRegOpenKeyEx(HKEY_LOCAL_MACHINE,szKey,0,KEY_QUERY_VALUE | KEY_SET_VALUE,&hkey) == ERROR_SUCCESS)
{
nValue = 1;
RMRegSetValueEx(hkey,UPDATESTAT,0,REG_DWORD,(BYTE*)&nValue,sizeof(nValue));
RMRegCloseKey(hkey);
}
}
catch(CInternetException& err)
{
err.GetErrorMessage();
}
}
Now what I would like to know is that while the first thread is downloading the first update will it go to the next update and download it? Or still my code will just wait for the first thread to download the first update? I am having a hard time debugging this as I dont know how the process splits.
Thanks,
Jayjay
|
|
|
|
|
monsieur_jj wrote: HANDLE Array_Of_Thread_Handles[3]; // Aray to store thread handles
Handle_Of_Thread_1 = CreateThread( NULL, 0, Thread_no_1, ((void*)prd), 0, NULL);
if ( Handle_Of_Thread_1 == NULL) ExitProcess(Data_Of_Thread_1);
// Store Thread handles in Array of Thread Handles as per the requirement of WaitForMultipleObjects()
Array_Of_Thread_Handles[0] = Handle_Of_Thread_1;
Here you're creating a uninitialized handle array, and then setting only the first member. The rest handles will contain junk values.
monsieur_jj wrote: // Wait until all threads have terminated.
WaitForMultipleObjects( 3, Array_Of_Thread_Handles, TRUE, INFINITE);
And here you are waiting for all handles include junk handle values which will finally result in error.
monsieur_jj wrote: Now what I would like to know is that while the first thread is downloading the first update will it go to the next update and download it?
You've just created a single thread.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi Jijo,
Thanks for the reply
so I have changed it to:
HANDLE Array_Of_Thread_Handles[3];
Handle_Of_Thread_1 = CreateThread( NULL, 0, Thread_no_1, ((void*)prd), 0, NULL);
if ( Handle_Of_Thread_1 == NULL) ExitProcess(Data_Of_Thread_1);
Array_Of_Thread_Handles[0] = Handle_Of_Thread_1;
WaitForMultipleObjects( 1, Array_Of_Thread_Handles, TRUE, INFINITE);
Are you saying it will just finish downloading of that update even if its on a thread and will not go downloading the other updates?
thanks,
Jayjay
|
|
|
|
|
What other updates? You've only called CreateThread() once.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
Here is the deal
if (isUpdateTime())
{
RMproduct* MPoint = new RMproduct(L"ManagePoint",ManagepointService, ManagepointVersion);
if (isPrdInstalled(MPoint))
{
GetVersion(MPoint);
MPoint->m_SiteCode = m_CSiteCode.GetMPSiteCode(MPoint->m_SerialNo.c_str());
dloadAvailable = DoCheckForProductUpdates(MPoint);
if(dloadAvailable)
{
GetUpdate(MPoint);
}
}
delete MPoint;
RMproduct* MPoint2 = new RMproduct(L"ManagePoint",ManagepointService, ManagepointVersion);
if (isPrdInstalled(MPoint2))
{
GetVersion(MPoint2);
MPoint2->m_SiteCode = m_CSiteCode.GetMPSiteCode(MPoint2->m_SerialNo.c_str());
dloadAvailable = DoCheckForProductUpdates(MPoint2);
if(dloadAvailable)
{
GetUpdate(MPoint)2;
}
}
delete MPoint;
RMproduct* MPoint3 = new RMproduct(L"ManagePoint",ManagepointService, ManagepointVersion);
if (isPrdInstalled(MPoint))
{
GetVersion(MPoint3);
MPoint3->m_SiteCode = m_CSiteCode.GetMPSiteCode(MPoint3->m_SerialNo.c_str());
dloadAvailable = DoCheckForProductUpdates(MPoint3);
if(dloadAvailable)
{
GetUpdate(MPoint3);
}
}
delete MPoint3;
}
<pre>
The GetUpdate function calls the function DownloadFile():
<pre>
bool CUpdateServiceModule::DownloadFile(RMUpdates* prd)
{
bool result = false;
int Data_Of_Thread_1 = 1;
HANDLE Handle_Of_Thread_1 = 0;
HANDLE Array_Of_Thread_Handles[1];
Handle_Of_Thread_1 = CreateThread( NULL, 0, Thread_no_1, ((void*)prd), 0, NULL);
if ( Handle_Of_Thread_1 == NULL) ExitProcess(Data_Of_Thread_1);
Array_Of_Thread_Handles[0] = Handle_Of_Thread_1;
WaitForMultipleObjects( 1, Array_Of_Thread_Handles, TRUE, INFINITE);
CloseHandle(Handle_Of_Thread_1);
Sleep( 100 );
return result;
}
Thing is MPoint2 and MPoint3 are not sure to exist if they dont the code will only download one update if they exist it may download 2 or 3 updates. But for sure one exists. How must I create a thread in this type of event?
Thanks,
Jayjay
|
|
|
|
|
Your code as show does nothing multi threaded.
The DownloadFile() method creates a thread, but since it
waits for the thread to complete, it is effectively a complicated
way to do work on ONE thread.
I'm not entirely sure what you are trying to do.
Do you want a separate thread for each download and then
a way to wait for all the threads to complete before the
app proceeds?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
I want a separate thread for each download and maybe wait for all of it to finish or let the app proceed while downloading whichever is ok with me.
Thanks,
Jayjay
|
|
|
|
|