OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [demos/] [mwin/] [mine.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#include <stdio.h>
2
#include <stdlib.h>
3
#include <time.h>
4
#include <string.h>
5
/*
6
 * Minesweeper for Microwindows, adapted from MiniGUI
7
 */
8
extern int mwCurrentButtons;    /* FIXME */
9
 
10
 
11
#ifdef __rtems__
12
#define  srandom  srand
13
#define  random   rand
14
#endif
15
 
16
#define MWINCLUDECOLORS
17
#include "windows.h"
18
#include "wintools.h"
19
 
20
typedef struct {
21
        int flag;
22
        int value;
23
        BOOL test;
24
        BOOL hit;
25
        BOOL bombout;
26
        BOOL error;
27
}BOM;
28
 
29
typedef struct  {
30
        int x;
31
        int y;
32
        BOOL NY;
33
}NO;
34
 
35
typedef struct {
36
    int highscore;
37
    char name[20];
38
}SCORE;
39
 
40
typedef struct {
41
        DWORD   dwStyle;
42
        LPSTR   spCaption;
43
        HMENU   hMenu;
44
        HCURSOR hCursor;
45
        HICON   hIcon;
46
        WNDPROC MainWindowProc;
47
        int     lx, ty, rx, by;
48
        COLORREF iBkColor;
49
        DWORD   dwAddData;
50
        HWND    hHosting;
51
} MAINWINCREATE, *PMAINWINCREATE;
52
 
53
#define IDOK    0
54
#define GetCharWidth()          11
55
#define GetCharHeight()         13
56
 
57
extern MWIMAGEHDR image_mineflag;
58
extern MWIMAGEHDR image_mineface;
59
extern MWIMAGEHDR image_minefacelost;
60
extern MWIMAGEHDR image_minebomb;
61
extern MWIMAGEHDR image_minedone;
62
extern MWIMAGEHDR image_minehitfalse;
63
 
64
HWND CreateMainWindow(PMAINWINCREATE pCreateInfo);
65
BOOL PtInRect2(const RECT *lprc, int x, int y);
66
void Draw3DUpFrame(HDC hDC, int l, int t, int r, int b, int fillc);
67
void SearchGround(HDC hdc,int x,int y);
68
int Open(HWND hWnd,int x,int y);
69
LRESULT TestMyWinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
70
void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo);
71
void InitAbHostedCreateInfo(HWND hHosting, PMAINWINCREATE  pCreateInfo);
72
void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);
73
void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo);
74
void* TestMyWindow(void* data);
75
void BombGame(HWND hWnd, int x, int y);
76
void Finished(HWND hWnd);
77
void Cancel3DFrame(HDC hdc, int l,int t,int r,int b);
78
void TextValue(HDC hdc, int x,int y,int value);
79
void BombOut(HWND hWnd);
80
void BothButtonDownProc(HWND hWnd, int x, int y);
81
void DrawDigit(HDC hdc, char* buffer, int CLOCK);
82
 
83
#define  ID_ABOUT  300
84
#define  ID_NEW    301  
85
#define  ID_LARGE  302
86
#define  ID_MIDDLE 303
87
#define  ID_SMALL  304
88
#define  ID_CLOSE  305
89
#define  ID_HIGHSCORE 306
90
#define  ID_CLOCK  400
91
 
92
#define  WIDTH_LARGEWIN   544
93
#define  HEIGHT_LARGEWIN  371
94
#define  WIDTH_MIDDLEWIN  287
95
#define  HEIGHT_MIDDLEWIN 332
96
#define  WIDTH_SMALLWIN   178
97
#define  HEIGHT_SMALLWIN  206
98
 
99
#define  WIDTH_FACE      30
100
#define  HEIGHT_FACE     30
101
 
102
#define  WIDTH_DIGIT     11
103
#define  WIDTH_BOMNUM    (2*WIDTH_DIGIT)
104
#define  HEIGHT_BOMNUM   30
105
 
106
#define  WIDTH_CLOCK     (3*WIDTH_DIGIT)
107
#define  HEIGHT_CLOCK    30
108
#define  FREQ_CLOCK      1000
109
 
110
#define  WIDTH_BOX       18
111
#define  HEIGHT_BOX      18
112
 
113
#if 0
114
static int winwidth = WIDTH_LARGEWIN;   /* change this for startup mine size */
115
static int winheight = HEIGHT_LARGEWIN;
116
static int sg_boxnumx = 30;
117
static int sg_boxnumy = 18;
118
static int bombnum = 99;
119
#endif
120
 
121
#if 1
122
static int winwidth = WIDTH_MIDDLEWIN;  /* change this for startup mine size */
123
static int winheight = HEIGHT_MIDDLEWIN;
124
static int sg_boxnumx = 16;
125
static int sg_boxnumy = 16;
126
static int bombnum = 40;
127
#endif
128
 
129
#if 0
130
static int winwidth = WIDTH_SMALLWIN;   /* change this for startup mine size */
131
static int winheight = HEIGHT_SMALLWIN;
132
static int sg_boxnumx = 8;
133
static int sg_boxnumy = 8;
134
static int bombnum = 10;
135
#endif
136
 
137
static BOM bom[30][18];
138
static NO NoAdr[540];
139
static SCORE score[3];
140
static int itime, leftbombnum;
141
static int oldx, oldy, adrx, adry;
142
static int flag_bombout, flag_finished, flag_size = 2;
143
static int second = 0 ;
144
static BOOL bTimer;
145
static HWND hHighscore,hCongratulate;
146
static int offsetx;
147
static int x_face, x_bomnum, x_clock;
148
 
149
void Cancel3DFrame(HDC hdc, int  l, int  t, int w, int h)
150
{
151
    HBRUSH hbr;
152
    RECT rc;
153
 
154
    SetTextColor (hdc,GRAY);
155
    Rectangle(hdc, l, t, l + w, t + h);
156
    hbr = CreateSolidBrush(LTGRAY);
157
    SetRect(&rc, l+1, t+1, l+w, t+h);
158
    FillRect(hdc, &rc, hbr);
159
    DeleteObject(hbr);
160
}
161
 
162
void TextValue(HDC hdc, int x, int y, int value)
163
 {
164
    int color = 0;
165
    char   va[20];
166
    switch(value)
167
    {
168
       case 1:  color=BLUE;       break;
169
       case 2:  color=GREEN;      break;
170
       case 3:  color=RED;        break;
171
       case 4:  color=MAGENTA;    break;
172
       case 5:  color=YELLOW;     break;
173
       case 6:  color=CYAN;       break;
174
       case 7:  color=RED;    break;
175
       case 8:  color=GREEN;  break;
176
    }
177
    SetBkColor(hdc,LTGRAY);
178
    SetTextColor(hdc,color);
179
    sprintf(va,"%d",value);
180
 
181
    TextOut(hdc, x + ((WIDTH_BOX - GetCharWidth ()) >> 1),
182
        y + ((HEIGHT_BOX - GetCharHeight ()) >> 1), va, -1);
183
}
184
 
185
void SearchGround(HDC hdc,int x,int y)
186
{
187
     int x1=0,y1=0;
188
     int i=1;
189
 
190
     bom[x][y].test=TRUE;
191
     NoAdr[itime].x=x;
192
     NoAdr[itime].y=y;
193
     NoAdr[itime].NY=FALSE;
194
     itime++;
195
     Cancel3DFrame(hdc,x*WIDTH_BOX+offsetx, y*HEIGHT_BOX+HEIGHT_FACE,
196
                        WIDTH_BOX, HEIGHT_BOX);
197
     while( i <= 8 )
198
     {
199
         switch(i)
200
         {
201
             case  1:  x1=x-1;  y1=y;    break;
202
             case  2:  x1=x-1;  y1=y-1;  break;
203
             case  3:  x1=x-1;  y1=y+1;  break;
204
             case  4:  x1=x+1;  y1=y;    break;
205
             case  5:  x1=x+1;  y1=y-1;  break;
206
             case  6:  x1=x+1;  y1=y+1;  break;
207
             case  7:  y1=y-1;  x1=x;    break;
208
             case  8:  y1=y+1;  x1=x;    break;
209
         }
210
         if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
211
                 &&!bom[x1][y1].hit&& !bom[x1][y1].test && !bom[x1][y1].value )
212
               SearchGround(hdc,x1,y1);
213
 
214
         if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
215
                            &&!bom[x1][y1].hit
216
                            &&!bom[x1][y1].test && bom[x1][y1].value!=0 )
217
         {
218
             bom[x1][y1].test=TRUE;
219
             NoAdr[itime].x=x1;
220
             NoAdr[itime].y=y1;
221
             NoAdr[itime].NY=TRUE;
222
             itime++;
223
             Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
224
                                 WIDTH_BOX, HEIGHT_BOX);
225
             TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
226
                                 bom[x1][y1].value);
227
         }
228
         i++;
229
     }
230
 }
231
 
232
BOOL Open(HWND hWnd,int x,int y)
233
{
234
    int x1=0,y1=0;
235
    int i=1;
236
    HDC hdc;
237
 
238
    hdc = GetDC(hWnd);
239
    while( i <= 8 )
240
    {
241
        switch( i ) {
242
            case  1:  x1=x-1;  y1=y;    break;
243
            case  2:  x1=x-1;  y1=y-1;  break;
244
            case  3:  x1=x-1;  y1=y+1;  break;
245
            case  4:  x1=x+1;  y1=y;    break;
246
            case  5:  x1=x+1;  y1=y-1;  break;
247
            case  6:  x1=x+1;  y1=y+1;  break;
248
            case  7:  y1=y-1;  x1=x;    break;
249
            case  8:  y1=y+1;  x1=x;    break;
250
        }
251
 
252
        if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
253
            && !bom[x1][y1].hit && bom[x1][y1].flag) {
254
            ReleaseDC(hWnd, hdc);
255
            return FALSE;
256
        }
257
 
258
        if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
259
                && !bom[x1][y1].test && !bom[x1][y1].value
260
                && !bom[x1][y1].flag ){
261
            SearchGround(hdc,x1,y1);
262
        }
263
 
264
        if( x1>=0 && y1>=0 && x1<sg_boxnumx && y1<sg_boxnumy
265
                  && !bom[x1][y1].test && bom[x1][y1].value!=0 )
266
        {
267
            bom[x1][y1].test=TRUE;
268
            NoAdr[itime].x=x1;
269
            NoAdr[itime].y=y1;
270
            NoAdr[itime].NY=TRUE;
271
            itime++;
272
             Cancel3DFrame(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
273
                                 WIDTH_BOX, HEIGHT_BOX);
274
             TextValue(hdc, x1*WIDTH_BOX+offsetx, y1*HEIGHT_BOX+HEIGHT_FACE,
275
                                 bom[x1][y1].value);
276
        }
277
        i++;
278
    }
279
 
280
    ReleaseDC(hWnd, hdc);
281
    return  TRUE;
282
}
283
 
284
void BombOut(HWND hWnd)
285
{
286
  int i,j;
287
  HDC hdc;
288
 
289
  hdc=GetDC(hWnd);
290
 
291
  for (i = 0; i < sg_boxnumx; i++) {
292
      for (j = 0; j < sg_boxnumy; j++) {
293
         if (bom[i][j].flag && !bom[i][j].hit) {
294
            Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE,
295
                    WIDTH_BOX,HEIGHT_BOX);
296
 
297
            DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
298
                        &image_minebomb);
299
            bom[i][j].bombout = TRUE;
300
          }
301
         if (!bom[i][j].flag && bom[i][j].hit){
302
            Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,j*HEIGHT_BOX+HEIGHT_FACE,
303
                    WIDTH_BOX,HEIGHT_BOX);
304
 
305
            DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
306
                        &image_minehitfalse);
307
            bom[i][j].error = TRUE;
308
 
309
          }
310
       }
311
   }
312
 
313
   DrawDIB(hdc, x_face, 0, &image_minefacelost);
314
   flag_bombout = 1;
315
   bTimer = FALSE;
316
   ReleaseDC(hWnd, hdc);
317
}
318
 
319
void Finished(HWND hWnd)
320
{
321
    int i,j;
322
    HDC hdc;
323
    RECT bombnumber;
324
    MAINWINCREATE CreateInfo;
325
 
326
    hdc = GetDC(hWnd);
327
 
328
    for (i = 0; i < sg_boxnumx; i++) {
329
        for (j = 0; j < sg_boxnumy; j++) {
330
            if (bom[i][j].flag && !bom[i][j].hit) {
331
 
332
                DrawDIB(hdc, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE,
333
                                 &image_mineflag);
334
                bom[i][j].hit = TRUE;
335
            }
336
        }
337
    }
338
 
339
    DrawDIB(hdc, x_face+1, 1, &image_minedone);
340
    flag_finished = 1;
341
    bTimer = FALSE;
342
    ReleaseDC(hWnd, hdc);
343
 
344
    leftbombnum = 0;
345
 
346
    SetRect (&bombnumber, x_bomnum, 0,
347
                         x_bomnum + WIDTH_BOMNUM, HEIGHT_BOMNUM);
348
    InvalidateRect (hWnd, &bombnumber, FALSE);
349
 
350
    if (second < score[flag_size].highscore){
351
        InitCongratulationCreateInfo(hWnd, &CreateInfo);
352
        hCongratulate = CreateMainWindow (&CreateInfo);
353
    }
354
}
355
 
356
#if 0
357
HMENU createpmenuabout()
358
{
359
    HMENU hmnu;
360
    MENUITEMINFO mii;
361
    memset (&mii, 0, sizeof(MENUITEMINFO));
362
    mii.type        = MFT_STRING;
363
    mii.id          = 0;
364
    mii.typedata    = (DWORD)"About";
365
    hmnu = CreatePopupMenu (&mii);
366
 
367
    memset (&mii, 0, sizeof(MENUITEMINFO));
368
    mii.type        = MFT_STRING ;
369
    mii.state       = 0;
370
    mii.id          = ID_ABOUT;
371
    mii.typedata    = (DWORD)"About Bomb Game";
372
    InsertMenuItem(hmnu, 3, TRUE, &mii);
373
 
374
    return hmnu;
375
}
376
 
377
HMENU createpmenustart()
378
{
379
    HMENU hmnu;
380
    MENUITEMINFO mii;
381
    memset (&mii, 0, sizeof(MENUITEMINFO));
382
    mii.type        = MFT_STRING;
383
    mii.id          = 0;
384
    mii.typedata    = (DWORD)"Start";
385
    hmnu = CreatePopupMenu (&mii);
386
 
387
    memset (&mii, 0, sizeof(MENUITEMINFO));
388
    mii.type        = MFT_STRING ;
389
    mii.state       = 0;
390
    mii.id          = ID_NEW;
391
    mii.typedata    = (DWORD)"New Game";
392
    InsertMenuItem(hmnu, 0, TRUE, &mii);
393
 
394
    mii.type        = MFT_STRING ;
395
    mii.state       = 0;
396
    mii.id          = ID_HIGHSCORE;
397
    mii.typedata    = (DWORD)"High Score";
398
    InsertMenuItem(hmnu, 1, TRUE, &mii);
399
 
400
    mii.type        = MFT_STRING ;
401
    mii.state       = 0;
402
    mii.id          = ID_CLOSE;
403
    mii.typedata    = (DWORD)"Quit Game";
404
    InsertMenuItem(hmnu, 2, TRUE, &mii);
405
 
406
    return hmnu;
407
}
408
 
409
HMENU createpmenulevel()
410
{
411
    HMENU hmnu;
412
    MENUITEMINFO mii;
413
    memset (&mii, 0, sizeof(MENUITEMINFO));
414
    mii.type        = MFT_STRING;
415
    mii.id          = 0;
416
    mii.typedata    = (DWORD)"Level";
417
    hmnu = CreatePopupMenu (&mii);
418
 
419
    mii.type        = MFT_STRING ;
420
    mii.state       = 0;
421
    mii.id          = ID_LARGE;
422
    mii.typedata    = (DWORD)"Large";
423
    InsertMenuItem(hmnu, 0, TRUE, &mii);
424
 
425
    mii.type        = MFT_STRING ;
426
    mii.state       = 0;
427
    mii.id          = ID_MIDDLE;
428
    mii.typedata    = (DWORD)"Middle";
429
    InsertMenuItem(hmnu, 1, TRUE, &mii);
430
 
431
    mii.type        = MFT_STRING ;
432
    mii.state       = 0;
433
    mii.id          = ID_SMALL;
434
    mii.typedata    = (DWORD)"Small";
435
    InsertMenuItem(hmnu, 2, TRUE, &mii);
436
 
437
    return hmnu;
438
}
439
 
440
HMENU createmenu1()
441
{
442
    HMENU hmnu;
443
    MENUITEMINFO mii;
444
 
445
    hmnu = CreateMenu();
446
 
447
    memset (&mii, 0, sizeof(MENUITEMINFO));
448
    mii.type        = MFT_STRING;
449
    mii.id          = 100;
450
    mii.typedata    = (DWORD)"Start";
451
    mii.hsubmenu    = createpmenustart();
452
 
453
    InsertMenuItem(hmnu, 0, TRUE, &mii);
454
 
455
    mii.type        = MFT_STRING;
456
    mii.id          = 110;
457
    mii.typedata    = (DWORD)"Level";
458
    mii.hsubmenu    = createpmenulevel();
459
    InsertMenuItem(hmnu, 1, TRUE, &mii);
460
 
461
    mii.type        = MFT_STRING;
462
    mii.id          = 120;
463
    mii.typedata    = (DWORD)"About";
464
    mii.hsubmenu    = createpmenuabout();
465
    InsertMenuItem(hmnu, 2, TRUE, &mii);
466
 
467
    return hmnu;
468
}
469
#endif
470
 
471
void BothButtonDownProc(HWND hWnd,int adrx,int adry)
472
{
473
    int test_open = 0;
474
    int i = 1;
475
    int adrx1 = 0, adry1 = 0;
476
    int flag_opened = 1;
477
 
478
    if (!bom[adrx][adry].test)
479
    return;
480
    if (!bom[adrx][adry].value)
481
    return;
482
    if (bom[adrx][adry].hit)
483
    return;
484
    while (i <= 8)
485
    {
486
       switch (i)
487
       {
488
        case 1:
489
           adrx1 = adrx-1;
490
           adry1 = adry;
491
        break;
492
 
493
        case 2:
494
           adrx1 = adrx-1;
495
           adry1 = adry-1;
496
        break;
497
 
498
        case 3:
499
           adrx1 = adrx-1;
500
           adry1 = adry+1;
501
        break;
502
 
503
        case 4:
504
           adrx1 = adrx;
505
           adry1 = adry-1;
506
        break;
507
 
508
        case 5:
509
            adrx1 = adrx;
510
            adry1 = adry+1;
511
        break;
512
 
513
        case 6:
514
            adrx1 = adrx+1;
515
            adry1 = adry;
516
        break;
517
 
518
        case 7:
519
            adrx1 = adrx+1;
520
            adry1 = adry+1;
521
        break;
522
 
523
        case 8:
524
            adrx1 = adrx+1;
525
            adry1 = adry-1;
526
        break;
527
       }
528
 
529
       if (adrx1>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy
530
                            && bom[adrx1][adry1].hit)
531
           test_open++;
532
       else
533
            if(adrx>=0 && adry1>=0 && adrx1<sg_boxnumx && adry1<sg_boxnumy
534
                            && !bom[adrx1][adry1].test)
535
                flag_opened = 0;
536
       i++;
537
    }
538
    if ((test_open == bom[adrx][adry].value) && !flag_opened)
539
    {
540
        if (!Open (hWnd, adrx, adry))
541
            BombOut (hWnd);
542
        if (itime == (sg_boxnumx*sg_boxnumy-bombnum))
543
            Finished(hWnd);
544
 
545
    }
546
 
547
}
548
 
549
void DrawDigit(HDC hdc, char* buffer, int CLOCK)
550
{
551
    int x;
552
 
553
    if (CLOCK)
554
        x = x_clock;
555
    else
556
        x = x_bomnum;
557
 
558
        SetBkMode(hdc, OPAQUE);
559
        SetBkColor(hdc, LTGRAY);
560
        TextOut(hdc, x, 0, buffer, -1);
561
        return;
562
}
563
 
564
LRESULT TestMyWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
565
{
566
    HDC hdc;
567
    char  bomn[30], seconds[30];
568
    int i, j;
569
    int ran1, ran2;
570
    static RECT bombregion, face, onerect, bombnumber, clock;
571
    static RECT winposition;
572
    MAINWINCREATE  CreateInfo;
573
 
574
    PAINTSTRUCT ps;
575
    switch (message) {
576
 
577
        case WM_CREATE:
578
#if 0
579
            FILE* pHighscore;
580
            char  buffer[256];
581
            if( LoadBitmap(&bmpbom,"res/lei.bmp")<0)
582
                fprintf(stderr,"bitmap error");
583
            else
584
                fValidbom = TRUE;
585
 
586
            if( LoadBitmap(&bmpface,"res/face1.bmp")<0)
587
                fprintf(stderr,"bitmap error");
588
            else
589
                fValidface = TRUE;
590
 
591
            if( LoadBitmap(&bitmap1,"res/face.bmp")<0)
592
                fprintf(stderr,"bitmap error");
593
            else
594
                fValid1 = TRUE;
595
 
596
            if( LoadBitmap(&bmpflag,"res/flag.bmp")<0)
597
                fprintf(stderr,"bitmap error");
598
            else
599
                fValidflag = TRUE;
600
 
601
            if( LoadBitmap(&bmpfinalface,"res/finished.bmp")<0)
602
                fprintf(stderr,"bitmap error");
603
            else
604
                fValidfinalface = TRUE;
605
 
606
            if( LoadBitmap(&bmphitfalse,"res/hitfalse.bmp")<0)
607
                fprintf(stderr,"bitmap error");
608
            else
609
                fValidhitfalse = TRUE;
610
 
611
            for (i = 0; i < 10; i++){
612
                sprintf(buffer, "res/%d.bmp", i);
613
                LoadBitmap(sg_bmpDigit + i, buffer);
614
            }
615
 
616
            if ((pHighscore = fopen("res/.highscore.bomb","r"))){
617
                for (i = 0; i < 3; i++)
618
                    fscanf(pHighscore, "%d, %s",
619
                            &score[i].highscore, score[i].name);
620
                fclose(pHighscore);
621
            }
622
            else
623
                for (i = 0; i < 3; i++){
624
                    score[i].highscore = 999;
625
                    strcpy(score[i].name, "unknown");
626
                }
627
#endif
628
            SetTimer(hWnd, ID_CLOCK, FREQ_CLOCK, NULL);
629
 
630
            PostMessage(hWnd,WM_COMMAND,ID_NEW,0);
631
        break;
632
 
633
        case WM_COMMAND:
634
            if (LOWORD(wParam) == ID_ABOUT)
635
            {
636
               InitAbHostedCreateInfo(hWnd,&CreateInfo);
637
               CreateMainWindow(&CreateInfo);
638
            }
639
 
640
            if (LOWORD(wParam) == ID_CLOSE)
641
            {
642
                PostMessage(hWnd, WM_CLOSE, 0, 0);
643
            }
644
 
645
            if (LOWORD(wParam) == ID_HIGHSCORE)
646
            {
647
               InitHighScoreCreateInfo(hWnd,&CreateInfo);
648
               hHighscore =  CreateMainWindow(&CreateInfo);
649
               ShowWindow(hHighscore,SW_SHOW);
650
            }
651
 
652
            if (LOWORD(wParam) == ID_LARGE)
653
            {
654
                bombnum = 99;
655
                sg_boxnumx = 30;
656
                sg_boxnumy = 18;
657
                winwidth = WIDTH_LARGEWIN;
658
                flag_size = 2;
659
                GetWindowRect(hWnd, &winposition);
660
                MoveWindow(hWnd, winposition.left, winposition.top,
661
                           WIDTH_LARGEWIN, HEIGHT_LARGEWIN, FALSE);
662
                PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
663
            }
664
            if (LOWORD(wParam) == ID_MIDDLE)
665
            {
666
                bombnum = 40;
667
                sg_boxnumx = 16;
668
                sg_boxnumy = 16;
669
                winwidth = WIDTH_MIDDLEWIN;
670
                flag_size = 1;
671
                GetWindowRect(hWnd, &winposition);
672
                MoveWindow(hWnd, winposition.left, winposition.top,
673
                           WIDTH_MIDDLEWIN, HEIGHT_MIDDLEWIN, FALSE);
674
                PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
675
            }
676
 
677
            if (LOWORD(wParam) == ID_SMALL)
678
            {
679
                bombnum = 10;
680
                sg_boxnumx = 8;
681
                sg_boxnumy = 8;
682
                winwidth = WIDTH_SMALLWIN;
683
                flag_size = 0;
684
                GetWindowRect(hWnd, &winposition);
685
                MoveWindow(hWnd, winposition.left, winposition.top,
686
                           WIDTH_SMALLWIN, HEIGHT_SMALLWIN, FALSE);
687
                PostMessage(hWnd, WM_COMMAND, ID_NEW, 0);
688
            }
689
 
690
            if (LOWORD(wParam) == ID_NEW)
691
            {
692
                bTimer = FALSE;
693
                second = 0;
694
                itime = 0;
695
                leftbombnum = bombnum;
696
                flag_bombout = 0;
697
                flag_finished = 0;
698
                x_bomnum = winwidth / 6;
699
                x_face = (winwidth*2) / 5;
700
                x_clock = (winwidth*3) / 5;
701
                offsetx = (winwidth - WIDTH_BOX*sg_boxnumx)/2-2;
702
                SetRect (&clock, x_clock, 0,
703
                            x_clock + WIDTH_CLOCK, HEIGHT_CLOCK);
704
 
705
                SetRect (&face, x_face, 0,
706
                            x_face + WIDTH_FACE, HEIGHT_FACE);
707
 
708
                SetRect (&bombregion, offsetx, HEIGHT_FACE,
709
                           WIDTH_BOX*sg_boxnumx+offsetx,
710
                           HEIGHT_BOX*sg_boxnumy+HEIGHT_FACE);
711
 
712
                SetRect (&bombnumber, x_bomnum, 0,
713
                     x_bomnum + WIDTH_BOMNUM, HEIGHT_BOMNUM);
714
 
715
               /**************initial bomb value************** */
716
 
717
              for (i = 0; i < sg_boxnumx; i++)
718
                for (j = 0; j < sg_boxnumy; j++)
719
                { bom[i][j].flag  = 0;
720
                  bom[i][j].hit   = FALSE;
721
                  bom[i][j].value = 0;
722
                  bom[i][j].test  = FALSE;
723
                  bom[i][j].bombout = FALSE;
724
                  bom[i][j].error = FALSE;
725
                 };
726
              for (i = 0; i < (sg_boxnumx*sg_boxnumy); i++)
727
                  NoAdr[i].NY = FALSE;
728
 
729
              srandom( time(NULL));
730
              i = 0;
731
              while( i < bombnum )
732
               {
733
                  ran1 = random()%sg_boxnumx;
734
                  ran2 = random()%sg_boxnumy;
735
                  if(!bom[ran1][ran2].flag)
736
                     {
737
                        bom[ran1][ran2].flag = 1;
738
                        i++;
739
                     }
740
#ifdef __rtems__
741
                      else i++;         /* bad rtems random function*/
742
#endif
743
                }
744
 
745
               for (i = 0; i < sg_boxnumx; i++)
746
                  for (j = 0; j < sg_boxnumy; j++)
747
                    {
748
                if (!bom[i][j].flag) {
749
                if(i-1>=0&&j-1>=0&&bom[i-1][j-1].flag)
750
                        bom[i][j].value++;
751
 
752
                if(i-1>=0&&bom[i-1][j].flag)
753
                        bom[i][j].value++;
754
 
755
                if(i-1>=0&&j+1<sg_boxnumy&&bom[i-1][j+1].flag)
756
                        bom[i][j].value++;
757
 
758
                if(j-1>=0&&bom[i][j-1].flag)
759
                        bom[i][j].value++;
760
 
761
                if(j+1<sg_boxnumy&&bom[i][j+1].flag)
762
                        bom[i][j].value++;
763
 
764
                if(i+1<sg_boxnumx&&j+1<sg_boxnumy&&bom[i+1][j+1].flag)
765
                        bom[i][j].value++;
766
 
767
                if(i+1<sg_boxnumx&&bom[i+1][j].flag)
768
                        bom[i][j].value++;
769
 
770
                if(i+1<sg_boxnumx&&j-1>=0&&bom[i+1][j-1].flag)
771
                        bom[i][j].value++;
772
                }
773
                     }
774
               InvalidateRect (hWnd, NULL, TRUE);
775
               }
776
        break;
777
 
778
        case WM_TIMER:
779
            if (wParam == ID_CLOCK)
780
                if (bTimer){
781
                    if (second < 1000){
782
                        second++;
783
                        InvalidateRect(hWnd, &clock, FALSE);
784
                    }
785
                }
786
        break;
787
 
788
        case WM_LBUTTONDOWN:
789
 
790
            oldx = LOWORD (lParam);
791
            oldy = HIWORD (lParam);
792
 
793
            adrx = (oldx-offsetx)/WIDTH_BOX;
794
            adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
795
 
796
            if (hCongratulate || hHighscore)
797
                break;
798
 
799
            if (!PtInRect2 (&bombregion, oldx, oldy)) {
800
                if (PtInRect2 (&face, oldx, oldy)){
801
                    PostMessage (hWnd, WM_COMMAND, ID_NEW, 0);
802
                    break;
803
                }
804
                else
805
                    break;
806
            }
807
            if (flag_bombout)
808
                break;
809
            if (flag_finished)
810
                break;
811
            if (!bTimer)
812
                bTimer = TRUE;
813
 
814
            if (bom[adrx][adry].hit)
815
                break;
816
 
817
#if 0
818
            if (GetShiftKeyStatus() & 0x00000200) {
819
#endif
820
            if(mwCurrentButtons & MWBUTTON_R) {
821
                BothButtonDownProc(hWnd,adrx,adry);
822
                break;
823
            }
824
 
825
 
826
            if (bom[adrx][adry].test)
827
                break;
828
 
829
            if (bom[adrx][adry].flag) {
830
                BombOut(hWnd);
831
                break;
832
            }
833
            if (bom[adrx][adry].value != 0)
834
            {
835
                    NoAdr[itime].x  = adrx;
836
                    NoAdr[itime].y  = adry;
837
                    NoAdr[itime].NY = TRUE;
838
                    itime++;
839
                    bom[adrx][adry].test = TRUE;
840
 
841
                    SetRect (&onerect, adrx*WIDTH_BOX+offsetx,
842
                           adry*HEIGHT_BOX+HEIGHT_FACE,
843
                           (adrx+1)*WIDTH_BOX+offsetx,
844
                           (adry+1)*HEIGHT_BOX+HEIGHT_FACE);
845
                    InvalidateRect (hWnd, &onerect, FALSE);
846
             }
847
             else {
848
                    hdc = GetDC(hWnd);
849
                    SearchGround (hdc, adrx, adry);
850
                    ReleaseDC(hWnd, hdc);
851
             }
852
 
853
             if (itime == (sg_boxnumx*sg_boxnumy - bombnum))
854
                Finished(hWnd);
855
 
856
        break;
857
 
858
        case WM_MBUTTONDOWN:
859
             oldx = LOWORD (lParam);
860
             oldy = HIWORD (lParam);
861
             adrx = (oldx-offsetx)/WIDTH_BOX;
862
             adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
863
 
864
            if (!PtInRect2 (&bombregion, oldx, oldy))
865
                break;
866
            if (flag_bombout)
867
                break;
868
            if (flag_finished)
869
                break;
870
 
871
            if (!bTimer)
872
                bTimer = TRUE;
873
 
874
           /*****RBUTTONDOWN & LBUTTONDOWN******/
875
 
876
                BothButtonDownProc(hWnd,adrx,adry);
877
                break;
878
 
879
        case WM_RBUTTONDOWN:
880
#if 0
881
             SetCapture (hWnd);
882
#endif
883
             oldx = LOWORD (lParam);
884
             oldy = HIWORD (lParam);
885
             adrx = (oldx-offsetx)/WIDTH_BOX;
886
             adry = (oldy-HEIGHT_FACE)/HEIGHT_BOX;
887
 
888
            if (!PtInRect2 (&bombregion, oldx, oldy))
889
                break;
890
            if (flag_bombout)
891
                break;
892
            if (flag_finished)
893
                break;
894
 
895
            if (!bTimer)
896
                bTimer = TRUE;
897
 
898
           /*****RBUTTONDOWN & LBUTTONDOWN******/
899
 
900
#if 0
901
            if (GetShiftKeyStatus() & 0x00000100){
902
#endif
903
            if(mwCurrentButtons & MWBUTTON_L) {
904
                BothButtonDownProc(hWnd,adrx,adry);
905
                break;
906
            }
907
           /*******  only  rbuttondown   *******/
908
 
909
            if (bom[adrx][adry].test)
910
               break;
911
            if (!bom[adrx][adry].hit )
912
               {
913
                     bom[adrx][adry].hit = TRUE;
914
                     leftbombnum--;
915
               }
916
            else
917
               { bom[adrx][adry].hit = FALSE;
918
                 leftbombnum++;
919
               }
920
            SetRect (&onerect, adrx*WIDTH_BOX+offsetx,
921
                      adry*HEIGHT_BOX+HEIGHT_FACE,
922
                      (adrx+1)*WIDTH_BOX+offsetx,
923
                      (adry+1)*HEIGHT_BOX+HEIGHT_FACE);
924
            InvalidateRect (hWnd, &onerect, FALSE);
925
            InvalidateRect (hWnd, &bombnumber, FALSE);
926
        break;
927
 
928
        case WM_PAINT:
929
            hdc = BeginPaint (hWnd, &ps);
930
 
931
            sprintf(seconds, "%03d", second);
932
            DrawDigit(hdc, seconds, TRUE);
933
 
934
            if (leftbombnum >= 0){
935
                sprintf(bomn,"%02d",leftbombnum);
936
                DrawDigit(hdc, bomn, FALSE);
937
            }
938
 
939
            if (flag_finished)
940
                DrawDIB(hdc, x_face+1, 1, &image_minedone);
941
#if 0
942
                DrawMyBitmap (hdc, fValidfinalface?&bmpfinalface:NULL,
943
#endif
944
            else
945
                if (flag_bombout)
946
                    DrawDIB(hdc, x_face, 0, &image_minefacelost);
947
                else
948
                    DrawDIB(hdc, x_face, 0, &image_mineface);
949
 
950
            for (i = 0; i < sg_boxnumx; i++)
951
                for (j = 0; j < sg_boxnumy; j++)
952
            {
953
                if (!bom[i][j].test && !bom[i][j].bombout){
954
                    SetTextColor (hdc,BLACK);
955
                    SelectObject(hdc, GetStockObject(NULL_BRUSH));
956
                    Draw3DUpFrame(hdc,
957
                            i*WIDTH_BOX+offsetx,
958
                            j*HEIGHT_BOX+HEIGHT_FACE,
959
                            (i+1)*WIDTH_BOX+offsetx,
960
                            (j+1)*HEIGHT_BOX+HEIGHT_FACE,
961
                            LTGRAY);
962
                }
963
 
964
 
965
                if ( bom[i][j].hit)
966
                    DrawDIB(hdc, i*WIDTH_BOX+offsetx+3, j*HEIGHT_BOX+3+HEIGHT_FACE,
967
                                 &image_mineflag);
968
 
969
                if (bom[i][j].error) {
970
                    Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,
971
                                 j*HEIGHT_BOX+HEIGHT_FACE,
972
                                 WIDTH_BOX,HEIGHT_BOX);
973
 
974
                    DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
975
                       &image_minehitfalse);
976
                }
977
 
978
                if (bom[i][j].bombout) {
979
                    Cancel3DFrame(hdc,i*WIDTH_BOX+offsetx,
980
                                        j*HEIGHT_BOX+HEIGHT_FACE,
981
                                        WIDTH_BOX,HEIGHT_BOX);
982
 
983
                    DrawDIB(hdc, i*WIDTH_BOX+offsetx+1, j*HEIGHT_BOX+1+HEIGHT_FACE,
984
                       &image_minebomb);
985
                }
986
            }
987
 
988
            for ( i = 0; i < itime; i++ )
989
            {
990
             Cancel3DFrame(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx,
991
                        (NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE,
992
                        WIDTH_BOX, HEIGHT_BOX);
993
             if(NoAdr[i].NY)
994
                 TextValue(hdc,(NoAdr[i].x)*WIDTH_BOX+offsetx,
995
                          (NoAdr[i].y)*HEIGHT_BOX+HEIGHT_FACE,
996
                          bom[NoAdr[i].x][NoAdr[i].y].value);
997
            }
998
            EndPaint (hWnd, &ps);
999
        break;
1000
 
1001
        case WM_CLOSE:
1002
            KillTimer(hWnd, ID_CLOCK);
1003
            DestroyWindow (hWnd);
1004
            PostQuitMessage (0);
1005
        return 0;
1006
    }
1007
    return DefWindowProc(hWnd, message, wParam, lParam);
1008
}
1009
 
1010
void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo)
1011
{
1012
    pCreateInfo->dwStyle = WS_CAPTION | WS_BORDER | WS_SYSMENU |  WS_VISIBLE;
1013
    pCreateInfo->spCaption="Microwindows Minesweeper";
1014
    pCreateInfo->hMenu = 0;      /* createmenu1(); */
1015
    pCreateInfo->hCursor = 0;    /* GetSystemCursor(0); */
1016
    pCreateInfo->hIcon = 0;
1017
    pCreateInfo->MainWindowProc = TestMyWinProc;
1018
    pCreateInfo->lx = 0;
1019
    pCreateInfo->ty = 0;
1020
    pCreateInfo->rx = winwidth;
1021
    pCreateInfo->by = winheight;
1022
    pCreateInfo->iBkColor = LTGRAY;
1023
    pCreateInfo->dwAddData = 0;
1024
    pCreateInfo->hHosting = HWND_DESKTOP;
1025
}
1026
 
1027
void* TestMyWindow(void* data)
1028
{
1029
    MSG Msg;
1030
    MAINWINCREATE CreateInfo;
1031
    HWND hMainWnd;
1032
 
1033
    InitMyWinCreateInfo(&CreateInfo);
1034
 
1035
    hMainWnd = CreateMainWindow(&CreateInfo);
1036
 
1037
    if (hMainWnd == 0)
1038
        return NULL;
1039
 
1040
    ShowWindow(hMainWnd,SW_SHOWNORMAL);
1041
    while( GetMessage(&Msg, NULL, 0, 0) ) {
1042
        TranslateMessage (&Msg);
1043
        DispatchMessage(&Msg);
1044
    }
1045
 
1046
    return NULL;
1047
}
1048
 
1049
int WINAPI
1050
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
1051
        int nShowCmd)
1052
{
1053
    TestMyWindow (NULL);
1054
    return 0;
1055
}
1056
 
1057
/**********   create a hosted about window****/
1058
LRESULT AbHostedWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1059
{
1060
    PAINTSTRUCT ps;
1061
 
1062
    switch (message) {
1063
        case WM_CREATE:
1064
        break;
1065
 
1066
        case WM_PAINT:
1067
        {
1068
            HDC hdc;
1069
 
1070
            hdc = BeginPaint (hWnd, &ps);
1071
            SetBkColor(hdc,LTGRAY);
1072
            TextOut (hdc, 10, 25, "Minesweeper Ver 0.9 (1999/08/27)", -1);
1073
            TextOut (hdc, 10, 55,
1074
                "Author: Mis. Zheng Xiang (xiang_zi@263.net).", -1);
1075
            TextOut (hdc, 10, 75,
1076
                "        Mis. Glory (glory@263.net).", -1);
1077
            EndPaint (hWnd, &ps);
1078
        }
1079
        return 0;
1080
 
1081
        case WM_CLOSE:
1082
            DestroyWindow (hWnd);
1083
        return 0;
1084
    }
1085
 
1086
    return DefWindowProc(hWnd, message, wParam, lParam);
1087
}
1088
void InitAbHostedCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
1089
{
1090
    pCreateInfo->dwStyle   = WS_BORDER | WS_CAPTION | WS_VISIBLE;
1091
    pCreateInfo->spCaption = "The about window" ;
1092
    pCreateInfo->hMenu = 0;
1093
    pCreateInfo->hCursor = 0;    /* GetSystemCursor(0); */
1094
    pCreateInfo->hIcon = 0;
1095
    pCreateInfo->MainWindowProc = AbHostedWinProc;
1096
    pCreateInfo->lx = 100;
1097
    pCreateInfo->ty = 200;
1098
    pCreateInfo->rx = 540;
1099
    pCreateInfo->by = 390;
1100
    pCreateInfo->iBkColor  = LTGRAY;
1101
    pCreateInfo->dwAddData = 0;
1102
    pCreateInfo->hHosting  = hHosting;
1103
}
1104
 
1105
/*************************** High Scores Window ******************************/
1106
#define IDC_RESET  110
1107
LRESULT HighScoreWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1108
{
1109
    PAINTSTRUCT ps;
1110
    static HWND hRESET, hOK;
1111
 
1112
    switch (message) {
1113
        case WM_CREATE:
1114
            hRESET = CreateWindowEx (0L, "button",
1115
                        "重置",
1116
                        WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
1117
                        100, 145, 60, 26,
1118
                        hWnd, (HMENU)IDC_RESET, 0, 0L);
1119
 
1120
            hOK    = CreateWindowEx (0L, "button",
1121
                        "确定",
1122
                        WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
1123
                        220, 145, 60, 26,
1124
                        hWnd, (HMENU)IDOK, 0, 0L);
1125
        break;
1126
 
1127
        case WM_COMMAND:
1128
        {
1129
            int id = LOWORD(wParam);
1130
            int i;
1131
 
1132
            if (id == IDC_RESET && HIWORD(wParam) == BN_CLICKED) {
1133
                for (i = 0; i < 3; i++){
1134
                    score[i].highscore = 999;
1135
                    strcpy(score[i].name, "unknown");
1136
                }
1137
 
1138
#if 0
1139
                FILE* pHighscore;
1140
                if ((pHighscore = fopen("res/.highscore.bomb", "w+"))){
1141
                    for (i = 0; i < 3; i++)
1142
                        fprintf(pHighscore, "%d, %s\n",
1143
                                    score[i].highscore,score[i].name);
1144
                    fclose(pHighscore);
1145
                }
1146
#endif
1147
                InvalidateRect(hWnd, NULL, TRUE);
1148
            }
1149
            if (id == IDOK && HIWORD(wParam) == BN_CLICKED)
1150
                PostMessage(hWnd, WM_CLOSE, 0, 0);
1151
        }
1152
        break;
1153
 
1154
        case WM_PAINT:
1155
        {
1156
            HDC hdc;
1157
            char buffer[50];
1158
            int i;
1159
 
1160
            hdc = BeginPaint (hWnd, &ps);
1161
            SetBkColor(hdc,LTGRAY);
1162
            TextOut(hdc, 130, 15, "英雄榜", -1);
1163
            TextOut(hdc, 15, 45, "SMALL" , -1);
1164
            TextOut(hdc, 15, 75, "MIDDLE", -1 );
1165
            TextOut(hdc, 15, 105, "LARGE", -1 );
1166
            for (i = 0; i < 3; i++){
1167
                sprintf(buffer, "%3d          %s",
1168
                            score[i].highscore, score[i].name);
1169
                TextOut(hdc, 150, 45+i*30, buffer, -1);
1170
            }
1171
            EndPaint (hWnd, &ps);
1172
        }
1173
        return 0;
1174
 
1175
        case WM_CLOSE:
1176
            DestroyWindow (hRESET);
1177
            DestroyWindow (hOK);
1178
            DestroyWindow (hWnd);
1179
            hHighscore = HWND_DESKTOP;
1180
        return 0;
1181
    }
1182
 
1183
    return DefWindowProc(hWnd, message, wParam, lParam);
1184
}
1185
 
1186
void InitHighScoreCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
1187
{
1188
    pCreateInfo->dwStyle   = WS_BORDER | WS_CAPTION;
1189
    pCreateInfo->spCaption = "High Score" ;
1190
    pCreateInfo->hMenu = 0;
1191
    pCreateInfo->hCursor   = 0;  /* GetSystemCursor(0); */
1192
    pCreateInfo->hIcon = 0;
1193
    pCreateInfo->MainWindowProc = HighScoreWinProc;
1194
    pCreateInfo->lx = 100;
1195
    pCreateInfo->ty = 200;
1196
    pCreateInfo->rx = 470;
1197
    pCreateInfo->by = 410;
1198
    pCreateInfo->iBkColor  = LTGRAY;
1199
    pCreateInfo->dwAddData = 0;
1200
    pCreateInfo->hHosting  = hHosting;
1201
}
1202
 
1203
/************************* Congratulation Window *****************************/
1204
 
1205
#define IDC_CTRL_NAME       100
1206
 
1207
LRESULT CongratulationWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1208
{
1209
    static HWND hPrompt, hName, hOK;
1210
 
1211
    switch (message) {
1212
        case WM_CREATE:
1213
#if 0
1214
            hPrompt = CreateWindow ("static",
1215
                          "请输入大虾尊姓大名: ",
1216
                          SS_SIMPLE | WS_VISIBLE,
1217
                          IDC_STATIC,
1218
                          10, 10, 185, 24, hWnd, 0);
1219
            hName   = CreateWindow ("edit",
1220
                          getlogin(),
1221
                          WS_CHILD | WS_VISIBLE | WS_BORDER,
1222
                          IDC_CTRL_NAME,
1223
                          10, 40, 175, 26, hWnd, 0);
1224
#endif
1225
            hOK     = CreateWindow ("button",
1226
                          "确定",
1227
                          WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE,
1228
                          110, 75, 75, 26,
1229
                          hWnd, (HMENU)IDOK, 0, 0L);
1230
        break;
1231
 
1232
        case WM_COMMAND:
1233
        {
1234
            int id = LOWORD(wParam);
1235
 
1236
            if (id == IDOK && HIWORD(wParam) == BN_CLICKED) {
1237
                score[flag_size].highscore = second;
1238
                SendMessage (hName, WM_GETTEXT,
1239
                                19, (LPARAM)score[flag_size].name);
1240
#if 0
1241
                FILE* pHighscore;
1242
                int i;
1243
                if ((pHighscore = fopen("res/.highscore.bomb", "w+"))){
1244
                    for (i = 0; i < 3; i++)
1245
                        fprintf(pHighscore, "%d, %s\n",
1246
                                    score[i].highscore,score[i].name);
1247
                    fclose(pHighscore);
1248
                }
1249
#endif
1250
                PostMessage (hWnd, WM_CLOSE, 0, 0);
1251
            }
1252
        }
1253
        break;
1254
                                                                                        case WM_CLOSE:
1255
            DestroyWindow (hPrompt);
1256
            DestroyWindow (hName);
1257
            DestroyWindow (hOK);
1258
            DestroyWindow (hWnd);
1259
            hCongratulate = HWND_DESKTOP;
1260
        return 0;
1261
    }
1262
 
1263
    return DefWindowProc(hWnd, message, wParam, lParam);
1264
}
1265
 
1266
void InitCongratulationCreateInfo (HWND hHosting, PMAINWINCREATE pCreateInfo)
1267
{
1268
    pCreateInfo->dwStyle   = WS_BORDER | WS_CAPTION | WS_VISIBLE;
1269
    pCreateInfo->spCaption = "Congratulation" ;
1270
    pCreateInfo->hMenu = 0;
1271
    pCreateInfo->hCursor   = 0;  /* GetSystemCursor(0); */
1272
    pCreateInfo->hIcon = 0;
1273
    pCreateInfo->MainWindowProc = CongratulationWinProc;
1274
    pCreateInfo->lx = 50;
1275
    pCreateInfo->ty = 60;
1276
    pCreateInfo->rx = 255;
1277
    pCreateInfo->by = 200;
1278
    pCreateInfo->iBkColor  = LTGRAY;
1279
    pCreateInfo->dwAddData = 0;
1280
    pCreateInfo->hHosting  = hHosting;
1281
}
1282
 
1283
HWND
1284
CreateMainWindow(PMAINWINCREATE pCreateInfo)
1285
{
1286
        HWND            hwnd;
1287
        RECT            rc;
1288
        WNDCLASS        wc;
1289
 
1290
        wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
1291
        wc.lpfnWndProc = (WNDPROC)pCreateInfo->MainWindowProc;
1292
        wc.cbClsExtra = 0;
1293
        wc.cbWndExtra = 0;
1294
        wc.hInstance = 0;
1295
        wc.hIcon = pCreateInfo->hIcon;
1296
        wc.hCursor = pCreateInfo->hCursor;
1297
        wc.hbrBackground = (HBRUSH)CreateSolidBrush(pCreateInfo->iBkColor);
1298
        wc.lpszMenuName = 0;
1299
        wc.lpszClassName = pCreateInfo->spCaption;
1300
        RegisterClass(&wc);
1301
 
1302
        SetRect(&rc, pCreateInfo->lx, pCreateInfo->ty, pCreateInfo->rx,
1303
                pCreateInfo->by);
1304
        AdjustWindowRectEx(&rc, pCreateInfo->dwStyle, FALSE, 0L);
1305
 
1306
        hwnd = CreateWindowEx(0L, pCreateInfo->spCaption,
1307
                        pCreateInfo->spCaption,
1308
                        pCreateInfo->dwStyle,
1309
                        rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
1310
                        pCreateInfo->hHosting,
1311
                        (HMENU)0, (HINSTANCE)0,
1312
                        (PVOID)pCreateInfo->dwAddData);
1313
        return hwnd;
1314
}
1315
 
1316
BOOL
1317
PtInRect2(const RECT *lprc, int x, int y)
1318
{
1319
        POINT   p;
1320
 
1321
        p.x = x;
1322
        p.y = y;
1323
        return PtInRect(lprc, p);
1324
}
1325
 
1326
void
1327
Draw3DUpFrame(HDC hDC, int l, int t, int r, int b, int fillc)
1328
{
1329
        RECT    rc;
1330
        HBRUSH  hbr;
1331
 
1332
        SetRect(&rc, l, t, r, b);
1333
        Draw3dBox(hDC, rc.left, rc.top,
1334
                rc.right-rc.left, rc.bottom-rc.top,
1335
                GetSysColor(COLOR_3DLIGHT),
1336
                GetSysColor(COLOR_WINDOWFRAME));
1337
        InflateRect(&rc, -1, -1);
1338
        Draw3dBox(hDC, rc.left, rc.top,
1339
                rc.right-rc.left, rc.bottom-rc.top,
1340
                GetSysColor(COLOR_BTNHIGHLIGHT),
1341
                GetSysColor(COLOR_BTNSHADOW));
1342
        InflateRect(&rc, -1, -1);
1343
 
1344
        hbr = CreateSolidBrush(LTGRAY);
1345
        FillRect(hDC, &rc, hbr);
1346
        DeleteObject(hbr);
1347
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.