|
i have a problem.i want to split a CString into a CStringArray which of each element holds a fixed length characters.
for example:
CString str;
CStringArray strArray=new CStringArray();
str="abcd";
afert spliting action,the result should be below:
the value of strArray[0] is "ab"
the value of strArray[1] is "cd"
how can i do?
thanks!!
Habbit--Beginner In MFC
|
|
|
|
|
<code>
{
#define STR_WIDTH 2
CStringArray arrStrings;
CString strSource(_T("abcdefghi"));
int nPosition(0);
while(nPosition < (strSource.GetLength()-1))
{
arrStrings.Add(strSource.Mid(nPosition,STR_WIDTH));
nPosition+=STR_WIDTH;
}
}</code>
or something of this effect. NB: this is untested.
I Dream of Absolute Zero
|
|
|
|
|
that's fine!
you are a good man!
|
|
|
|
|
Hi !
I'd like to have in my application a console window. To do it, I just have a normal multiline edit control, which I would have to use to implement by myself the console functionalities.
I tried to think how to do it, but I have no idea how to solve these points :
-How can I make sure the cursor will stay at the prompt if the user click anywhere else ?
-How can I make sure that, even if the cursor stays at the prompt, the user will be able to select some text and copy it.
-How can I make sure that any keyboard input will be captured by my console window ?
Any suggestions or help will be greatly appreciated !
Thanks !
Jerome
|
|
|
|
|
Jerome Conus wrote:
I'd like to have in my application a console window. To do it, I just have a normal multiline edit control...
An edit control implies a GUI application.
If you meant something else, I missed it. Please elaborate more.
|
|
|
|
|
Yes, it is a GUI application, but the user is allowed to display a small terminal window (console window) in which he/she will type some commands to display internal states of the application.
I hope I made myself clear, now !
Jerome
|
|
|
|
|
Yes, more clear, but still not feasible to my knowledge. In other words, I know of no way to put a console window on top of a GUI window such that it acts like any other type of control.
What you could do, however, is to use two edit controls, one for input and the other for output. You'd type commands into the one box, send them to a hidden console window, and capture the output in the other edit control. See here and MSDN article Q190351 for a better explanation.
|
|
|
|
|
I know exactly what you mean and I am trying to do the same thing. We don't want a "console" as in a DOS prompt, we want a control that lets us display a prompt, get user input, take some action, display results in the same window. MatLab and SciLab do this to allow the user to enter commands to do math and then it prints out the result in the window.
|
|
|
|
|
hi,ive just started to use visual c++,i'm working on program that can draw different shapes,the problem is that i dont know how to save the drawing in an appropriate format which i can open latter.plz help.urgent
|
|
|
|
|
|
You can design a new file format youself
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
my trouble is: Is necessary to send two request for downloading a file and after download some piece data of a file
Way it stop for ever?
1、To support resume,Download a file from server(the Server has't "keep-alive" feature but support resume), I think we must send
two request, the first one get the size of the file and other feature, the second request for download.(the way may be wrong, please figure it )
2、i want to study progrmming CAsyncSocket,derived a class "CHttpAsyncSocket" from CAsyncSocket:
// define download status in HttpAsyncSocket.h
typedef enum { CONNECT_NONE = 0, CONNECT_FILEINFO = 1, RECEIVE_FILEINFO = 2, CONNECT_DOWNLOAD = 3, RECEIVE_DOWNLOAD = 4} DOWNLOADSTATUS;
DOWNLOADSTATUS m_dsCurStatus;
// CHttpAsyncSocket.cpp
//connect server
void CHttpAsyncSocket::BeginDownload()
{
if(Connect(m_strServerIP, m_nServerPort) == SOCKET_ERROR)
{
Close();
m_dsCurStatus = CONNECT_NONE;
}
else
{
m_dsCurStatus = CONNECT_FILEINFO;
}
}
//if connect successfully, then send one of the two request
void CHttpAsyncSocket::OnConnect(int nErrorCode)
{
CAsyncSocket::OnConnect(nErrorCode);
if (nErrorCode)
{
Close();
m_dsCurStatus = CONNECT_NONE;
}
else if(m_dsCurStatus == CONNECT_FILEINFO) //send request that can Get the size of the file in server and may support resume
{
CString strSend;
strSend.Format( "GET %s HTTP/1.1\r\n"
"Host: %s:%d\r\n"
"Accept: */*\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=100-\r\n"
"\r\n",
m_strFileUrl, m_strServerIP, m_nServerPort);
int ret = Send(strSend.GetBuffer(0), strSend.GetLength());
if(ret == SOCKET_ERROR)
{
Close();
m_dsCurStatus = CONNECT_NONE;
}
else
{
m_dsCurStatus = RECEIVE_FILEINFO;
}
}
else if(m_dsCurStatus == CONNECT_DOWNLOAD) //send request for download
{
CString strSend;
strSend.Format( "GET %s HTTP/1.1\r\n"
"Host: %s:%d\r\n"
"Accept: */*\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=%d-%d\r\n"
"\r\n",
m_strFileUrl, m_strServerIP, m_nServerPort, m_dwLocalFileSize, m_dwServerFileSize);
//m_dwLocalFileSize, m_dwServerFileSize are separately the size of local and server
int ret = Send(strSend.GetBuffer(0), strSend.GetLength());
if(ret == SOCKET_ERROR)
{
Close();
m_dsCurStatus = CONNECT_NONE;
}
else
{
m_dsCurStatus = RECEIVE_DOWNLOAD;
m_bAlreadyGetHeader = FALSE; //has decode the header of package
}
}
else
{
ASSERT(FALSE);
}
}
//received data
const int MAX_RECV_BUFFER = 1024;
void CHttpAsyncSocket::OnReceive(int nErrorCode)
{
CAsyncSocket::OnReceive(nErrorCode);
char szReadBuf[MAX_RECV_BUFFER];
ZeroMemory(szReadBuf, MAX_RECV_BUFFER);
if (nErrorCode)
{
Close();
m_dsCurStatus = CONNECT_NONE;
}
if(m_dsCurStatus == RECEIVE_FILEINFO) //get size of file in server , etc
{
m_dwServerFileSize = 0;
BOOL bSupportResume = FALSE;
if(ParseHttpHeader(&m_dwServerFileSize, &bSupportResume) == TRUE) //parse the header of packet
{
Close(); //Is it necessary? -------------
Create(); //create a new socket and connect to server again
if(Connect(m_strServerIP, m_nServerPort) == SOCKET_ERROR)
{
Close();
m_dsCurStatus = CONNECT_NONE;
}
else
{
m_dsCurStatus = CONNECT_DOWNLOAD;
}
}
else
{
Close();
m_dsCurStatus = CONNECT_NONE;
}
}
else if(m_dsCurStatus == RECEIVE_DOWNLOAD)
{
//open local file and receive data
CFile file;
int bOpenSuc = file.Open(m_strLocalFile, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::typeBinary | CFile::shareExclusive);
if(bOpenSuc == FALSE)
{
TRACE("Error in file open!\n");
Close();
m_dsCurStatus = CONNECT_NONE;
}
file.SeekToEnd();
int ret = 0, nHeadLength = 0;
if(m_bAlreadyGetHeader == FALSE)
{
//reject the header of the packet in first time
do
{
ret = Receive(szReadBuf, MAX_RECV_BUFFER);
nHeadLength = GetHeadLength(szReadBuf);
}while(ret <= nHeadLength);
if(ret > nHeadLength)
{
file.Write(szReadBuf + nHeadLength, ret - nHeadLength);
}
m_bAlreadyGetHeader = TRUE;
}
while(TRUE)
{
ZeroMemory(szReadBuf,MAX_RECV_BUFFER);
int num = Receive(szReadBuf, MAX_RECV_BUFFER);
if(num == 0 || num == SOCKET_ERROR) //download finish or meet net error
{
if (GetLastError() != WSAEWOULDBLOCK && num == 0)
{
file.Close(); //HERE: thread may come here, and can not continue receive data again when download about 10 - 600 K,
return; //why? maybe use timer?
}
break;
}
file.Write(szReadBuf, num);
}
file.Close();
}
}
else
{
ASSERT(FALSE);
}
}
First, thank you look through my code above!
I study socket just now, many question are "naive", need you direct or give some advice.... thanks again ^_^
C/C++ code fans
|
|
|
|
|
The GET HTTP request seems valid. Make sure you append the to the resumed data instead of overwriting.
Kuphryn
|
|
|
|
|
Hello,
how do I get a pointer to the CMainFrame class of my project from the CView class?
I must modify the main toolbar from the CView class. Sure, I could use a global pointer, but isn't there a function like GetDocument() for CMainFrame?
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Hmm, no, I can do it the other way round... I use GetActiveView() to get the view from the CMainFrame.
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
You can use AfxGetMainWnd() to get a pointer to the main frame window.
|
|
|
|
|
I have a Edit Control field to enter variable Numbers and a Combo box from 1 to 10, every Index in Combo Box has to have a certain changed Edit Control Number.
A the End The edit control numbers are saved for each Combo box index, just like this:
Combo box index: 1------------->entered Number in Edit Controll for example 67.3
2--------------------------------->234.7
3--------------------------------->90
10------>
so if i return to Combo Box index 1 i will find 67.3 , for 3 --> 90 and so ...
Best Reguards!!
|
|
|
|
|
|
Hi,
i'm a beginner to all this so pls forgive me if this is a silly qn...i hv a dll that works on win 98 but i recently migrated to win xp. I've changed the project settings to _Unicode but i'm not sure how to modify the code so that it works the same way on win xp. For eg. how do i use AfxMessageBox? Also, how do i use CFileDialog class?
The code i hv is:
CFileDialog filenewdlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT |OFN_HIDEREADONLY, "Part Files(*.asm)|*.sldasm||", this);
But on compiling, the error i get is
cannot convert parameter 5 from 'char[29]' to 'const unsigned short'
1) How do i correct this?
2) Is there anything else i need to know?
Best regards and thanks in advance...
|
|
|
|
|
If you are going to do a unicode project then all strings must begin with L eg. L"Part Files(*.asm)|*.sldasm||" to tell the compiler you want a wide string.
But I would recommend you read up on TCHAR, that way you can compile your program in both UNICODE and single byte mode.
I dont know any good unicode resource on the web, but if you are going to do a unicode project, then I recommend you read some books on the subject. Its a lot more to unicode than meets the eye.
Also here on codeproject is
http://www.codeproject.com/cpp/unicode.asp?target=unicode[^]
http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp[^]
Magnus
|
|
|
|
|
CListCtrl m_List ;<br />
m_List.ModifyStyle(0, LVS_LIST) ;<br />
<br />
CImageList ListImage ;<br />
HIMAGELIST hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1) ;<br />
ListImage.Attach(hList) ;<br />
<br />
CBitmap bmp ;<br />
bmp.LoadBitmap(IDB_BITMAP1) ;<br />
ListImage.Add(&bmp, RGB(255,0,255)) ; <br />
<br />
m_List.SetImageList(&ListImage, LVSIL_SMALL) ;<br />
<br />
<br />
LVITEM lvi ;<br />
CString strItem ; <br />
<br />
m_List.DeleteAllItems() ;<br />
<br />
for (int i=0; i<9; i++)<br />
{<br />
strItem.Format(_T("Item %i"), i) ;<br />
lvi.mask = LVIF_IMAGE | LVIF_TEXT ; <br />
lvi.iItem = i ;<br />
lvi.iSubItem = 0 ;<br />
lvi.pszText = (LPTSTR)(LPCTSTR)(strItem) ;<br />
lvi.iImage = i ;<br />
m_List.InsertItem(&lvi) ; <br />
m_List.SetItemData(i, i+100) ;<br />
}
Yes, this was the code I wrote for the CListCtrl object.
The Problem is it won't display the images in the list control.
Can anybody tell me what's wrong with the code.
Regards,
-The Phantom
|
|
|
|
|
Hi..
following problems:
i have got a project with dialogs with a lot of activeX elemts on it (the form elements from microsoft)
the program runs & compiles fine under WinNt4.0
when i run & compile the program under Win2k i have got the following program.
Before it jumps into "OnInitDialog" the Dialog is closed (e.g. PostNCDestroy is called)..
The error (difference) occured at this piece of code.
BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate,
CWnd* pParentWnd, HINSTANCE hInst)
{
....
m_nModalResult = -1;
m_nFlags |= WF_CONTINUEMODAL;
AfxHookWindowCreate(this);
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,
pParentWnd->GetSafeHwnd(), AfxDlgProc);
if (hWnd != NULL && !(m_nFlags & WF_CONTINUEMODAL))
{
::DestroyWindow(hWnd);
hWnd = NULL;
}
..
}
Any Ideas anyone ?
Thanks in advance,
Bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
When I've had dialogs failing to create, its (alomst) always because one of the child windows failed
to create. To check this, set the "no fail create" style of the dialog. This should make the dialog
appear, but with a gap. You'll have to make sure your OnInit routines don't try to set things on the
non-existent control.
Then investigate the non-appearance of that particular control.
I hope that helps a little.
Iain.
|
|
|
|
|
Thank you...
this really helped!
indeed it was a problem with a child window (a.k.a. control).. never heard of the "no fail create" (and i think it is funny that you have to set it to true that it creates the dialog when something fails.. )
thanks..
bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
I have a Dialog with progress bar and status bar.
System has to perform some processing on number of TXT files, those will be opened,processed and closed, by other function of another class.
UI has to be updated with name of file in the status bar and also progress bar has to be pisitioned according to the number of files processed.
I am using VC++, and Worker threads, updating a global structure with file name and count,
But the problem is UI is not getting updated, and Its Dialog based application.
Any suggesstions ?? Any tutorials are avilable on Threads, Events ...online
Thanks in advance
Warm Regards,
KKR
|
|
|
|
|