HBITMAP WINAPI CreateCompatibleBitmap(HDC hdc, int nWidth, int nHeight) { MWBITMAPOBJ * hbitmap; int size; int linelen; if(!hdc) return NULL; nWidth = MWMAX(nWidth, 1); nHeight = MWMAX(nHeight, 1); /* calc memory allocation size and linelen from width and height*/ if(!GdCalcMemGCAlloc(hdc->psd, nWidth, nHeight, 0, 0, &size, &linelen)) return NULL; /* allocate gdi object*/ hbitmap = (MWBITMAPOBJ *)GdItemAlloc(sizeof(MWBITMAPOBJ)-1+size); if(!hbitmap) return NULL; hbitmap->hdr.type = OBJ_BITMAP; hbitmap->hdr.stockobj = FALSE; hbitmap->width = nWidth; hbitmap->height = nHeight; /* create compatible with hdc*/ hbitmap->planes = hdc->psd->planes; hbitmap->bpp = hdc->psd->bpp; hbitmap->linelen = linelen; hbitmap->size = size; return (HBRUSH)hbitmap; }
HWND WINAPI CreateWindowEx(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hwndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) { HWND pwp; /* parent window */ HWND wp; /* new window */ HWND hwndOwner; PWNDCLASS pClass; CREATESTRUCT cs; int titLen; static int nextx = 20; static int nexty = 20; /* WARNING: All modification made here should be reported on MwInitialize for the rootwp window */ pClass = MwFindClassByName(lpClassName); if(!pClass) return NULL; if(x == CW_USEDEFAULT || y == CW_USEDEFAULT) { x = nextx; nextx += 10; y = nexty; nexty += 10; if(nextx > 200) nextx = nexty = 20; } if(nWidth == CW_USEDEFAULT || nHeight == CW_USEDEFAULT) { nWidth = 250; nHeight = 250; } if(hwndParent == NULL) { if(dwStyle & WS_CHILD) return NULL; pwp = rootwp; } else pwp = hwndParent; /* WS_POPUP z-order parent is the root window (passed parent is owner)*/ if(dwStyle & WS_POPUP) pwp = rootwp; /* force clip to root, not z-parent*/ /* window owner is NULL for child windows, else it's the passed parent*/ if(dwStyle & WS_CHILD) hwndOwner = NULL; else hwndOwner = hwndParent; wp = (HWND)GdItemAlloc(sizeof(struct hwnd) - 1 + pClass->cbWndExtra); if(!wp) return NULL; /* force all clipping on by default*/ dwStyle |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN; wp->pClass = pClass; wp->lpfnWndProc = pClass->lpfnWndProc; wp->style = dwStyle; wp->exstyle = dwExStyle; wp->parent = pwp; wp->owner = hwndOwner; wp->children = NULL; wp->siblings = pwp->children; pwp->children = wp; wp->next = listwp; listwp = wp; wp->winrect.left = pwp->clirect.left + x; wp->winrect.top = pwp->clirect.top + y; wp->winrect.right = wp->winrect.left + nWidth; wp->winrect.bottom = wp->winrect.top + nHeight; wp->cursor = pwp->cursor; wp->cursor->usecount++; wp->unmapcount = pwp->unmapcount + 1; wp->id = (int)hMenu; wp->gotPaintMsg = PAINT_PAINTED; titLen = 0; if (lpWindowName != NULL) titLen = strlen(lpWindowName); if (titLen < 64) titLen = 64; /* old mw compatibility */ wp->szTitle = (LPTSTR)malloc(titLen + 1); if (wp->szTitle == NULL) { free(wp); return NULL; } if (lpWindowName != NULL) strcpy(wp->szTitle, lpWindowName); else wp->szTitle[0] = '\0'; #if UPDATEREGIONS wp->update = GdAllocRegion(); #endif wp->nextrabytes = pClass->cbWndExtra; wp->hInstance = hInstance; wp->nEraseBkGnd = 1; wp->paintBrush = NULL; wp->paintPen = NULL; /* calculate client area*/ MwCalcClientRect(wp); cs.lpCreateParams = lpParam; cs.hInstance = hInstance; cs.hMenu = hMenu; cs.hwndParent = hwndParent; cs.cy = nHeight; cs.cx = nWidth; cs.y = y; cs.x = x; cs.style = dwStyle; cs.lpszName = lpWindowName; cs.lpszClass = lpClassName; cs.dwExStyle = dwExStyle; if(SendMessage(wp, WM_CREATE, 0, (LPARAM)(LPSTR)&cs) == -1) { MwDestroyWindow(wp, FALSE); return NULL; } /* send SIZE and MOVE msgs*/ MwSendSizeMove(wp, TRUE, TRUE); if(wp->style & WS_VISIBLE) { MwShowWindow(wp, TRUE); SetFocus(wp); } return wp; }