As my subject says, when i call GetWindowText with the string to fill, it comes back with nothing copied into it. I also tried directly sending the message to the edit control and also got nothing. Here is my code. any ideas?
#include <windows.h>
#include <stdio.h>
#pragma comment (lib, "comctl32.lib")
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK printout(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
HWND mainwindow;
HWND editbox;
HWND sendbutton;
HWND printbox;
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
#define PO_ADDTEXT (WM_USER + 1)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
WNDCLASSEX print;
MSG Msg;
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_BACKGROUND + 1;
wc.lpszMenuName = NULL;
wc.lpszClassName = "clientstuffs";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
print.cbSize = sizeof(WNDCLASSEX);
print.style = 0;
print.lpfnWndProc = printout;
print.cbClsExtra = 0;
print.cbWndExtra = 0;
print.hInstance = hInstance;
print.hIcon = LoadIcon(NULL, IDI_APPLICATION);
print.hCursor = LoadCursor(NULL, IDC_ARROW);
print.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(255,255,255));
print.lpszMenuName = NULL;
print.lpszClassName = "printbox";
print.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&print))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
mainwindow = CreateWindowEx(
WS_EX_CLIENTEDGE,
"clientstuffs",
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 600, 500,
NULL, NULL, hInstance, NULL);
editbox = CreateWindowEx(0, "EDIT", "",
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
40, 410, 420, 30,
mainwindow,
(HMENU)5, hInstance, NULL);
SendMessage(editbox, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
printbox = CreateWindowEx(0, "printbox", "",
WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL,
40, 40, 420, 360,
mainwindow,
NULL, hInstance, NULL);
sendbutton = CreateWindowEx( 0, "BUTTON", "Send",
WS_VISIBLE | WS_CHILD | BS_CENTER | BS_VCENTER,
470, 410, 70, 30,
mainwindow,
(HMENU)5, hInstance, NULL);
SendMessage(sendbutton, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
if(mainwindow == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(mainwindow, nCmdShow);
UpdateWindow(mainwindow);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static LPTSTR textmessage = "";
static char buffer[256];
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_KEYDOWN:
{
switch (wParam)
{
case VK_RETURN:
{
SendMessage(sendbutton, BM_CLICK, 0, 0);
}
}
break;
}
case WM_COMMAND:
{
switch(HIWORD(wParam))
{
case BN_CLICKED:
{
SendMessage(editbox, WM_GETTEXT, (WPARAM) 256, (LPARAM) textmessage);
sprintf(buffer,"number of chacacters copied : %i", strlen(textmessage));
MessageBox(hwnd, buffer, "yerp", MB_OK);
SetWindowText(editbox, "");
SendMessage(printbox, PO_ADDTEXT, (WPARAM) textmessage , 0);
}
}
break;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK printout(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
static PAINTSTRUCT paint;
static RECT textbox = {20, 20, 373, 200};
static RECT clientrect;
static char prompt[50000] = "this is a testing string filled with a bunch of insignifigant words where i fill the string to make it as large as possible so that it makes testing the string in multiple lines possible";
static char linebreak[3] = "\n\n";
switch(msg)
{
case WM_CLOSE:
{
DestroyWindow(hwnd);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &paint);
SelectObject(hdc, hFont);
DrawText(hdc, prompt, strlen(prompt), &textbox, DT_CALCRECT | DT_WORDBREAK);
DrawText(hdc, prompt, strlen(prompt), &textbox, DT_WORDBREAK);
EndPaint(hwnd, &paint);
break;
}
case PO_ADDTEXT:
{
strcat(prompt, linebreak);
strcat(prompt, (char*) wParam);
GetClientRect(printbox, &clientrect);
InvalidateRect(printbox, &clientrect, true);
break;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}