/ Forside / Teknologi / Udvikling / Delphi/Pascal / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Delphi/Pascal
#NavnPoint
oldwiking 603
jrossing 525
rpje 520
EXTERMINA.. 500
gandalf 460
gubi 270
DJ_Puden 250
PARKENSS 230
technet 210
10  jdjespers.. 200
WordWrap
Fra : Jens Borrisholt


Dato : 18-12-00 15:41

Hej NG

Hvordan implemterer man wordWrap i en edit control (win32).

Det følgende kode giver en form med en edit kontrpl på, men hvordan får jeg
den til at lave tekst ombrydning ?

program Project1;

uses
Windows, Messages;
type
pWNDPROC = function (hWnd, uMsg, wParam, lParam: Integer): Integer;
stdcall;
var
hGlobalInst : HWND;
hMainWindow : HWND;
hEditor : HWND;
oldEditorWndProc : pWNDPROC;
const
FileExit = 0028;
FormatWordWrap = 0027;

function MainWindowWndProc(hWnd, uMsg, wParam, lParam: Integer): Integer;
stdcall;
var
ClientWidth, ClientHeight : Integer;
begin
Result := 0;
case uMsg of
WM_DESTROY :
begin
PostQuitMessage(0);
exit;
end;
WM_SIZE :
begin
ClientWidth := LOWORD(lParam);
ClientHeight := HIWORD(lParam);
SetWindowPos(hEditor, HWND_TOP, -2, 0, ClientWidth+4,
ClientHeight+2, SWP_SHOWWINDOW );
end;
WM_COMMAND :
begin
case wParam of
FileExit :
begin
PostMessage(hMainWindow, WM_CLOSE,0,0);
Result := 0;
end;
FormatWordWrap :
begin
Result := 0;
end;
end;
end;
else
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
end;
end;

function EditorWindowWndProc(hWnd, uMsg, wParam, lParam: Integer): Integer;
stdcall;
begin
result := oldEditorWndProc(hwnd, uMsg, wParam, lParam);
end;

function NewEditor(Inst : HWND) : Word;
var
rect : TRect;
Height, Width : Integer;
begin
GetClientRect(hMainWindow,Rect);
Width := Rect.Right - Rect.Left;
Height := Rect.Bottom - Rect.Top;
hEditor := CreateWindow('Edit','', WS_CHILD or WS_DLGFRAME or WS_VISIBLE
or ES_AUTOHSCROLL or ES_MULTILINE or ES_AUTOVSCROLL or WS_HSCROLL or
WS_VSCROLL,Rect.Left-2,
Rect.Top,Width+4,Height+2,hMainWindow,0,hInstance,nil);
ShowWindow(hEditor,SW_SHOW);
oldEditorWndProc := pWNDPROC(SetWindowLong(hEditor, GWL_WNDPROC,
Integer(@EditorWindowWndProc)));

result := hEditor;
end;

function RegisterClass(Inst : HWND) : Word;
var
wcex : WNDCLASSEX;
begin
wcex.cbSize := sizeof(WNDCLASSEX);
wcex.style := CS_HREDRAW or CS_VREDRAW;
wcex.lpfnWndProc := @MainWindowWndProc;
wcex.cbClsExtra := 0;
wcex.cbWndExtra := 0;
wcex.hInstance := hInstance;
wcex.hIcon := LoadIcon(hInstance, LPCTSTR('MAINICON'));
wcex.hCursor := LoadCursor(0, IDC_ARROW);
wcex.hbrBackground := HBRUSH(COLOR_WINDOW+1);
wcex.lpszClassName := 'HEST';
wcex.hIconSm := LoadIcon(wcex.hInstance, LPCTSTR('MAINICON'));
Result := RegisterClassEx(wcex);
end;

Function CreateMenu : HMenu;
var
hPopup : HMENU;
begin
Result := Windows.CreateMenu;

hPopup := CreatePopupMenu;
AppendMenu(Result,MF_POPUP,hPopup,'&Filer');
AppendMenu(hPopup,MF_STRING,FileExit,'&Afslut');

hPopup := CreatePopupMenu;
AppendMenu(Result,MF_POPUP,hPopup,'F&ormater');
AppendMenu(hPopup,MF_STRING,FormatWordWrap,'&Tekstombrydning');
end;

Function InitInstance(Inst : Hwnd; nCmdShow : Integer) : boolean;
begin
hGlobalInst := Inst;
hMainWindow := CreateWindow('HEST', 'HEST', WS_OVERLAPPEDWINDOW, 100,
100, 350,350, 0, CreateMenu, hInstance, nil);
if hMainWindow = 0 then
begin
result := false;
exit;
end;

ShowWindow(hMainWindow, nCmdShow);
UpdateWindow(hMainWindow);
result := true;
end;

var
message : MSG;
begin
RegisterClass(hInstance);
InitInstance (hInstance, SW_NORMAL);

NewEditor(hInstance);

SetFocus(hEditor);
while(GetMessage(message, 0, 0, 0)) do
begin
TranslateMessage(message);
DispatchMessage(message);
end;
ExitCode := message.wParam;
end.

Jens B



 
 
Thomas Due (19-12-2000)
Kommentar
Fra : Thomas Due


Dato : 19-12-00 08:28

Du skal vel bare holde øje med hvor når du er i nærheden af højre kant og så
bryde linien.
Det er lidt svært at følge dit eksempel pga. de mange API kald, men det jeg
ville gøre, var
at holde øje med cursorens position, og når den nærmede sig kanten, så
flytte den ned på næste
linie. Hvis så den sidst karakter inden brydningen _ikke_ er et mellemrum,
så må du så
tælle baglæns (indtil det sidste mellemrum) og flytte det sidst ord ned på
den nye linie.

Om det så kan gøres meget nemt med API er jeg så ikke klar over, men det
skulle ikke undre
mig.

Mvh
Thomas Due

"Jens Borrisholt" <Jens@Borrisholt.com> wrote in message
news:91l7lk$7ad$1@news.inet.tele.dk...
> Hej NG
>
> Hvordan implemterer man wordWrap i en edit control (win32).
>
> Det følgende kode giver en form med en edit kontrpl på, men hvordan får
jeg
> den til at lave tekst ombrydning ?
>
> program Project1;
>
> uses
> Windows, Messages;
> type
> pWNDPROC = function (hWnd, uMsg, wParam, lParam: Integer): Integer;
> stdcall;
> var
> hGlobalInst : HWND;
> hMainWindow : HWND;
> hEditor : HWND;
> oldEditorWndProc : pWNDPROC;
> const
> FileExit = 0028;
> FormatWordWrap = 0027;
>
> function MainWindowWndProc(hWnd, uMsg, wParam, lParam: Integer): Integer;
> stdcall;
> var
> ClientWidth, ClientHeight : Integer;
> begin
> Result := 0;
> case uMsg of
> WM_DESTROY :
> begin
> PostQuitMessage(0);
> exit;
> end;
> WM_SIZE :
> begin
> ClientWidth := LOWORD(lParam);
> ClientHeight := HIWORD(lParam);
> SetWindowPos(hEditor, HWND_TOP, -2, 0, ClientWidth+4,
> ClientHeight+2, SWP_SHOWWINDOW );
> end;
> WM_COMMAND :
> begin
> case wParam of
> FileExit :
> begin
> PostMessage(hMainWindow, WM_CLOSE,0,0);
> Result := 0;
> end;
> FormatWordWrap :
> begin
> Result := 0;
> end;
> end;
> end;
> else
> Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
> end;
> end;
>
> function EditorWindowWndProc(hWnd, uMsg, wParam, lParam: Integer):
Integer;
> stdcall;
> begin
> result := oldEditorWndProc(hwnd, uMsg, wParam, lParam);
> end;
>
> function NewEditor(Inst : HWND) : Word;
> var
> rect : TRect;
> Height, Width : Integer;
> begin
> GetClientRect(hMainWindow,Rect);
> Width := Rect.Right - Rect.Left;
> Height := Rect.Bottom - Rect.Top;
> hEditor := CreateWindow('Edit','', WS_CHILD or WS_DLGFRAME or WS_VISIBLE
> or ES_AUTOHSCROLL or ES_MULTILINE or ES_AUTOVSCROLL or WS_HSCROLL or
> WS_VSCROLL,Rect.Left-2,
> Rect.Top,Width+4,Height+2,hMainWindow,0,hInstance,nil);
> ShowWindow(hEditor,SW_SHOW);
> oldEditorWndProc := pWNDPROC(SetWindowLong(hEditor, GWL_WNDPROC,
> Integer(@EditorWindowWndProc)));
>
> result := hEditor;
> end;
>
> function RegisterClass(Inst : HWND) : Word;
> var
> wcex : WNDCLASSEX;
> begin
> wcex.cbSize := sizeof(WNDCLASSEX);
> wcex.style := CS_HREDRAW or CS_VREDRAW;
> wcex.lpfnWndProc := @MainWindowWndProc;
> wcex.cbClsExtra := 0;
> wcex.cbWndExtra := 0;
> wcex.hInstance := hInstance;
> wcex.hIcon := LoadIcon(hInstance, LPCTSTR('MAINICON'));
> wcex.hCursor := LoadCursor(0, IDC_ARROW);
> wcex.hbrBackground := HBRUSH(COLOR_WINDOW+1);
> wcex.lpszClassName := 'HEST';
> wcex.hIconSm := LoadIcon(wcex.hInstance, LPCTSTR('MAINICON'));
> Result := RegisterClassEx(wcex);
> end;
>
> Function CreateMenu : HMenu;
> var
> hPopup : HMENU;
> begin
> Result := Windows.CreateMenu;
>
> hPopup := CreatePopupMenu;
> AppendMenu(Result,MF_POPUP,hPopup,'&Filer');
> AppendMenu(hPopup,MF_STRING,FileExit,'&Afslut');
>
> hPopup := CreatePopupMenu;
> AppendMenu(Result,MF_POPUP,hPopup,'F&ormater');
> AppendMenu(h

Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408526
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste