C++ win32 api How to get Edit control box text to a Text file

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small

Hello,
Im new at this and not too quick to pick up thing but i have this code. What im trying to do is take the inputed text from a edit contorl box and output to a text file. I tryed a few thing but failed. I been looking up function like GetDlgItemText() but
seem to fail as well. Please help me but editing my code so i can see what i need to do.
#include <Windows.h><br/>
#include <string><br/>
#include <fstream> <br/>
#include "resource.h"<br/>
using namespace std;
HWND ghDlg = 0;
BOOL CALLBACK<br/>
EditDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)<br/>
{
char name [256]; <br/>
ofstream outFile;
outFile.open("output.txt");
char msgText[256];
static HWND hEditBox = 0;
switch( msg )
{<br/>
case WM_INITDIALOG:<br/>
hEditBox = GetDlgItem(hDlg, IDC_MSGTEXT);
SetWindowText(hEditBox, "Enter a message here.");<br/>
return true;
case WM_COMMAND:<br/>
switch(LOWORD(wParam))<br/>
{<br/>
case IDB_MSG:<br/>
GetWindowText(hEditBox, msgText, 256);<br/>
MessageBox(0, msgText, "Message", MB_OK);<br/>
return true;<br/>
}<br/>
return true;<br/>
case WM_CLOSE:<br/>
DestroyWindow(hDlg);<br/>
return true;<br/>
case WM_DESTROY:<br/>
PostQuitMessage(0);<br/>
return true;<br/>
}
<br/>
//outFile << GetDlgItemText(hEditBox, IDC_MSGTEXT, msgText , 256);<br/>
//outFile << GetWindowText(hEditBox, msgText, 1) << endl; // outputs 0<br/>
//outFile << SetWindowText(hEditBox, msgText) << endl; // output garbage in the window text<br/>
//outFile << hEditBox << endl; // outputs 0004062E seems like an address<br/>
//outFile << msgText << endl; // outputs garbage text
<br/>
return false;<br/>
}
int WINAPI<br/>
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd)<br/>
{<br/>
ghDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MSGDLG), 0, EditDlgProc);
ShowWindow(ghDlg, showCmd);
MSG msg;<br/>
ZeroMemory(&msg, sizeof(MSG));
while(GetMessage( &msg, 0, 0, 0))<br/>
{<br/>
if( ghDlg == 0 || !IsDialogMessage(ghDlg, &msg))<br/>
{<br/>
TranslateMessage(&msg);<br/>
DispatchMessage(&msg);<br/>
}<br/>
}<br/>
return (int)msg.wParam;<br/>
}


View the full article
 
Back
Top