Recent

Author Topic: my programs crash  (Read 3889 times)

d2010

  • Full Member
  • ***
  • Posts: 171
Re: my programs crash
« Reply #15 on: February 13, 2025, 02:36:47 am »
00=First you add MainFunction. You rename my function  "flistsvc_lomain" with your "nameMAIN"
01=Before  the DestroyWindow(, then you you add while...dispatchMessage..end
02=You add this procedure ,exactly this name "flistsvc_lbwndproc"
03=You search flistsvc_lbwndproc at Function flistsvc_lomain(h

Code: [Select]
Function  flistsvc_lbwndproc(hWnd: HWND; message: UINT;  wParam: WPARAM;  lParam: LPARAM): LRESULT;
Begin
    Assert_cxx(523);
    mtjig_before:=nt_itoa(Message)+'=';
    str_fileechoPASCAL(ktoolfini_flistsvc32ini,mtjig_before);
    mtjig_before:='';
    case Message of
         WM_CREATE : Begin message_wm_create;
                     End;
//          WM_CTLCOLORLISTBOX,
          WM_SETFOCUS : Begin   SetFocus (a14_getvar[04].handr) ;
                                result:=0;
                                exit;
                         End;

          WM_KEYDOWN :  ShowKey (hwnd, 0, 'WM_KEYDOWN', wParam, lParam) ;
          WM_KEYUP :    ShowKey (hwnd, 0, 'WM_KEYUP', wParam, lParam) ;
          WM_CHAR :     ShowKey (hwnd, 1, 'WM_CHAR', wParam, lParam) ;
          WM_DEADCHAR :  ShowKey (hwnd, 1, 'WM_DEADCHAR', wParam, lParam) ;
          WM_SYSKEYDOWN :ShowKey (hwnd, 0, 'WM_SYSKEYDOWN', wParam, lParam) ;
          WM_SYSKEYUP :  ShowKey (hwnd, 0, 'WM_SYSKEYUP', wParam, lParam) ;
          WM_SYSCHAR :  ShowKey (hwnd, 1, 'WM_SYSCHAR', wParam, lParam) ;
          WM_SYSDEADCHAR :ShowKey (hwnd, 1, 'WM_SYSDEADCHAR', wParam, lParam) ;

         WM_COMMAND: result:=message_wmcommand(wParam,lParam);
         WM_QUIT:      Begin //ShowWindow(hWnd, SW_HIDE);
                             PostQuitMessage (0) ;
                             result:=0;
                        end;
         WM_DESTROY : Begin //ShowWindow(hWnd, SW_HIDE);
                            result:=DefWindowProc(hwnd,0, 0, 0) ;
                            //PostQuitMessage (WM_DESTROY) ;
                         end;
        else bootstat_dat;
     end;
End;
Eu multumesc tie ArsenieBoca2025.
Code: [Select]
   while(GetMessage(msg, 0, 0, 0)) do
   begin
      {$ifdef keyboard.inf}
        if (PeekMessage (msg,0, 0, 0, PM_REMOVE)) then
          if  keyboard_inf_loc then break;
      {$endif}
      TranslateMessage(msg);
      DispatchMessage(msg);
   end;
   result:=errorlevel+100;
   DestroyWindow(hWnd);
end;
Code: [Select]
Function flistsvc_lomain(hInstance : HINST; hPrevInstance : HINST;lpCmdLine : PChar; nCmdShow : Integer;libraryTD_Db,pidonertf:strff) : Integer;
var
  hWnd     : THandle;
  Msg      : TMsg;
  wndClass : TWndClass;
  adcstate:boolean;

       Function  keyboard_inf_loc:boolean;
          Begin  result:=(msg.message = WM_QUIT);
                 writeln('(jey=',msg.message);
                  if (result) then exit;
                  if msg.message = WM_KEYDOWN then
                     case MapVirtualKey (msg.wparam, 0) of
                      13..255: writeln('*****');
                    end;
           End;


begin
   kscreensize.y:=GetSystemMetrics(SM_CYSCREEN);Assert_cxx(512);
   kscreensize.x:=GetSystemMetrics(SM_CXSCREEN);
   adcstate:=(HIWORD(nCmdShow)=WM_VSCROLL);
   if adcstate then
     Begin  hwnd:=LOWORD(nCmdShow);
            if (hwnd<1) then hwnd:=0;
            if (hwnd>77) then hwnd:=77;   //rem:   77.procente
             with kscreensize do  hwnd:=hwnd*y div 100;
     End;
   imagedef.h.resolutionunits:=if_int(adcstate,hwnd,0);
   hwnd:=0;
   wndClass.style          := CS_HREDRAW or CS_VREDRAW;
   wndClass.lpfnWndProc    := @flistsvc_lbwndproc;
   wndClass.cbClsExtra     := 0;
   wndClass.cbWndExtra     := 0;
   wndClass.hInstance      := hInstance;
   wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
   wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
   wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
   wndClass.lpszMenuName   :=nil;
   wndClass.lpszClassName  :='GettingStarted';
   RegisterClass(wndClass);
   errorlevel:=0;
   size3_rm_cur.y:=Integer(CW_USEDEFAULT);
   size3_rm_cur.x:=Integer(CW_USEDEFAULT);

   if (length(libraryTD_Db)<2) then libraryTD_Db:=kNsiMessageLength_i02 else
   if (fileexists(libraryTD_Db)) then libraryTD_Db:=concat('(FListSVc "',ExtractFile2Name('',libraryTD_Db),'?>',pidonertf,'")'#0#0#0) else
   if (pos('.',libraryTD_Db)>0) then libraryTD_Db:=concat('(FlisTSvc "',ExtractFile2Name('',libraryTD_Db),
        '?=',pidonertf,'")'#0#0#0) else
       libraryTD_Db:=kNsiMessageLength_i02;
   Assert_cxx(513);
   hWnd := CreateWindow(
      'GettingStarted',       // window class name
      @A14_dwgtitled[1],    // window caption
      WS_CAPTION or WS_THICKFRAME or WS_MAXIMIZEBOX ,    // window style
      Integer(CW_USEDEFAULT), // initial x position
      Integer(CW_USEDEFAULT), // initial y position
      size3_rm_cur.x, // initial x size width
      size3_rm_cur.y, // initial y size
      0,                      // parent window handle
      0,                      // window menu handle
      hInstance,              // program instance handle
      nil);                   // creation parameters


   ShowWindow(hWnd, SW_SHOW);
   UpdateWindow(hWnd);

   while(GetMessage(msg, 0, 0, 0)) do
   begin
      {$ifdef keyboard.inf}
        if (PeekMessage (msg,0, 0, 0, PM_REMOVE)) then
          if  keyboard_inf_loc then break;
      {$endif}
      TranslateMessage(msg);
      DispatchMessage(msg);
   end;
   result:=errorlevel+100;
   DestroyWindow(hWnd);
end;//off-flistsvc_lbmain("")


Thaddy

  • Hero Member
  • *****
  • Posts: 17198
  • Ceterum censeo Trump esse delendam
Re: my programs crash
« Reply #16 on: February 13, 2025, 07:11:24 am »
Please use code=pascal between brackets
The coding style on its own is horrible enough, so a better view of what is happening is appreciated
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Nitorami

  • Hero Member
  • *****
  • Posts: 510
Re: my programs crash
« Reply #17 on: February 13, 2025, 10:26:30 am »
The OP is a novice and may not know that GUI programs in Lazarus can be made without calls to the windows API ?

440bx

  • Hero Member
  • *****
  • Posts: 5477
Re: my programs crash
« Reply #18 on: February 13, 2025, 10:42:57 am »
is the forum not replacing the book?
No.  The forum participants will gladly help but, they are not here to teach you or anyone else how to program.

was that not simply enough, that everybody know how to code this?
It doesn't matter if everyone knows how to code this, if you don't have the knowledge to understand the "solution" (which your questions have made clear, you don't.)

with what must the queue filled up and for whom?
i ask there only for mouse and keyboard, but the program crashes.
this problem is not solved, and why?
and why the window-handle needs informations, when the
code-part shall know keyboard and mouse instead all?
what can be messaged around no participiant parts of what ever,
so that it not crash?
if you took the time to read a good Windows book, you'd know the answers to those questions and many more.

You have to have the minimum necessary knowledge to understand the answers to the questions you have.  You got to make an effort, help yourself.  Nothing can take the place of that.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

turunk

  • New Member
  • *
  • Posts: 29
Re: my programs crash
« Reply #19 on: May 22, 2025, 03:02:09 pm »
d2010,
but your getmessage-loop ends still if his first result is 0.
and the most procedures i do not know.

Gigatron

  • Sr. Member
  • ****
  • Posts: 282
  • Amiga Rulez !!
Re: my programs crash
« Reply #20 on: May 23, 2025, 05:44:07 pm »
Hi

When you program, you have to make sure that, for example, you free up the memory you have reserved. The size of the arrays, the images, the windows, the stacks, etc., everything must be destroyed when you exit the program. Otherwise memory leak, cpu at 100% crash. In your case, windows must absolutely stack the messages and remove them as you go otherwise you can have an overflow of unreleased messages. Sorry for my poor English, I use google translate which doesn't translate well at all. I hope that in your future projects this recommendation will help you. Read all about programming and try,try try use debugger  best of lazarus pascal tool . For example, I spent 3 weeks for 10 lines of code;)

eg windows message remove, this code not crashing ;

Code: Pascal  [Select][+][-]
  1. msg.hwnd := hndw;   // window handler
  2.     repeat
  3.       // win system message important !
  4.       while PeekMessage(msg,0,0,0,PM_REMOVE) do
  5.       begin
  6.         if msg.message = WM_QUIT then break;
  7.         if (msg.message = WM_LBUTTONDOWN) and (msg.hwnd = hndw) then begin
  8.             fillrect(DC,rect0,color0);fillrect(DC,rect3,color3);
  9.         end;
  10.         if (msg.message = WM_RBUTTONDOWN) and (msg.hwnd = hndw) then begin
  11.             fillrect(DC,rect0,color0);fillrect(DC,rect4,color4);
  12.         end;
  13.           TranslateMessage(msg); // translate keys to char
  14.           DispatchMessage(msg);  // send to hwnd
  15.       end;
  16.  
  17.       {keyboard 1 or 2:}
  18.       if (getasynckeystate($31) )<>0 then
  19.       begin
  20.           fillrect(DC,rect0,color0);fillrect(DC,rect1,color1);
  21.           TextOut(DC,240,100,'HELLO',6);
  22.       end;
  23.  
  24.       if (getasynckeystate($32) )<>0 then
  25.       begin
  26.           fillrect(DC,rect0,color0);fillrect(DC,rect2,color2);
  27.       end;
  28.  
  29.     Sleep(10);   // wait a bit for cpu
  30.     until (getasynckeystate(65))<>0 ;  // A key  65 to quit !
  31.  
  32.     // Free All
  33.     ReleaseDC(hndw,DC);
  34.     DeleteObject(color0);
  35.     DeleteObject(color1);
  36.     DeleteObject(color2);
  37.     DeleteObject(color3);
  38.     DeleteObject(color4);
  39.     DestroyWindow(hndw);
  40.     unregisterclass(wcn,0);  


Regards GTR
« Last Edit: May 23, 2025, 06:03:15 pm by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

turunk

  • New Member
  • *
  • Posts: 29
Re: my programs crash
« Reply #21 on: May 24, 2025, 02:54:49 pm »
thank you gigatron,
because of your program i got this solution:
in your program-loop only:
while PeekMessage(msg,msg.hwnd,0,0,PM_REMOVE) do DispatchMessage(msg);
and it does not crash

Gigatron

  • Sr. Member
  • ****
  • Posts: 282
  • Amiga Rulez !!
Re: my programs crash
« Reply #22 on: May 25, 2025, 06:23:41 pm »
thank you gigatron,
because of your program i got this solution:
in your program-loop only:
while PeekMessage(msg,msg.hwnd,0,0,PM_REMOVE) do DispatchMessage(msg);
and it does not crash

Nice , you are welcome,

Just one last step for you is that you need to understand why the program is not crashing and why it was crashing. :)

Finally, you can close this topic with the title [Solved]
« Last Edit: May 25, 2025, 06:27:00 pm by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

turunk

  • New Member
  • *
  • Posts: 29
Re: my programs crash
« Reply #23 on: May 26, 2025, 02:01:12 pm »
the program does not crash, but i have now the problem,
that i have to click often the mouse until the program reacts,
but on the keys typed there is no problem.
and on one program, if i have clicked and move the mouse
over other buttons without click again, all buttons are reacting.

i have on several programs only added the while-peek-dispatch
line, with type and msg:=hwnd

 

TinyPortal © 2005-2018