Forum > Other

Quirky windows

(1/3) > >>

440bx:
Hello,

The following code might be the shortest possible Windows GUI program and the behavior is a bit unusual in some cases (hint: the scrollbar is the most fun to play with.)  Here is the code:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$APPTYPE GUI} program FunMess;  { short and quirky GUI programs                                             }   {---------------------------------------------------------------------------}  { UNUSUAL: creating a main window that is a standard control may give the   }  { window a caption but, the caption isn't always active/functional.         }   { 1. Button    - ignores the button styles,                                 }  {                caption is partially functional                            }  { 2. Listbox   - caption is partially functional                            }  { 3. Scrollbar - when used, the scroll bars get redrawn incorrectly, the    }  {                caption if partially functional                            }  { 4. Static    - the caption is utterly useless                             }  { 5. Edit      - caption is partially functional                            }   { 1. Combobox  - there is no caption                                        }   { for all the above, the window style is mostly ignored                     }  {---------------------------------------------------------------------------} uses  Windows  ; function WinMain : integer;  { application entry point                                                   }var  Wnd : HWND;  Msg : TMSG; begin  { Create the main application window                                        }                        { uncomment your choice of control, recompile and run  }   Wnd := CreateWindow ('listbox',                       //'scrollbar',                       //'static',                       //'edit',                       //'Combobox',                       //'Button',              { class name                  }                        'Hello World',           { window caption text         }                       0,                       { window style                }                        10,                       10,                       100,                       100,                        0,                       0,                       GetModuleHandle(nil),    { instance handle             }                       nil);                    { parameter sent to WM_CREATE }   if Wnd = 0 then halt;                         { could not create the window }  ShowWindow(Wnd, SW_NORMAL);   while GetMessage (Msg, 0, 0, 0) do            { pump and dispatch messages  }  begin    DispatchMessage(Msg);  end;    WinMain := Msg.wParam;                        { terminate with return code  }end; begin  WinMain;end. you can copy/paste that into a Lazarus source editor window or if you like your code with a side of .lpi and .lps, download the attachment.

NOTE: you will almost every time have to forcefully terminate the little program (use Task Manager or whatever system monitoring program you like/use.)

Have fun!

ASerge:

--- Quote from: 440bx on April 21, 2024, 04:32:04 am ---The following code might be the shortest possible Windows GUI program...

--- End quote ---
It can be shorten by removing ShowWindow, but specifying the WS_VISIBLE style.


--- Quote ---NOTE: you will almost every time have to forcefully terminate the little program (use Task Manager or whatever system monitoring program you like/use.)

--- End quote ---
Hook WM_DESTROY to terminate app:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$APPTYPE GUI} uses Windows, CommCtrl; function SubclassProc(Wnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM;  uIdSubclass: UINT_PTR; dwRefData: DWORD_PTR): LRESULT; stdcall;begin  if uMsg = WM_DESTROY then    PostQuitMessage(0);  Result := DefSubclassProc(Wnd, uMsg, wParam, lParam);end; function WinMain: Integer;var  Wnd: HWND;  Msg: TMSG;begin  Wnd := CreateWindow(    //'listbox',    'scrollbar',    //'static',    //'edit',    //'Combobox',    //'Button',     'Hello World',    WS_VISIBLE,    10, 10, 100, 100, 0, 0, 0, nil);  if Wnd = 0 then    Halt;  SetWindowSubclass(Wnd, @SubclassProc, 1, 0);  while GetMessage(Msg, 0, 0, 0) do    DispatchMessage(Msg);  Result := Msg.wParam;end; begin  WinMain;end.

440bx:

--- Quote from: ASerge on April 21, 2024, 10:18:40 am ---It can be shorten by removing ShowWindow, but specifying the WS_VISIBLE style.

--- End quote ---
Good idea! 


--- Quote from: ASerge on April 21, 2024, 10:18:40 am ---Hook WM_DESTROY to terminate app:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$APPTYPE GUI} uses Windows, CommCtrl; function SubclassProc(Wnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM;  uIdSubclass: UINT_PTR; dwRefData: DWORD_PTR): LRESULT; stdcall;begin  if uMsg = WM_DESTROY then    PostQuitMessage(0);  Result := DefSubclassProc(Wnd, uMsg, wParam, lParam);end; function WinMain: Integer;var  Wnd: HWND;  Msg: TMSG;begin  Wnd := CreateWindow(    //'listbox',    'scrollbar',    //'static',    //'edit',    //'Combobox',    //'Button',     'Hello World',    WS_VISIBLE,    10, 10, 100, 100, 0, 0, 0, nil);  if Wnd = 0 then    Halt;  SetWindowSubclass(Wnd, @SubclassProc, 1, 0);  while GetMessage(Msg, 0, 0, 0) do    DispatchMessage(Msg);  Result := Msg.wParam;end; begin  WinMain;end.
--- End quote ---
I didn't want to incur the extra code and just thought of the fact that alt-F4 might work and, it does!  therefore, no need for that code, Alt-F4 ends the program.

ASerge:

--- Quote from: 440bx on April 21, 2024, 03:20:03 pm ---I didn't want to incur the extra code and just thought of the fact that alt-F4 might work and, it does!  therefore, no need for that code, Alt-F4 ends the program.

--- End quote ---
Windows 7, x64. The Alt+F4 keyboard shortcut does not terminate the program (I tested all the controls).

440bx:

--- Quote from: ASerge on April 21, 2024, 09:51:59 pm ---Windows 7, x64. The Alt+F4 keyboard shortcut does not terminate the program (I tested all the controls).

--- End quote ---
You're right !!  It makes the window disappear but the program is still running, which on second thought makes sense because the control isn't supposed to post a quit message.

Navigation

[0] Message Index

[#] Next page

Go to full version