• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            // ?INCLUDES? ////////////////////////////////////////////// /
            #define ?WIN32_LEAN_AND_MEAN?? // ?just?say?no?to?MFC

            #include?
            < windows.h > ??? // ?include?all?the?windows?headers
            #include? < windowsx.h > ?? // ?include?useful?macros
            #include? < stdio.h > ?????
            #include?
            < math.h >

            // ?DEFINES? ////////////////////////////////////////////////

            // ?defines?for?windows?
            #define ?WINDOW_CLASS_NAME?"WINCLASS1"

            // ?GLOBALS? ////////////////////////////////////////////////


            // ?FUNCTIONS? //////////////////////////////////////////////
            LRESULT?CALLBACK?WindowProc(HWND?hwnd,?
            ????????????????????????????UINT?msg,?
            ????????????????????????????WPARAM?wparam,?
            ????????????????????????????LPARAM?lparam)
            {
            ????
            // ?this?is?the?main?message?handler?of?the?system
            ????PAINTSTRUCT????????ps;???????? // ?used?in?WM_PAINT
            ????HDC????????????????hdc;???? // ?handle?to?a?device?context

            ????
            // ?what?is?the?message?
            ???? switch (msg)
            ????
            {????
            ????
            case ?WM_CREATE:?
            ????????
            {
            ????????????
            // ?do?initialization?stuff?here

            ????????????
            // ?return?success
            ???????????? return ( 0 );
            ????????}
            ? break ;

            ????
            case ?WM_PAINT:?
            ????????
            {
            ????????????
            // ?simply?validate?the?window
            ????????????hdc? = ?BeginPaint(hwnd, & ps);?????
            ????????????
            // ?you?would?do?all?your?painting?here
            ????????????EndPaint(hwnd, & ps);

            ????????????
            // ?return?success
            ???????????? return ( 0 );
            ????????}
            ? break ;

            ????
            case ?WM_DESTROY:?
            ????????
            {
            ????????????
            // ?kill?the?application,?this?sends?a?WM_QUIT?message?
            ????????????PostQuitMessage( 0 );

            ????????????
            // ?return?success
            ???????????? return ( 0 );
            ????????}
            ? break ;

            ????
            default : break ;

            ????}
            ? // ?end?switch

            ????
            // ?process?any?messages?that?we?didn't?take?care?of?
            ???? return ?(DefWindowProc(hwnd,?msg,?wparam,?lparam));

            }
            ? // ?end?WinProc

            // ?WINMAIN? ////////////////////////////////////////////////
            int ?WINAPI?WinMain(????HINSTANCE?hinstance,
            ???????????????????HINSTANCE?hprevinstance,
            ???????????????????LPSTR?lpcmdline,
            ???????????????????
            int ?ncmdshow)
            {

            ????WNDCLASSEX?winclass;?
            // ?this?will?hold?the?class?we?create
            ????HWND???????hwnd;????? // ?generic?window?handle
            ????MSG???????????msg;????????? // ?generic?message

            ????
            // ?first?fill?in?the?window?class?stucture
            ????winclass.cbSize????????? = ? sizeof (WNDCLASSEX);
            ????winclass.style????????????
            = ?CS_DBLCLKS? | ?CS_OWNDC? | ?
            ????????CS_HREDRAW?
            | ?CS_VREDRAW;
            ????winclass.lpfnWndProc????
            = ?WindowProc;
            ????winclass.cbClsExtra????????
            = ? 0 ;
            ????winclass.cbWndExtra????????
            = ? 0 ;
            ????winclass.hInstance????????
            = ?hinstance;
            ????winclass.hIcon????????????
            = ?LoadIcon(NULL,?IDI_APPLICATION);
            ????winclass.hCursor????????
            = ?LoadCursor(NULL,?IDC_ARROW);
            ????winclass.hbrBackground????
            = ?(HBRUSH)GetStockObject(BLACK_BRUSH);
            ????winclass.lpszMenuName????
            = ?NULL;
            ????winclass.lpszClassName????
            = ?WINDOW_CLASS_NAME;
            ????winclass.hIconSm????????
            = ?LoadIcon(NULL,?IDI_APPLICATION);

            ????
            // ?register?the?window?class
            ???? if ?( ! RegisterClassEx( & winclass))
            ????????
            return ( 0 );

            ????
            // ?create?the?window
            ???? if ?( ! (hwnd? = ?CreateWindowEx(NULL,?????????????????? // ?extended?style
            ????????WINDOW_CLASS_NAME,????? // ?class
            ???????? " Your?Basic?Window++ " ,? // ?title
            ????????WS_OVERLAPPEDWINDOW? | ?WS_VISIBLE,
            ????????
            0 , 0 ,???????? // ?initial?x,y
            ???????? 400 , 400 ,?? // ?initial?width,?height
            ????????NULL,???????? // ?handle?to?parent?
            ????????NULL,???????? // ?handle?to?menu
            ????????hinstance, // ?instance?of?this?application
            ????????NULL)))???? // ?extra?creation?parms
            ???????? return ( 0 );

            ????
            // ?enter?main?event?loop,?but?this?time?we?use?PeekMessage()
            ????
            // ?instead?of?GetMessage()?to?retrieve?messages
            ???? while (TRUE)
            ????
            {
            ????????
            // ?test?if?there?is?a?message?in?queue,?if?so?get?it
            ???????? if ?(PeekMessage( & msg,NULL, 0 , 0 ,PM_REMOVE))
            ????????
            {?
            ????????????
            // ?test?if?this?is?a?quit
            ???????????? if ?(msg.message? == ?WM_QUIT)
            ????????????????
            break ;

            ????????????
            // ?translate?any?accelerator?keys
            ????????????TranslateMessage( & msg);

            ????????????
            // ?send?the?message?to?the?window?proc
            ????????????DispatchMessage( & msg);
            ????????}
            ? // ?end?if

            ????????
            // ?main?game?processing?goes?here
            ????????
            // ?Game_Main();? // ?or?whatever?your?loop?is?called
            ????}
            ? // ?end?while

            ????
            // ?return?to?Windows?like?this
            ???? return (msg.wParam);

            }
            ? // ?end?WinMain

            一? include頭文件和宏定義
            #define?WIN32_LEAN_AND_MEAN??//?不使用mfc
            #include?
            <windows.h>???//?包含所有的windows頭文件,
            #include?<windowsx.h>??//包含有用的宏定義
            二 winmain()函數(shù)
            int?WINAPI?WinMain(????HINSTANCE?hinstance,
            ???????????????????HINSTANCE?hprevinstance,
            ???????????????????LPSTR?lpcmdline,
            ???????????????????
            int?ncmdshow);
            函數(shù)原型如上,其中hinstance是windows為應(yīng)用程序生成的句柄,hprevinstance參數(shù)現(xiàn)在一般不用,用來向以前的兼容,lpcmdline就相當(dāng)于dos程序的命令行參數(shù),ncmdshow枚舉類型指出如何打開主應(yīng)用程序窗口,比如最大化,最小化,最前端等
            WINAPI 不能少,相當(dāng)于以前的pascal 關(guān)鍵字
            三 WNDCLASSEX 結(jié)構(gòu)
            ????? WNDCLASSEX?winclass;?//?this?will?hold?the?class?we?create
            ????
            ????
            //?first?fill?in?the?window?class?stucture
            ????winclass.cbSize?????????=?sizeof(WNDCLASSEX);???????????????????? //指她本身的大小
            ????winclass.style????????????
            =?CS_DBLCLKS?|?CS_OWNDC?|??????? //窗口樣式,一般選這4個(gè)
            ????????CS_HREDRAW?
            |?CS_VREDRAW;
            ????winclass.lpfnWndProc????
            =?WindowProc;???????????????????????????????? //要回調(diào)的函數(shù)指針
            ????winclass.cbClsExtra????????
            =?0;???????????????????????????????????????????????????//額外的類信息空間,現(xiàn)在一般不用
            ????winclass.cbWndExtra????????
            =?0;????????????????????????????????????????????????//額外的窗口信息空間,現(xiàn)在一般不用
            ????winclass.hInstance????????
            =?hinstance;??????????????????????????????????????????//窗口的實(shí)例句柄,從winmain()傳來
            ????winclass.hIcon????????????
            =?LoadIcon(NULL,?IDI_APPLICATION); //圖標(biāo)
            ????winclass.hCursor????????
            =?LoadCursor(NULL,?IDC_ARROW);?????? //鼠標(biāo)
            ????winclass.hbrBackground????
            =?(HBRUSH)GetStockObject(BLACK_BRUSH); //背景刷,用于刷新窗口的畫刷句柄,可以用GetStockObject()
            ????winclass.lpszMenuName????
            =?NULL;?????????????????????? //菜單,要加入到窗口中的菜單名稱
            ????winclass.lpszClassName????
            =?WINDOW_CLASS_NAME;?? //要?jiǎng)?chuàng)建的窗口類的類名
            ????winclass.hIconSm????????
            =?LoadIcon(NULL,?IDI_APPLICATION); //圖標(biāo),顯示在標(biāo)題蘭和狀態(tài)蘭

            四 注冊(cè)windows類
            RegisterClassEx(&winclass); 傳入指向類的指針
            五 創(chuàng)建窗口
            CreateWindowEx(NULL,??????????????????//?extended?style?????? 擴(kuò)張的窗口樣式,高級(jí),一般不用
            ????????WINDOW_CLASS_NAME,?????//?class??????? 創(chuàng)建窗口需要的類指針
            ????????"Your?Basic?Window++",?//?title??????????? 標(biāo)題蘭的文本
            ????????WS_OVERLAPPEDWINDOW?|?WS_VISIBLE,???????? //窗口樣式
            ????????
            0,0,????????//?initial?x,y?? 窗口的左上角,象素表示
            ????????400,400,??//?initial?width,?height 寬高,象素表示
            ????????NULL,????????//?handle?to?parent? 父窗口句柄
            ????????NULL,????????//?handle?to?menu??????? 菜單句柄或子窗口標(biāo)示
            ????????hinstance,//?instance?of?this?application? winmain(0中的instance
            ????????NULL))???//?extra?creation?parms? 高級(jí)參數(shù),一般不用
            六 顯示窗口且刷新一下
            ShowWindow()//可以控制不顯示,或在狀態(tài)蘭也不顯示
            UpdateWindow() //刷新窗口,就是生成一個(gè)WM_PAINT消息
            七 主消息循環(huán)
            LRESULT?CALLBACK?WindowProc(HWND?hwnd,? //窗口句柄
            ????????????????????????????UINT?msg,?????????????????? //消息id
            ????????????????????????????WPARAM?wparam,??? //用于進(jìn)一步確定msg指定的消息
            ????????????????????????????LPARAM?lparam)????? //用于進(jìn)一步確定msg指定的消息
            LRESULT?CALLBACK 不能少,以下是簡(jiǎn)單的幾種消息:
            WM_CREATE: //可以此時(shí)執(zhí)行各種初始化
            WM_PAINT:??? ?hdc? =?BeginPaint(hwnd,&ps);?????//確認(rèn)窗口是否有效
            ????????????
            ?????????? //?you?would?do?all?your?painting?here? //繪制工作
            ???????????? ???????? EndPaint(hwnd,&ps);??????????????????????? //結(jié)束繪制

            WM_KEYDOWN:? //處理鍵盤按下
            WM_DESTROY:???? //將要關(guān)閉應(yīng)用程序,發(fā)出WM_QUIT消息
            WM_QUIT:??????????? //推出程序
            注意 函數(shù)DefWindowProc(),是處理其他的消息,除了WindowProc()已經(jīng)處理的其他消息.

            GetMessage(LPMSG,?????? //消息結(jié)構(gòu)的地址
            ??????????????????? hWnd,??????????????? //窗口的句柄
            ?????????????????????uint,????????????????? //first message
            ?????????????????????? uint)?????????????????? //last messge
            她從事件隊(duì)列獲得下一個(gè)消息,然后調(diào)用TranslateMessage()函數(shù),進(jìn)行消息的轉(zhuǎn)換和處理,然后通過DispatchMessage()來調(diào)用winproc()函數(shù).

            PeekMessage( &msg,NULL,0,0,PM_REMOVE))中參數(shù):消息結(jié)構(gòu)的指針,窗口的句柄,第一條消息,最后一條消息,刪除標(biāo)記 ,其中參數(shù)刪除標(biāo)記是GetMessage()中沒有的,該標(biāo)記有2個(gè)值,PM_NOREMOVE和PM_REMOVE,前一個(gè)經(jīng)過peekmessage()后不將其從消息隊(duì)列中刪除,后一個(gè)表示經(jīng)過peekmessage()后從消息隊(duì)列中刪除.
            Posted on 2006-09-14 15:10 艾凡赫 閱讀(611) 評(píng)論(0)  編輯 收藏 引用 所屬分類: win32 sdk 編程
            久久久久久一区国产精品| 欧美激情精品久久久久久久| 久久婷婷五月综合97色直播| MM131亚洲国产美女久久| 久久久久久国产精品无码下载 | 97久久国产综合精品女不卡| 日本精品久久久中文字幕| 久久精品中文无码资源站| 久久亚洲精品成人AV| 久久综合给合久久狠狠狠97色69| 欧美伊人久久大香线蕉综合69| 99久久综合国产精品二区| 中文精品久久久久国产网址| 久久最近最新中文字幕大全| 久久久国产精品网站| 久久婷婷久久一区二区三区| 青青青国产成人久久111网站| 国内精品伊人久久久久av一坑| 亚洲人成精品久久久久| 久久婷婷五月综合97色直播| 久久亚洲国产精品成人AV秋霞| 久久久精品人妻一区二区三区蜜桃| 久久久久久久久波多野高潮| 伊人色综合久久天天人手人婷| 欧美va久久久噜噜噜久久| 久久精品人人槡人妻人人玩AV| 69SEX久久精品国产麻豆| 久久综合九色综合精品| 久久久91人妻无码精品蜜桃HD| 久久夜色精品国产| 久久无码专区国产精品发布| 久久久久亚洲av无码专区| 青青草原综合久久| 亚洲国产天堂久久综合| 亚洲人成网站999久久久综合| 无码国内精品久久人妻| 91性高湖久久久久| 久久伊人五月丁香狠狠色| 精品久久777| 亚洲国产成人精品女人久久久 | 久久精品一本到99热免费|