|
sorry , i don't want the "\n", because it not readable
if there is a solution that present multile line is very good!
I love Programming
|
|
|
|
|
I'm afraid you are not in a position to write the language yourself, you have to live with the language as it exists. Best you can do is this:
#define NEWLINE \r\n
and then use NEWLINE, or something similar.
In any case, \n won't work, it's \r\n ( or \n\r, I forget ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
the solution as:
const string TEMPLATE =
"HELLO! \n\
IF YOU CAN HELP ME ,\n\
I WILL THANK YOU VERY MUCH!";
I love Programming
|
|
|
|
|
Do you want it to be multiline only in your source code
const string TEMPLATE = "These three string literals will be "
"concatenated and the result assigned "
"to TEMPLATE as a single string";
or do you want it to contain multiple lines
const string TEMPLATE = "These are the first,\r\nsecond,\r\nand third lines";
or both?
const string TEMPLATE = "These are the first,\r\n"
"second,\r\n"
"and third lines";
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
very good! what i need is the third solution , both the source code in multiline and the output! thank you! thanks all!
I love Programming
|
|
|
|
|
I want to create a CEdit as a child window of a CListCtrl when CListCtrl is si created and destroy it when CListCtrl is destroyed.
I declare a member var in CListCtrl like this, CEdit m_edit,
and use m_edit.Create(...) in CListCtrl's constructor or CListCtrl's OnCreate,
but it doesn't work, the m_edit.m_hWnd is 0.
|
|
|
|
|
It won't work in the list control constructor because you need to pass the list's hWnd to m_edit.Create and hWnd will be null at that point.
I think it should work in the list's OnCreate, though. Post some code to see how you are doing it...
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
in mylist.h
class CMyList:
{
private:
CEdit m_edit;
}
in mylist.cpp
int CMyList::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
edit.Create(WS_BORDER|ES_AUTOHSCROLL,CRect(0,0,1,1),this,0);
return 0;
}
|
|
|
|
|
I don't see anything obviously wrong, but the problem might be with using zero as the control id. Try using a non zero id.
As a reference, the example shown in the documentation is as follows:
Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
CRect(10, 10, 100, 100), this, 1);
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I edit a program that write by my supervisor and it was a server source code.
After I edit, I found out three error. Can anybody solve it?
#include "stdafx.h"
#define DEFAULT_TCPPORT 1000;
typedef struct
{
SOCKET Skt;
SOCKADDR_IN AddrFrom;
int nAddrFromLen;
LPVOID ParamPointer;
}SOCKETDATA;
SOCKET ServerSkt;
SOCKET eServerSkt;
CString ServerStatus="Waiting for Request(s)....";
CString PortStatus="Starting TCP/IP Services.";
long SocketClosedDelay=DEFAULT_DELAY;
UINT ListenThread(LPVOID lParam)
{
HANDLE hThread;
SOCKADDR_IN SktAddr;
char szMessage[300];
ServerSkt = socket ( AF_INET, SOCK_STREAM, 0 );
if ( ServerSkt == INVALID_SOCKET )
{
printf("Error INVALID_SOCKET 1\n");
}
else
{
SktAddr.sin_family=AF_INET;
SktAddr.sin_port=htons(6000);
SktAddr.sin_addr.s_addr=htonl("127.0.0.1");
if ( bind ( ServerSkt, ( LPSOCKADDR ) &SktAddr, sizeof ( SktAddr ) ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 2\n");
}
else
{
if ( listen ( ServerSkt, SOMAXCONN ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 3\n");
}
else
{
return 0;
}
}
}
return 0;
}
UINT AcceptThread ( LPVOID lParam )
{
SOCKADDR_IN AddrFrom;
int nAddrFromLen = sizeof ( AddrFrom );
SOCKETDATA* psktData;
HANDLE hThread;
char szMessage[300];
while (hHeap!=NULL)
{
psktData -> Skt = accept ( ServerSkt, ( LPSOCKADDR ) &AddrFrom, &nAddrFromLen );
if ( psktData -> Skt == INVALID_SOCKET )
{
printf("Error INVALID_SOCKET 4\n");
HeapFree ( hHeap, 0, psktData ); break;
}
psktData -> AddrFrom = AddrFrom;
psktData -> nAddrFromLen = nAddrFromLen;
psktData -> ParamPointer = lParam;
}
return 0;
}
UINT ClientThread ( LPVOID lParam )
{
SOCKETDATA* psktClient = ( SOCKETDATA* ) lParam;
SOCKET MySkt = psktClient -> Skt;
LPVOID ParamPointer = psktClient ->ParamPointer;
SOCKADDR_IN MyAddrFrom = psktClient -> AddrFrom;
int nMyAddrFromLen = psktClient -> nAddrFromLen;
IN_ADDR InFrom;
long nBytesRecv;
long nBytesSent;
char ReceivedData [400];
char ReceivedDataP[400];
char szMessage[300];
char RequestStr [400];
char RespondStr [400];
char RespondStrA[400];
long Count1;
long Count2;
long i=0, j=0;
BOOL DataRequest=FALSE;
BOOL S;
HeapFree ( hHeap, 0, psktClient );
nBytesRecv = recv ( MySkt, ReceivedData, sizeof(ReceivedData), 0 );
if (nBytesRecv==SOCKET_ERROR)
{
printf("Error INVALID_SOCKET 5\n");
closesocket ( MySkt );
}
else
{
DataRequest=TRUE;
ReceivedData[nBytesRecv]=NULL;
for(i; i<nbytesrecv; i++)
="" {
="" if(((receiveddata[i]="" &="" 0xf0)="" ^="" 0x00="" !="0x00)" &&="" ((receiveddata[i]="" 0x10="" (receiveddata[i]="" 0x80="" 0x90=""
="" 0xa0="" 0xb0="" 0xc0="" 0xd0="" 0xe0="" 0xf0="" if(receiveddata[i]!="0x20)
" receiveddatap[j]="ReceivedData[i];
" j++;
="" }
="" }
="" memcpy="" (="" &infrom,="" &myaddrfrom.sin_addr.s_addr,="" 4="" );
="" if(datarequest="=TRUE)
" wsprintf(requeststr,="" "%s;",="" inet_ntoa="" (infrom));
="" strcat="" (requeststr,="" receiveddatap);
="" strcpy(respondstra,="" cachedatapop(receiveddatap));
="" if(strcmp(respondstra,="" "null")!="0)
" cachehit="TRUE;
" if(cachehit="=FALSE)
" waitforsingleobject(requestqempty,="" infinite);
="" s="RequestStringPush(RequestStr);
" releasesemaphore(requestqfull,="" 1,="" &count1);
="" while(s="=FALSE)
" sleep="" (30);
="" &count1);
="" }=""
="" "%s",="" waitforsingleobject(respondqfull,="" infinite);="" strcpy(respondstr,="" respondstringextract(requeststr));
="" releasesemaphore(respondqempty,="" &count2);
="" while(strcmp(respondstr,="" "null")="=0)
" if(debugsession="=TRUE)
" writerespondlog(respondstr);
="" nbytessent="send" (myskt,="" respondstr,="" lstrlen(respondstr),="" 0);
="" if(nbytessent="=SOCKET_ERROR)
" wsprintf(szmessage,="" "send()="" error.="" unable="" to="" send="" respond="" packet="" %s="" -="" data="" discarded.",="" writesyslog(szmessage);
="" serverstatus="szMessage;" ::sendmessage((hwnd)="" parampointer,="" wm_timer,="" (wparam)="" 25,="" (lparam)="" 0);
="" sleep(socketcloseddelay);
="" closesocket="" (myskt);
="" writetocache(receiveddatap,="" respondstr);
="" wsprintf(respondstr,="" strcat(respondstr,="" respondstra);
="" (myskt);
="" return="" 0;
}
uint="" closeconnection(lpvoid="" lparam)
{
="" char="" szmessage[300];
="" if(serverskt="" (serverskt);
="" if(eserverskt="" (eserverskt);
="" "(closeconnection)="" all="" services="" stopped="" and="" connections="" closed.");
="" 0;
}
uint="" exitlistenthread(lpvoid="" lparam)=""
{
="" handle="" hthread;
="" sockaddr_in="" sktaddr;
="" "(exitlistenthread)="" starting="" tcp="" ip="" initialisations.");
="" eserverskt="socket" af_inet,="" sock_stream,="" 0="" );="" if="" invalid_socket="" )
="" socket()="" create="" server="" socket.");
="" writesyslog(szmessage);
="" else
="" sktaddr.sin_family="AF_INET;
" sktaddr.sin_port="htons(6000);
" sktaddr.sin_addr.s_addr="htonl(INADDR_ANY);
" bind="" eserverskt,="" lpsockaddr="" )="" &sktaddr,="" sizeof="" sktaddr="" socket_error="" printf("error="" 7\n");
="" socket="" binding="" completed="" successfully.");
="" listen="" somaxconn="" 8\n");
="" listening="" stage="" hthread="AfxBeginThread" (exitacceptthread,lparam,thread_priority_normal);
="" null="" 4\n");
="" else="" {="" 0;
="" exitacceptthread="" lpvoid="" lparam="" )
{
="" addrfrom;
="" int="" naddrfromlen="sizeof" addrfrom="" socketdata*="" psktdata;
="" "(exitacceptthread)="" begining="" connection="" accepting="" stage.");
="" eheap="GetProcessHeap();
" if(eheap="=NULL)
" getprocessheap()="" request="" for="" system="" heap.");
="" while="" (eheap!="NULL)
" {
="" psktdata="(" heapalloc="" eheap,="" 0,="" socketdata="" );
="" heapalloc()="" allocate="" memory.");
="" break;
=""> Skt = accept ( eServerSkt, ( LPSOCKADDR ) &AddrFrom, &nAddrFromLen );
if ( psktData -> Skt == INVALID_SOCKET )
{
wsprintf(szMessage, "(ExitAcceptThread) - accept() Error. Server Unable to Accept Connection Request.");
WriteSysLog(szMessage);
HeapFree ( eHeap, 0, psktData );
break;
}
psktData -> AddrFrom = AddrFrom;
psktData -> nAddrFromLen = nAddrFromLen;
psktData -> ParamPointer = lParam;
hThread = AfxBeginThread ( ( AFX_THREADPROC ) ExitClientThread, ( LPVOID ) psktData, THREAD_PRIORITY_NORMAL, 0, 0, NULL );
if ( hThread == NULL )
{
wsprintf(szMessage, "(ExitAcceptThread) - AfxBeginThread() Error. Unable to Create ExitClientThread() Thread.");
WriteSysLog(szMessage);
HeapFree ( eHeap, 0, psktData );
closesocket ( psktData -> Skt );
break;
}
}
return 0;
}
UINT ExitClientThread ( LPVOID lParam )
{
SOCKETDATA* psktClient = ( SOCKETDATA* ) lParam;
SOCKET MySkt = psktClient -> Skt;
LPVOID ParamPointer = psktClient ->ParamPointer;
SOCKADDR_IN MyAddrFrom = psktClient -> AddrFrom;
int nMyAddrFromLen = psktClient -> nAddrFromLen;
IN_ADDR InFrom;
long nBytesRecv;
char ReceivedData [500];
char ReceivedDataP[500];
char RequestStr[600];
char szMessage[300];
long i=0, j=0;
BOOL ShutdownRequest=FALSE;
HeapFree ( eHeap, 0, psktClient );
nBytesRecv = recv ( MySkt, ReceivedData, sizeof(ReceivedData), 0 );
Sleep(SocketClosedDelay);
closesocket ( MySkt );
if (nBytesRecv==SOCKET_ERROR)
{
wsprintf(szMessage, "(ExitClientThread) - recv() Error. Server Shutdown Request Ignored.");
WriteSysLog(szMessage);
}
else if (nBytesRecv==0)
{
wsprintf(szMessage, "(ExitClientThread) - recv() - 0 Byte Data Received. Server Shutdown Request Ignored.");
WriteSysLog(szMessage);
}
else if (nBytesRecv<10)
{
wsprintf(szMessage, "(ExitClientThread) - recv() - Corrupted Shutdown Request Packet Received - Discarded. Server Shutdown Request Ignored.");
WriteSysLog(szMessage);
}
else
{
ShutdownRequest=TRUE;
ReceivedData[nBytesRecv]=NULL;
for(i; i
|
|
|
|
|
It looks like CString is not defined. If you're not using MFC, why not use std::string ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
when I use std::string but got error below:
error C2653: 'std' : is not a class or namespace name
|
|
|
|
|
You also need to include headers for string, it's just easier to get there if your app is not using MFC.
#include <string>
using std::string;
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It accur more error. I think nevermind.
The program that I edit have AfxBeginThread but I don't want it. But I cant confirm whether it correct or not. Below is the ListenThread and I just disable the AfxBeginThread.
UINT ListenThread(LPVOID lParam)
{
HANDLE hThread;
SOCKADDR_IN SktAddr;
char szMessage[300];
ServerSkt = socket ( AF_INET, SOCK_STREAM, 0 );
if ( ServerSkt == INVALID_SOCKET )
{
printf("Error INVALID_SOCKET 1\n");
}
else
{
SktAddr.sin_family=AF_INET;
SktAddr.sin_port=htons(6000);
//SktAddr.sin_addr.s_addr=htonl(INADDR_ANY);
SktAddr.sin_addr.s_addr=htonl("127.0.0.1");
if ( bind ( ServerSkt, ( LPSOCKADDR ) &SktAddr, sizeof ( SktAddr ) ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 2\n");
}
else
{
if ( listen ( ServerSkt, SOMAXCONN ) == SOCKET_ERROR )
{
printf("Error INVALID_SOCKET 3\n");
}
else
{
/*hThread=AfxBeginThread (AcceptThread,lParam,THREAD_PRIORITY_NORMAL);
if ( hThread == NULL )
{
wsprintf(szMessage, "(ListenThread) - AfxBeginThread() Error. Unable to Create AcceptThread() Thread.");
WriteSysLog(szMessage);
}
else
{
wsprintf(szMessage, "(ListenThread) - AcceptThread() Thread Spinoff Completed Successfully.");
WriteSysLog(szMessage);
return 0;
}*/
}
}
return 0;
}
}
}
return 0;
}
The AfxBeginThread have a AcceptThread, how do I simplify it if I don't want the AfxBeginThread? Below is the AcceptThread code:
UINT AcceptThread ( LPVOID lParam )
{
SOCKADDR_IN AddrFrom;
int nAddrFromLen = sizeof ( AddrFrom );
SOCKETDATA* psktData;
HANDLE hThread;
char szMessage[300];
while (hHeap!=NULL)
{
psktData -> Skt = accept ( ServerSkt, ( LPSOCKADDR ) &AddrFrom, &nAddrFromLen );
if ( psktData -> Skt == INVALID_SOCKET )
psktData -> AddrFrom = AddrFrom;
psktData -> nAddrFromLen = nAddrFromLen;
psktData -> ParamPointer = lParam;
hThread = AfxBeginThread ( ( AFX_THREADPROC ) ClientThread, ( LPVOID ) psktData, THREAD_PRIORITY_NORMAL, 0, 0, NULL );
if ( hThread == NULL )
{
wsprintf(szMessage, "(AcceptThread) - AfxBeginThread() Error. Unable to Create ClientThread() Thread.");
WriteSysLog(szMessage);
HeapFree ( hHeap, 0, psktData );
closesocket ( psktData -> Skt );
break;
}
}
return 0;
}
|
|
|
|
|
In my app I need to right a function to search through all the files in a directory for a particular statement. Is there a way my program can retrieve a list of the files in a directory so that I can step through that list and open one at a time?
Danny
|
|
|
|
|
If you use MFC you might look at CFileFind
Cheers,
|
|
|
|
|
|
|
u can also use API FindFirstFile()AND
FindNextFile()
|
|
|
|
|
I am very new to using Internet Explorer MSHTML Controls, mostly developing my code by gleaning the web for useful code snippits. However, I have not been able to find anything that addresses the issue I am having. Hopefully somebody knows the answer to my question. I found DHTMLUI on this site, but it only has placeholders for the "SELECT ELement" code I seek.
I am programming using Visual C++ version 6.0.
I am running Internet Explorer 6.0.3790.1830 on OS Microsoft Windows Server 2003 Web Edition Service Pack 1.
Background:
I am trying to automate a web-based management interface to our company's product. My first step is to come up with a proof-of-concept that will demonstrate that I can control any of the DOm elements that I encounter. After much Googling I have been able to write a C++ program to navigate the Internet Explorer web-browser to the desired login page, parse that login page and input username/password to login, parse the various frames in the subsequent frames, (as a test) and automatically click on all anchor links in the frame that contains "navigation-related" links and see another frame display the various different pages.
Question:
Now I am trying to set values in things such as SELECT/OPTION elements, radio inputs, etc.
However, I am having trouble with the SELECT/OPTION and radio inputs. The problem is that there is an "onchange=<javascript_function>" in the SELECT and radio inputs. I have tried to select an option in various ways, and the visible browser does in fact show the Selected value in the GUI changes, but for some reason the onchange javascript function does not execute.
Does anybody know how to do what I am trying to do? How can I debug this issue? I feel that the "event" for onchange is not "firing". I read some user group posting (from another website) that made an off-handed reference to a possible bug in IE, but I would be surprised if that were true because I think I am doing something very basic.
FYI, here is the HTML that contains the example select/option item I am trying to control/automate via MSHTML C++:
10
25
50
100
All
Basically, it is supposed to refresh the screen with more items-per-page depending on what the user selects. When I manually do it with my mouse, it works fine. I just cannot seem to get it to do the ChangeRecPerPage() when I use IE MSHTML Controls. Here is a code excerpt of what I am doing in C++:
bool
Frame::SetOptionElement(IHTMLSelectElement*& prSelect, const char* pOptionName)
{
IHTMLOptionElement* ptr_option = NULL;
IDispatch* ptr_disp = NULL;
HRESULT hr;
long len = 0;
prSelect->get_length(&len);
// find and set the option value specified
for (int i=0; i < len; i++)
{
VARIANT var_index;
var_index.vt = VT_UINT;
var_index.lVal = i;
hr = prSelect->item(var_index, var_index, &ptr_disp);
if (FAILED(hr))
{
// error: could not get option item dispatcher
cerr << i << ") Could not get option item dispatcher " << hr << endl;
continue;
}
hr = ptr_disp->QueryInterface(IID_IHTMLOptionElement,(LPVOID*)&ptr_option);
if (FAILED(hr))
{
// error: could not get option item
cerr << i << ") Could not get option item" << hr << endl;
continue;
}
BSTR text;
ptr_option->get_text(&text);
CString text_str = text;
if(text_str.Find(pOptionName) >= 0)
{
cerr << "Found option named " << text_str << endl;
BSTR value;
hr = ptr_option->get_value(&value);
hr = prSelect->put_value(value);
/*
// Also attempted using put_selectedIndex with hard-coded index value.
// It did change the value shown (i.e. index 3 -> display "100"), but the
// displayed number of items per page remained.
long selected_index = 0;
hr = prSelect->get_selectedIndex(&selected_index);
long debug_selected_index = 3;
hr = prSelect->put_selectedIndex(debug_selected_index);
hr = prSelect->get_selectedIndex(&selected_index);
*/
return true;
}
}
return false;
}
|
|
|
|
|
The following is from MSDN documentation for onchange Event[^] (emphasis added):
Remarks
This event is fired when the contents are committed and not while the value is changing. For example, on a text box, this event is not fired while the user is typing, but rather when the user commits the change by leaving the text box that has focus. In addition, this event is executed before the code specified by onblur when the control is also losing the focus.
The onchange event does not fire when the selected option of the select object is changed programatically.
I've never worked with any of this, but I'd think you might be able to do what you want if, after changing the selection, you use IHTMLDocument4::createEventObject[^] to create an event, set the relevant properties for that event using the IHTMLEventObj Interface[^] (check the doc for the onchange Event[^] to see which properties are available for handlers), and finally use either IHTMLDocument4::fireEvent[^] or IHTMLElement3::fireEvent[^] to the fire the event yourself.
As a side note, I don't see in your code the Release calls for the COM interfaces you are acquiring. Consider using ATL's CComPtr[^] and CComQIPtr[^], which automatically handle that for you.
Hope that helps,
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Thanks for the information. It gives me more to try. I do have a follow-up question to you or anyone else based on your reply:
Is there a way to programmatically (C++) make the select element "lose focus" after setting its value? Would that cause the event to fire?
Any example code to create an event would also be helpful. I just recall I looked at the fireEvent interface but it was not readily apparent what to do. But I will look again.
Thanks again.
|
|
|
|
|
SureshMahanty wrote:
Is there a way to programmatically (C++) make the select element "lose focus" after setting its value?
To make it lose focus, I think you could make something else get it, and yes, I think that would be possible, but...
SureshMahanty wrote:
Would that cause the event to fire?
I don't think so.
SureshMahanty wrote:
Any example code to create an event would also be helpful.
As I said before, I've never worked with this so I'm afraid I can't offer any concrete example.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
Thanks Jose. I was actually posting the follow-up to anyone who may want to respond. I appreciate the info you have given already.
If anyone has pointers on how to use the fireEvent method to fire an onchange event for a particular SELECT Element, that would be much appreciated. Here is what the MSDN documentation says for fireEvent:
IHTMLDocument4::fireEvent Method Internet Development Index
Fires a specified event on the object.
Syntax
HRESULT fireEvent( BSTR bstrEventName,
VARIANT *pvarEventObject,
VARIANT_BOOL *pfCancelled
);
Parameters
bstrEventName
[in] BSTR that specifies the name of the event to fire.
pvarEventObject
[in] Pointer to a VARIANT that specifies the IHTMLEventObj
interface from which the event properties are obtained.
pfCancelled
[out, retval] VARIANT_BOOL that receives one of the
following values:
VARIANT_TRUE - Event fired successfully.
VARIANT_FALSE - Event was cancelled.
If I just want to fire the onchange event, does anybody have a clue what the parameters values should be?
Should bstrEventName literally be set to "onchange"?
How do I create an IHTMLEventObj for pVarEventObj and what would the "event properties" be? It must somehow include a "handle" to the specific DOM object (i.e. the specific SELECT element) or some sort of event "handler". I am just using those terms as a "lay person", rather than exact meanings.
Also, I am not sure how to get the IHTMLDocument4 object...I already have an IHTMLDocument2, do I just "redundantly" call queryInterface in the same way/context that I got the IHTMLDocument2 object, except query for IID_IHTMLDocument4?
BTW, I ordered "Programming Internet Explorer 5" and hopefully it will help with this question (whenever it arrives). But unfortunately, I need to try to push forward regardless of whether it arrives or is useful.
|
|
|
|
|