pWin->vscroll.barStart = 0; pWin->vscroll.barLen = 10;
pWin->vscroll.status = SBS_NORMAL; } else
pWin->vscroll.status = SBS_HIDE | SBS_DISABLED;
if (pWin->dwStyle & WS_HSCROLL) { pWin->hscroll.minPos = 0; pWin->hscroll.maxPos = 100; pWin->hscroll.curPos = 0; pWin->hscroll.pageStep = 0; pWin->hscroll.barStart = 0; pWin->hscroll.barLen = 10;
pWin->hscroll.status = SBS_NORMAL; } else
pWin->hscroll.status = SBS_HIDE | SBS_DISABLED;
5、SendMessage ((HWND)pWin, MSG_NCCREATE, 0, (LPARAM)pCreateInfo)
#define MSG_NCCREATE 0x0061 作用:表示该窗口已经创建但是还没有向系统进行注册,当收到这种类型的消息时可以对自己创建的对象进行初始化,但不能创建子窗口,也不能进行绘图。如果函数返回值为非零值,创建的窗口将被销毁。
* \\code
* MSG_NCCREATE for main windows:
* PMAINWINCREATE create_info = (PMAINWINCREATE)lParam; *
* MSG_NCCREATE for controls: * DWORD add_data = (DWORD)lParam; * \\endcode *
* \\param create_info The pointer to the MAINWINCREATE structure which is * passed to CreateMainWindow function.
* \\param add_data The first additional data passed to CreateWindowEx function. *
* \\sa CreateMainWindow, CreateWindowEx, MAINWINCREATE main?CreateMainWindow(&CreateInfo)
? SendMessage ((HWND)pWin, MSG_NCCREATE, 0, (LPARAM)pCreateInfo)
? HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) ? DefaultMainWinProc(hWnd, message, wParam, lParam)
(message >= MSG_FIRSTCREATEMSG && message <= MSG_LASTCREATEMSG)
? DefaultCreateMsgHandler(pWin, message, wParam, lParam) 返回0,什么也没做
6、SendMessage ((HWND)pWin, MSG_SIZECHANGING,(WPARAM)&pCreateInfo->lx, (LPARAM)&pWin->left);
#define MSG_SIZECHANGING 0x0025
作用:指示了将要被更改的窗口的大小,当窗口大小将要发生改变时,该消息会发送给窗口。如果你想要控制窗口改变后的实际位置和大小(窗口改变可能是MoveWindow或者其他函数引起的),你需要使用MSG_SIZECHANGING作为SendMessage函数的第二个参数,并且通过第二个参数返回位置和大小信息。
* \\code
* MSG_SIZECHANGING
* const RECT* rcExpect = (const RECT*)wParam; * RECT* rcResult = (RECT*)lParam; * \\endcode *
* \\param rcExpect The expected size of the window after changing. * \\param rcResult The actual size of the window after changing. *
main?CreateMainWindow(&CreateInfo)
?SendMessage((HWND)pWin,MSG_SIZECHANGING,(WPARAM)&pCreateInfo->lx,(LPARAM)&pWin->left)
? HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) ? DefaultMainWinProc(hWnd, message, wParam, lParam)
( message >= MSG_FIRSTPOSTMSG && message <= MSG_LASTPOSTMSG) ? DefaultPostMsgHandler(pWin, message, wParam, lParam) memcpy ((PRECT)lParam, (PRECT)wParam, sizeof (RECT))
将wParam的信息复制给lParam,返回0
7、SendMessage ((HWND)pWin, MSG_CHANGESIZE, (WPARAM)&pWin->left, 0) #define MSG_CHANGESIZE 0x0022 作用:确定改变后的窗口大小
main?CreateMainWindow(&CreateInfo)
?SendMessage((HWND)pWin,MSG_CHANGESIZE,(WPARAM)&pWin->left,0) ? HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) ? DefaultMainWinProc(hWnd, message, wParam, lParam)
(message >= MSG_FIRSTPOSTMSG && message <= MSG_LASTPOSTMSG)
(1)? OnChangeSize (pWin, (PRECT)wParam, (PRECT)lParam)确定边界、标题、滚动条等的大小
(2)? RecalcClientArea ((HWND)pWin) 确定客户区域的坐标和大小
8、SendMessage (HWND_DESKTOP, MSG_ADDNEWMAINWIN, (WPARAM) pWin, (LPARAM) pWin->pZOrderNode);
#define MSG_ADDNEWMAINWIN 0x00F0 作用:绘制窗口
main?CreateMainWindow(&CreateInfo)
? SendMessage (HWND_DESKTOP, MSG_ADDNEWMAINWIN, (WPARAM) pWin, (LPARAM)
pWin->pZOrderNode)
? DesktopWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
(message >= MSG_FIRSTWINDOWMSG && message <= MSG_LASTWINDOWMSG)
? WindowMessageHandler (message, (PMAINWIN)wParam, lParam)
case MSG_ADDNEWMAINWIN
? dskAddNewMainWindow(pWin, (PZORDERNODE)lParam) 1? dskUpdateGCRInfoOnShowNewMainWin (pWin)
2? SendAsyncMessage ((HWND)pWin, MSG_NCPAINT, 0, 0)(相当于SendMessage)
* MSG_NCPAINT:绘制非客户区域brief Indicates that paints non-client area. #define MSG_NCPAINT 0x00B2
2? HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) 2? DefaultMainWinProc(hWnd, message, wParam, lParam)
(message >= MSG_FIRSTPAINTMSG && message <= MSG_LASTPAINTMSG) 2? DefaultPaintMsgHandler(pWin, message, wParam, lParam) 2? wndDrawNCFrame (pWin, (HDC)wParam, (const RECT*)lParam) (1)? wndDrawNCArea (pWin, hdc)(绘制边框) (2)? wndDrawScrollBar (pWin, hdc)(绘制滚动条)
(3)? wndDrawCaption (pWin, hdc, !(pWin->dwStyle & WS_DISABLED) &&
(GetActiveWindow() == (HWND)pWin));(绘制标题) (4)? DrawMenuBarHelper (pWin, hdc, prcInvalid)
3? SendNotifyMessage ((HWND)pWin, MSG_SHOWWINDOW, SW_SHOWNORMAL, 0) 4?InvalidateRect ((HWND)pWin, NULL, TRUE) 5?dskChangActiveWindow (pWin)
9、SendMessage ((HWND)pWin, MSG_CREATE, 0, (LPARAM)pCreateInfo) #define MSG_CREATE 0x0060 作用:表示窗口已经创建成功
四、ShowWindow函数流程
该函数的作用:根据窗口的显示状态信息对窗口进行显示 1、MG_CHECK_RET (MG_IS_NORMAL_WINDOW(hWnd), FALSE)
作用:如果不是一个正规窗口,返回FALSE;结束ShowWindow
#define MG_CHECK_RET(condition, ret) if (!(condition)) return ret
#define MG_IS_NORMAL_WINDOW(hWnd) (hWnd != HWND_DESKTOP && MG_IS_WINDOW(hWnd))
/* hWnd is a normal window, not including HWND_DESKTOP*/
2、根据窗口类型和窗口的显示类型对窗口的显示状态进行调整
SW_SHOWNORMAL:激活并显示一个窗口,会将窗口显示在最上层,通过在DesktopWinProc中调用dskMoveToTopMost()实现。如果窗口被最小化或最大化,系统将其恢复到原来的尺寸和大小。应用程序在第一次显示窗口的时候应该指定此标志。
SW_SHOW:在窗口原来的位置以原来的尺寸激活和显示窗口。在DesktopWinProc中调用dskShowMainWindow如果窗口原来被覆盖,使用该消息后依然维持原样。
SW_HIDE:隐藏窗口并激活其他窗口。
如果hWnd指示的窗口是主窗口:
switch (iCmdShow) {
case SW_SHOWNORMAL:
SendMessage (HWND_DESKTOP,
MSG_MOVETOTOPMOST, (WPARAM)hWnd, 0); break;
case SW_SHOW:
SendMessage (HWND_DESKTOP,
MSG_SHOWMAINWIN, (WPARAM)hWnd, 0); break;
case SW_HIDE:
SendMessage (HWND_DESKTOP,
MSG_HIDEMAINWIN, (WPARAM)hWnd, 0); break; }
如果hWnd指示的窗口是控件窗口:
#define WS_EX_CTRLASMAINWIN 0x40000000L
* \\brief The control can be displayed out of the main window which contains the control. //WS_EX_CTRLASMAINWIN便是空间窗口可以被显示在主窗口之外
if (pControl->dwExStyle & WS_EX_CTRLASMAINWIN) {//控件可以显示在主窗口之外
if (iCmdShow == SW_SHOW)
SendMessage (HWND_DESKTOP, MSG_SHOWGLOBALCTRL, (WPARAM)hWnd, iCmdShow);
else if (iCmdShow == SW_HIDE)
SendMessage (HWND_DESKTOP, MSG_HIDEGLOBALCTRL, (WPARAM)hWnd, iCmdShow);
else
return FALSE; }
else { //控件不可以显示在主窗口之外 switch (iCmdShow) {
case SW_SHOWNORMAL: //正常显示窗口 case SW_SHOW:
if (!(pControl->dwStyle & WS_VISIBLE)) { pControl->dwStyle |= WS_VISIBLE;
SendAsyncMessage (hWnd, MSG_NCPAINT, 0, 0); InvalidateRect (hWnd, NULL, TRUE); }
break;
case SW_HIDE: //隐藏窗口
if (pControl->dwStyle & WS_VISIBLE) {
pControl->dwStyle &= ~WS_VISIBLE; InvalidateRect ((HWND)(pControl->pParent), (RECT*)(&pControl->left), TRUE); } break; } }
3、根据iCmdShow等信息确定当前窗口是否失去输入焦点
#define MSG_KILLFOCUS 0x0031
* \\brief Indicates that the window has lost the input focus. //MSG_KILLFOCUS,指示当前控制窗口失去输入焦点
//如果窗口的显示状态为SW_HIDE且控制窗口的父窗口的活动窗口为当前的控制窗口 if (iCmdShow == SW_HIDE && pControl->pParent->active == pControl) { SendNotifyMessage (hWnd, MSG_KILLFOCUS, 0, 0); pControl->pParent->active = NULL; } }
4、向消息队列发送消息MSG_SHOWWINDOW根据iCmdShow指示当前窗口的显示状态
SendNotifyMessage (hWnd, MSG_SHOWWINDOW, (WPARAM)iCmdShow, 0);
五、获取消息GetMessage()
1、函数作用:将消息队列中最先发生的消息参数传递给pMsg
static inline BOOL GUIAPI GetMessage (PMSG pMsg, HWND hWnd) {
return PeekMessageEx (pMsg, hWnd, 0, 0, TRUE, PM_REMOVE); }
2、数据结构
struct _MSGQUEUE {
DWORD dwState; // 消息队列的状态
PQMSG pFirstNotifyMsg; // head of the notify message queue,notify消息队列的队首 PQMSG pLastNotifyMsg; // tail of the notify message queue,notify消息队列的队尾 IDLEHANDLER OnIdle; // Idle handler空闲的处理程序 MSG* msg; /* post message buffer */消息的地址 int len; /* buffer len */消息队列占用缓存大小 int readpos, writepos; /* positions for reading and writing */读写位置
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库minigui代码分析(2)在线全文阅读。
相关推荐: