News:

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

Main Menu

Miscellaneous snippets

Started by jj2007, August 20, 2017, 08:02:31 AM

Previous topic - Next topic

jj2007

Quote from: daydreamer on December 14, 2019, 12:00:52 PMAlso seen map drawing,why don't add a Fun quiz to geography and country stats on different things?

Yes, that could be fun. Prepare a file with questions and answers, and we'll add it to the attached template (which requires Europe.zip from the MB extras).

Here is the source (attached, with exe):

include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyMap, "canvas", w660      ; define a canvas control using 66% of the client rect width
  GuiControl TheManual, "richedit", res:92, x660, w340, bcol RgbCol(255, 255, 240)
  GuiControl Sbar, "statusbar"
  ArrayLoadMap 0, 90                    ; Europe.dmi and Europe.map in resources
  MapColours(0, "abcdefghiabcdefghiabcdefghiabcdefghiabcdefghiabcdefghi")      ; set colours to map 0 (a=red, i=green)
Event CanvasPaint
  ArrayPlot RgbCol(0, 240, 255)         ; init and set background colour
  PaintMap RgbCol(127, 127, 127), lines=2       ; map with grey borders 2px thick
  GuiTextBox 99.0-120, 51.0, 120, auto, "This program requires the file Europe.map", bcol LiteGreen, font -16:FW_NORMAL
  ArrayPlot exit, "Europe"
Event Message
  .if uMsg_==WM_MAPCLICKED
        .if MapRegion>=0
                SetWin$ hSbar="You clicked on "+MapRegion$      ; *** add your ideas here ***
        .else
                SetWin$ hSbar=Time$     ; user clicked into water ;-)
        .endif
  .endif
GuiEnd

LiaoMi

Quote from: jj2007 on December 14, 2019, 01:48:12 PM
Quote from: daydreamer on December 14, 2019, 12:00:52 PMAlso seen map drawing,why don't add a Fun quiz to geography and country stats on different things?

Yes, that could be fun. Prepare a file with questions and answers, and we'll add it to the attached template (which requires Europe.zip from the MB extras).

Here is the source (attached, with exe):

include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyMap, "canvas", w660      ; define a canvas control using 66% of the client rect width
  GuiControl TheManual, "richedit", res:92, x660, w340, bcol RgbCol(255, 255, 240)
  GuiControl Sbar, "statusbar"
  ArrayLoadMap 0, 90                    ; Europe.dmi and Europe.map in resources
  MapColours(0, "abcdefghiabcdefghiabcdefghiabcdefghiabcdefghiabcdefghi")      ; set colours to map 0 (a=red, i=green)
Event CanvasPaint
  ArrayPlot RgbCol(0, 240, 255)         ; init and set background colour
  PaintMap RgbCol(127, 127, 127), lines=2       ; map with grey borders 2px thick
  GuiTextBox 99.0-120, 51.0, 120, auto, "This program requires the file Europe.map", bcol LiteGreen, font -16:FW_NORMAL
  ArrayPlot exit, "Europe"
Event Message
  .if uMsg_==WM_MAPCLICKED
        .if MapRegion>=0
                SetWin$ hSbar="You clicked on "+MapRegion$      ; *** add your ideas here ***
        .else
                SetWin$ hSbar=Time$     ; user clicked into water ;-)
        .endif
  .endif
GuiEnd


If you reduce the window, then everything is well rendered, but if you enlarge the window on the left side, especially in large sections, you can see an unusual drawing line from the text container.

daydreamer

is there a nice site to get updated country facts and figures with help of recall?to fill a country array of struct with different categorys
and create quiz similar to this:
http://masm32.com/board/index.php?topic=7834.15
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Quote from: LiaoMi on December 14, 2019, 10:34:20 PMIf you reduce the window, then everything is well rendered, but if you enlarge the window on the left side, especially in large sections, you can see an unusual drawing line from the text container.

No such line here :rolleyes:

Does anybody else see a line in the wrong place? Which OS?

LiaoMi

#139
Quote from: jj2007 on December 15, 2019, 05:13:59 AMthe picture jumps here and there, photo report can be downloaded here https://www.upload.ee/files/10847594/jj2.zip.html

jj2007: Thanks, now I see what you mean: the delay when updating the richedit control. There is a simple explanation for this effect: it can't be done fast enough. Even when sizing the window slowly, cpu usage goes up to 100% for the core of the process. The map is about 18k lines to draw - and this is not done via StretchBlt, it really gets completely drawn for each frame. Watch the Norwegian coastline when sizing the main window very slowly.

In theory, I could switch to StretchBlt, but 1. sizing the window frenetically is not a typical usage and 2. painting a single country to achieve the feedback effect when you click into the country would require more sophisticated code and logic.

P.S.: I just realised that instead of quoting your post, I modified it, and also deleted most of it - sorry. These are the pros and cons of being the administrator of a sub-forum :cool:

LiaoMi

Changing the DC a Control paints on
Hello,

Is it possible to make a control (a richedit control for example) paint onto your own DC instead of the window DC?

http://www.asmcommunity.net/forums/topic/?id=15998

WS_EX_COMPOSITED
0x02000000L
Paints all descendants of a window in bottom-to-top painting order using double-buffering. Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects, but only if the descendent window also has the WS_EX_TRANSPARENT bit set. Double-buffering allows the window and its descendents to be painted without flicker. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC.
Windows 2000: This style is not supported.

As an option ..
myRichCtrl.ShowWindow(SW_HIDE);
myRichCtrl.DoSomething();
myRichCtrl.ShowWindow(SW_SHOW);

jj2007

Quote from: LiaoMi on December 15, 2019, 10:08:09 PMWS_EX_COMPOSITED

Looks interesting, thanks :thumbsup:

But when I add this style to an edit or richedit control, CreateWindowEx fails. Raymond Chen writes about another issue, though.

Attached another one from the life expectancy series, now comparing two countries. The red line gets chosen with the left and right arrows, the blue one by clicking into the map. Source included.

Biterider

#142
Hi
I used the WS_EX_COMPOSITED style for my own controls and it works fine if you follow the MS rules.
One problem I noticed is that the scrollbar loses the scrollbox transition effects.
It's a trifle if you get rid of the awful flicker.

Biterider

LiaoMi

Quote from: Biterider on December 16, 2019, 05:37:45 PM
Hi

I used the WS_EX_COMPOSITED style for my own controls and it works fine if you follow the MS rules.
One problem I noticed is that the scrollbar loses the scrollbox transition effects.
It's a trifle if you get rid of the awful flicker.[/size]

Biterider

Hi Biterider,

:biggrin: Is the font specially size=2px small? Yes  :thumbsup:, following the recommendations of Microsoft, it should work.

Biterider

Hi LiaoMi
Sorry, better now?  :biggrin:


jj2007

It should work, yes, but...

push 0                     ; ÚlParam = NULL
push dword ptr [40FA34]    ; ³hInst = 00400000
push 2A                    ; ³ID = 42.
push dword ptr [ebp+8]     ; ³hParent
push 28                    ; ³Height = 40.
push 5A                    ; ³Width = 90.
push 0A                    ; ³Y = 10.
push 0A                    ; ³X = 10.
push 54A41144              ; ³Style = WS_CHILD|WS_BORDER|WS_THICKFRAME|WS_VISIBLE|WS_CLIPSIBLINGS|WS_VSCROLL|1144
push 0                     ; ³WindowName = NULL
push offset 004101DE       ; ³ClassName = "RichEdit20W"
push 2000020               ; ³ExtStyle = WS_EX_TRANSPARENT|2000000
call <jmp.&user32.CreateWi ; ÀUSER32.CreateWindowExW


Now that I applied WS_EX_COMPOSITED to the parent window,
1. the control gets created using WS_EX_COMPOSITED = 2000000h
2. but WinID shows exstyle 0x120 for the child (and 2000100 for the parent)
3. and the flicker is as before

It certainly looks nice when dragging the edit over the map :tongue:
:sad:

jj2007

There are many numbers with matching "mirrored squares", like 13^2=169, 31^2=961:

matches number  mirror  square  mirror
1       11      11      121     121
2       12      21      144     441
3       13      31      169     961
4       21      12      441     144
5       22      22      484     484
6       31      13      961     169
100 numbers tested, 5.9% matches


include \masm32\MasmBasic\MasmBasic.inc         ; download
  SetGlobals matches
  Init
  For_ ct=1 To 100000000                ; 100 million iterations
        Let esi=Str$(ct)                ; e.g. "13"
        void Val(esi)                   ; 13
        mul eax                         ; 169
        push Mirror$(Str$(eax))         ; "961"
        void Val(Mirror$(esi))          ; 31
        mul eax                         ; 961
        xchg Str$(eax), edi             ; edi: "961"
        pop ecx                         ; "961"
       .if !StringsDiffer(ecx, edi)     ; "961"=="961"
                inc matches
                PrintLine Str$(matches), Tb$, esi, Tb$, Mirror$(esi), Str$("\t%i\t", ct*ct), edi
        .endif
  Next
  Inkey Str$("%i numbers tested", ct-1), Str$(", %5f% matches", matches/ct*100)
EndOfCode

daydreamer

Quote from: jj2007 on December 14, 2019, 01:48:12 PM
Quote from: daydreamer on December 14, 2019, 12:00:52 PMAlso seen map drawing,why don't add a Fun quiz to geography and country stats on different things?

Yes, that could be fun. Prepare a file with questions and answers, and we'll add it to the attached template (which requires Europe.zip from the MB extras).

so far something to test with
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

LiaoMi

Quote from: jj2007 on December 17, 2019, 01:13:45 AM
It should work, yes, but...

push 0                     ; ÚlParam = NULL
push dword ptr [40FA34]    ; ³hInst = 00400000
push 2A                    ; ³ID = 42.
push dword ptr [ebp+8]     ; ³hParent
push 28                    ; ³Height = 40.
push 5A                    ; ³Width = 90.
push 0A                    ; ³Y = 10.
push 0A                    ; ³X = 10.
push 54A41144              ; ³Style = WS_CHILD|WS_BORDER|WS_THICKFRAME|WS_VISIBLE|WS_CLIPSIBLINGS|WS_VSCROLL|1144
push 0                     ; ³WindowName = NULL
push offset 004101DE       ; ³ClassName = "RichEdit20W"
push 2000020               ; ³ExtStyle = WS_EX_TRANSPARENT|2000000
call <jmp.&user32.CreateWi ; ÀUSER32.CreateWindowExW


Now that I applied WS_EX_COMPOSITED to the parent window,
1. the control gets created using WS_EX_COMPOSITED = 2000000h
2. but WinID shows exstyle 0x120 for the child (and 2000100 for the parent)
3. and the flicker is as before

It certainly looks nice when dragging the edit over the map :tongue:
:sad:

Hi jj2007,

:sad: everything looks softer, but flicker is noticeable, frame-by-frame recording shows that the frame rate has increased, its not a solution.

jj2007

Quote from: LiaoMi on December 18, 2019, 07:23:19 AM:sad: everything looks softer, but flicker is noticeable, frame-by-frame recording shows that the frame rate has increased, its not a solution.

I can't see much difference, but in any case there is no solution because the map drawing is so slow that flicker on resize cannot be avoided.