LRESULT IdleControlProc( HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam ) { RECT rc; HDC hDC; char* pFileName; PAINTSTRUCT ps; PWindowsTree pWin; pWin=(PWindowsTree)hWnd; switch(iMsg) { case LMSG_CREATE: pFileName=(char*)malloc(strlen((char*)lParam)+1); if(!pFileName) return false; strcpy(pFileName,(char*)lParam); pWin->dwAddData = (DWORD)pFileName; break; case LMSG_PENDOWN: break; case LMSG_PENUP: break; case LMSG_PENMOVE: break; case LMSG_PAINT: ps.bPaintDirect=false; hDC=BeginPaint(hWnd, &ps); if(!hDC) { return true; } scrGetClientRect(hWnd,&rc); ScreenToClientRect(hWnd,&rc); ShowBitmap(hDC,0,0,(char*)(pWin->dwAddData)); DrawText(hDC,"12:00",strlen("12:00"),&rc,DT_CENTER); EndPaint(hWnd, &ps); break; case LMSG_DESTROY: if((char*)(pWin->dwAddData)) free((char*)(pWin->dwAddData)); break; case LMSG_COMMAND: break; default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } return true; }
VOID GetChildRect( HWND hwndChild, PRECT prc) { HWND hwndParent; hwndParent = GetParent(hwndChild); GetClientRect(hwndChild, prc); ClientToScreenRect(hwndChild, prc); ScreenToClientRect(hwndParent, prc); }
BOOL EraseBackground(HWND hWnd, HDC hDC) { RECT rc; /* window's screen coordinates */ HWND hwItem; GetWindowRect(hWnd, &rc); ScreenToClientRect(hWnd, &rc); FillRect(hDC, &rc, brGrey); hwItem = GetDlgItem(hWnd, IDC_TOPFRAME); GetWindowRect(hwItem, &rc); ScreenToClientRect(hWnd, &rc); FillRect(hDC, &rc, brShade); hwItem = GetDlgItem(hWnd, IDC_BOTTOMFRAME); GetWindowRect(hwItem, &rc); ScreenToClientRect(hWnd, &rc); FillRect(hDC, &rc, brWhite); return TRUE; }
LRESULT StartMenuCtrlProc( HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam ) { RECT rc,rcItem,rcWin; HDC hDC; PAINTSTRUCT ps; int iWidth,iHeight; PWindowsTree pWin; int iCounter,iTotal; int iRetMsg; int x,y; pWin=(PWindowsTree)hWnd; switch(iMsg) { case LMSG_CREATE: pData = (PMENUDATA)malloc(sizeof(MENUDATA)); if(!pData) return false; memset(pData,0, sizeof(MENUDATA)); pWin->dwData = (DWORD)pData; pData->itemHeight = DEF_MENU_ITEM_HEIGHT;//default item height pData->itemHilighted = -1; pWin->dwData = (DWORD)pData; break; case LMSG_PENDOWN: CaptureMouse(hWnd,BYCLIENT); scrGetClientRect(hWnd,&rc); ScreenToClientRect(hWnd,&rc); x = (int)wParam; y = (int)lParam; ScreenToClient(hWnd,&x,&y); pData = (PMENUDATA)(pWin->dwData); iTotal =pData->itemCount; for(iCounter=0;iCounter<iTotal;iCounter++){ mnuGetItemsRect(pData,iCounter,&rcItem); rcItem.left=rc.left; rcItem.right =rc.right; if(PtInRect(&rcItem,x,y)){ pData->itemHilighted = iCounter; InvalidateRect(hWnd,&rcItem,true); break; } } break; case LMSG_PENUP: DisCaptureMouse(); scrGetClientRect(hWnd,&rc); ScreenToClientRect(hWnd,&rc); x = (int)wParam; y = (int)lParam; ScreenToClient(hWnd,&x,&y); pData = (PMENUDATA)(pWin->dwData); iTotal =pData->itemCount; for(iCounter=0;iCounter<iTotal;iCounter++){ mnuGetItemsRect(pData,iCounter,&rcItem); rcItem.left=rc.left; rcItem.right =rc.right; if(PtInRect(&rcItem,x,y)){ iRetMsg=STARTMENU_ITEM_CLICKED; iRetMsg=iRetMsg<<16; iRetMsg=iRetMsg | (unsigned long)(pData->items[iCounter].id); SendNotifyMessage((HWND)(pWin->pParent), LMSG_COMMAND,(WPARAM)iRetMsg,(LPARAM)NULL); break; } } break; case LMSG_PENMOVE: break; case LMSG_PAINT: { HFONT hFont; ps.bPaintDirect=false; hDC=BeginPaint(hWnd, &ps); if(!hDC){ return true; } scrGetClientRect(hWnd,&rc); ScreenToClientRect(hWnd,&rc); GetWindowRect(hWnd,&rcWin); iWidth =rcWin.right - rcWin.left + 1; iHeight =rcWin.bottom - rcWin.top + 1; pData = (PMENUDATA)(pWin->dwData); if(!pData) return false; iTotal =pData->itemCount; hFont = GetStockObject(FONT_12_12); SelectObject(hDC,hFont); for(iCounter=0;iCounter<iTotal;iCounter++){ mnuGetItemsRect(pData,iCounter,&rcItem); rcItem.left=rc.left; rcItem.right =rc.right; if(iCounter == pData->itemHilighted) FillRectangle(hDC,rcItem.left,rcItem.top,rcItem.right,rcItem.bottom,RGB_SYSTEMBRIGHT,RGB_SYSTEMBRIGHT); OutputBmpObjWithTrColor(hDC,rcItem.left , rcItem.top + 2, iWidth,iHeight,(HBITMAP)(pData->items[iCounter].pBitmap),RGB(230,230,230)); rcItem.left +=14; DrawText(hDC,pData->items[iCounter].lpszName, strlen(pData->items[iCounter].lpszName),&rcItem,DT_CENTER); } DeleteObject(hFont); EndPaint(hWnd, &ps); break; } case LMSG_DESTROY: DestroyStartMenuItems(hWnd); break; case SM_ADDITEM: pData = (PMENUDATA)(pWin->dwData); mnuAddItem(hWnd,pData,(PMENUITEM)wParam); return true; default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } return true; }
HWND WINAPI SetParent(HWND hWndChild, HWND hWndNewParent) { HWND32 hWndChild32, hWnd32Parent, hWndFrame32; HWND hWndOldParent,hWndFrame; WINCREATESTRUCT wcs; RECT rcOldFrame; RECT rcOldChild; RECT rcFrame; RECT rcChild; RECT rcParent; DWORD dwOldStyle; APISTR((LF_API, "SetParent(hWndChild:%.04x,hWndNewParent:%.04x)\n", hWndChild, hWndNewParent)); if (!(hWndChild32 = GETHWND32(hWndChild))) { return(0); } if ((hWndOldParent = hWndChild32->hWndParent) == hWndNewParent) { RELEASEWININFO(hWndChild32); return hWndOldParent; } if (hWndNewParent) { if (!(hWnd32Parent = GETHWND32(hWndNewParent))) { RELEASEWININFO(hWndChild32); return hWndOldParent; } } GetWindowRect(hWndChild,&rcOldChild); RemoveFromList(hWndChild32); dwOldStyle = hWndChild32->dwStyle; hWndFrame = GetWindowFrame(hWndChild); GetWindowRect(hWndFrame,&rcOldFrame); hWndFrame32 = GETHWND32(hWndFrame); hWndChild32->hWndParent = hWndNewParent; hWndFrame32->hWndParent = hWndNewParent; if (hWndNewParent) { hWndChild32->dwStyle &= ~WS_POPUP; hWndChild32->dwStyle |= WS_CHILD; hWndFrame32->dwStyle &= ~WS_POPUP; hWndFrame32->dwStyle |= WS_CHILD; } else { hWndChild32->dwStyle &= ~WS_CHILD; hWndChild32->dwStyle |= WS_POPUP; hWndFrame32->dwStyle &= ~WS_CHILD; hWndFrame32->dwStyle |= WS_POPUP; } TWIN_InsertAsFirstSibling(hWndChild32); if ((dwOldStyle & WS_CHILD) && (hWndNewParent == 0)) { POINT pt; HICON hIcon; HCURSOR hCursor; memset((LPSTR)&wcs,0,sizeof(WINCREATESTRUCT)); wcs.lpszName = hWndChild32->lpWindowName; wcs.dwStyle = hWndChild32->dwStyle; wcs.dwExStyle = hWndFrame32->dwExStyle; wcs.nBorder = hWndChild32->wXBorder; if ((hIcon = GetClassIcon(hWndChild))) FillIconData(&wcs,hIcon); if ((hCursor = GetClassCursor(hWndChild))) FillCursorData(&wcs,hCursor); wcs.hWndFrame = Get32WindowFrame(hWndChild32); wcs.hWndClient = hWndChild; pt.x = hWndFrame32->rWnd.left; pt.y = hWndFrame32->rWnd.top; ClientToScreen(hWndOldParent,&pt); SetRect(&wcs.rcFrame,pt.x,pt.y, pt.x + hWndFrame32->wWidth, pt.y + hWndFrame32->wHeight); hWndFrame32->lpDrvData = (LPVOID)DRVCALL_WINDOWS(PWSH_CREATEWINDOW, 0,0,&wcs); } else if (!(dwOldStyle & WS_CHILD) && hWndNewParent) { DRVCALL_WINDOWS(PWSH_DESTROYWINDOW,0L,0L, WIN_GETDRVDATA(Get32WindowFrame(hWndChild32))); } TWIN_ReparentDC(hWndChild); RELEASEWININFO(hWndChild32); RELEASEWININFO(hWndFrame32); RELEASEWININFO(hWnd32Parent); if (hWndOldParent && IsWindowVisible(hWndOldParent)) { ScreenToClientRect(hWndOldParent, &rcOldFrame, &rcParent); InvalidateRect(hWndOldParent, &rcParent, TRUE); ScreenToClientRect(hWndOldParent, &rcOldChild, &rcParent); InvalidateRect(hWndOldParent, &rcParent, TRUE); } if (IsWindowVisible(hWndChild)) { GetClientRect(hWndFrame,&rcFrame); InvalidateRect(hWndFrame, &rcFrame, TRUE); GetClientRect(hWndChild,&rcChild); InvalidateRect(hWndChild, &rcChild, TRUE); } return hWndOldParent; }
static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static activePage = 0; switch (msg) { /* init */ case WM_INITDIALOG: { LOCALDATA *data = LocalAlloc(LPTR, sizeof(LOCALDATA)); HINSTANCE inst = (HINSTANCE)lParam; TCITEM item; /* init */ SetWindowLong(hwnd, GWL_USERDATA, (LONG)data); data->htab = GetDlgItem(hwnd, IDC_TABS); data->hdlg = NULL; /* add pages */ item.mask = TCIF_TEXT; data->all[0] = CreateDialog(inst, MAKEINTRESOURCE(IDD_CONFIG_GENERAL), hwnd, GeneralProc); item.pszText = "General"; TabCtrl_InsertItem(data->htab, 0, &item); data->all[1] = CreateDialog(inst, MAKEINTRESOURCE(IDD_CONFIG_OUTPUT), hwnd, OutputProc); item.pszText = "Output"; TabCtrl_InsertItem(data->htab, 1, &item); /* get rect (after adding pages) */ GetWindowRect(data->htab, &data->r); ScreenToClientRect(hwnd, &data->r); TabCtrl_AdjustRect(data->htab, 0, &data->r); /* simulate item change */ TabCtrl_SetCurSel(data->htab, activePage); OnSelChange(hwnd); } return TRUE; /* destory */ case WM_DESTROY: { LOCALDATA *data = (LOCALDATA*)GetWindowLong(hwnd, GWL_USERDATA); int i; activePage = TabCtrl_GetCurSel(data->htab); for (i=0; i<NUM_PAGES; i++) DestroyWindow(data->all[i]); LocalFree(data); } break; /* commands */ case WM_COMMAND: switch (LOWORD(wParam)) { /* ok/cancel */ case IDOK: BroadcastCommand(hwnd, IDOK); /* fall through */ case IDCANCEL: EndDialog(hwnd, LOWORD(wParam)); return TRUE; case IDC_RESET: SendCommand(hwnd, IDC_RESET); break; } break; /* notification */ case WM_NOTIFY: if (LOWORD(wParam) == IDC_TABS) { NMHDR *hdr = (NMHDR*)lParam; switch (hdr->code) { case TCN_SELCHANGE: OnSelChange(hwnd); break; } } break; } return 0; }