Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-12-2004, 06:03 PM   #1 (permalink)
Amaranthine
Registered User
 
Amaranthine's Avatar
 
Join Date: May 2004
Posts: 47
Amaranthine is on a distinguished road
Windows Programming Help

I'm fairly new to windows programming and am currently teaching myself MFC so I don't know the windows API at all.

My main area that you write in is based off of the CView class and I have a notepad type program right now. How do you get individual pieces out of the view? I found the
GetWindowText(LPTSTR lpszStringBuf, int nMaxCount) and the GetWindowTextLength() functions
but I only want one letter at a time. So how would I get one letter at a time out of the view and increment that point each time?
Amaranthine is offline   Reply With Quote
Old 05-13-2004, 03:11 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Store the text in a CString or a char* for example and parse through the string to lookup the character you are interesting in.

Otherwise, to stay within your code using GetWindowTextLength:
Code:
char* buffer =  NULL;
length = GetWindowTextLength(whatever_control_box); //Like Edit box.
 //Add one for the terminating character.
length++;
// Size the buffer to hold all the data;
buffer = new char[length]; 
//Fill the bufer with text
GetWindowText(whatever_control_box, buffer, length); 
// Now iterate through "buffer" your C++ way.
__________________

Last edited by Valmont; 05-13-2004 at 04:00 PM.
Valmont is offline   Reply With Quote
Old 05-13-2004, 08:46 PM   #3 (permalink)
Amaranthine
Registered User
 
Amaranthine's Avatar
 
Join Date: May 2004
Posts: 47
Amaranthine is on a distinguished road
thankyou very much, I face a new problem.
Code:
void CWinEncrypterDoc::OnOptionEncrypt() 
{
        CWinEncrypterView* aView = CWinEncrypterView::GetView();// get current view
	char* buffer = NULL;    // create holder for text
	int length = aView->GetWindowTextLength();    // get text length
	length++;	// add room for terminating character
	buffer = new char[length];	// set buffer equal to size of text in view
	CString encrypted;    // initialize encryption holding CString
	aView->GetWindowText(buffer,length);    // get the text and store in buffer
	// loop through and xor accordingly
	for(int i = 0; i < length; i++)
		encrypted += buffer[i] |= static_cast<char>(m_Seed);
	// output encrypted text
	CEncryptedDlg aDlg;
	aDlg.m_Encrypted = encrypted;    // set text to show to encrypted text
	aDlg.DoModal();    // show dialog with xored text
}
I wrote this program in assembly a while back, but it got the text out of a file and was a 16 bit program.
This one works kind-of, but when you try to "decrypt"(un-xor) the text by simply xoring it again with the same value it just spits out the same value, why?
Is there an error in my logic?

(GetView() is a function I made that returns a pointer to the current view)
Amaranthine is offline   Reply With Quote
Old 05-13-2004, 11:49 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
|= is not an XOR operator but an OR-Assignment operator.
^ is the XOR operator for bitwise manipulation.

Furthermore, I am not sure if your proggy still would work. You need to convert the individual characters to asci integer and then use the XOR for manipulation back and forth. That will work guaranteed. Obviously you have to convert the integers (wich are the ASCI numbers) back to asci characters and store it in a string variable.

Also make sure to convert m_seed to an integer first, if not already.
And when you don't need buffer anymore, make sure you free the memory with delete[]!
Observe the subscript ( [] ) operator! When you use new [...], delete with delete[ ] .
__________________
Valmont is offline   Reply With Quote
Old 05-14-2004, 12:48 PM   #5 (permalink)
Amaranthine
Registered User
 
Amaranthine's Avatar
 
Join Date: May 2004
Posts: 47
Amaranthine is on a distinguished road
Thanks, I had always thought that |= was the xor assignment, when I switched it over to ^= it worked correctly.

If you care to see, here are my two added/edited lines:
Code:
encrypted += buffer[i] ^= static_cast<char>(m_Seed);
delete[] buffer;
(thanks for reminding me to free up the space with delete[])
Now I can go through and search for possible optimizations.

Last edited by Amaranthine; 05-14-2004 at 03:10 PM.
Amaranthine is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison of Different Programming Languages Punch-M6.net All Other Coding Languages 23 04-19-2007 01:34 PM
Accessing the Windows desktop remotely bdl Windows 7 11-10-2004 07:39 AM
Microsoft probes Windows code leak redhead Code Newbie News 0 02-13-2004 12:41 AM
restoring windows mbr ashley Windows 4 02-27-2003 12:41 AM
Bloody Windows IE rendering sarah31 PHP 6 06-05-2002 07:31 PM


All times are GMT -8. The time now is 11:37 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting