Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Problem with SendMessage and MessageBox



Permlink Replies: 2 - Last Post: Aug 6, 2016 4:16 AM Last Post By: Alex Belo Threads: [ Previous | Next ]
Chris Damhus

Posts: 2
Registered: 5/15/01
Problem with SendMessage and MessageBox
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 5, 2016 3:23 AM
Hello,

firstly, I am a Newby to programming. I found a piece of code and tried to compile it with the C++Builder 10.1 Berlin. It compiles, but somehow it does not work. I try to read from an Edit-Controll and I use the SendMessage with WM_GETTEXT. I want this string to be shown in a Messagebox. But I does not show anything. What am I doing wrong?

Thank you and kind regards

Chris

{source}
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <windows.h>

//---------------------------------------------------------------------------
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
LPCTSTR ClsName = L"BasicApp";
LPCTSTR WndName = L"A Simple Window";

/*INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)*/
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;

// Create the application window
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

// Register the application
RegisterClassEx(&WndClsEx);

// Create the window object
hWnd = CreateWindow(ClsName,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
300,
180,
NULL,
NULL,
hInstance,
NULL);

// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application

// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

return Msg.wParam;
}

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
// If the user wants to close the application
case WM_CREATE:
// Zeichnen der einzelnen Kontrollelemente via WinApi
HWND hWndButton, hWndButton2, hWndLabel, hWndLabel2, hWndEdit;
hWndLabel = CreateWindow(TEXT("edit"), TEXT("Ein non-VCL-Fenster mit dem C++Builder"),
WS_CHILD | WS_VISIBLE,
10, 10, 270, 30, hWnd, (HMENU) 3, NULL, NULL);
hWndLabel2 = CreateWindow(TEXT("edit"), TEXT("Ihren Namen bitte:"),
WS_CHILD | WS_VISIBLE,
10, 40, 130, 40, hWnd, (HMENU) 4, NULL, NULL);
hWndEdit = CreateWindow(TEXT("EDIT"), TEXT(""),
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
135,40,140,20, hWnd, (HMENU) 5, GetModuleHandle(NULL), NULL);
//HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
//SendMessage (hWndEdit, WM_SETFONT, (WPARAM) hfDefault, MAKELPARAM(FALSE,0));
hWndButton = CreateWindow(TEXT("Button"), TEXT("Submit"),
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
10, 100, 124, 25, hWnd, (HMENU) 1, NULL, NULL );
hWndButton2 = CreateWindow(TEXT("Button"), TEXT("Cancel"),
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
150, 100, 124, 25, hWnd, (HMENU) 2, NULL, NULL );
return 0;

case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
if (LOWORD(wParam) == 1)
{
LPWSTR buffer[256];
SendMessage(hWndEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]),
reinterpret_cast<LPARAM> (buffer));
MessageBox(0, (LPWSTR) buffer, _T("Meldung"),0);
}
if (LOWORD(wParam) == 2)
{
PostQuitMessage(WM_QUIT);
}
}
return 0;

case WM_DESTROY:
// then close it
PostQuitMessage(WM_QUIT);
break;
default:
// Process the left-over messages
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
// If something was not done, let it go
return 0;
}
{code}

Chris Damhus

Posts: 2
Registered: 5/15/01
Re: Problem with SendMessage and MessageBox
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 5, 2016 7:23 AM   in response to: Chris Damhus in response to: Chris Damhus
PROBLEM SOLVED :-)
Alex Belo

Posts: 626
Registered: 10/8/06
Re: Problem with SendMessage and MessageBox
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 6, 2016 4:16 AM   in response to: Chris Damhus in response to: Chris Damhus
Chris Damhus wrote:

PROBLEM SOLVED

NG's rules require at least small comment on solved problem for record
even if a problem is solved by yourself...

--
Alex
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02