新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > hello world 程序優化

        hello world 程序優化

        作者: 時間:2016-09-12 來源:網絡 收藏

        這樣使添加處理消息函數變得簡單

        本文引用地址:http://www.104case.com/article/201609/303403.htm

        步驟1: 頭文件中添加相關項

        步驟2: cpp添加具體實現方法

        步驟3: 結構體數組中添加相關項

        .h 文件:

        struct DecodeUint{

        UINT meesage;

        LONG (*fun)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

        };

        #define dim(x) (sizeof(x)/sizeof(x[0]))

        LONG OnDestory(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

        LONG OnPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

        .c文件:

        #include

        #include Border.h

        struct DecodeUint MainMessageProc[] = {

        WM_DESTROY,OnDestory,

        WM_PAINT,OnPaint,

        };

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

        int WinMain(HINSTANCE hInstance,

        HINSTANCE hPrevInstance,

        LPTSTR lpCmdLine,

        int nCmdShow)

        {

        WNDCLASS wc;

        wc.cbClsExtra = 0;

        wc.cbWndExtra = 0;

        wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

        wc.hCursor = NULL;

        wc.hIcon = NULL;

        wc.hInstance = hInstance;

        wc.lpfnWndProc = WndProc;

        wc.lpszClassName = TEXT(hello);

        wc.lpszMenuName = NULL;

        wc.style = CS_HREDRAW | CS_VREDRAW;

        if (!RegisterClass(wc)) return -1;

        HWND hWnd = CreateWindow(TEXT(hello),TEXT(helloworld), WS_VISIBLE | WS_BORDER | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_CAPTION,

        10,10,320,240,NULL,NULL,hInstance,NULL);

        UpdateWindow(hWnd);

        ShowWindow(hWnd,nCmdShow);

        MSG msg;

        while (GetMessage(msg, NULL, 0, 0))

        {

        TranslateMessage(msg);

        DispatchMessage(msg);

        }

        return 1;

        }

        LONG OnDestory(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

        {

        PostQuitMessage(1);

        return TRUE;

        }

        LONG OnPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

        {

        PAINTSTRUCT ps;

        HDC hdc;

        RECT rect;

        GetClientRect(hWnd,rect);

        hdc = BeginPaint(hWnd,ps);

        DrawText(hdc,TEXT(hello world),-1,rect,DT_VCENTER | DT_CENTER);

        EndPaint(hWnd,ps);

        return TRUE;

        }

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

        {

        for (int i = 0;i dim(MainMessageProc); i++)

        {

        if (MainMessageProc[i].meesage == message)

        {

        (*MainMessageProc[i].fun)(hWnd,message,wParam,lParam);

        }

        }

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

        }



        關鍵詞: WinCE

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 邻水| 福安市| 富源县| 开远市| 台州市| 西藏| 寿宁县| 香格里拉县| 昭平县| 保德县| 托克托县| 霞浦县| 克东县| 克山县| 定州市| 怀柔区| 永年县| 彰化县| 平塘县| 甘洛县| 淮南市| 同德县| 浠水县| 鄢陵县| 灵石县| 苍溪县| 三门县| 桐梓县| 北京市| 万年县| 土默特右旗| 仲巴县| 化隆| 聊城市| 绥阳县| 和政县| 家居| 游戏| 视频| 城步| 宁河县|