// Sysnap 2009.5.15
//1 MainWin 主窗口..由 HANDLE CreateMianWin(...)创建, 在这个MAINWIN里可以创建其他控件
//2 任何控件的创建都需要父窗口的HANDLE...HANDLE ConctrolCreateXXX(HANDLE hParent,...);
//3 消息路油: 当一个消息到达一个MainWindow时,怎样处理消息的一个过程.如果多个控件都要响应同一个消息,那么谁将响应
// 这个消息? 可以这么设置, 当一个鼠标左单击一个区域时..这个区域作为响应消息的第一站...
// 我们可以维护一个优先级表...提供SetMsgDispatchPa来设置优先级...
响应区: 对消息进行响应处理的一个区域...
一个MAINWIN中可以有多个响应区..所以必须把这些响应区用一个链表维护起来..
消息:
定义一个结构体来表示消息/
typedef struct __MSG
{
DWORD dwCommand; // 消息类型..比如WM_KEY_DOWN, WM_KEY_UP, WM_MOUSE_RCLICK
DWORD dwParamA; // 下面俩个数据的意义根据..dwCommand而变
DWORD dwParamB;
}MSG;
BOOLEAN SendMSG()
{
// GET THE RIGHT MAINWIN AND
// INSERT THE MSG INTO THE MSG QUEUE
// 当鼠标 左单击 点某个区域时,,我们会把这个区域所以MAIMWIN当作活动窗口...任何消息将会投到
// 这个活动窗口的消息队列中去...
return TRUE;
}
BOOLEAN GetMSG()
{
//GET MSG FROM MSG QUEUE
//从消息队列中取消息//
return TRUE;
}
typedef struct __RECT
{
DWORD dw_x; // (dw_x,dw_y) 左点,即原点...
DWORD dw_y;
DWORD dw_cx; //(dw_cx,dw_cy) 右下点..
DWORD dw_cy;
}RECT;
typedef (*WINPROC)(MSG* pMSG);
typedef struct __REGION_OBJECT
{
struct __REGION_OBJECT* pRegionParent;
struct __REGION_OBJECT* pChildRegionList;
RECT Rect;
WINPROC pCallBack;
DWORD dwRegionType; // eg: menu list...
PVOID lpSaveScreen; // 覆盖了哪些区域,以便还原...一般不用管,是MAINWIN做的事//
}REGION_OBJECT;
typedef struct __MAINWIN_OBJECT
{
//struct __MAINWIN_OBJECT* pMainWinObj;
MSG* pMSGQUEUE;
RECT MainWinRect;
WINPROC pDefualtCallBack;
REGION_OBJECT* pRegionList;
PVOID lpSaveScreen;
DWORD dwstyle;
PSTR szTiltle;
};
到现在为止..我们可以来模拟一下处理过程...
当鼠标 单击 时..
1 确定当前的鼠标坐标 MOUSE(X,Y)
//2 确定动窗口,找到 MAINWIN_OBJECT ..遍历 pRegionList
BOOLEAN DispatchMSG(MSG* pMSG)
{
//HANLE THE MSG
// 其实这里只是把MSG发给响应区域的"CALL BACK PROC"...由其处理...
// SO Here we should find out which region the MSG will ""Send to""
// ""Send to"" means we will call it's "call back proc"
// so
XX = FindActiveRegion(); // for we will implement like so
XX->CALL_BACK(pMSG);
return TRUE;
}
FindActiveRegion() // 必须确定活动窗口..活动REGION_OBJECT 找到 MAINWIN_OBJECT ..遍历 pRegionList
// 如果是鼠标消息..确定当前的鼠标坐标 MOUSE(X,Y)..判断落在哪个区域内..调用其回调..
// 具体的功能由 回调 处理..
// 如果没有找到区域或者没人响应消息..调用默认处理..
///////////////////////////////////////////////////////////////////
// 底层屏幕管理...__VIDEO
#define __COLOR DWORD
#define POOLTYPE DWORD
typedef struct __VIDEO
{
DWORD dwHieght; // screen height
DWORD dwwidth; // screen width
DWORD dwbitsPerPixe;
DWORD dwDisplayMode; // if flat mode,dwDisplayMode is num of flats..or ti will be 0
PVOID lpVideoMapAddress; //
PVOID lpMemDcAddress;
DWORD dwMemDcAllocateSize;
typedef BOOL (*InitializeVideo)(__VIDEO* pVideo);
typedef BOOL (*UnInitializeVideo)(__VIDEO* pVideo);
typedef VOID (*DrawPixel)(struct __VIDEO* pVideo,int x,int y,__COLOR color);
typedef VOID (*GetPixel)(struct __VIDEO* pVideo,int x,int y,__COLOR color);
typedef VOID (*DrawLine)(__VIDEO* pVideo,int xa,int ya,int xb,int yb,__COLOR color)
typedef VOID (*DrawHorizontalLine)(struct __VIDEO* pVideo,int x,int y,int cx,__COLOR color);
typedef VOID (*DrawVerticalLine)(struct __VIDEO* pVideo,int x,int y,int cy,__COLOR color);
typedef VOID (*DrawSeprateLine)(__VIDEO* pVideo,int xa,int ya,int xb,int yb,__COLOR color);
//Converts the mouse dimension into screen dimension.
typedef VOID (*MouseToScreen)(__VIDEO* pVideo,int x,int y,int* px,int* py);
typedef VOID (*DrawRectangle)(__VIDEO* pVideo,int x1,int y1,int x2,int y2,__COLOR lineclr,
BOOLEAN bFill,__COLOR fillclr);
typedef BOOL (*GetVideoBuffer)(VOID);
// MEMORY OPERATIONS..
// sometimes when we do lots of operations direct access the video ram..it may cause some bad feelings..
// may be we can do the same work in the memory..and when we finish them..copy(memory,VRAM)
typedef PVOID (*MemDCAllocate)(__VIDEO* pVideo,POOLTYPE type,DWORD dwSize...);
typedef PVOID (*MemDCMap)(__VIDEO* pVideo,DWORD dwSize,DWORD dw_w,DWORD dw_h,DWORD dwbitsPerPixe);
typedef PVOID (*MemDCFree)(__VIDEO* pVideo,DWORD dwSize,DWORD dw_w,DWORD dw_h,DWORD dwbitsPerPixe);
typedef PVOID (*MemDCCopyTo)(__VIDEO* pVideo,RECT* pRect, PVOID lpDestBuffer);
typedef PVOID (*MemDCGetFrom)(__VIDEO* pVideo,RECT* pRect, PVOID lpSrcBuffer);
// and so on...
};
// struct __VIDEO is hardly depend on hardware
// now we wiil define a object which will have nothing to do with ant hardware----GDI
//
typedef struct __BRUSH
{
__COLOR BrushColor;
DWORD dwBrushSize;
DWORD dwBrushAttr; // PURE_COLOR ...
}BRUSH;
typedef struct __REGION
{
DWORD dwType; // eg: rect
DWORD dwRadius;
RECT Rect;
// add more youself
};
#define FONT_POINTER PVOID
typedef struct __FONT
{
DWORD dwFontType;
FONT_POINTER lpFontPtr;
}FONT;
typedef struct tagDC {
INT iType; /* the DC's type, screen DC | memory DC | print DC*/
HANDLE hDevice; /* 物理输出设备句柄 */
REGION_OBJECT* pRegionObj; /* DC所属的窗口 */
DWORD dwFlags; /* 窗口设备裁剪标记 */
DWORD dwBlackMode; /* 背景模式 */
UINT uTextAlign; /* 文字对齐方式 */
COLORREF bkColor; /* 文字输出时的背景颜色 */
COLORREF textColor; /* 文字的颜色 */
INT iDrawMode; /* rop2 覆盖绘图模式 */
POINT pt; /* 当前的画笔坐标*/
FONT FontInfo;
BRUSH BrushInfo;
}DC, *PDC;
///////////////////////////////////
Control////..
菜单..Menu...
#define SZ char
#define MAX_MENUITEM_TEXT 100
typedef struct __MENU_ITEM
{
DWORD dwMenuItemID;
SZ szItemText[MAX_MENUITEM_TEXT];
DWORD dwItemType; // 0 ----- 1 normal
WINPROC pCallBack;
__REGION_OBJECT regionobj;
}MENU_ITEM,*PMENU_ITEM;
typedef struct __MENU_OBJECT
{
DWORD dwMenuID;
PMENU_ITEM pMenuItemList; // if we call InsetMenuItem..we use this...
DWORD dwMenu_x; // fill by xx
DWORD dwMenu_y;
RECT Rect;
SZ szMenuText[36] ; // not use for the context menu...
}MENU_OBJECT;
BOOLEAN MenuCreate()
{
// 首先每个菜单项都是一个响应区域...创建的时候必须在其响应的区域 注册 响应区域...
// create MENU_OBJECT
}
BOOLEAN IniMenu()
{
}
BOOLEAN PopUpMenu()
{
}