M
Hallo,
ich brauche eine Eingabezeile mit Return (war schon oft, ich weiß). Problem ist, dass mein Compiler (Borland C++ Builder 2005) in der Unterklasse die Variable m_EditProc nicht mag, Fehler im Datentyp. Kann jemand mal nach Sinn und Unsinn durchschauen, ich bin völlig neu in Windows-Programmierung.
(Ohne Unterklasse und ohne Return funktioniert das Programm.)
Grüße,
Martin
// -----------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <windows.h>
// -----------------------------------------------------------------------------
#define ID_EDIT 1
// -----------------------------------------------------------------------------
TCHAR szAppName[] = TEXT ("MTR--MTR") ;
WNDPROC m_EditProc;
// -----------------------------------------------------------------------------
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditProc (HWND, UINT, WPARAM, LPARAM);
// -----------------------------------------------------------------------------
// START
// -----------------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
// WNDCLASSEX *wndclassex;
// wndclassex = (WNDCLASSEX*) malloc (sizeof (WNDCLASSEX));
// wndclassex.cbSize = sizeof (WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
// wndclassex.hIconSm = LoadIcon (NULL, IDI_HAND);
if (! RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Programm arbeitet mit Unicode und setzt Windows NT voraus!"),
szAppName, MB_ICONERROR);
return (0);
}
hwnd = CreateWindow (szAppName, // Name Fensterklasse
TEXT ("MTR"), // Titel
WS_OVERLAPPEDWINDOW, // Stil
100, // x-Pos
300, // y-Pos
600, // Breite
400, // Höhe
NULL, // übergeordnetes Fenster
NULL, // Menü
hInstance, // Programm-Kopiezähler (Programm-ID)
NULL); // zusätzliche Parameter
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return (msg.wParam);
}
// -----------------------------------------------------------------------------
LRESULT CALLBACK WndProc (HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
static HWND hwndEdit;
switch (message)
{
case WM_CREATE:
hwndEdit = CreateWindow (TEXT ("edit"), NULL,
WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | WS_BORDER,
100, 200, 300, 20, hwnd, (HMENU) ID_EDIT,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
m_EditProc = (WNDPROC) SetWindowLongPtr (hwndEdit, GWLP_WNDPROC, (LONG_PTR) EditProc);
return (0);
case WM_SETFOCUS:
SetFocus (hwndEdit);
return (0);
case WM_SIZE:
MoveWindow (hwndEdit, 100, 200, 300, 20, TRUE);
return (0);
case WM_COMMAND:
if (LOWORD (wParam) == ID_EDIT)
if (HIWORD (wParam) == EN_ERRSPACE ||
HIWORD (wParam) == EN_MAXTEXT)
MessageBox (hwnd, TEXT ("Edit control out of space."),
szAppName, MB_OK | MB_ICONSTOP);
return (0);
case WM_DESTROY:
PostQuitMessage (0);
return (0);
}
return (DefWindowProc (hwnd, message, wParam, lParam));
}
// -----------------------------------------------------------------------------
#if 1
LRESULT CALLBACK EditProc (HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
LRESULT rc;
switch(msg)
{
case WM_KEYDOWN:
//Mach Was
break;
}
rc = CallWindowProc (m_EditProc, hwnd, msg, wParam, lParam);
return (rc);
}
#endif
// -----------------------------------------------------------------------------
// Dateiende: mtr.cpp
// -----------------------------------------------------------------------------