| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3773 人关注过本帖
标题:运行了一下般就运行不了,怎么办?
只看楼主 加入收藏
huangqiandgz
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-24
收藏
 问题点数:0 回复次数:1 
运行了一下般就运行不了,怎么办?
// WindowsProject1.cpp: 定义应用程序的入口点。
//

#include "stdafx.h"
#include "WindowsProject1.h"
#include "resource.h"
#define MAX_LOADSTRING 100

// 全局变量:
RECT rect;
HINSTANCE hInst;                                // 当前实例
WCHAR szTitle[MAX_LOADSTRING];                  // 标题栏文本
WCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口类名
HWND ii,ii2,sea;
static int img[60],all;
static int img2[12][8];
static int height = 84;
static POINT p1, p2;
static int state[12][8];
static int allwin = 30;
static int Time = 0;
static int initGame = 0;
static int compare, compare2, same = 0, same2 = 0;
// 此代码模块中包含的函数的前向声明:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
void mouseMove(HWND hWnd,int n);
void PUSHBUTTON(int n, HWND hWnd);
BOOL Connect(int n, int m, HWND hWnd);
BOOL Connect2(int nx, int ny, int mx,int my,HWND hWnd );
void seachSame(HWND hWnd);
BOOL surplusConnect(int n, int m, HWND hWnd);
BOOL surplusConnect2(int nx, int ny, int mx, int my, HWND hWnd);
void deleteArray(int index);
void array1(HWND hWnd);
void newArray(HWND hWnd);
void init(HWND hwnd);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: 在此放置代码。

    // 初始化全局字符串
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_WINDOWSPROJECT1, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // 执行应用程序初始化:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINDOWSPROJECT1));

    MSG msg;

    // 主消息循环:
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}



//
//  函数: MyRegisterClass()
//
//  目的: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT1));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = NULL;//MAKEINTRESOURCEW(IDC_WINDOWSPROJECT1);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassExW(&wcex);
}

//
//   函数: InitInstance(HINSTANCE, int)
//
//   目的: 保存实例句柄并创建主窗口
//
//   注释:
//
//        在此函数中,我们在全局变量中保存实例句柄并
//        创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // 将实例句柄存储在全局变量中

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的:    处理主窗口的消息。
//
//  WM_COMMAND  - 处理应用程序菜单
//  WM_PAINT    - 绘制主窗口
//  WM_DESTROY  - 发送退出消息并返回
//
//

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    all = 60;
    int index;
    static POINT p;
    static PAINTSTRUCT ps;
    static HDC hdc = BeginPaint(hWnd, &ps);
    //static HDC hdc = GetDC(hWnd);
    static int g_nXCoor, g_nYCoor;
    int g[10]{ 0,IDB_BITMAP1,IDB_BITMAP2 };
    TCHAR n[10];
    int a = 1;
   
   
    switch (message)
    {
    case WM_CREATE:
        ii = CreateWindow(TEXT("BUTTON"), TEXT(""), WS_CHILD | WS_VISIBLE | BS_BITMAP,
            650, 50, 50, 50, hWnd, (HMENU)412, NULL, NULL);
        ii2 = CreateWindow(TEXT("BUTTON"), L"重来", WS_CHILD | WS_VISIBLE ,
            350, 50, 100, 50, hWnd, (HMENU)413, NULL, NULL);
         sea = CreateWindow(TEXT("BUTTON"), L"search", WS_CHILD | WS_VISIBLE,
            450, 50, 100, 50, hWnd, (HMENU)414, NULL, NULL);
        init(hWnd);
        initGame++;
        break;
    case WM_MOUSEMOVE:
        
        //HDC hdc = GetDC(hWnd);
    //    MessageBox(NULL, L"xx", NULL, NULL);
        g_nXCoor = LOWORD(lParam);
        g_nYCoor = HIWORD(lParam);
        p.x = g_nXCoor;
        p.y = g_nYCoor;
        //mouseMove(hWnd, g_nXCoor);
        //EndPaint(hWnd, &ps);
    //    ReleaseDC(hWnd, hdc);
   
        break;
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // 分析菜单选择:
            if (wmId>200)
            {
                Time++;
                //TCHAR m[5],n[5];
                ////int k = GetDlgCtrlID(WindowFromPoint(p));
                //wsprintf(m, L"%d", (wmId-200)/10);
                //wsprintf(n, L"%d", (wmId - 200) % 10);
               
                PUSHBUTTON(wmId, hWnd);
        //        MessageBox(NULL, m, n, NULL);
            }
            switch (wmId)
            {
            case 412:
                //WindowFromPoint()
                 //g=    GetDlgCtrlID(GetActiveWindow());
                //int k = GetDlgCtrlID(GetActiveWindow());
                //array1(hWnd);
                newArray(hWnd);
               
                break;
            case 413:
                init(hWnd);
                break;
            case 414:
                seachSame(hWnd);
                break;
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            /*for (size_t i = 0; i < 11; i++)
            {
                MoveToEx(hdc, 0, 50 * i, 0);
                LineTo(hdc, 845, 50 * i);
                MoveToEx(hdc, 50*i, 0, 0);
                LineTo(hdc, 50 * i, 800);
               
               
            }
            for (size_t i = 0; i < 12; i++)
            {
                for (int j = 0; j < 8; j++) {
                    TCHAR n[5];
                    wsprintf(n, L"%d", img2[i][j]);
                    TextOut(hdc, i * 50, 25 * j, n, 4);
                }
            }*/
            

            // TODO: 在此处添加使用 hdc 的任何绘图代码...
            

            //UpdateWindow(hWnd);
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
void deleteArray(int index) {
    for (int i = index; i <= all - 1; i++)
    {
        img[i] = img[i + 1];
    }
//    if (all < 60) {
//    for (int j = all + 1; j <= 60; j++) {
//        img[j] = 0;
//    }
//}
}
void newArray(HWND hWnd) {
    int k1 = 0,index;
    for (int j = 1; j < 7; j++) {
        for (size_t i = 1; i < 11; i++)
        {
            if (img2[i][j] != 0) {
                img[k1] = img2[i][j];
                k1++;
            }
        
        
        }
    }
    HDC hdc = GetDC(hWnd);
    for (int i = 0; i <= k1; i++)
    {
        TCHAR n[5];
        wsprintf(n,L"%d",img[i]);
            TextOut(hdc,i*30,0,n, 3);
    }
    ReleaseDC(hWnd, hdc);
        all=k1;

   
    for (int j = 1; j < 7; j++) {
        for (size_t i = 1; i < 11; i++)
        {
            if (img2[i][j] != 0) {
                index = rand() % all;

                    img2[i][j] = img[index];
                    deleteArray(index);
                    HBITMAP hbmp2 = LoadBitmap((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(img2[i][j]));//
                    ::SendMessage(GetDlgItem(hWnd, 200 + j * 12 + i), BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, LPARAM(hbmp2));
                all--;
            }

            //k1++;
        }
    }
    //TCHAR n[5];
    //wsprintf(n, L"%d", all);
    //MessageBox(NULL, n, L"all", NULL);
    //UpdateWindow(hWnd);
}
void array1(HWND hWnd) {
   
    HDC hdc = GetDC(hWnd);
   
    for (int i=0;i<60;i++)
    {
        TCHAR n[5];
        wsprintf(n, L"%d", img[i]);
        TextOut(hdc, i * 50,25, n, 4);
        
    }
    MoveToEx(hdc, 0, 0, 0);
    LineTo(hdc, 400, 400);

    //UpdateWindow(hWnd);
    //MessageBox(NULL, L"text", NULL, NULL);
    ReleaseDC(hWnd,hdc);
}
// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}
void mouseMove(HWND hWnd,int n) {
    HDC hdc = GetDC(hWnd);
    TCHAR m[5];
    wsprintf(m, L"%d", n);
    TextOut(hdc,20, 20,m, 5);
   
    ReleaseDC(hWnd, hdc);
}
void PUSHBUTTON(int n, HWND hWnd) {

    int a = (n - 200) % 12;
    int b = (n - 200) / 12;
    /*TCHAR  f[5],e[5];*/

    //wsprintf(e, L"%d", img2[a][b]);
    //wsprintf(f, L"%d", Time);
    //MessageBox(NULL, e, L"img", NULL);
    //MessageBox(NULL, f, L"time", NULL);

    //static int hwndChar[8] = { hbtn1,L"hbtn2",L"hbtn3",L"hbtn4",L"hbtn5",L"hbtn6",L"hbtn7",L"hbtn8" };
    if (Time == 1)
    {

        compare = n;

    }
   
    if (Time == 2) {
        compare2 = n;
        int a = (compare - 200) % 12;
        int b = (compare - 200) / 12;
        int c = (compare2 - 200) % 12;
        int d = (compare2 - 200) / 12;
        if (compare == n) {
            Time = 1;
            //break;
        }
        else if (img2[a][b] == img2[c][d])
        {


            


            TCHAR e[5], f[5];

            /*wsprintf(e, L"%d", img2[a][b]);
            wsprintf(f, L"%d", img2[c][d]);
            MessageBox(NULL, e, L"e", NULL);
            MessageBox(NULL, f, L"f", NULL);

            MessageBox(hWnd, L"==", NULL, NULL);*/
        //    Connect(compare, compare2, hWnd);
            if (Connect(compare, compare2, hWnd))
            {
            //    MessageBox(hWnd, L"PUSHBUTTON true", NULL, NULL);
                Time = 0;
            }
            else
            {
            //    MessageBox(hWnd, L"PUSHBUTTON false", NULL, NULL);
                Time = 1;
            }
            

        }
        else {
            Time = 1;
            compare = compare2;
            compare2 = NULL;
        }

    }
}
BOOL Connect(int n, int m, HWND hWnd) {

    int a = (n - 200) % 12;
    int b = (n - 200) / 12;
    int c = (m - 200) % 12;
    int d = (m - 200) / 12;
    for (int i = b; (b - i >= 0)&&(b - i <= 7); i--)

    {
        /*TCHAR n[5];
        wsprintf(n, L"%d", b - i);
        MessageBox(NULL, n, L"555", NULL);*/
        //MessageBox(NULL, L"continue4", NULL, NULL);

        if (Connect2(a, b, a, b - i, hWnd)) {
            //MessageBox(NULL, L"continue3", NULL, NULL);
            p1.x = a;
            p1.y = b - i;
            if (Connect2(a, b - i, c, b - i, hWnd)) {

                p2.x = c;
                p2.y = b - i;
                if (Connect2(c, b - i, c, d, hWnd)) {
                    //MessageBox(NULL, L"continue2xxxx1", NULL, NULL);
                    int com1x = (compare - 200) % 12;
                    int com1y = (compare - 200) / 12;
                    int com2x = (compare2 - 200) % 12;
                    int com2y = (compare2 - 200) / 12;

                    //MessageBox(NULL, L"n", NULL, NULL);

                    //TCHAR f[5];
                        //wsprintf(f, L"win%d",allwin);
                    //    MessageBox(hWnd,L"f", NULL, NULL);

                    img2[com1x][com1y] = 0;
                    img2[com2x][com2y] = 0;
                    ShowWindow(GetDlgItem(hWnd, compare), SW_HIDE);
                    ShowWindow(GetDlgItem(hWnd, compare2), SW_HIDE);


                    HDC hdc = GetDC(hWnd);
                    HPEN hPen = CreatePen(PS_SOLID, 5, RGB(0, 0, 0));
                    SelectObject(hdc, hPen);
                    MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                    LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                    LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                    LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                    Sleep(500);
                    HPEN hPen2 = CreatePen(PS_SOLID, 5, RGB(255, 255, 255));
                    SelectObject(hdc, hPen2);
                    MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                    LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                    LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                    LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                    UpdateWindow(hWnd);
                    ReleaseDC(hWnd, hdc);
                    allwin--;
                    if (allwin == 0)
                    {
                        init(hWnd);
                        allwin = 30;
                    }


                    //MessageBox(NULL, L"n", NULL, NULL);
                    return TRUE;
                }
                else {
                    //    MessageBox(NULL, L"continue", NULL, NULL);
                    continue;
                }
            }
            else {
                //    MessageBox(NULL, L"continue", NULL, NULL);
                continue;
            }

        }

    }
    for (int i =0; i<=11; i++)

    {
        /*TCHAR n[5];
        wsprintf(n, L"%d", b - i);
        MessageBox(NULL, n, L"555", NULL);*/
        //MessageBox(NULL, L"continue4", NULL, NULL);

        if (Connect2(a, b,i, b , hWnd)) {
            //MessageBox(NULL, L"continue3", NULL, NULL);
            p1.x = i;
            p1.y = b ;
            if (Connect2(i, b , i, d, hWnd)) {
                //MessageBox(NULL, L"mid", NULL, NULL);
p2.x = i;
                p2.y = d;
                if (Connect2(i,d, c, d, hWnd)) {
                    //MessageBox(NULL, L"continue2xxxx1", NULL, NULL);
                    int com1x = (compare - 200) % 12;
                    int com1y = (compare - 200) / 12;
                    int com2x = (compare2 - 200) % 12;
                    int com2y = (compare2 - 200) / 12;

                    //MessageBox(NULL, L"n", NULL, NULL);

                    //TCHAR f[5];
                    //wsprintf(f, L"win%d",allwin);
                    //    MessageBox(hWnd,L"f", NULL, NULL);

                    img2[com1x][com1y] = 0;
                    img2[com2x][com2y] = 0;
                    ShowWindow(GetDlgItem(hWnd, compare), SW_HIDE);
                    ShowWindow(GetDlgItem(hWnd, compare2), SW_HIDE);


                    HDC hdc = GetDC(hWnd);
                    HPEN hPen = CreatePen(PS_SOLID, 5, RGB(0, 0, 0));
                    SelectObject(hdc, hPen);
                    MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                    LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                    LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                    LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                    Sleep(500);
                    HPEN hPen2 = CreatePen(PS_SOLID, 5, RGB(255, 255, 255));
                    SelectObject(hdc, hPen2);
                    MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                    LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                    LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                    LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                    UpdateWindow(hWnd);
                    ReleaseDC(hWnd, hdc);
                    allwin--;
                    if (allwin == 0)
                    {
                        init(hWnd);
                        allwin = 30;
                    }


                    //MessageBox(NULL, L"n", NULL, NULL);
                    return TRUE;
                }
                else {
                    //    MessageBox(NULL, L"continue", NULL, NULL);
                    continue;
                }
            }
            else {
                //    MessageBox(NULL, L"continue", NULL, NULL);
                continue;
            }

        }

    }        //state[a-i][b]
    return FALSE;
}

    BOOL surplusConnect(int n, int m, HWND hWnd) {

        int a = (n - 200) % 12;
        int b = (n - 200) / 12;
        int c = (m - 200) % 12;
        int d = (m - 200) / 12;
        for (int i = b; (b - i >= 0)&(b - i <= 12); i--)

        {
            /*TCHAR n[5];
            wsprintf(n, L"%d", b - i);
            MessageBox(NULL, n, L"555", NULL);*/
            //MessageBox(NULL, L"continue4", NULL, NULL);

            if (surplusConnect2(a, b, a, b - i, hWnd)) {
                //MessageBox(NULL, L"continue3", NULL, NULL);
                p1.x = a;
                p1.y = b - i;
                if (surplusConnect2(a, b - i, c, b - i, hWnd)) {

                    p2.x = c;
                    p2.y = b - i;
                    if (surplusConnect2(c, b - i, c, d, hWnd)) {
                        //MessageBox(NULL, L"continue2xxxx1", NULL, NULL);
                        int com1x = (n - 200) % 12;
                        int com1y = (n - 200) / 12;
                        int com2x = (m - 200) % 12;
                        int com2y = (m - 200) / 12;

                        //MessageBox(NULL, L"n", NULL, NULL);

                        //TCHAR f[5];
                            //wsprintf(f, L"win%d",allwin);
                        //    MessageBox(hWnd,L"f", NULL, NULL);

                        //img2[com1x][com1y] = 0;
                        //img2[com2x][com2y] = 0;
                        //ShowWindow(GetDlgItem(hWnd, compare), SW_HIDE);
                        //ShowWindow(GetDlgItem(hWnd, compare2), SW_HIDE);


                        HDC hdc = GetDC(hWnd);
                        HPEN hPen = CreatePen(PS_SOLID, 5, RGB(0, 0, 0));
                        SelectObject(hdc, hPen);
                        MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                        LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                        LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                        LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                        Sleep(500);
                        HPEN hPen2 = CreatePen(PS_SOLID, 5, RGB(255, 255, 255));
                        SelectObject(hdc, hPen2);
                        MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                        LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                        LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                        LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                        UpdateWindow(hWnd);
                        ReleaseDC(hWnd, hdc);
                        


                        //MessageBox(NULL, L"n", NULL, NULL);
                        return TRUE;
                    }
                    else {
                        //    MessageBox(NULL, L"continue", NULL, NULL);
                        continue;
                    }
                }
                else {
                    //    MessageBox(NULL, L"continue", NULL, NULL);
                    continue;
                }

            }

        }    //state[a-i][b]
        for (int i = a; (a - i >= 0) && (a - i <=8); i--)

        {
            /*TCHAR n[5];
            wsprintf(n, L"%d", b - i);
            MessageBox(NULL, n, L"555", NULL);*/
            //MessageBox(NULL, L"continue4", NULL, NULL);

            if (surplusConnect2(a, b, a - i, b, hWnd)) {
                //MessageBox(NULL, L"continue3", NULL, NULL);
                p1.x = a - i;
                p1.y = b;
                if (surplusConnect2(a - i, b, a - i, d, hWnd)) {

                    p2.x = a - i;
                    p2.y = d;
                    if (surplusConnect2(a - i, d, c, d, hWnd)) {
                        //MessageBox(NULL, L"continue2xxxx1", NULL, NULL);
                        int com1x = (compare - 200) % 12;
                        int com1y = (compare - 200) / 12;
                        int com2x = (compare2 - 200) % 12;
                        int com2y = (compare2 - 200) / 12;

                        //MessageBox(NULL, L"n", NULL, NULL);

                        //TCHAR f[5];
                        //wsprintf(f, L"win%d",allwin);
                        //    MessageBox(hWnd,L"f", NULL, NULL);

                        


                        HDC hdc = GetDC(hWnd);
                        HPEN hPen = CreatePen(PS_SOLID, 5, RGB(0, 0, 0));
                        SelectObject(hdc, hPen);
                        MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                        LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                        LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                        LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                        Sleep(500);
                        HPEN hPen2 = CreatePen(PS_SOLID, 5, RGB(255, 255, 255));
                        SelectObject(hdc, hPen2);
                        MoveToEx(hdc, com1x * height + height / 2, com1y *height + 25, 0);
                        LineTo(hdc, p1.x * height + height / 2, p1.y * height + height / 2);
                        LineTo(hdc, p2.x * height + height / 2, p2.y * height + height / 2);
                        LineTo(hdc, com2x * height + height / 2, com2y * height + height / 2);
                        UpdateWindow(hWnd);
                        ReleaseDC(hWnd, hdc);
                    


                        //MessageBox(NULL, L"n", NULL, NULL);
                        return TRUE;
                    }
                    else {
                        //    MessageBox(NULL, L"continue", NULL, NULL);
                        continue;
                    }
                }
                else {
                    //    MessageBox(NULL, L"continue", NULL, NULL);
                    continue;
                }

            }

        }
        return FALSE;
    }
BOOL Connect2(int nx, int ny, int mx, int my, HWND hWnd) {
    //MessageBox(NULL, L"a", NULL, NULL);

    int a = (compare - 200) % 12;
    int b = (compare - 200) /12;
    int c = (compare2 - 200) % 12;
    int d = (compare2 - 200) / 12;
    if (nx != mx) {
        for (int i = min(nx, mx); i <= max(mx, nx); i++)
        {
            if (img2[i][ny] != 0) {
                if ((i==a&&b==ny)|| (i == c&&d== ny))
                continue;
                /*TCHAR n[5];
                        wsprintf(n, L"%d", b - i);
               
                MessageBox(NULL, L"dd", NULL, NULL);*/
                return FALSE;

            }

        }
    }
    else
    {
        //MessageBox(NULL, L"aa", NULL, NULL);
        for (int i = min(ny, my); i <=max(my, ny); i++) {
            if (img2[nx][i] != 0) {
                if ((nx == a&&b == i) || (nx== c&&d == i))
                    continue;
                /*TCHAR n[5];
                wsprintf(n, L"%d", i);
                MessageBox(NULL, n, L"cc", NULL);
                */return FALSE;
            }

        }

    }

    return TRUE;
}
BOOL surplusConnect2(int nx, int ny, int mx, int my, HWND hWnd) {
    //MessageBox(NULL, L"a", NULL, NULL);

    int a = (same - 200) % 12;
    int b = (same - 200) / 12;
    int c = (same2 - 200) % 12;
    int d = (same2 - 200) / 12;
    if (nx != mx) {
        for (int i = min(nx, mx); i <= max(mx, nx); i++)
        {
            if (img2[i][ny] != 0) {
                if ((i == a&b == ny) || (i == c&d == ny))
                    continue;
                /*TCHAR n[5];
                wsprintf(n, L"%d", b - i);

                MessageBox(NULL, L"dd", NULL, NULL);*/
                return FALSE;

            }

        }
    }
    else
    {
        //MessageBox(NULL, L"aa", NULL, NULL);
        for (int i = min(ny, my); i <= max(my, ny); i++) {
            if (img2[nx][i] != 0) {
                if ((nx == a&b == i) || (nx == c&d == i))
                    continue;
                /*TCHAR n[5];
                wsprintf(n, L"%d", i);
                MessageBox(NULL, n, L"cc", NULL);
                */return FALSE;
            }

        }

    }

    return TRUE;
}
void init(HWND hWnd) {
    all = 60;
    GetClientRect(hWnd, &rect);

    InvalidateRect(hWnd, &rect, TRUE);
   
     int k = 0, k2;

    for (int i = 0; i <= 11; i++)
    {
        for (int j = 0; j <= 7; j++) {
            img2[i][j] = 0;

        }

    }
    for (size_t i = 129; i <= 158; i++)
    {
        img[(i - 129) * 2] = i;
        img[(i - 129) * 2 + 1] = i;
    }
    array1(hWnd);
   
    //UpdateWindow(hWnd);
    for (size_t i = 1; i <= 10; i++)
    {
        for (int j = 1; j <= 6; j++) {

            k2 = rand() % (60 - k);
            img2[i][j] = img[k2];
            all--;
        
            k++;
        
            deleteArray(k2);

        }
    }
    TCHAR n[5];
    wsprintf(n, L"%d", k);
    MessageBox(NULL, L"k", n, NULL);
   

    k = 0;
    for (int j = 0; j <= 7; j++)
    {
        for (int i = 0; i <= 11; i++) {
            if (img2[i][j] != 0) {
                if (initGame == 0)CreateWindow(TEXT("BUTTON"), TEXT(""), WS_CHILD | WS_VISIBLE | BS_BITMAP,
                    i * height, j * height, height, height, hWnd, (HMENU)(200 + k), NULL, NULL);
                else
                    ShowWindow(GetDlgItem(hWnd, 200 + k), SW_SHOW);
                /*TCHAR n[10], m[5];
                wsprintf(n, L"imgn%d", img2[i][j]);
                MessageBox(NULL,n, NULL, NULL);*/
                HBITMAP hbmp2 = LoadBitmap((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(img2[i][j]));//
                ::SendMessage(GetDlgItem(hWnd, 200 + j * 12 + i), BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, LPARAM(hbmp2));
                UpdateWindow(hWnd);
            }
            k++;
        }

    }


}
void seachSame(HWND hWnd) {

    for (size_t z = 129; z <= 158; z++)
    {
        for (size_t i = 1; i < 12; i++)
        {
            for (int j = 1; j < 7; j++)
            {
                if (img2[i][j] == z) {
                    if (same==0)
                    {
                        same = i + j * 12 + 200;
                    }
                    else {
                        same2 = i  + j * 12 + 200;
                        if (surplusConnect(same, same2, hWnd)) {
                            TCHAR n[15];
                            wsprintf(n, L"%dsameB %dsame%d  %d", i, j,(same-200)/12, (same - 200) % 12);
                            MessageBox(hWnd, n, NULL, NULL);
                        }
                        same = 0;
                    }
                    

                }
            }
               
        }
    }


}
搜索更多相关主题的帖子: HWND int NULL MessageBox for 
2017-11-24 11:13
aibiancheng8
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-10-12
收藏
得分:0 
发来的代码, 注释太少了,多注释一点吧。不然高手们很难快速看懂
2018-10-12 06:57
快速回复:运行了一下般就运行不了,怎么办?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034927 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved