|
Perhaps this will give you some ideas:
--------------------------------------
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <ostream>
#include <deque>
#include <set>
#include <iterator>
class CData
{
public:
CData(int priority, int group)
: priority_(priority)
, group_(group)
{}
// Define the sorting criteria.
friend bool operator<(const CData &l, const CData &r)
{
if (l.priority_<r.priority_)
{
return true;
}
else
{
return l.priority_==r.priority_ && l.group_<r.group_;
}
}
int priority_;
int group_;
};
// So we can output the data to the console.
template <typename CH, typename TR>
inline std::basic_ostream<CH, TR>& operator<<(std::basic_ostream<CH, TR> &os, const CData &d)
{
os << "Priority: " << d.priority_ << std::endl;
os << "Group: " << d.group_ << std::endl;
return os;
}
typedef std::set<CData> DataCollecton_t;
int main(int arvc, char* argv[])
{
// Populate the collection.
DataCollecton_t coll;
coll.insert(CData(3, 2));
coll.insert(CData(3, 3));
coll.insert(CData(2, 2));
coll.insert(CData(1, 1));
coll.insert(CData(2, 3));
coll.insert(CData(1, 2));
coll.insert(CData(2, 1));
coll.insert(CData(1, 3));
coll.insert(CData(3, 1));
// Print the results.
std::copy(coll.begin(), coll.end(), std::ostream_iterator<CData>(std::cout));
return 0;
}
Steve
|
|
|
|
|
Hi Steve!
thanks for the reply!
im sure your post will give me some idea and help me great deal.
thanks again!
newbie
|
|
|
|
|
I have to create uninstall software which can uninstall any software installed in my pc.
Can anyone help me?
Mazhar
|
|
|
|
|
|
Hi every one,
now I want to build a module about download http file with multi thread.
I create several threads.Following is my code:
DWORD CMyThread::Execute( )
{
CInternetSession session;
CHttpFile* phttpFile = (CHttpFile*)session.OpenURL( m_strHttpFile,1,INTERNET_FLAG_TRANSFER_BINARY
|INTERNET_FLAG_RELOAD );
phttpFile->Seek( m_beginPosition,0 );//m_beginPosition is the position of http file that this thread begin to read
CFile localFile;
if( FALSE == localFile.Open(szLocalFileName,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary,NULL))
{
return 0;
}
int readlen = -1;
BYTE buffer[1024];
int nTotalReadLen = 0;
while( 1 )
{
readlen = phttpFile->Read( buffer,1024 );//the second thread can't be running here until the first thread finished.
localFile.Write( buffer,1024 );
nTotalReadLen += readlen;
if( nTotalReadLen == m_size )//finish download the part,m_size is the part of the total size
{
localFile.Close( );
phttpFile->Close();
session.Close();
m_pFileDownLoader->SendMessage( T_MESSAGE_READ_FINISHED );
break;
}
}
}
but only the first one can running smoothly.the second stop in "pHttpFile->Read( )".but It can retrieve running Until the first finished.
How can I make the threads running at the same time?I am a fresh man in web programe ,If you have the instance about this ,please give me.thanks a lot.
|
|
|
|
|
How can I check if the text inside a CEdit is numeric? I mean:
"2355345" Yes
"3452fsgd" No
"fsdgsdg" No
"sds334" No
I usually use the IsNumeric () function but it seems that in Visual C++ is not available... Can somebody help me?
|
|
|
|
|
You can choose to let the user enter only the numbers . Right click the edit box and set the number property to true. So in this manner the user won't be able to enter any text in the edit box(except number)
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
If you just want to allow only numeric value in the Edit Box, Go to property window and Set the Number property to True.
Or
If you want to validate it after user have entered the character, use Dailog Data Exchange (DDX) and Dialog Data Validate (DDV) in
DoDataExchange(CDataExchange* pDX) function.
Else
Scan the text and use isdigit() for each char.
If any one have better solution, pls let me know.
Anurag Gandhi.
|
|
|
|
|
Gosh!! Thank you very mucho to both of you.
As _AnShUmAn_ says, "Some things are hard to do UNTIL WE KNOW HOW TO DO THEM".
That´s true...
|
|
|
|
|
Most Welcome. It's my pleasure.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Try to use CRT function isdigit() or Windows API GetStringTypeEx().
|
|
|
|
|
Hi every one,
now I want to build a module about download http file with mylti thread.
I create several threads.Following is my code:
DWORD CMyThread::Execute( )
{
CInternetSession session;
CHttpFile* phttpFile = (CHttpFile*)session.OpenURL( m_strHttpFile,1,INTERNET_FLAG_TRANSFER_BINARY
|INTERNET_FLAG_RELOAD );
phttpFile->Seek( m_beginPosition,0 );//m_beginPosition is the position of http file that this thread begin to read
CFile localFile;
if( FALSE == localFile.Open(szLocalFileName,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary,NULL))
{
return 0;
}
int readlen = -1;
BYTE buffer[1024];
int nTotalReadLen = 0;
while( 1 )
{
readlen = phttpFile->Read( buffer,1024 );//the second thread can't be running here until the first thread finished.
localFile.Write( buffer,1024 );
nTotalReadLen += readlen;
if( nTotalReadLen == m_size )//finish download the part,m_size is the part of the total size
{
localFile.Close( );
phttpFile->Close();
session.Close();
m_pFileDownLoader->SendMessage( T_MESSAGE_READ_FINISHED );
break;
}
}
}
but only the first one can running smoothly.the second stop in "pHttpFile->Read( )".but It can retrieve running Until the first finished.
How can I make the threads running at the same time?I am a fresh man in web programe ,If you have the instance about this ,please give me.thanks a lot.
|
|
|
|
|
Dear all
Hi
is there any example which uses SendMessage routine.
Regards
Monhi
|
|
|
|
|
There is (of course) a lot of doumentation about (with related samples), see, for instance http://msdn2.microsoft.com/en-us/library/ms644950.aspx[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: There is (of course) a lot of doumentation about (with related samples), see, for instance http://msdn2.microsoft.com/en-us/library/ms644950.aspx[^].
I wonder how you find these things.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
I wonder how the OP cannot!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: I wonder how the OP cannot!
Maybe you are lucky.;P
|
|
|
|
|
//LRESULT SendMesage ( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam )
//hWnd : Handle to window
//message : WM_***** message ( eg:EM_CLOSE , WM_PAINT ... )
wParam & lParam : additional message specific arguments
//MFC
//---
void CMyDlg::OnBnClickedOk()
{
SendMessage( WM_CLOSE , (WPARAM)0 , (LPARAM)0 ) ; //close current window
//or
::SendMessage( HWND_BROADCAST , WM_CLOSE , (WPARAM)0 , (LPARAM)0 ) ; /*close desktop windows */
};
//WIN32
//
//#include<windows.h>
LRESULT OnAnyEvent( HWND hWnd )//invoked from windowproc
{
SendMessage( hWnd , WM_CLOSE , (WPARAM)0 , (LPARAM)0 ) ;
}
//Visit msdn for complete reference for Windows Messages
|
|
|
|
|
|
pls let me knowHow to block Alt+F4 for any dialogbox
There Is Nothing Right & Wrong
|
|
|
|
|
Do you *really* want to block the keys or you want to do something else when the [X] button is clicked? Blocking the ALT + F4 keys can be done by overriding PreTranslateMessage() . If you want to handle the [X] button too, handle the WM_CLOSE message.
found at bash.org
[kernx]|.|.|.|.|.|.|.|
[kernx]sorry, wrong window
[beox33]say me why in the f*ck will you type that in any window
|
|
|
|
|
Hi,
How can i remove temporary internet file programmatically, i get the Temporary internet files path by calling SHGetSpecialFolderPath function, but when i call the function remove by appending file name it is unable to delete that file, and GetLastError returns 123(The filename, directory name, or volume label syntax is incorrect.). Any Help regarding this
Warm Regards,
Mushq
|
|
|
|
|
|
Thanks a lot for the help, i have done my work
|
|
|
|
|