Previous page Select page Next page

Improving the "peg" handler - step 5

Now for the big one. We have pegged 4 buttons simultaneously but we're moving on to handling 9 of them as you can see in the illustration on the right. So how are we going to tackle this? One step at a time. Let's start by going to the window designer in EasyCode and putting in all the extra buttons, named "btn0" to "btn8". Then go to the code for the "OnResize" handler and add all the relevant calls to the pegPosition routine:


    UseData winMainProcedure

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN0, 0, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN1, 1, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN2, 2, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN3, 3, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN4, 4, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN5, 5, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN6, 6, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN7, 7, 4

    Invoke pegObject, [hWnd], IDC_WINMAIN_BTN8, 8, 4

    Return (TRUE)

  ; End OnResize


That didn't hurt, did it? Now we need to go to the pegPosition routine itself and to amend the "compare and jump" code to include the extra locations:

    Mov Ebx, [pegPosition]

    Cmp Ebx, 0

      Jz >>.position_0

    Cmp Ebx, 1

      Jz >>.position_1

    Cmp Ebx, 2

      Jz >>.position_2

    Cmp Ebx, 3

      Jz >>.position_3

    Cmp Ebx, 4

      Jz >>.position_4

    Cmp Ebx, 5

      Jz >>.position_5

    Cmp Ebx, 6

      Jz >>.position_6

    Cmp Ebx, 7

      Jz >>.position_7

    Cmp Ebx, 8

      Jz >>.position_8

That means, of course that you will now have to put in all the new labels in the subsequent code. All of the new buttons (with the exception of "btn4") have one of their co-ordinates against the border of the window and is therefore easy to calculate using the approach we have used before. As for the other co-ordinates, I have already explained how to do it - calculate the position as if it was on the far side or bottom of the window and then divide by 2. But remember - you don't need to add the border to those co-ordinates which are centred.

At any rate, this is another little exercise I want you to try out for yourself. So, complete the pegPosition code and, if you're stuck, check here for the full example.

Previous page Select page Next page