|
i am a collegestudent in China,i does a hard work to learn vc++ well,now I encountered cwindowdc but i have no ideas about it ,please give me some detail device or example ,thanks alot!
besides,i want to know how to learn vc++ very well.
|
|
|
|
|
Hi,
I need to implement Undo/Redo feature in a simple Notepad application. Is this task involve SaveDC() and RestoreDC() APIs??
Note: Solution should only be in Win32 APIs. No MFC please. (It is the requirement.)
|
|
|
|
|
ummmmm think about it for a minute
savedc() etc is dealing with the device context u have drawn into ... ie, a grafics surface in effect
this has NOTHING to do with the text u are displaying which should come from ur document in the doc / view model
when a user makes an edit to the document u need to save the changes to the doc data and be able to restore / remove those changes
"there is no spoon" biz stuff about me
|
|
|
|
|
i need a function the removes a char array from another. here is the description:
textString = new char[ strlen(ptr) + 1 ]
void remove(int startPos, int numToRemove);
// Removes the indicated number of characters from the text,
// starting at the indicated position. This involves allocating
// a new (smaller) array and copying characters from the original
// array into it, not including the ones to be removed.
the remove function removes characters from the array given an int staring position and an into number to remove
for example:
char* textString[] = "I like stinky cheese";
remove(7,7);
cout<<textString;
would yield: "I like cheese"
|
|
|
|
|
We are not here to do your homework. Shows us what you have done so far and then we might be able to help you.
|
|
|
|
|
ive been working on this forever. this is all i came up with:
void text::remove(int startPos, int numToRemove) {
char* temp = new char[strlen(textString) - numToRemove];
for (int i = 0; i <strlen(textString); i++) {
if (i != startPos) {
temp[i] = textString[i];
}
else {
i += (numToRemove -1);
}
}
textString = temp;
}
it doesnt work though. it seems to remove everything after startPos regardless of numToRemove
|
|
|
|
|
nevermind. i got it. this code seems to work:
void text::remove(int startPos, int numToRemove) {
char* temp = new char[strlen(textString) - numToRemove];
for (int i = 0; i <strlen(textString); i++) {
if (i < startPos) {
temp[i] = textString[i];
}
else if (i>startPos) {
temp[i-numToRemove] = textString[i];
}
else {
i += (numToRemove -1);
}
}
textString = temp;
}
|
|
|
|
|
Don't forget to delete temp !
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
I am creating a dialog-based application using C++, MFC.
This application will need to open a socket and retrieve
data from a socket, assign it to a buffer and need to process
the buffer after that.
The application is working fine but while it is retrieving
the data and processing on it, the GUI seems "hang" and not
responsive!. So I wanted to create a worker thread to taking
care of the retrieving and processing the data, but I am not
familiar much with thread.
So do you have any simple window applications/samples that creates a
worker thread that is taking care of the processing part while
the GUI is still "active", responsive to user's action?
Currently, I have a wrapper class derived from CAsynSocket that
takes care of connecting and getting the data buffer from the
socket. Then when I have a complete data buffer, I notify the
dialog using a callback function.
So in the main dialog, I have:
CMainDialog::OnReceiveCompleteMessage( BYTE * pbData, int len)
And this method will be called everytime there is a new complete
data buffer. I have to process these messages so within this
method, I call "ProcessingMessage()". It works OK so far but
after it is running for while, if I bring up some other applications,
and then click on the icon to bring this dialog back up, it seems
"freeze" for awhile, and takes some time to refresh and display
the whole dialog..
So I want to create worker thread so that everytime the
OnReceiveCompleteMessage() is called, this thread will do the
processing part background and the GUI is still "active". Is it
OK if within the OnReceiveCompleteMessage(), I have the code:
m_hRunThread = ::CreateThread(NULL, 0, RunThreadFunc,
(LPVOID) this, 0, &dwThreadId);
so that each time the function is called, it will create a new
thread to do the processing (with same m_hRunThread handle but
different dwThreadId)? Within the RunThreadFunc(), I call the
ProcessingMessage().
I tried but it didn't work. So please help!
Thanks a lot!!!
TQD
|
|
|
|
|
tqdo wrote:
The application is working fine but while it is retrieving
the data and processing on it, the GUI seems "hang"
tqdo wrote:
Currently, I have a wrapper class derived from CAsynSocket that
takes care of connecting and getting the data buffer from the
socket.
The two statements contradict each other. CAsyncSocket is used asynchronously, that is in a non blocking manner. No hanging should be possible then.
If you decided to use multiple threads I would recommend you to use syncronous socket - just as you describe- in your worker thread.
Worker threads are really easy to use:
1. Create a global function wich will execute your communication task (if you insist on using dialog member functions for this purpose then create a static member of your dialog)
2. From your dialog call AfxBeginThread which will launch your worker thread (i.e. the function from 1./
3.AfxBeginThread returns immediately after you called it so your app reserves responsiveness
while your worker thread "works".
Peter Molnar
|
|
|
|
|
Hiya I have an struct with a max of 6 entries
i.e
struct my_test
{
char* name;
char* surname;
etc.
}test[6]
and the elements are filled in as so:
[0] = name
[1] = surname
[2] = age
[3] = occupation and so on.
What I need to do is shift all the elements one to the right so:
[0] = (used for a new unique I.D)
[1] = name
[2] = surname
[3] = occupation and so on.
How do I do this?? Have tried to do this but the first element is fine but copies the second element to ALL remaining elements!!
Thanks for any help.
|
|
|
|
|
IrishSonic wrote:
copies the second element to ALL remaining elements!!
You're copying the wrong direction. You copy element 0 to element 1, then element 1 to 2, then 2 to 3... so you end up with the original element 0 copied over and over. Copy from the upper bound down.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Laugh it up, fuzzball.
|
|
|
|
|
i need a method that inserts a string into a char array at a certain point. i need code to fufill this description:
char* textString[] = "I like cheese";
void insert(char* ptr, int startPos);
// Inserts a new string into the current text starting at the
// position indicated by the value of startPos. This involves
// allocating a new array and copying characters from the original
// array into it, as well as characters pointed to by ptr.
where textString is the array you were inserting it to. startPos is where you want to put it within the string. and ptr is a substring
for example
insert(" stinky", 6);
cout<<textString;
would look like: I like stinky cheese
you can use anything from the cstring library but no vectors
|
|
|
|
|
<code>
char* insert(char *szString, char* szInsert, int nPos) {
if(!szString) return NULL;
if(!szInsert) return NULL;
if(nPos<=0) return NULL;
if(nPos>strlen(szString) return NULL; // or fill it with spaces ?!?!?!
char *pBuf=(char*)malloc(strlen(szString)+strlen(szInsert)+1);
if(!pBuf) return NULL;
strncpy(pBuf,szString,nPos); // insert the string
strncpy(pBuf+nPos,szInsert,strlen(szInsert)); // we don't copy the '\0'
strcpy(pBuf+nPos+strlen(szInsert), szString+nPos); // the '\0' automatically at the end
free(szString);
szString=NULL;
return pBuf;
</code>
--------
I don't know if this works... I just wrote it... I tlooks good to me...
|
|
|
|
|
Hi, i need to get the port number from a SOCKADDR_IN structure but for some reason i always get a wrong number. Either the number is too big (out of the valid port range) or it is some weird number that cant be the real port since the port number is known to me. This is my code:
struct sockaddr_in * sin;
sin = (struct sockaddr_in*)name->sa_data;
char sport[10];
memset(sport,0,10);
unsigned short int port = ntohs(sin->sin_port);
sprintf(sport,"%u",&port);
name is of type struct sockaddr* and points to a valid sockaddr structure. For some reason i never get the right port number in sport. I can't understand why. I also tried "%i" in the format string for sprintf().
Kuniva
--------------------------------------------
|
|
|
|
|
Kuniva wrote:
sprintf(sport,"%u",&port);
Remove that & and you'll be set. You're outputting the address of the variable port , not its contents.
The debugger should have shown you that the value in port was correct.
|
|
|
|
|
Thanks a lot! it works now
I also had to change:
struct sockaddr_in * sin;
sin = (struct sockaddr_in*)name->data;
to
struct sockaddr_in * sin;
sin = (struct sockaddr_in*)name;
Thanks!
Kuniva
--------------------------------------------
|
|
|
|
|
I don't know what I'm doing wrong here but I'm getting some strange results from TrimLeft(). Take the following code for example:
CString m_Anchorage = _T("C:\\Project\\Final\\Data\\Anchorage, AK"));
CString m_Fairbanks = _T("C:\\Project\\Final\\Data\\Fairbanks, AK"));
CString sAnchorage = m_Anchorage;
CString sFairbanks = m_Fairbanks;
sAnchorage.TrimLeft(_T("C:\\Project\\Final\\Data\\"));
sFairbanks.TrimLeft(_T("C:\\Project\\Final\\Data\\"));
MessageBox(sAnchorage,NULL,MB_OK);
MessageBox(sFairbanks,NULL,MB_OK);
The code doesn't really look like this, just showing it this way for simplicity's sake. In this case, "sAnchorage" will return properly, "Anchorage, AK". However, "sFairbanks" will return "rbanks, AK". As a matter of fact, anything that starts with the letter "F" is causing this.
Anyone know why?
Thanks in advance,
Wolf
|
|
|
|
|
Sorry, nevermind. I get it.

|
|
|
|
|
Still have a question though... I thought CString::Left() would work, but it's not working the way I expected either.
So, how do I trim off the first part of this string, to get only the city and state? Better yet, how can I get the current directory, pass that to a CString, and then strip that value out of another string, as per the example above?
Thanks,
Wolf
|
|
|
|
|
I have been single stepping through this code and still have not found out what is happening. I have learned that if you substiture A in Anchorage with a printf white space formating character (n, t, f) then the same problem occurs.
I recommend that you write your own TrimLeft() routine, it is easy to do.
Good luck!
Oh and thanks for the puzzler. I'll find a solution eventualy, but not today.
INTP
|
|
|
|
|
Thanks for your response. I've got it now. TrimLeft() (after a little RTFM'ing) removes ALL characters from the left that you specify, not the string as it appears. So, what I did was subtract the length of the current directory from the length of the entire string, and then use that number to extract only the data I wanted from the string, like so:
CString m_Fairbanks = _T("C:\\Project\\Final\\Data\\Fairbanks, AK");
int FairbanksLength = strlen(m_Fairbanks);
TCHAR SourcePath[MAX_PATH+1] = {0};
GetCurrentDirectory(MAX_PATH,SourcePath);
int DirLength = strlen(SourcePath);
int DataLength = FairbanksLength - DirLength;
CString string = m_Fairbanks.Right(DataLength-1);
MessageBox(string,NULL,MB_OK);
I'm actually loading the data from an XML file and overriding an OnBeforeNavigate2() message from a WebBrowser Control, so it thinks it's a URL (VARIANT) and adding the local path to the element, which isn't what I wanted. It seems to be working now though.
Thanks again,
Wolf
|
|
|
|
|
I think PathStripPath will do what you want.
The PathXxx APIs are very powerful.
|
|
|
|
|
Greetings,
Please bare with me as I am rather new to Microsoft Visual C++ and haven't coded in C in many years.
I have searched for as many examples as I was able to find but nothing has helped me understand my needs at this point in time.
I have an application that has the following requirements:
NOTE: The coding in done in NON MFC C code using Microsoft Visual C++. (That was a requirement handed down to me.)
1. Read in a specially delimited file and display it's contents, one row per each delimited section. (This is done and works perfectly)
2. Form all those rows, pick one, a bunch of them, or none.
3. When the print button is clickes, take those choices (in the case of none, all the rows are printed) and print the information to a special Barcode Printer.
Now my problem is this.
Although I have found many examples of printing and can get data printed to our lazer printer, I am having problems getting it to line up exactly as I wish it to be. I am using the GDI TEXTOUT functionality to print.
Should I be using something different like creating a Bitmap and printing it that way? If so then I am in need of help on how to actually create a bitmap from scratch programatically.
I have searched and all the examples I was able to find only deals with loading and existing bitmap and massaging it in different ways to get different effects.
Also, I wish to be able to print to these printers using the windows drivers instead of specifically code for the printer.
Any help on this problem would be wonderfully greatful and please bare with me if I ask a few stupid questions along the way. I am finding it confusing at the moment and when the light clicks on, I might actually get somewhere. This is pretty much the last thing left to complete the project.
Tagni.
|
|
|
|
|
"NON MFC C code using" sounds like use ANSI C coding to me.
If you do not have a copy of Charles Petzod "Programming Windows" around then get it (a must have, all C).
1) Should I be using something different like creating a Bitmap and printing it that way?
Answer: no (normaly)
Last resort:
Even though you are not using MFC, it may be possible to take advantage of it via examination. Example: Load up WordPad example program and single step through the printing porcedure, to see how MFC is handling the printing.
Do not forget MFC is mostly a wrapper around C code, and C++ is a supper set of C.
:(I hope this at least helps a little.
INTP
|
|
|
|
|