News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

A window in 30 lines of code, using the Masm32 SDK

Started by jj2007, November 20, 2023, 03:24:09 AM

Previous topic - Next topic

greenozon

another idea/question to get -1 line ...

how about this:

it is possible to make 1 line instead of these 2?

wc   WNDCLASSEX <WNDCLASSEX, 0, WndProc, 0, 0, 1, 2, 3, COLOR_BTNFACE+1, 0, txClass, 4>
txClass   db "Masm32GUI", 0         ; class name, will be registered below


focus on txClass

jj2007

Quote from: greenozon on March 13, 2024, 02:58:29 AMtell me, from the bottom of your heart,
what is the % of probability

Unless you have an extremely valid reason to ignore the documentation, don't do it.

Quote from: greenozon on March 13, 2024, 03:02:45 AMit is possible to make 1 line instead of these 2?

The txClass string is being used twice. You might use chr$(..) instead and save one line, but in contrast to MasmBasic's Chr$(..), the Masm32 SDK chr$() generates two entries for identical strings - therefore I would hate that :cool:

sinsi

Quote from: sinsi on May 21, 2014, 03:01:57 PMWhen will GetMessage return -1?

Quote from: Raymond ChenBut don't worry, the standard message pump is safe. If your parameters are exactly
•a valid pointer to a valid MSG structure,
•a null window handle,
•no starting message range filter,
•no ending message range filter,

then GetMessage will not fail with -1.

greenozon

Quote from: jj2007 on March 13, 2024, 04:07:19 AMThe txClass string is being used twice.

I've read the .asm code thrice  and... I can't find the used twice case!?

jj2007

Check the WNDCLASSEX structure:

Quotewc    WNDCLASSEX <WNDCLASSEX, 0, WndProc, 0, 0, 1, 2, 3, COLOR_BTNFACE+1, 0, txClass, 4>
txClass    db "Masm32GUI", 0            ; class name
...
  invoke CreateWindowEx, WS_EX_ACCEPTFILES, wc.lpszClassName, chr$("Hi there") ...

However, you are right that it can be a one line shorter, see attachment :cool:

Quote from: sinsi on March 13, 2024, 05:48:56 AMIf your parameters are exactly
Exactly, Sinsi ;-)

(if not, it's called a bug, and if you don't play the shr eax, 1 trick, the program will most likely become an invisible zombie that must be manually killed in Task Manager)

sinsi

Two things to cause an error, but you break for the error and a quit message. To be properly paranoid your code should jump to an error handler if the return code is -1.

He also warns against using any sort of filter, as another window (e.g. OLE, CBT) might use your window procedure, and since GetMessage is blocking it might have messages piling up that don't match your filter but other code relies on them being processed.

jj2007

Quote from: sinsi on March 13, 2024, 07:32:29 AMyou break for the error and a quit message.

Yep, that's the intention. Here is a loop that is foolproof:

  invoke CreateWindowEx, WS_EX_ACCEPTFILES, wc.lpszClassName, chr$("Hi there"), ; class, title
     WS_OVERLAPPEDWINDOW or WS_VISIBLE, 120, 120, 240, 180, ; style, x, y, width, height
     NULL, rv(LoadMenu, wc.hInstance, 100), wc.hInstance, NULL
  .While eax
inc rv(GetMessage, addr msg, 0, 0, 0)
shr eax, 1
.Break .if Zero? ; 0 (OK) or -1 (error)
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
or eax, -1
  .Endw
  invoke ExitProcess, msg.wParam

If there is an error when creating the window, the loop will not be entered at all. The or eax, -1 makes sure that the loop keeps going until WM_QUIT or an error occur. Back to 36 lines, unfortunately, but it's worth it - I checked, an error in CreateWindowEx will indeed create a zombie...

TimoVJL

May the source be with you

jj2007

Quote from: TimoVJL on March 13, 2024, 10:22:15 PMSure, on purpose.
WS_EX_ACCEPTFILES

Indeed, using this style would require an appropriate handler, which is a bit beyond this simple template.

include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyEdit, "RichEdit", wCL$()
  invoke SetWindowPos, hGui, HWND_TOPMOST, eax, eax, eax, eax, SWP_NOMOVE or SWP_NOSIZE

Event DropFiles  ; load a dropped text or rtf file into the RichEdit control
  SetWin$ hMyEdit=FileRead$(Files$(0))
GuiEnd

You can test it with the attached Ansi, Utf16 and RTF files ;-)

greenozon

the last DropFiles.exe looks interesting indeed!
it could handle .rtf (wow!)
but... the emoji's support is very limited, it was able to render a couple out of hundreds available...

jj2007

Quote from: greenozon on March 13, 2024, 11:42:57 PMthe emoji's support is very limited, it was able to render a couple out of hundreds

Can you post some examples that didn't work?

greenozon

It's easy
goto https://emojipedia.org/flags
then copy whatever you like, eg:

🏁
🚩
🎌
🏴
🏳�
🏳��🌈
🏳��⚧️
🏴�☠️
🇺🇳

and paste into the DropFiles.exe editor pane

or whatever emojis you like eg
😺😺😺
😱
😨
😰
😥
😓

jj2007


sinsi

Easy emojis in Windows 11

Windows+.
😁😊🤣😂❤️👍


jj2007