| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6359 人关注过本帖
标题:All about windows programming
只看楼主 加入收藏
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqi.cpp 的第二部分代码

void QiPan::setCurrentMark(int x, int y)

{

    int xIndex, yIndex;

    if(findIndex(x, y, xIndex, yIndex))

        current_mark = Mark(points[xIndex][yIndex].getX()-18, points[xIndex][yIndex].getY()-18);

    else

        current_mark = Mark(-50, -50);

}



bool QiPan::setStep(int x, int y, int round, Step & step)

{

    int xIndex, yIndex;

    if(findIndex(x, y, xIndex, yIndex))

    {

        step = Step(round, xIndex, yIndex, (round-1)&1);

        return true;

    }

    else

        return false;

}

void QiPan::eraseMark(HWND hwnd, const COLORREF & col)

{

    prev_mark.erase(hwnd, col);

}



void QiPan::paintMark(HWND hwnd)

{

    current_mark.paintMark(hwnd);

}



bool QiPan::isSetable(int x, int y)

{

    int xI, yI;

    int state;

    findIndex(x, y, xI, yI);

    state = points[xI][yI].getState();

    if(state == -1)   // noChessman, so in this position is still setable

        return true;

    else

        return false;

}



void QiPan::addAStep(Step & step)

{

    int xI, yI, player;

    step.getStepInfo(xI, yI, player);

    if(player == 0)   // black

        points[xI][yI].setBlack();

    else              // otherwise white

        points[xI][yI].setWhite();

    vcSteps.push_back(step);

}



Point & QiPan::getPoint(int xIndex, int yIndex)

{

    return points[xIndex][yIndex];

}



void QiPan::paint(HWND hwnd)

{

    HDC hdc = GetDC(hwnd);

    HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 125));

    SelectObject(hdc, hPen);

   

   for(int i = 0; i<SIZE; i++)

   {

       MoveToEx(hdc, points[i][0].getX(), points[i][0].getY(), NULL);

       LineTo(hdc, points[i][14].getX(), points[i][14].getY());



       MoveToEx(hdc, points[0][i].getX(), points[0][i].getY(), NULL);

       LineTo(hdc, points[14][i].getX(), points[14][i].getY());



       SetBkMode(hdc, TRANSPARENT);

       TextOut(hdc, points[14][i].getX() - 5, points[14][i].getY() + 5, &(zeichen1[i]), 1);

       TextOut(hdc, points[i][0].getX() - 25, points[i][0].getY()-10, zeichen2[i].begin(), 2);

   }



   DeleteObject(hPen);

   ReleaseDC(hwnd, hdc);

}



void QiPan::drawAllChessman(HWND hwnd)

{

    HDC hdc = GetDC(hwnd);

    HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 125));

    SelectObject(hdc, hPen);

   

    for(int i = 0; i<SIZE; i++)

    {

       for(int j = 0; j<SIZE; j++)

       {

           if(points[i][j].getState() == Point::BLACK)

               drawChessman(hwnd, points[i][j], Point::BLACK);

           else if(points[i][j].getState() == Point::WHITE)

               drawChessman(hwnd, points[i][j], Point::WHITE);

       }

    }

   

    DeleteObject(hPen);

    ReleaseDC(hwnd, hdc);

}



bool QiPan::judger()   // if return true, game over

{

    int i, j, round = 0;

    bool over = false;

    // horizontal judgement

    for(i = 0; i<SIZE; i++)

    {

        for(j = 0; j<11; j++)

        {

           
if(points[i][j].getState() == points[i][j+1].getState() &&
points[i][j].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i][j+1].getState() ==
points[i][j+2].getState() &&
points[i][j+1].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[i][j+2].getState() ==
points[i][j+3].getState() &&
points[i][j+2].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[i][j+3].getState() == points[i][j+4].getState() &&
points[i][j+3].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner =
points[i][j].getState()==Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

        }

    }

    // vertikale judgement

    for(i = 0; i<SIZE; i++)

    {

        for(j = 0; j<11; j++)

        {

           
if(points[j][i].getState() == points[j+1][i].getState() &&
points[j][i].getState()!=Point::NOCHESSMAN )

            {

           
    if(points[j+1][i].getState() ==
points[j+2][i].getState() &&
points[j+1][i].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[j+2][i].getState() ==
points[j+3][i].getState()&&points[j+2][i].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[j+3][i].getState() ==
points[j+4][i].getState()&&points[j+3][i].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner =
points[j][i].getState()==Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

        }

    }

    // WS-NE

    for(j = 10; j>0; j--)

    {

        for(i = 0; i<j; i++)

        {

           
if(points[14-i][i+1+round].getState() ==
points[13-i][i+2+round].getState() &&
points[14-i][i+1+round].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[13-i][i+2+round].getState() ==
points[12-i][i+3+round].getState() &&
points[13-i][i+2+round].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[12-i][i+3+round].getState() ==
points[11-i][i+4+round].getState() &&
points[12-i][i+3+round].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[11-i][i+5+round].getState() ==
points[10-i][i+6+round].getState() &&
points[11-i][i+5+round].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[14-i][i+1+round].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

            else
if(points[i+1+round][i].getState() == points[i+2+round][i+1].getState()
&& points[i+1+round][i].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i+2+round][i+1].getState() ==
points[i+3+round][i+2].getState() &&
points[i+2+round][i+1].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[i+3+round][i+2].getState() ==
points[i+4+round][i+3].getState() &&
points[i+3+round][i+2].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[i+4+round][i+3].getState() ==
points[i+5+round][i+4].getState() &&
points[i+4+round][i+3].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[i+1+round][i].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

            else
if(points[i][i+1+round].getState() == points[i+1][i+2+round].getState()
&& points[i][i+1+round].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i+1][i+2+round].getState() ==
points[i+2][i+3+round].getState() &&
points[i+1][i+2+round].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[i+2][i+3+round].getState() ==
points[i+3][i+4+round].getState() &&
points[i+2][i+3+round].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[i+3][i+4+round].getState() ==
points[i+4][i+5+round].getState() &&
points[i+3][i+4+round].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[i][i+1+round].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

            else
if(points[13-i-round][i].getState() ==
points[12-i-round][i+1].getState() &&
points[13-i-round][i].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[12-i-round][i+1].getState() ==
points[11-i-round][i+2].getState() &&
points[12-i-round][i+1].getState()!=Point::NOCHESSMAN)

                {

           
      
if(points[11-i-round][i+2].getState() ==
points[10-i-round][i+3].getState() &&
points[11-i-round][i+2].getState()!=Point::NOCHESSMAN)

                    {

           
           
if(points[10-i-round][i+3].getState() ==
points[9-i-round][i+4].getState() &&
points[10-i-round][i+3].getState()!=Point::NOCHESSMAN)

                        {

           
           
    //found the winner, game over, send Message

           
           
    over = gameover = true;

           
           
    winner = points[13-i-round][i].getState() ==
Point::BLACK?"Black":"White";

                        }

                    }

                }

            }

        }

        round++;

    }

   

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

    {

        if(points[14-i][i].getState() ==
points[13-i][i+1].getState() &&
points[14-i][i].getState()!=Point::NOCHESSMAN)

        {

           
if(points[13-i][i+1].getState() == points[12-i][i+2].getState()
&& points[13-i][i+1].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[12-i][i+2].getState() ==
points[11-i][i+3].getState() &&
points[12-i][i+2].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[11-i][i+3].getState()
== points[10-i][i+4].getState() &&
points[11-i][i+3].getState()!=Point::NOCHESSMAN)

                    {

           
            //found the
winner, game over, send Message

           
            over =
gameover = true;

           
            winner =
points[14-i][i].getState() == Point::BLACK?"Black":"White";

                    }

                }

            }

        }

        else if(points[i][i].getState()
== points[i+1][i+1].getState() &&
points[i][i].getState()!=Point::NOCHESSMAN)

        {

           
if(points[i+1][i+1].getState() ==
points[i+2][i+2].getState()&&points[i+1][i+1].getState()!=Point::NOCHESSMAN)

            {

           
    if(points[i+2][i+2].getState() ==
points[i+3][i+3].getState()&&points[i+2][i+2].getState()!=Point::NOCHESSMAN)

                {

           
        if(points[i+3][i+3].getState() ==
points[i+4][i+4].getState()&&points[i+3][i+3].getState()!=Point::NOCHESSMAN)

                    {

           
            //found the
winner, game over, send Message

           
            over =
gameover = true;

           
            winner =
points[i][i].getState() == Point::BLACK?"Black":"White";

                    }

                }

            }

        }

    }

    return over;

}


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:30
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqi.cpp 的最后一部分代码

void WuZiQi::createWindow(HWND hwnd)

{

    hGroupMode = CreateWindow("BUTTON", "Mode", WS_CHILD|WS_VISIBLE|BS_GROUPBOX,

           
           50, 600,
192, 55, hwnd, (HMENU)IDGROUP_MODE, hInst, NULL);

    hRadioBtnPP = CreateWindow("BUTTON", "person vs person", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           70, 620,
160, 15, hwnd, (HMENU)IDRADIOBTN_PP, hInst, NULL);

    hRadioBtnPC = CreateWindow("BUTTON", "person vs computer", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           70, 635,
160, 15, hwnd, (HMENU)IDRADIOBTN_PC, hInst, NULL);

    hGroupSequence = CreateWindow("BUTTON", "Sequence", WS_CHILD|WS_VISIBLE|BS_GROUPBOX,

           
           350, 600,
192, 55, hwnd, (HMENU)IDGROUP_SEQUENCE, hInst, NULL);

    hRadioBtnBlack = CreateWindow("BUTTON", "black", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           370, 620,
160, 15, hwnd, (HMENU)IDRADIOBTN_BLACK, hInst, NULL);

    hRadioBtnWhite = CreateWindow("BUTTON", "white", WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON,

           
           370, 635,
160, 15, hwnd, (HMENU)IDRADIOBTN_WHITE, hInst, NULL);

    hPushBtnStepback = CreateWindow("BUTTON", "step back", WS_CHILD|WS_VISIBLE,

           
           76, 565,
120, 30, hwnd, (HMENU)IDPUSHBTN_STEPBACK, hInst, NULL);

    hPushBtnBegin = CreateWindow("BUTTON", "begin", WS_CHILD|WS_VISIBLE,

           
           232, 565,
120, 30, hwnd, (HMENU)IDPUSHBTN_BEGIN, hInst, NULL);

    hPushBtnGiveup = CreateWindow("BUTTON", "give up", WS_CHILD|WS_VISIBLE,

           
           388, 565,
120, 30, hwnd, (HMENU)IDPUSHBTN_GIVEUP, hInst, NULL);

}



void WuZiQi::init(HWND hwnd)

{

    chessboard.setBkgColor(BKGCOL);

    this->createWindow(hwnd);

    this->setGameState();

    this->setModeState();

}



void WuZiQi::paintMark(HWND hwnd, int x, int y)

{

    if(gameState == PLAYING)

    {

        chessboard.setCurrentMark(x, y);

        Mark current_mark = chessboard.getCurrentMark();

        Mark prev_mark = chessboard.getPrevMark();

        if(current_mark != prev_mark)

        {

            chessboard.eraseMark(hwnd, BKGCOL);

            chessboard.paintMark(hwnd);

            chessboard.updateMark();

        }

    }

}



void WuZiQi::executeCommand(HWND hwnd, const int command)

{

    switch(command)

    {

    case IDRADIOBTN_PP:

        setModeState(WuZiQi::PVSP);

            SendMessage(hRadioBtnPP, BM_SETCHECK, 1, 0);

            SendMessage(hRadioBtnPC, BM_SETCHECK, 0, 0);

            SendMessage(hRadioBtnBlack, BM_SETCHECK, 0, 0);

            SendMessage(hRadioBtnWhite, BM_SETCHECK, 0, 0);

            break;

        case IDRADIOBTN_PC:

            setMode(WuZiQi::PVSC);

            SendMessage(hRadioBtnPP, BM_SETCHECK, 0, 0);

            SendMessage(hRadioBtnPC, BM_SETCHECK, 1, 0);

            break;

        case IDRADIOBTN_BLACK:

            if(getMode() == WuZiQi::PVSC)

            {

                getComputerPlayer()->setSequence(WuZiQi::WHITE);

                SendMessage(hRadioBtnBlack, BM_SETCHECK, 1, 0);

                SendMessage(hRadioBtnWhite, BM_SETCHECK, 0, 0);

            }

            break;

        case IDRADIOBTN_WHITE:

            if(getMode() == WuZiQi::PVSC)

            {

                getComputerPlayer()->setSequence();

                SendMessage(hRadioBtnBlack, BM_SETCHECK, 0, 0);

                SendMessage(hRadioBtnWhite, BM_SETCHECK, 1, 0);

            }

            break;

        case IDPUSHBTN_STEPBACK:

            chessboard.stepBack();  

            break;

        case IDPUSHBTN_BEGIN:

            beginPlay(hwnd);

            break;

        case IDPUSHBTN_GIVEUP:

            gameOver();

           
MessageBox(hMessage, (getCurrentPlayer() == WuZiQi::BLACK)?"Black give
up":"White give up", "Give up", MB_OK);

            break;

        }

}

void WuZiQi::setMode(const int m)

{

    this->mode = m;

    if(mode == WuZiQi::PVSC)

        this->pc = new ComputerPlayer;

}




自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:32
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
// wuziqiplayer.cpp

// wuqiqiplayer.cpp

#include "wuziqi.h"



LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);



WuZiQi myWuZiQi;

int WuZiQi::step = 0;



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

                    LPSTR lpszCmdLine, int nCmdShow)

{

    HWND hwnd;

    MSG Msg;

    WNDCLASS wndclass;

    char lpszClassName[] = "window";

    char lpszTitle[] = "Îå×ÓÆå";



    wndclass.cbClsExtra = 0;

    wndclass.cbWndExtra = 0;

    wndclass.hbrBackground =
CreateSolidBrush(myWuZiQi.getBackgroudColor());
//(HBRUSH)GetStockObject(WHITE_BRUSH);

    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);

    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);

    wndclass.hInstance = hInstance;

    wndclass.lpfnWndProc = WndProc;

    wndclass.lpszClassName = lpszClassName;

    wndclass.lpszMenuName = NULL;

    wndclass.style = 0;



    if(! RegisterClass(&wndclass))

    {

        MessageBeep(0);

        return FALSE;

    }



    hwnd = CreateWindow(

        lpszClassName,

        lpszTitle,

        WS_BORDER | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU,// |WS_THICKFRAME,

        0, 0, 592, 690, NULL, NULL, hInstance, NULL);

    ShowWindow(hwnd, nCmdShow);

    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0))

    {

        TranslateMessage(&Msg);

        DispatchMessage(&Msg);

    }

    return Msg.wParam;

}



LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

    PAINTSTRUCT ps;

    HDC hdc;

    static int x, y;

   

    switch(message)

    {

    case WM_CREATE:

        myWuZiQi.init(hwnd);

        break;

    case WM_SETFOCUS:

        myWuZiQi.setFocus();

        break;

    case WM_COMMAND:

        myWuZiQi.executeCommand(hwnd, LOWORD(wParam));

        break;

    case WM_MOUSEMOVE:

        x = LOWORD(lParam);

        y = HIWORD(lParam);

        myWuZiQi.paintMark(hwnd, x, y);

        break;

    case WM_LBUTTONDOWN:

        myWuZiQi.setChessman(hwnd, x, y);

        break;

    case WM_PAINT:

        hdc = BeginPaint(hwnd, &ps);

        myWuZiQi.paintChessboard(hwnd);

        myWuZiQi.paintAllChessman(hwnd);

        EndPaint(hwnd, &ps);

        break;

    case WM_DESTROY:

        PostQuitMessage(0);

    default:

        return DefWindowProc(hwnd, message, wParam, lParam);

    }

    return 0;

}






自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-18 22:33
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
程序有很多不足之处,如棋盘的闪烁现象。

所以这两天一直在修改程序。在添置新的功能之前,先完善代码是有必要的。

就在刚才又做了新的改动。

考虑到在这里粘贴代码不是很方便,又无法上传文件。所以对改动后的代码不再在这里粘贴了。如有朋友需要,可以向我索取代码。


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-02-19 01:09
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
source code

IymlfVKZ.zip (11.55 KB)


[此贴子已经被作者于2005-8-4 15:15:55编辑过]



自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-07-31 09:24
yeshirow
Rank: 4
等 级:贵宾
威 望:10
帖 子:854
专家分:0
注 册:2006-6-8
收藏
得分:0 
Re: About Windows Programming...

About Windows Programming..

既然這樣, 這需要處理這個程式的方方面面, 在這裏我有一個問題(困擾有一段時間了),
沒有使用 MFC, 手工作的窗口和子窗口, 其中子窗口之前的焦點切換應該怎麽處理,
就是當按下 TAB 時, 焦點會在各個子窗口之間來回切換.
(我曾經發表過一個貼子, 期望可以得到解答, 很可惜, 沒有任何回應----到現在爲止. 是不是因爲我的問題太可笑了, 我卻不覺得.)

對於建立的子窗口(例如 BUTTON), 當它的 CAPTION 爲 &Caption 這類似的樣子, Alt+C 要如何才能起作用. (直接建立後, 如果不加處理, 當按下 Alt+C, 回應你的是一個警告聲音).

-------------------------------------------------------------------------------
在 Message Loop 中有一個 TranslateMessage 這個函數的工作原理是怎麽樣的. 在 MSDN 裏, 我看得不是很明白, 哪個人願簡要的解答一下.


原來朋友仔感情再天真, 亦是我永遠也會愛惜的人, 明日愛他人, 也記住學會不要緊; 原來朋友比戀人更高分, 亦讓我開始懂得不記恨, 若大家都敏感, 我更要永遠記得拒絕再因小事怪人, 爲何沒有這條校訓...Twins-朋友仔 MCSD Training
2006-08-06 19:07
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
yeshirow,

actually I havn't written windows program some long. I have seen your question in my blog. Can you give a program within that you have problem?

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-08-07 04:58
yeshirow
Rank: 4
等 级:贵宾
威 望:10
帖 子:854
专家分:0
注 册:2006-6-8
收藏
得分:0 

#include <windows.h>

HINSTANCE hInst;
HWND g_hWnd;

HRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


void PrintString(HWND hWnd)
{
HDC hDC = GetDC(hWnd);

RECT ret = {140, 10, 400, 400};

DrawText(hDC, "用 Tab 無法切換兩個 BUTTON 的焦點... Alt+F 不能引發第一個 BUTTON 被按下, Alt+S 不能引發第二個 BUTTON 被按下", -1, &ret, DT_LEFT | DT_WORDBREAK);

ReleaseDC(hWnd, hDC);
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "ccc";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&wc);
hInst = hInstance;

g_hWnd = CreateWindowEx(0, "ccc", "cccc", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
400, 300, NULL, NULL, hInstance, NULL);
ShowWindow(g_hWnd, nShowCmd);
UpdateWindow(g_hWnd);

MSG msg;

while(GetMessage(&msg, 0, 0, 0))
{
//TranslateMessage(&msg);

DispatchMessage(&msg);
}
return msg.wParam;
}


HRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hCmd1, hCmd2;
switch(uMsg)
{
case WM_CREATE:
hCmd1 = CreateWindowEx(0, "BUTTON", "&First", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_TEXT, 10, 10, 120, 80, hWnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
hCmd2 = CreateWindowEx(0, "BUTTON", "&Second", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_TEXT, 10, 100, 120, 80, hWnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
SetWindowLong(hCmd1, GWL_ID, 1);
SetWindowLong(hCmd2, GWL_ID, 2);
break;
case WM_PAINT:
PrintString(hWnd);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 1:
MessageBox(hWnd, "Command1 was clicked", "OK", MB_OK);
break;
case 2:
MessageBox(hWnd, "Command2 was clicked", "OK", MB_OK);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0L;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}


原來朋友仔感情再天真, 亦是我永遠也會愛惜的人, 明日愛他人, 也記住學會不要緊; 原來朋友比戀人更高分, 亦讓我開始懂得不記恨, 若大家都敏感, 我更要永遠記得拒絕再因小事怪人, 爲何沒有這條校訓...Twins-朋友仔 MCSD Training
2006-08-07 05:19
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
Alt+F 不能引發第一個 BUTTON 被按下


这句话怎么理解?

我觉得你的问题是键盘相应的问题。

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-08-07 06:29
yeshirow
Rank: 4
等 级:贵宾
威 望:10
帖 子:854
专家分:0
注 册:2006-6-8
收藏
得分:0 

Alt+F. (鍵盤輸入)
我第一個 BUTTON 的 Caption 是 &First,

對於 MFC 建立的窗口和由資源加載的對話框中的 Button, 會自動處理鍵盤輸入----- 將 Alt+F 解析爲 "按了一次這個 Button".

但是由 ::CreateWindow 在運行期間加入的 Button, 即使指定了 &First 這個 Caption, 從鍵盤輸入的 Alt+F 將不會被解析成 "按了一次這個 Button". 這就需要處理這些鍵盤消息.

至於怎麽處理這些消息, 就是我所問的問題...


原來朋友仔感情再天真, 亦是我永遠也會愛惜的人, 明日愛他人, 也記住學會不要緊; 原來朋友比戀人更高分, 亦讓我開始懂得不記恨, 若大家都敏感, 我更要永遠記得拒絕再因小事怪人, 爲何沒有這條校訓...Twins-朋友仔 MCSD Training
2006-08-07 06:40
快速回复:All about windows programming
数据加载中...
 
   



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

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