Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrong text in Window. WINAPI

Status
Not open for further replies.

nullplan

Programmer
Dec 10, 2005
2
DE
Please help me!
It is so: I'm just reading the tutorial on but I have a problem with writing text into a window. Just look at the source:
Code:
[ignore]{$DEFINE STRICT}
program ausgabetest;
uses windows;
const
  szAppName='Textausgabe im Anwendungsbereich';

var
  hwind:hwnd;
  mesg:msg;
  wc:wndclass;
  v:variant;

function wndproc(hwind:hwnd; message:uint; wordparam: wparam; longparam:lparam):lresult; stdcall;

var
  ps:paintstruct;
  hdevc:hdc;
  sztext:shortstring;
  hstr:shortstring;
begin
  case message of
    wm_paint: begin
      szText:='Hallo, dies ist der Text.';
      @hstr:=@szText[25]+1;
      hstr:='       ';
      hdevc:= beginPaint(hwind, ps);
      begin
        textout(hdevc, 50, 50, @szText+1, ord(sztext[0])-5);
      end;
      endpaint(hwind, ps);
      exit(0);
    end;
    wm_destroy: begin
      postquitmessage(0);
      exit(0);
    end;
  end;
  exit (defwindowproc(hwind,message,wordparam,longparam));
end;

begin
  wc.style := cs_hredraw + cs_vredraw;
  wc.lpfnwndproc := @wndproc;
  wc.cbclsextra := 0;
  wc.cbwndextra := 0;
  wc.hinstance := hinstance;
  wc.hcursor := loadcursor(0, IDC_ARROW);
  wc.hIcon := loadicon(0, IDI_APPLICATION);
  wc.hbrbackground := getstockobject(white_brush);
  wc.lpszclassname := szAppName;
  wc.lpszMenuName := nil;
  registerclass (wc);

  v:= cw_usedefault;
  hwind := createwindow( szAppName,
                         'Titelleiste',
                         ws_overlappedwindow,
                         v,
                         v,
                         v,
                         v,
                         0,
                         0,
                         hinstance,
                         nil);
  showwindow (hwind, sw_show);
  updatewindow(hwind);
  while getmessage(mesg, 0, 0, 0) do begin
    translatemessage(mesg);
    dispatchmessage(mesg);
  end;
  halt(mesg.wparam);
end.[/ignore]
Now I get a window with the following text:
"Hallo, dies ist der Text.3nhll" When I make the program redraw, the "3nhll" shortens to ")". What the?? And how to make the Prog write the text properly?
 
Anything has come clear. When I define hstr as pshortstring and adjust the terms in which I used it, the text will be written properly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top