winmain 창 코드

12199 단어 main
#include<Windows.h>

#include<windowsx.h>

#include <string.h>

#include <cstdio>

#include "enginApp.h"

//#include "resource.h"



using namespace std;











#define WCLASSNAME "WindowClassName"

#define WINDOW_WIDTH 800

#define WINDOW_HEIGHT 600

#define COLOR_BPP 32

HDC hdc;

PAINTSTRUCT scPaint;



LRESULT CALLBACK windowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);



int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)

{

    WNDCLASSEX windowClass;

    HWND hwnd;

    MSG msg;

    ZeroMemory(&msg, sizeof(MSG));



    //        

    windowClass.cbSize=sizeof(WNDCLASSEX);

    windowClass.style=CS_HREDRAW|CS_VREDRAW;

    windowClass.lpfnWndProc=windowProc;

    windowClass.cbClsExtra=0;

    windowClass.cbWndExtra=0;

    windowClass.hInstance=hInstance;

    windowClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);

    windowClass.hCursor=LoadCursor(NULL,IDC_ARROW);

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

    windowClass.lpszClassName=WCLASSNAME;

    windowClass.lpszMenuName=0;

    windowClass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);



    //windowClass.hIconSm            = LoadIcon(hInstance, MAKEINTRESOURCE(ICON_T3DX));

    //windowClass.hCursor        = LoadCursor(hInstance, MAKEINTRESOURCE(CURSOR_CROSSHAIR));



    //     

    RegisterClassEx(&windowClass);



    //    

    hwnd=CreateWindowEx(NULL,WCLASSNAME,"Window  Application",WS_OVERLAPPEDWINDOW|WS_VISIBLE,200,200,WINDOW_WIDTH,WINDOW_HEIGHT,NULL,NULL,hInstance,NULL);

    if (!hwnd)

    {

        return 0;

    }

    //

    ShowWindow(hwnd,nShowCmd);

    UpdateWindow(hwnd);



    // load the menu resource

    //HMENU hmenuhandle = LoadMenu(hInstance, "MainMenu");



    // attach the menu to the window

    //SetMenu(hwnd, hmenuhandle);



    CEnginApp *enginApp=new CEnginApp(WINDOW_WIDTH,WINDOW_HEIGHT,COLOR_BPP,hwnd,true);

    enginApp->Init();



    while (true)

    {

        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))

        {

            if (msg.message==WM_QUIT)

                break;

            TranslateMessage(&msg);

            DispatchMessage(&msg);

        }else

        {

            if(!enginApp->OnIdle())

                DestroyWindow(hwnd);

                //SendMessage(hwnd,WM_CLOSE,0,0);

            Sleep(300);

        }



    }



    enginApp->Release();



    return msg.message;

}



LRESULT CALLBACK windowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)

{

    switch (msg)

    {

    case WM_MOVE:

        {

            //hdc=GetDC(hwnd);

            //if (hdc)

            //{

            //    int ix=LOWORD(lparam);

            //    int iy=HIWORD(lparam);

            //    char cTemp[128];

            //    sprintf_s(cTemp,"   :x=%d,y=%d",ix,iy);

            //    SetTextColor(hdc,RGB(0,0,255));

            //    SetBkColor(hdc,RGB(0,255,0));

            //    SetBkMode(hdc,OPAQUE);

            //    TextOut(hdc,0,20,cTemp,strlen(cTemp));

            //    ReleaseDC(hwnd,hdc);

            //}

        }

        break;

    case WM_PAINT:

        {

            //hdc=BeginPaint(hwnd,&scPaint);

            //if (hdc)

            //{

            //    SetTextColor(hdc,RGB(255,0,0));

            //    SetBkColor(hdc,RGB(0,255,0));

            //    SetBkMode(hdc,TRANSPARENT);

            //    TextOut(hdc,0,0,"Welcome!",8);



            //    EndPaint(hwnd,&scPaint);



            //    ReleaseDC(hwnd,hdc);

            //}

        }

        break;

    case WM_CLOSE:

        {

            if (MessageBox(0,"        ?","    ",MB_YESNO|MB_ICONEXCLAMATION|MB_DEFBUTTON1)==IDYES)

            {

                DestroyWindow(hwnd);

            }

        }

        break;

    case WM_DESTROY:

        {

            PostQuitMessage(0);

        }

        break;

    case WM_KEYUP:

        {

            if (wparam==VK_ESCAPE)

            {

                //PostQuitMessage(0);

                DestroyWindow(hwnd);

            }

        }

        break;

    case WM_COMMAND:

        {

            switch (LOWORD(wparam))

            {

            //case MENU_FILE_ID_EXIT:

            //    {

            //        DestroyWindow(hwnd);

            //    }

            //    break;

            }



        }

        break;



    }



    return DefWindowProc(hwnd,msg,wparam,lparam);

}

좋은 웹페이지 즐겨찾기