Your code is off. First of all, there is no need to call GlobalAlloc(). Regular malloc() works just fine. Also you need to call GetWindowText() to get the text.
Your code is off. First of all, there is no need to call GlobalAlloc(). Regular malloc() works just fine. Also you need to call GetWindowText() to get the text.
hM..whoops. a good point with the whole GetWindowText()..i had that originally in my code, but it was commented out so when i posted, i deleted it. lol but what do i store the window text in? like, what kind of variable? or how does that work? lol
also, my child windows have a title. doesn't GetWindowText() retrieve the title of a window?
Last edited by willc0de4food; 05-18-2005 at 08:26 AM.
Registered Linux User #380033. Be counted: http://counter.li.org
Yeah, GetWindowText() would just get the title text of a Child window. You need to pass the HWND of the window you want to get the text of (Like an EditBox) to GetWindowText().
The proper use of the function would look something like:
Code:TCHAR szText[1024]; HWND hwndEdit = GetDlgItem(hwnd,IDC_MYEDIT); if(hwndEdit) { GetWindowText(hwndEdit,szText,sizeof(szText)/sizeof(TCHAR)); }
ok, and then to modify the text entered i would modify szText? and then send that text back to the window?
// edit
yay ^_^ i got it to work. here's my code:now if i wanted to add a required password to decrypt.. how would i incorporate this? i was thinking either having a master password and then storing it in the same directory as the program or a folder inside that which contains the program, OR having a password to be entered for each save. however, this could be bad b/c if i put more then 1 password, i may not remember what pw i did for which file. but i think i want to first prompt the user to set a password if the password doesn't exist (the password existing in the file would be encrypted also). so any suggestions? lolCode:case ID_SHIBBY_ENCRYPT: { char algorithm[25] = "Az!By@Cx#Dw$Ev%Fu^Gt&Hs*"; int i; DWORD dwTextLength; dwTextLength = GetWindowTextLength(hwnd); if (dwTextLength <= 0) MessageBox(hwnd, "There is no text to encrypt.", "Error.", MB_OK | MB_ICONERROR); else if(dwTextLength > 0)// No need to bother if there's no text. { LPSTR pszText; pszText = (LPSTR)GlobalAlloc(GPTR, dwTextLength + 1); if (pszText == NULL) MessageBox(hwnd, "An error occured.\n\nWhoops!", "OOPs!", MB_OK | MB_ICONERROR); else if(pszText != NULL) { TCHAR szText[1024]; HWND hwndEdit = GetDlgItem(hwnd,IDC_CHILD_EDIT); DWORD txtLength; txtLength = GetWindowTextLength(hwndEdit); if(hwndEdit) { GetWindowText(hwndEdit,szText,sizeof(szText)/sizeof(TCHAR)); } MessageBox(hwnd, szText, "szText variable", MB_OK); if(szText != NULL) { for (i = 0; i <= txtLength; i++) { szText[i] = szText[i] ^ algorithm[i % 24]; } SetWindowText(hwndEdit, szText); } } } } break;
Last edited by willc0de4food; 05-18-2005 at 04:45 PM.
Registered Linux User #380033. Be counted: http://counter.li.org
Yep. Using the Message WM_SETTEXT, or by using an API. I forget which one; I don't like to use them unless necessary. It's probably SetWindowText() or similar. Of course, I would hope that you know this already.
would this code be better for my purposes:?Code:case ID_SHIBBY_ENCRYPT: { char algorithm[31] = "Az!By@Cx#Dw$Ev%Fu^Gt&Hs*Ir(Js)"; char* buf; int i, len; HWND hwndEdit = GetDlgItem(hwnd,IDC_CHILD_EDIT); len = GetWindowTextLength(hwndEdit); buf = (char*)GlobalAlloc(GPTR, len + 1); GetDlgItemText(hwnd, IDC_CHILD_EDIT, buf, len + 1); for (i = 0; i <= len; i++) { buf[i] = buf[i] ^ algorithm[i % 30]; } SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM)buf); } break;
i would assume so, because its shorter and i believe its more efficient but i'm just talking out of that which i am sitting on
also, i'm having a little trouble with decrypting the text after i encrypt. here's an example:the tabbed text was actually tabbed, but the post untabbed it.? loloriginal text: This is some text. This is text tabbed.
This is text on a new line.
Encrypted text: H1Y)0XP+Ae@>pN N!
Decrypted text: This is some text. This
Also, this text encrypts / decrypts perfectly:
This is some text. This is text spaced over 6 spaces.
This is text on a new line.
other times, the decrypted text will have some junk characters that are not readable. how do i fix this? :-[ please and thank you!
Last edited by willc0de4food; 05-18-2005 at 10:19 PM.
Registered Linux User #380033. Be counted: http://counter.li.org
Don't forget to check any memory allocs for fails and to free them when finished.
Use the text length in GetWindowtext() not the length +1
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
thanks one last thing.. how would i close all open child edit windows?
Registered Linux User #380033. Be counted: http://counter.li.org
Are these MDI child windows?
If so, do something like the following:
Code:BOOL CALLBACK CloseEnumProc(HWND hwnd, LPARAM lParam) { if(GetWindow(hwnd,GW_OWNER)) { /* Window is an icon title */ return TRUE; } /* Close the window */ SendMessage(hwnd,WM_CLOSE,0,0); return TRUE; } // .... EnumChildWindows(hwndClient, CloseEnumProc,0);
Registered Linux User #380033. Be counted: http://counter.li.org
:-D sweet.. i got it to work ^_^ i used your function but before the call to it, i had to declare hwndClient and i tried using the hwnd var i declared at the beginning of the function so i tried HWND hwndClient = GetDlgItem(hwnd, IDC_CHILD_EDIT); but obviously that didn't work.. but what DID work was:however, i have yet to resolve the whole "setting a password for decryption" problem.. i want to create a dialogbox that prompts the user to enter the password they would like to set. then i would like to take the password they create, encrypt it, maybe add some text to the beginning and end of it just to make it more secure, and then save it in the same folder as that which the program is being run in. I can do the whole file save / manipulation thing as I know C, but how would i create the dialog prompt and then get the text entered in the prompt?Code:HWND hwndClient = GetWindow(g_hMainWindow, GW_CHILD); EnumChildWindows(hwndClient, CloseEnumProc,0);
// edit
ok, i created the dialog and can get / manipulate the text. but i also need to store the length of the original string as i believe thats the reason i have having problems with decrypting the string in the beginning. so i want to take the length of the string and append it to the beginning of the encrypted string, but i've been running in to problems here (i think, i was pretty tired last night). but i'm at work so i have to go, just figured i'd update...
Last edited by willc0de4food; 05-20-2005 at 01:00 PM.
Registered Linux User #380033. Be counted: http://counter.li.org