WinAPI - problem with dialog box based app lazarus / 21-General ---------------------------------------------------------------------- Conrad_404 · 2025-01-06 19:55 Hi, I am asking for help with a seemingly simple problem. I'm trying to write a simple GUI window application based solely on the dialog box. Despite correct compilation, the window does not appear. Below is the code. I am using an external application (Resource Builder 4) to compile resource files. Will you help? ==================== {$APPTYPE        GUI} {$LONGSTRINGS    OFF} {$WRITEABLECONST ON} {$DESCRIPTION    'Default DialogBox based App'} Program DefBox; Uses Windows, Strings, Messages, CommDlg, DOS; {$ifdef VER90} { Delphi 2.0 } type        ptrint  = longint;        ptruint = dword; {$endif} var       DialogWnd : hWND;                  Msg : TMsg; {$R Defbox.res} const      MAIN_DIALOG = 200;         TIMER_ID = 9999;      EXIT_BUTTON = 1;        OK_BUTTON = 2;    CANCEL_BUTTON = 3; function MainDialogProc( Dialog : hWnd; Msg : UINT; wParam, lParam : ptrint ) : ptrint; stdcall; begin   case Msg of    WM_INITDIALOG : begin                      Result:=0;                      SetTimer( Dialog, TIMER_ID, 500, nil );                    end;         WM_TIMER : begin                    end;       WM_COMMAND : begin                      case LoWord( wParam ) of                   OK_BUTTON : begin                               end;               CANCEL_BUTTON : begin                               end;                 EXIT_BUTTON : SendMessage( Dialog, WM_CLOSE, 0, 0 );                      end                    end;         WM_CLOSE : begin                                     KillTimer( Dialog, TIMER_ID );                      DestroyWindow( Dialog );                    end;       WM_DESTROY : begin                      PostQuitMessage( 0 );                      Result:=0;                    end;   else Result:=0;   end end; BEGIN   DialogWnd:=CreateDialogParam( hInstance, MakeIntResource( MAIN_DIALOG ), 0, @MainDialogProc, 0 );             //-- main window   ShowWindow( DialogWnd, SW_SHOWNORMAL );   while GetMessage( @Msg, 0, 0, 0 ) do          { wait for message          }     begin       TranslateMessage( Msg );                        { key conversions             }       DispatchMessage( Msg );                         { send to window procedure    }     end; END. ================= Resource: 100 ICON "ruler_pencil.ico" 200 DIALOG MOVEABLE PURE LOADONCALL DISCARDABLE 0, 0, 403, 237 STYLE DS_FIXEDSYS |DS_SETFONT |WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX |WS_CAPTION CAPTION "Dialog" FONT 9, "Ms Shell Dlg" LANGUAGE LANG_NEUTRAL, 0 BEGIN   CONTROL "Exit",1,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,339,200,50,25   CONTROL "OK",2,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,7,200,50,25   CONTROL "Cancel",3,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,177,200,50,25 END ---------------------------------------------------------------------- marcov · 2025-01-06 20:07 Quote from: Conrad_404 on January 06, 2025, 08:55:27 pmI am asking for help with a seemingly simple problem. I'm trying to write a simple GUI window application based solely on the dialog box. Despite correct compilation, the window does not appear. Below is the code. I am using an external application (Resource Builder 4) to compile resource files. Will you help? I compiled with brcc32 (had to find  a suitable icon, as that one afaik doesn't grok vista icons in "icon" resources), but then it simply worked with both FPC 3.2.2 (32-bit) and fpc 3.1.1 (development, also 32-bit) I couldn't attach my res file on the forum, so I put it here:  https://www.stack.nl/~marcov/files/defbox.res ---------------------------------------------------------------------- Fibonacci · 2025-01-06 20:13 I used windres.exe to compile the RC file, and then compiled the FPC code, the window is visible. ---------------------------------------------------------------------- marcov · 2025-01-06 20:50 I tried fpcres, but I got fpcres -of res defbox.rc -o defbox.res ------------------------------ #MAIN.RC(3:50): at "0": syntax error 200 DIALOG MOVEABLE PURE LOADONCALL DISCARDABLE 0, 0, 403, 237                                                  ^ Error: EResourceReaderUnexpectedEndOfStreamException The marker is on the first comma of "0, 0, .." ---------------------------------------------------------------------- 440bx · 2025-01-06 21:27 Like marcov, I used BRCC32 and after commenting out the icon line (can't find the .ico file), it compiled without problem. I also tried Resource Hacker and it didn't like it even after commenting out the icon line. ---------------------------------------------------------------------- Conrad_404 · 2025-01-06 21:28 Thank you for the answer. I compile it under Lazarus 3.6 and I still don't see the dialog nevertheless it exists in the memory. I am sure that the problem is not with the resource file compiler because other programs where the main window is registered and used and dialog boxes just support it, are work correctly. Any clue about Lazarus IDE settings...? ---------------------------------------------------------------------- 440bx · 2025-01-06 21:31 Quote from: Conrad_404 on January 06, 2025, 10:28:48 pmAny clue about Lazarus IDE settings...? Yes, the problem is due to the name you've given to the .res resource file.  Change the name to something like "MyResourceFile.res" and it will work. ETA: You need to recompile the .rc file into a "MyResourceFile.res" because the original .res file is not the result of compiling your .rc file, it's something else. Also, choose any name you want _except_ the one you're currently using.  ETA2: if you want details about why renaming the .rc file will make the thing work see the thread: https://forum.lazarus.freepascal.org/index.php/topic,40830.msg291257.h tml#msg291257 the posts show the problem and the last post explains why it didn't work. HTH. ---------------------------------------------------------------------- Conrad_404 · 2025-01-06 22:04 I restarted everything as a new project and now I got the following information (see attached file). Surprisingly, the executable file saved in the directory works when run independently, outside the Lazarus IDE. I think that in this case the problem is not in the name of the resource file. ---------------------------------------------------------------------- 440bx · 2025-01-06 22:19 It's difficult to provide effective help without having access to the project files. Compress the project files and attach them to your post while stating the problem you're having.  That will make it much easier to diagnose the problem. ---------------------------------------------------------------------- Conrad_404 · 2025-01-07 17:47 Thank you all for your help. Finally everything works. Indeed, my problem was caused by the fact that one MUST NOT name your resource file the same way the application is named. In such a case Lazarus creates its own resource file with this name and overwrites existing resource file. My later problems resulted from the fact that changing the name itself did not help - everything had to be recompiled. I attached zip file with a working version. Maybe someone will need it in the future. Regards! ---------------------------------------------------------------------- 440bx · 2025-01-07 20:26 Quote from: Conrad_404 on January 07, 2025, 06:47:18 pmIndeed, my problem was caused by the fact that one MUST NOT name your resource file the same way the application is named. That reminds me of what my father used to tell me: you learn fast after explaining it to you a long time. You're welcome. ---------------------------------------------------------------------- Conrad_404 · 2025-01-08 20:06 You father was absolutely right :-) ---------------------------------------------------------------------- marcov · 2025-01-08 20:50 I filed a bug for fpcres not understanding the dialog line btw.