I am working on a really cool application and i don't know how to access the text in an EDIT field so i can print it. Please give source code. I all ready have the sandard print dialog availible in the dev c++ examples. Please help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am working on a really cool application and i don't know how to access the text in an EDIT field so i can print it. Please give source code. I all ready have the sandard print dialog availible in the dev c++ examples. Please help.
this program uses send message WM_GETTEXT and WM_SETTEXT to access the text in an EDIT field/ dawe@attcanada.net
#include <windows.h>
HINSTANCE hInstGlobal;
LRESULT CALLBACK MsgHandler (HWND, UINT, WPARAM, LPARAM);
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance = NULL, LPSTR CmdLine, int CmdShow = SW_SHOWNORMAL)
{
WNDCLASS myclass;
myclass.style = 0;
myclass.cbClsExtra = 0;
myclass.cbWndExtra = 0;
myclass.lpfnWndProc = MsgHandler;
myclass.hInstance = hPrevInstance;
myclass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
myclass.hCursor = LoadCursor(NULL,IDC_ARROW);
myclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
myclass.lpszMenuName = 0;
myclass.lpszClassName = "Window";
RegisterClass (&myclass);
HWND mywindow= CreateWindow ("Window","Loop Back RS232",WS_CAPTION |WS_SYSMENU |WS_MINIMIZEBOX,
0,0,500,340,NULL,NULL,hInstance,NULL);
ShowWindow (mywindow, CmdShow);
UpdateWindow (mywindow);
HANDLE hCom = CreateFile( "COM1",GENERIC_WRITE , 0, 0, CREATE_NEW, 0, 0);
BOOL test;
DCB dcb;
dcb.BaudRate = 9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = 0;
test = SetCommState(hCom, &dcb);
if (test=0)
{
MessageBox(mywindow, "No write", "No Function",MB_OK );
}
MSG Message;
while (GetMessage(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage (&Message);
}
return (Message.wParam);
}
LRESULT CALLBACK MsgHandler(HWND mywindow, UINT Message, WPARAM wParam, LPARAM lParam)
{
RECT rect;
PAINTSTRUCT ps;
HDC hdc;
static HWND input,_return;
LPCTSTR in="Input",_ret="Return";
HANDLE hCom;
DWORD cbWritten;
switch(Message)
{
case WM_CREATE:
input = CreateWindow("Edit",NULL, WS_CHILD | WS_VISIBLE | ES_LEFT |WS_BORDER |ES_MULTILINE
|ES_WANTRETURN, 10, 30,475, 100, mywindow, (HMENU) 1, hInstGlobal, NULL);
_return = CreateWindow("Edit",NULL, WS_CHILD | WS_VISIBLE | ES_LEFT |WS_BORDER |ES_MULTILINE
,10, 160,475, 100, mywindow, (HMENU) 2, hInstGlobal, NULL);
return(0);
case WM_PAINT:
hdc = BeginPaint (mywindow, &ps);
TextOut(hdc,10,10,in,5);
TextOut(hdc,10,140,_ret,6);
EndPaint (mywindow, &ps);
return 0;
case WM_COMMAND:
char szBuffer[290];
SendMessage(input, WM_GETTEXT, (WPARAM)sizeof szBuffer, (LPARAM) ((LPSTR) szBuffer));
HANDLE hCom = CreateFile( "COM1",GENERIC_WRITE , 0, 0, CREATE_NEW, 0, 0);
WriteFile(hCom, (LPARAM) ((LPSTR) szBuffer), (WPARAM)sizeof szBuffer, &cbWritten, (LPOVERLAPPED) NULL);
SendMessage(_return, WM_SETTEXT, (WPARAM)sizeof szBuffer, (LPARAM)szBuffer) ;
return(0);
case WM_DESTROY:
CloseHandle(hCom);
PostQuitMessage(0);
break;
default:
return DefWindowProc(mywindow, Message, wParam, lParam);
}
}