04-24-2010, 08:06 AM
(This post was last modified: 04-24-2010, 08:13 AM by blow_fly98.)
Here's the deal:
I'm try to set the text of a multiline textbox to something. I know how to do that.
Here's the problem:
The text that's displayed in the textbox is missing all of the \r\n's.
What's going wrong?!?!?!
The line that stuffs up is:
If you have a brain, you have probably figured what this program was going to be...
I'm try to set the text of a multiline textbox to something. I know how to do that.
Here's the problem:
The text that's displayed in the textbox is missing all of the \r\n's.
What's going wrong?!?!?!
The line that stuffs up is:
Code:
SetDlgItemTextA(hwnd, ID_MAIN_EDIT, result);
Source Code (Click to View)
C++-Code:
/* * HelloWorld.cpp * * Created on: 17/04/2010 * Author: You DON'T need to know my name */ #include <iostream> #include <fstream> #include <windows.h> #define ID_MAIN_EDIT 101 #define ID_FILE_NEW 102 #define ID_FILE_OPEN 103 #define ID_FILE_SAVE 104 #define ID_FILE_SAVE_AS 105 const char g_szClassName[] = "DCPad"; const char encKey[] = "odBearBecauseHeIsVeryGoodSiuHungIsAGo"; //37 characters int offset = 123; HWND hEdit; char* Decrypt(char* bytes); char* DecryptOffset(char* bytes); using namespace std; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: { //Creating the textbox hEdit = CreateWindowEx(WS_EX_WINDOWEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 0, 0, 100, 100, hwnd, (HMENU) ID_MAIN_EDIT, GetModuleHandle(NULL), NULL); if (hEdit == NULL) MessageBox(hwnd, "Could not create textbox.", "Error", MB_OK | MB_ICONERROR); HFONT hFont = CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, TEXT("Courier New")); SendMessage(hEdit, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(FALSE, 0)); //Setting the font //Creating the menu HMENU hMenu = CreateMenu(); HMENU hSubMenus; hSubMenus = CreateMenu(); //File menu AppendMenu(hSubMenus, MF_STRING, ID_FILE_NEW, "&New\tCtrl+N"); AppendMenu(hSubMenus, MF_STRING, ID_FILE_OPEN, "&Open...\tCtrl+O"); AppendMenu(hSubMenus, MF_STRING, ID_FILE_SAVE, "&Save\tCtrl+S"); AppendMenu(hSubMenus, MF_STRING, ID_FILE_SAVE_AS, "Save &As...\tCtrl+Shift+S"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT) hSubMenus, "&File"); SetMenu(hwnd, hMenu); } break; case WM_COMMAND: { switch (LOWORD(wParam)) { case ID_FILE_NEW: { } break; case ID_FILE_OPEN: { OPENFILENAME FileDialog; char szFileName[MAX_PATH] = ""; ZeroMemory(&FileDialog, sizeof(FileDialog)); FileDialog.lStructSize = sizeof(FileDialog); // SEE NOTE BELOW FileDialog.hwndOwner = hwnd; FileDialog.lpstrFilter = "LF2 DAT Files (*.dat)\0*.dat\0Text Documents (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; FileDialog.lpstrFile = szFileName; FileDialog.nMaxFile = MAX_PATH; FileDialog.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; FileDialog.lpstrDefExt = "dat"; if (GetOpenFileName(&FileDialog)) { ifstream input; input.open(szFileName); if (input.is_open()) { //Get the length of the file input.seekg(0, ios::end); int length = input.tellg(); input.seekg(0, ios::beg); //Read file into memory char* bytes = new char[length]; input.read(bytes, (streamsize) length); char* result = DecryptOffset(bytes); SetDlgItemTextA(hwnd, ID_MAIN_EDIT, result); // <- Where it stuffs up //The thing is, the 'result' variable actually has all the \r\n's, but when I try to set the textbox's text, //it stuffs up. } } } break; } } break; case WM_SIZE: { RECT rcClient; GetClientRect(hwnd, &rcClient); SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; //Step 1: Registering the Window Class wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if (!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } // Step 2: Creating the Window hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "DCPad", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 400, NULL, NULL, hInstance, NULL); if (hwnd == NULL) { MessageBox(NULL, "Error!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); // Step 3: The Message Loop while (GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } char* Decrypt(char* bytes) { int length = strlen(bytes); char* result = new char[length]; unsigned int keyindex = 0; for (int i = 0; i < length; i++) { if (keyindex >= strlen(encKey)) keyindex = 0; result[i] = (bytes[i] - encKey[keyindex]); keyindex++; } return result; } char* DecryptOffset(char* bytes) { int length = strlen(bytes); if (length <= offset) return bytes; else { char* input = new char[length - offset]; memmove(input, bytes + offset, length - offset); return Decrypt(input); } } |
blow_fly98 edited this post 04-24-2010 08:14 AM because: |
Oh look, I'm moderating myself. No seriously. I need help. |
Hiding users' signatures and avatars was the best decision ever.
| Avatar made by Alectric |
4ye 6anDy (Click to View)
hey blow :P ~ Bamboori
can I call ya koalafly? ~ Phil
Pogofly - Simoneon
k0a1af1y, looks much more stylish ~ Blue Phoenix
So hey, blow, say something! - Simoneon
Quack? ~ blow_fly98
Hi blow ~Ramond
So... is it decided that we call him "blow"? ~ Blue Phoenix
No. ~ blow_fly98
But blow, all the members now will follow us because of this convo. You're ruined!!! - Simoneon
Meh. But I'll leave this convo here anyway. ~ blow_fly98
meh koala is much more awesome so I will stick to that ~ Phil
Wait, what? Koalas can edit profiles? - Simoneon
lol, seems that i started a long discussion :P ~ Bamboori
You did, indeed. I wonder who will exceed the sig-limit... ~ Blue Phoenix
Please don't trash this. It's good eye-candy. ~ blow_fly98
koala has spoken and so shall it be =) ~ Phil
there're some html here, and bla bla bla, so I think I might exceed it. Period - Simoneon
WHY THE SPOILER?! ~ Blue Phoenix
didn't you spoiler the conversation yourself? ~ Bamboori
BLOW BLOW!!! YOU FORGOT TO WRITE NAKATO IN 'WE'RE WATCHING YOU'!!!!! - Simoneon
To0 8ad. H4 D045n't d0 any MoDdin9 at A11!!!!!!! ~ blow_fly98
Evil Sonidow does, eh? - Simoneon
Of course. Just n0t v4ry 0ft4n. ~ blow_fly98
WHY THE 1337-SPEAK?! ~ Blue Phoenix
Because I am a KOALA!!! ~ blow_fly98
To be honest, I thought they use Eucalyptus-Speal..........
......
......
D: - Simoneon
Noez, Simon forgot to close his notice! ~ Blue Phoenix
oh no its the end of the world! *panic* ~ Bamboori
Gzz Hizz Fz Mzzz
Anyone got a Eucalyptus-speak interpreter?
And did you know that a user can have more than 4 images in their signature if we edit it for them? Or am I just the last one to find out?
~ blow_fly98
OMG spoilers in spoilers! ~ Bamboori
OMG offtopic in offtopic! - Simoneon
OH HAI GUYZ, i didnt you see you thar :P ~ Alectric
Now, I seriously need to be a part of this. ~ SirFrog
Wasn't there something about childish mods editing signatures lately? ~ Reaper
What?!?! Where was it?!?!?! ~ blow_fly98
DO YOU HAVE SUGAR?! - Simoneon
I heard if you edit someone's signature enough, your profile automatically is set to Admin status. BP told me. ~ Alectric
then let's do this! ~ Bamboori
Just because I don't go around checking every single post and editing signatures doesn't mean that I don't mod here. I just don't check posts that aren't reported. ~ Evil Sonidow
Seriously. We should encourage people to start reporting more :/ - Simoneon
EvErYoNe'S pOsTeD hErE eXcEpT mH.
Hey, maybe we could report every single post just so ES could check them. ~ blow_fly98
You know, that's a hell lot of work. What about a rule that everyone has to report at least one post whenever he logs in? Or an auto-report function? ~ Reaper
I liked the report-part until we got to the point of an auto-report function. That's something that requires work --> No. ~ Blue Phoenix
Finally, I get to see some invisible users. *sniggers* ~ blow_fly98
Oh, i came back. Well, since im already here, i may as well shoot bees ~ Alectric
You know, the ducks are watching. Always watching... ~ SirFrog
Hmm, I think, Lauli is about to climax due to the awesomeness of this color-wall ~ Blue Phoenix
can I call ya koalafly? ~ Phil
Pogofly - Simoneon
k0a1af1y, looks much more stylish ~ Blue Phoenix
So hey, blow, say something! - Simoneon
Quack? ~ blow_fly98
Hi blow ~Ramond
So... is it decided that we call him "blow"? ~ Blue Phoenix
No. ~ blow_fly98
But blow, all the members now will follow us because of this convo. You're ruined!!! - Simoneon
Meh. But I'll leave this convo here anyway. ~ blow_fly98
meh koala is much more awesome so I will stick to that ~ Phil
Wait, what? Koalas can edit profiles? - Simoneon
lol, seems that i started a long discussion :P ~ Bamboori
You did, indeed. I wonder who will exceed the sig-limit... ~ Blue Phoenix
Please don't trash this. It's good eye-candy. ~ blow_fly98
koala has spoken and so shall it be =) ~ Phil
there're some html here, and bla bla bla, so I think I might exceed it. Period - Simoneon
WHY THE SPOILER?! ~ Blue Phoenix
didn't you spoiler the conversation yourself? ~ Bamboori
BLOW BLOW!!! YOU FORGOT TO WRITE NAKATO IN 'WE'RE WATCHING YOU'!!!!! - Simoneon
To0 8ad. H4 D045n't d0 any MoDdin9 at A11!!!!!!! ~ blow_fly98
Evil Sonidow does, eh? - Simoneon
Of course. Just n0t v4ry 0ft4n. ~ blow_fly98
WHY THE 1337-SPEAK?! ~ Blue Phoenix
Because I am a KOALA!!! ~ blow_fly98
To be honest, I thought they use Eucalyptus-Speal..........
......
......
D: - Simoneon
Noez, Simon forgot to close his notice! ~ Blue Phoenix
oh no its the end of the world! *panic* ~ Bamboori
Gzz Hizz Fz Mzzz
Anyone got a Eucalyptus-speak interpreter?
And did you know that a user can have more than 4 images in their signature if we edit it for them? Or am I just the last one to find out?
~ blow_fly98
OMG spoilers in spoilers! ~ Bamboori
OMG offtopic in offtopic! - Simoneon
OH HAI GUYZ, i didnt you see you thar :P ~ Alectric
Now, I seriously need to be a part of this. ~ SirFrog
Wasn't there something about childish mods editing signatures lately? ~ Reaper
What?!?! Where was it?!?!?! ~ blow_fly98
DO YOU HAVE SUGAR?! - Simoneon
I heard if you edit someone's signature enough, your profile automatically is set to Admin status. BP told me. ~ Alectric
then let's do this! ~ Bamboori
Just because I don't go around checking every single post and editing signatures doesn't mean that I don't mod here. I just don't check posts that aren't reported. ~ Evil Sonidow
Seriously. We should encourage people to start reporting more :/ - Simoneon
EvErYoNe'S pOsTeD hErE eXcEpT mH.
Hey, maybe we could report every single post just so ES could check them. ~ blow_fly98
You know, that's a hell lot of work. What about a rule that everyone has to report at least one post whenever he logs in? Or an auto-report function? ~ Reaper
I liked the report-part until we got to the point of an auto-report function. That's something that requires work --> No. ~ Blue Phoenix
Finally, I get to see some invisible users. *sniggers* ~ blow_fly98
Oh, i came back. Well, since im already here, i may as well shoot bees ~ Alectric
You know, the ducks are watching. Always watching... ~ SirFrog
Hmm, I think, Lauli is about to climax due to the awesomeness of this color-wall ~ Blue Phoenix
We're watching you... (Click to View)
<table border="0" cellspacing="1" cellpadding="4" class="tborder">
<thead>
<tr>
<td class="thead">
<div class="expcolimage"><img src="images/unrealblack//collapse.gif" id="boardstats_img" class="expander" alt="[-]" title="[-]" /></div>
<div><strong>Board Statistics</strong></div>
</td>
</tr>
</thead>
<tbody style="" id="boardstats_e">
<tr>
<td class="tcat"><span class="smalltext"><strong>Who's Online</strong> </span></td>
</tr>
<tr>
<td class="trow1"><span class="smalltext">13 users active in the past 5 minutes (13 members, 0 of whom are invisible, and 0 guests).<br /><a href="member.php?action=profile&uid=838"><span style="color: #ff7f00"><b>Alectric</b></span></a>, <a href="member.php?action=profile&uid=17"><span style="color: #ff7f00"><b>Azriel</b></span></a>, <a href="member.php?action=profile&uid=26"><span style="color: #8888ff"><b>Bamboori</b></span></a>, <a href="member.php?action=profile&uid=1056"><span style="color: #008800"><b>blow_fly98</b></span></a>, <a href="member.php?action=profile&uid=15"><span style="color: #ff0000;"><b>Blue Phoenix</b></span></a>, <a href="member.php?action=profile&uid=5"><span style="color: #8888ff;"><b>Evil Sonidow</b></span></a>, <a href="http://www.lf-empire.de/forum/member.php?action=profile&uid=8"><span style="color: #8888ff;"><b>Lord Silva</b></span></a>, <a href="member.php?action=profile&uid=3"><span style="color: #8888ff;"><b>Marshall</b></span></a>, <a href="member.php?action=profile&uid=1"><span style="color: #ff0000;"><b>MH-Razen</b></span></a>, <a href="member.php?action=profile&uid=736"><span style="color: #8888ff;"><b>Phil</b></span></a>, <a href="member.php?action=profile&uid=10"><span style="color: #ff7f00;"><b>Ramond</b></span></a>, <a href="member.php?action=profile&uid=1659"><span style="color: #008800"><b>Reaper</b></span></a>, <a href="member.php?action=profile&uid=1317"><span style="color: #ff7f00;"><b>Simoneon</b></span></a>, <a href="member.php?action=profile&uid=245"><span style="color: #008800"><b>SirFrog</b></span></a></span></td>
</tr>
</tbody>
</table>
<thead>
<tr>
<td class="thead">
<div class="expcolimage"><img src="images/unrealblack//collapse.gif" id="boardstats_img" class="expander" alt="[-]" title="[-]" /></div>
<div><strong>Board Statistics</strong></div>
</td>
</tr>
</thead>
<tbody style="" id="boardstats_e">
<tr>
<td class="tcat"><span class="smalltext"><strong>Who's Online</strong> </span></td>
</tr>
<tr>
<td class="trow1"><span class="smalltext">13 users active in the past 5 minutes (13 members, 0 of whom are invisible, and 0 guests).<br /><a href="member.php?action=profile&uid=838"><span style="color: #ff7f00"><b>Alectric</b></span></a>, <a href="member.php?action=profile&uid=17"><span style="color: #ff7f00"><b>Azriel</b></span></a>, <a href="member.php?action=profile&uid=26"><span style="color: #8888ff"><b>Bamboori</b></span></a>, <a href="member.php?action=profile&uid=1056"><span style="color: #008800"><b>blow_fly98</b></span></a>, <a href="member.php?action=profile&uid=15"><span style="color: #ff0000;"><b>Blue Phoenix</b></span></a>, <a href="member.php?action=profile&uid=5"><span style="color: #8888ff;"><b>Evil Sonidow</b></span></a>, <a href="http://www.lf-empire.de/forum/member.php?action=profile&uid=8"><span style="color: #8888ff;"><b>Lord Silva</b></span></a>, <a href="member.php?action=profile&uid=3"><span style="color: #8888ff;"><b>Marshall</b></span></a>, <a href="member.php?action=profile&uid=1"><span style="color: #ff0000;"><b>MH-Razen</b></span></a>, <a href="member.php?action=profile&uid=736"><span style="color: #8888ff;"><b>Phil</b></span></a>, <a href="member.php?action=profile&uid=10"><span style="color: #ff7f00;"><b>Ramond</b></span></a>, <a href="member.php?action=profile&uid=1659"><span style="color: #008800"><b>Reaper</b></span></a>, <a href="member.php?action=profile&uid=1317"><span style="color: #ff7f00;"><b>Simoneon</b></span></a>, <a href="member.php?action=profile&uid=245"><span style="color: #008800"><b>SirFrog</b></span></a></span></td>
</tr>
</tbody>
</table>