News:

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

Main Menu

[First timer]Window will not show up

Started by carre89, November 21, 2012, 07:33:52 AM

Previous topic - Next topic

MichaelW

If the buttons are supposed to behave as the Minesweeper buttons do, then all of the functionality that the MASM32 bitmap button example implements will not be necessary. You will have the initial button face that is replaced by any one of ~11 "flat" bitmaps when the button is actuated.

Well Microsoft, here's another nice mess you've gotten us into.

dedndave

yah - that is way overkill

here is the bitmap used by WinMine
it is oriented vertically instead of horizonally (don't know why - i would use horz)
it kind of tells you that they are not using individual buttons


CommonTater

Quote from: dedndave on November 22, 2012, 09:07:56 AM
it would make much more sense to just handle the displayed grid in WM_PAINT
and handle the mouse clicks by calculating the grid location - essentially making one big customized button, if you will
set up an array that holds the state for each grid square

The WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_RBUTTONDOWN and GetCursorPos() would be particularly suited to this kind of activity.  It's actually pretty easy to do...


dedndave

i think you can do it with just WM_LBUTTONDOWN and WM_RBUTTONDOWN
those 2 messages provide the cursor position in wParam, as i recall
you don't care about WM_MOUSEMOVE, capturing the mouse or any of that
it would be pretty simple, i think

if you wanted to use a small array, 1 byte for each grid-square would be plenty
use the lower 4 bits to hold the current displayed state and the upper 4 bits to hold the "hidden" contents
something like that   :P

CommonTater

Quote from: dedndave on November 22, 2012, 09:32:42 AM
i think you can do it with just WM_LBUTTONDOWN and WM_RBUTTONDOWN
those 2 messages provide the cursor position in wParam, as i recall
you don't care about WM_MOUSEMOVE, capturing the mouse or any of that
it would be pretty simple, i think

if you wanted to use a small array, 1 byte for each grid-square would be plenty
use the lower 4 bits to hold the current displayed state and the upper 4 bits to hold the "hidden" contents
something like that   :P

The WM_MOUSEMOVE message provides a real quick check to see if the mouse is inside the program's window or not... inside the window you get a stream of them, but they stop at the border.


dedndave

right - but in mine sweeper, nothing changes on mouse movement
only when you click does something happen
the program doesn't have to consume a lot of processor cycles handling all those WM_MOUSEMOVE's

CommonTater

Quote from: dedndave on November 22, 2012, 10:57:30 AM
right - but in mine sweeper, nothing changes on mouse movement
only when you click does something happen
the program doesn't have to consume a lot of processor cycles handling all those WM_MOUSEMOVE's

true.

carre89

That sounds like a better idea haha. Do you know a project/tutorial that I can work off - I need to have this done by next week... Thank you for your help so far.

dedndave

not off-hand
if time permits, i may do a very basic one tomorrow, just so you get the idea

carre89

So I did a little bit work on it. I found this basic tutorial on how to paint to the Window,
http://www.asmcommunity.net/book/tutorials/iczelion/simple-bitmap

Using this tutorial I was able to paint a cell/button to the window. Now I need to figure out how to catch click events in the window properly. Can someone show me a quick code snippet of catch a mouse click event and getting it's position?

How do I repaint the window with the updated cells?

If you look at my code you can see I added alot of new procedures and structures to the program. Most notably a minefield struct. The problem is I am not sure how to use it properly as it seems. I am getting some sort of error.

I am going to try to figure as much as I can by myself and update this post accordingly. Once again thankyou for your help so far. This has been the most helpful forum I have ever used.  :greenclp: :greenclp: :greenclp:

Edit ********************
I have another quick question. Is it possible to have a struct within a struct? I was thinking about creating a cell struct within the minefield struct that would contain the properties of each cell(e.g. opened || closed, mine || num etc). So I would have an array of mines within the minefield struct. It would make accessing each of the cell's properties much easier and clearer.

dedndave

you can just handle the WM_LBUTTONDOWN and WM_RBUTTONDOWN messages

    .elseif uMsg==WM_LBUTTONDOWN
        movzx   ecx,word ptr lParam    ;ECX = X client coordinate
        movzx   edx,word ptr lParam+2  ;EDX = Y client coordinate

        ;rest of button click code

        xor     eax,eax                ;return 0

dedndave

as for repainting, i was thinking of having a 256-color DIB section for the grid area
then, you can modify the bytes directly for a specific square
then, create a RECT that outlines that square and pass it to InvalidateRect
then call UpdateWindow and let the paint routine update just that square

you can create a byte array for the grid
each byte can represent a grid square
the upper 4 bits can be used as an index (0-15) into the image strip, indicating the current display state
the lower 4 bits can describe what the hidden content is

CommonTater

Quote from: carre89 on November 24, 2012, 12:37:33 PM
How do I repaint the window with the updated cells?

You might want to look into the BitBlt function in the Windows API

This would require you to store small bitmaps for each button state in your program's resources (a common technique) and drop them into place as needed.

carre89

I think I got a little bit ahead of myself. I had a lot of coffee today :dazzled: . I want to focus on getting it to run first before I worry about anything else.

So I divided up the project into separate source files. main.asm handling the painting while all my minefield functions are in minefield.asm. I just commented a bunch of code I that I'll worry about later. What I need to figure out is why my MineFieldStruct is throwing me an error;

fatal error A1010: unmatched block nesting : MineField

I attached my latest revision if anybody wants to look at it.

dedndave

MineFieldStruct STRUCT
;
;
;
MineField ENDS


the name you use to open a structure definition should match the one you use to close   :P
block nesting errors are usually easy "operator error" problems - lol

get some sleep
i started a program for this - was busy yesterday and today
maybe i'll finish it off tomorrow