嗯嗯- -b  rt.

/*  frame.h :os::frame */

#ifndef APPFRAME__

#define APPFRAME__

#include 
<windows.h>
#include 
<tchar.h>
#include 
<stdio.h>

#include 
"axiom.h"
#include 
"string.h"
#include 
"geo.h"
#include 
"runtime.h"

#include 
"vector.h"



namespace gui
{
    
class component
    
{
    
public:
        arith::point pos;
/*position*/
        
int isvis;/*is visible*/
        
double getx();
        
double gety();
        arith::point getpos();

    }
;

    
class gtext:public component
    
{
        adt::ustring text;
    
public:
        gtext(adt::ustring _t,
int x,int y,int isv=1);

    }
;
    
class gbutton:public component
    
{
    
public:
        geo::polygon figure;
        adt::ustring text;
        COLORREF bklist[
5];
        gbutton(
int _x,int _y);

        
int isIn(int _x,int _y);


    }
;
    
class compoList
    
{
    
public:
        
int i;
        adt::vector
<gbutton*> buttonList;
        adt::vector
<gtext*> textList;
    }
;

}


namespace appinfo
{

    
static const int max_form=500;

    
static int iCmdShow,regNum,listIndex;
    
static HINSTANCE hInstance;
    
static HINSTANCE hPrevInstance;
    
static PSTR szCmdLine;
    
static MSG  msg;
    
/* register windowclass-name */
    
static TCHAR regList[max_form][4];

    
static void decform();
    
static void incform();
    
static void setListIndex(int & reg_index,LPCWSTR & wc_name);
    
static gui::compoList controlList[appinfo::max_form];


}

namespace frame
{


    
using adt::ustring;

    
using adt::vector;
    
using arith::point;
    
using geo::polygon;



    
class compoList;
    
class form;
    
//using namespace adt;

    
    
namespace api
    
{

        
class def
        
{
        
public:
            
static const int nil =0;
            
static const int sm_x = 0;
            
static const int sm_y = 1;
            
static const int wm_create=WM_CREATE;
            
static const int wm_paint=WM_PAINT;
            
static const int wm_destroy=WM_DESTROY;
            
static const int wm_mousemove=WM_MOUSEMOVE;
            
static const int wm_lbuttondown=WM_LBUTTONDOWN;
            
static const int wm_lbuttonup=WM_LBUTTONUP;
            
static const int wm_lbuttondblclk=WM_LBUTTONDBLCLK;

            
static const unsigned int cs_default= CS_HREDRAW | CS_VREDRAW ;
        }
;
        
namespace type
        
{
            typedef HDC__
* hdc;
            typedef HWND hwnd;
            typedef ustring 
string;
            typedef UINT 
uint;
            typedef RECT rect;
            typedef LPRECT lprc;
            typedef WPARAM wp;
            typedef LPCWSTR lpcwstr;
            typedef LPARAM lp;
            typedef PAINTSTRUCT ps;
            typedef LPPAINTSTRUCT lpps;
            typedef BYTE 
byte;
            typedef LONG_PTR result;
            typedef WNDCLASS wndclass;
            typedef HICON hicon;
            typedef HCURSOR hcursor;
            typedef HBRUSH__
* hbrush;
            typedef HINSTANCE hinstance;
            typedef PSTR  pstr;
            typedef MSG msg;
            typedef TCHAR tchar;
            typedef BOOL state;
            typedef POINT point;
        }

        
namespace handle
        
{
            type::hicon icon(
int i=0);
            type::hcursor cursor(
int i=0);
            type::hbrush brush(
int i=WHITE_BRUSH);

        }

        
class paint
        
{
        
public:
            type::hdc hdc;
            type::rect rect;
            type::hwnd hwnd;
            type::ps ps;
            
bool ready;
            paint():ready(
false){}
            
~paint();
            type::hdc begin(type::hwnd 
& hwnd);
            
int end();
            
int text(type::string & tx);
            type::state polygon(type::point 
*apt,int i,int m=WHITE_BRUSH);
            type::state rectangle(
int x,int y,int w,int h);
            type::state line(
int x,int y,int x_,int y_);



        }
;
        
class mouse
        
{
        
public:
            
static double x(type::lp & lp);
            
static double y(type::lp & lp);

        }
;
        
class sm
        
{
        
public:
            
static int screeny();
            
static int screenx();

        }
;
        
class message
        
{
        
public:
        }
;
        
class proc
        
{
        
public:
            type::hwnd hwnd;
            type::
uint msg;
            type::wp wp;
            type::lp lp;

            proc()
{}
            proc(type::hwnd 
&hwnd_t,type::uint &msg_t,type::wp &wp_t,type::lp &lp_t);
            
void update(type::hwnd &hwnd_t,type::uint &msg_t,type::wp &wp_t,type::lp &lp_t);
            type::result defproc();
            
void postquit(int exitCode_t=0);
        }
;
        
class bitmap
        
{
        
public:
         HBITMAP hBitmap ;
        
        HDC            hdcMem ;    
        
int           cxBitmap, cyBitmap;

        
public:
            
int begin(HWND hwnd);
            
void setPixel(int x,int y,COLORREF cl=RGB(100,0,0));
            
int paint(HWND hwnd,int cxClient,int cyClient);
            
int end();
            
void getLargestDisplayMode (int *pcxBitmap, int * pcyBitmap);
    

        }
;
        
static void d2s(wchar_t s[],double d,int p=2);
    


        
class wndclass
        
{
        
public:
            type::hwnd   hwnd ;
            type::hwnd   parenthwnd;
            type::
string  title;
            type::wndclass wc;
/* wndclass info */
            
int regIndex;/* self-wndclass index in regList */


            
static type::result __stdcall wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
            
void init();
            wndclass();
            
~wndclass();
            
void setStyle(UINT style);
            
void setIcon(HICON hIcon);
            
void setCursor(HCURSOR hCursor);
            
void setBackground(HBRUSH hbr);
            
int renew();
            
void setTitle(wchar_t  _title[]);
    
        }
;
    }

    
class form
    
{
        api::wndclass tf;
    
public:

        form();
        
~form();
        form(wchar_t 
*title);
        
int add(gui::gtext & control_gtext);
        
int show();
    
    }
;
}

int cpp();
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow);



#endif





实现部分:


/* frame.cpp os::frame*/

#include 
"appframe.h"


namespace gui
{
    
double component::getx()
    
{
        
return pos.x_;
    }

    
double component::gety()
    
{
        
return pos.y_;
    }

    arith::point component::getpos()
    
{
        
return pos;
    }

    gtext::gtext(adt::ustring _t,
int x,int y,int isv)
    
{
        pos.
set(x,y);
        isvis
=isv;
        text
=_t;
    }

    gbutton::gbutton(
int _x,int _y)
    
{
        pos.x_
=_x;
        pos.y_
=_y;
        figure.push(
0,0);
        figure.push(
0,50);
        figure.push(
100,50);
        figure.push(
100,0);
        figure.add(_x,_y);
        text
<<"Button";
        bklist[
0]=RGB(12,0,0);
        bklist[
1]=RGB(41,12,44);
        bklist[
2]=RGB(111,111,111);
    }

    
int gbutton::isIn(int _x,int _y)
    
{
        
return figure.isIn(_x,_y);
    }

}


namespace appinfo
{
    
void decform()
    
{
        
--regNum;
    }
    
    
void incform()
    
{
        
++regNum;
    }

    
void setListIndex(int & reg_index,LPCWSTR & wc_name)
    
{
        reg_index
=listIndex;
        regList[listIndex][
0]=1;
        regList[listIndex][
1]=reg_index;
        regList[listIndex][
2]=0;
        wc_name
=regList[listIndex];
        
++listIndex;
        
++regNum;
    }

}

namespace frame
{


    
namespace api
    
{

        type::hicon handle::icon(
int i)
        
{
            
return  LoadIcon (NULL, IDI_APPLICATION);
        }

        type::hcursor handle::cursor(
int i)
        
{
            
return  LoadCursor (NULL, IDC_ARROW);
        }

        type::hbrush handle::brush(
int i)
        
{
            
return (type::hbrush) GetStockObject (i);
        }

        paint::
~paint()
        
{
            
if(ready!=false)
                end();
            ready
=false;
        }

        type::hdc paint::begin(type::hwnd 
& hwnd)
        
{                
            ready
=true;
            hdc 
= BeginPaint(hwnd,&ps);
            GetClientRect (hwnd, 
&rect);

            
return (hdc );
        }

        
int paint::end()
        
{
            ready
=false;
            
return EndPaint(hwnd,&ps);
        }

        
int paint::text(type::string & tx)
        
{
            
if(ready)
                
return DrawTextW (hdc, tx(), -1&rect,
                DT_SINGLELINE 
| DT_CENTER | DT_VCENTER) ;
            
else return 0;
        }

        type::state paint::rectangle(
int x,int y,int w,int h)
        
{
            
int sx=sm::screenx();
            
int sy=sm::screeny();
            
return Rectangle (hdc,x,y,x+w, y+h) ;
        }

        type::state paint::polygon(type::point 
*apt,int i,int m)
        
{
            SelectObject(hdc,GetStockObject(m));
            
return Polygon(hdc,apt,i) ;
        }

        type::state paint::line(
int x,int y,int x_,int y_)
        
{
            MoveToEx (hdc, x, y, NULL) ;

            
return LineTo (hdc, x_, y_) ;

        }

        
double mouse::x(type::lp & lp)
        
{
            
return LOWORD(lp) ;
        }

        
double mouse::y(type::lp & lp)
        
{
            
return HIWORD(lp) ;

        }

        
int sm::screenx()
        
{
            
return GetSystemMetrics(def::sm_x); 
        }

        
int sm::screeny()
        
{
            
return GetSystemMetrics(def::sm_y); 
        }

        proc::proc(type::hwnd 
&hwnd_t,type::uint &msg_t,type::wp &wp_t,type::lp &lp_t)
        
{
            update(hwnd_t,msg_t,wp_t,lp_t);
        }

        
void proc::update(type::hwnd &hwnd_t,type::uint &msg_t,type::wp &wp_t,type::lp &lp_t)
        
{
            hwnd
=hwnd_t;
            msg
=msg_t;
            wp
=wp_t;
            lp
=lp_t;
        }

        type::result proc::defproc()
        
{
            
return DefWindowProcW (hwnd, msg, wp, lp); 
        }


        
void proc::postquit(int exitCode_t)
        
{
            
if(appinfo::regNum==1)
            
{

                
--appinfo::regNum;
                PostQuitMessage(exitCode_t);
            }
else
            
{
                
--appinfo::regNum;
            }

        }

        
int bitmap::begin(HWND hwnd)
        
{
            getLargestDisplayMode (
&cxBitmap, &cyBitmap) ;


            HDC  hdc 
= GetDC (hwnd) ;

            hBitmap 
= CreateCompatibleBitmap (hdc, cxBitmap, cyBitmap) ;

            hdcMem  
= CreateCompatibleDC (hdc) ;

            ReleaseDC (hwnd, hdc) ;


            
if (!hBitmap)                                // no memory for bitmap

            
{

                DeleteDC (hdcMem) ;

                
return -1 ;

            }



            SelectObject (hdcMem, hBitmap) ;

            PatBlt (hdcMem, 
00, cxBitmap, cyBitmap, WHITENESS) ;
            
return 0 ;
        }


        
void bitmap::setPixel(int x,int y,COLORREF cl)
        
{
            SetPixel(hdcMem,x,y,cl);

        }

        
int bitmap::paint(HWND hwnd,int cxClient,int cyClient)
        
{

            PAINTSTRUCT ps;
            HDC hdc 
= BeginPaint (hwnd, &ps) ;

            BitBlt (hdc, 
00, cxClient, cyClient, hdcMem, 00, SRCCOPY) ;

            EndPaint (hwnd, 
&ps) ;
            
return 1;
        }

        
int bitmap::end()
        
{
            DeleteDC (hdcMem) ;

            DeleteObject (hBitmap) ;
            
return 1;
        }

        
void bitmap::getLargestDisplayMode (int *pcxBitmap, int * pcyBitmap)
        
{

            DEVMODE       devmode ;

            
int           iModeNum = 0 ;


            
* pcxBitmap =  *pcyBitmap = 0 ;


            ZeroMemory (
&devmode, sizeof (DEVMODE)) ;

            devmode.dmSize 
= sizeof (DEVMODE) ;



            
while (EnumDisplaySettings (NULL, iModeNum++&devmode))

            
{

                
*pcxBitmap = max ( *pcxBitmap, (int) devmode.dmPelsWidth) ;

                
*pcyBitmap = max ( *pcyBitmap, (int) devmode.dmPelsHeight) ;

            }


        }

        
static void d2s(wchar_t s[],double d,int p)
        
{


            
int i,a;
            
for(int j=0;s[j]!=0;j++)
                
if(s[j]=='.')
                
{
                    i
=1;
                }

                
if(p==0)
                
{
                    a
=d;
                    
for(i=0;a/10.0>0.0;i++)
                    
{

                        s[i]
=(wchar_t)(10*(a/10.0-(int)(a/10))+48);
                        a
/=10;
                    }


                }
else
                
{
                    a
=(int)(d*pow(10.0,p));
                    
for(i=0;i!=p;i++)
                    
{
                        s[i]
=(wchar_t)(10*(a/10.0-(int)(a/10))+48);
                        a
/=10;
                    }

                    s[p]
=(wchar_t)'.';

                    
for(i=p+1;a/10.0>0.0;i++)
                    
{
                        s[i]
=(wchar_t)(10*(a/10.0-(int)(a/10))+48);
                        a
/=10;
                    }

                }

                s[i]
=0;
                a
=i-1;
                i
=0;
                
char t;
                
for(;i<a;i++,a--)
                
{
                    t
=s[i];
                    s[i]
=s[a];
                    s[a]
=t;
                }

        }

        type::result __stdcall  wndclass::wndproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        
{

            
static proc proc;
            
static paint pt;


            
using geo::polygon;
            
static polygon plg;

            
static int temp=0;
            
static int cxClient, cyClient, x, y;

            
static POINT apt[6];

            
static gui::gbutton button(100,100);

            
static bitmap bm;

            
static wchar_t buf[20];

            proc.update(hwnd,message,wParam,lParam);



            
switch (message)
            
{

            
case   WM_SIZE:


                cxClient 
= LOWORD (lParam) ;

                cyClient 
= HIWORD (lParam) ;

                
for(int y=0;y!=cyClient;y++)
                
{
                    
for(int x=0;x!=cxClient;x++)
                    
{
                        bm.setPixel(x,y,RGB(
111,0,4));
                    }

                }

                InvalidateRect(hwnd,
0,TRUE); 
                
return 0;
            
case WM_TIMER:

                
return 0;
            
case api::def::wm_lbuttondown:
                x
=mouse::x(lParam),y=mouse::y(lParam);



                InvalidateRect(hwnd,NULL,TRUE); 
                
return 0;
            
case api::def::wm_create:

                bm.begin(hwnd);

                
return 0 ;
            
case api::def::wm_mousemove:

                x
=mouse::x(lParam),y=mouse::y(lParam);


                
return 0;

            
case api::def::wm_paint:



                bm.paint(hwnd,cxClient,cyClient);
                
return 0;

            
case api::def::wm_destroy:
                bm.end();
                proc.postquit();
                
return 0 ;

            }

            
return proc.defproc();
        }

        
void wndclass::init()
        
{
            wc.style         
= def::cs_default;
            wc.lpfnWndProc   
= wndproc ;
            wc.cbClsExtra    
= def::nil ;
            wc.cbWndExtra    
= def::nil ;
            wc.hInstance     
= appinfo::hInstance ;
            wc.hIcon         
= handle::icon() ;
            wc.hCursor       
= handle::cursor();
            wc.hbrBackground 
= handle::brush();
            wc.lpszMenuName  
= def::nil;

            appinfo::setListIndex(regIndex,wc.lpszClassName);

            
if (!RegisterClassW (&wc))
                
return ;
        }

        wndclass::wndclass()
        
{

            init();
        }

        wndclass::
~wndclass()
        
{
            appinfo::decform();
        }

        
void wndclass::setStyle(UINT style)
        
{
            wc.style 
= style;
        }

        
void wndclass::setIcon(HICON hIcon)
        
{
            wc.hIcon 
= hIcon;
        }

        
void wndclass::setCursor(HCURSOR hCursor)
        
{
            wc.hCursor 
= hCursor;
        }

        
void wndclass::setBackground(HBRUSH hbr)
        
{
            wc.hbrBackground 
= hbr;
        }

        
int wndclass::renew()
        
{
            hwnd 
= CreateWindowW(appinfo::regList[regIndex],      // window class name
                title(),   // window caption
                WS_OVERLAPPEDWINDOW,  // window style
                CW_USEDEFAULT,// initial x position
                CW_USEDEFAULT,// initial y position
                CW_USEDEFAULT,// initial x size
                CW_USEDEFAULT,// initial y size
                NULL,                 // parent window handle
                NULL,            // window menu handle
                appinfo::hInstance,   // program instance handle
                NULL) ;      // creation parameters
            return 1;

        }

        
void wndclass::setTitle(wchar_t  _title[])
        
{
            title.
set(_title);
        }

    }

    form::form()
    
{


        tf.setTitle(TEXT(
"ving"));
        tf.init();
        tf.renew();
    }

    form::
~form()
    
{
    }

    form::form(wchar_t 
*title)
    
{
        tf.setTitle(title);
        tf.init();
        tf.renew();
    }


    
int form::add(gui::gtext & control_gtext)
    
{
    
        appinfo::controlList[tf.regIndex].textList.push(
&control_gtext);
        
return 1;
    }

    
int form::show()
    
{
        tf.renew();
        
int scx=api::sm::screenx(); 
        
int scy=api::sm::screeny(); 
        SetWindowPos(tf.hwnd,NULL,scx
/3 ,scx/3 ,scx/3,scy/3,SWP_HIDEWINDOW);
        ShowWindow (tf.hwnd, appinfo::iCmdShow) ;
        UpdateWindow (tf.hwnd) ;
        
return 1;
    }


}



int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{

    appinfo::regNum
=0;
    appinfo::listIndex
=0;
    appinfo::hInstance
=hInstance;
    appinfo::hPrevInstance
=hPrevInstance;
    appinfo::szCmdLine
=szCmdLine;
    appinfo::iCmdShow
=iCmdShow;

    cpp();

    
while (GetMessageW(&appinfo::msg, NULL, 00))
    
{
        TranslateMessage (
&appinfo::msg) ;
        DispatchMessage (
&appinfo::msg) ;
    }

    
return (int)appinfo::msg.wParam ;
}








史上最短小的demo:
/**//* init.h  */

#include 
"appframe.h"
//#include "component.h"

int cpp()
{
    
    
using frame::form;
    
using gui::gtext;
    form f;
    

    adt::ustring s(L
"ving");
    gtext text(s,
100,150);
    f.add(text);
    
    f.show();
    
return 0;
}




睡觉....zzzZZzz。