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; }
/* * Initialize the graphics and mouse devices at startup. * Returns nonzero with a message printed if the initialization failed. */ int MwInitialize(void) { HWND wp; /* root window */ PSD psd; WNDCLASS wc; int fd; static MWCURSOR arrow = { /* default arrow cursor*/ 16, 16, 0, 0, RGB(255, 255, 255), RGB(0, 0, 0), { 0xe000, 0x9800, 0x8600, 0x4180, 0x4060, 0x2018, 0x2004, 0x107c, 0x1020, 0x0910, 0x0988, 0x0544, 0x0522, 0x0211, 0x000a, 0x0004 }, { 0xe000, 0xf800, 0xfe00, 0x7f80, 0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc, 0x1fe0, 0x0ff0, 0x0ff8, 0x077c, 0x073e, 0x021f, 0x000e, 0x0004 } }; extern MWLISTHEAD mwClassHead; #if (UNIX | DOS_DJGPP) && !_MINIX for (fd = 0; fd < FD_SETSIZE; fd++) { userregfd[fd].read = NULL; userregfd[fd].write = NULL; userregfd[fd].except = NULL; userregfd[fd].next = -1; } userregfd_head = -1; #endif /* catch terminate signal to restore tty state*/ signal(SIGTERM, (void *)MwTerminate); startTicks = GetTickCount(); if ((keyb_fd = GdOpenKeyboard()) == -1) { EPRINTF("Cannot initialise keyboard\n"); return -1; } if ((psd = GdOpenScreen()) == NULL) { EPRINTF("Cannot initialise screen\n"); GdCloseKeyboard(); return -1; } if ((mouse_fd = GdOpenMouse()) == -1) { EPRINTF("Cannot initialise mouse\n"); GdCloseScreen(psd); GdCloseKeyboard(); return -1; } #if ANIMATEPALETTE setfadelevel(psd, 0); #endif /* * Initialize the root window. */ wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; wc.lpfnWndProc = (WNDPROC)DefWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/ wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/ wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND)); wc.lpszMenuName = NULL; wc.lpszClassName = "DeskTop"; RegisterClass( &wc); wp = GdItemNew(struct hwnd); if (!wp) { EPRINTF("No memory for root window\n"); GdCloseMouse(); GdCloseScreen(psd); GdCloseKeyboard(); return -1; } /* remove the WS_CAPTION to have bare desktop window*/ /*wp->style = WS_CLIPCHILDREN | WS_CAPTION | WS_VISIBLE;*/ wp->style = WS_CLIPCHILDREN | WS_VISIBLE; wp->exstyle = 0; wp->pClass = (PWNDCLASS)mwClassHead.head; wp->parent = NULL; wp->children = NULL; wp->siblings = NULL; wp->next = NULL; SetRect(&wp->winrect, 0, 0, psd->xvirtres, psd->yvirtres); MwCalcClientRect(wp); wp->cursor = NULL; wp->unmapcount = 0; wp->id = 0; strcpy(wp->szTitle, "Microwindows"); wp->gotPaintMsg = PAINT_PAINTED; #if UPDATEREGIONS wp->update = GdAllocRegion(); #endif listwp = wp; rootwp = wp; focuswp = wp; mousewp = wp; /* schedule desktop window paint*/ InvalidateRect(rootwp, NULL, TRUE); #if VTSWITCH MwInitVt(); /* Check for VT change every 50 ms: */ GdAddTimer(50, CheckVtChange, NULL); #endif /* * Initialize and position the default cursor. */ curcursor = NULL; cursorx = -1; cursory = -1; GdShowCursor(psd); MwMoveCursor(psd->xvirtres / 2, psd->yvirtres / 2); MwSetCursor(rootwp, &arrow); /* * Finally tell the mouse driver some things. */ GdRestrictMouse(0, 0, psd->xvirtres - 1, psd->yvirtres - 1); GdMoveMouse(psd->xvirtres / 2, psd->yvirtres / 2); return 0; }
BOOL SetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags) { int hidden; BOOL bMove, bSize, bZorder; MWCOORD offx = 0, offy = 0; /* = 0 for bad gcc warning*/ WINDOWPOS winpos; if(!hwnd || hwnd == rootwp || cx < 0 || cy < 0) return FALSE; /* FIXME SWP_NOACTIVATE*/ if((fuFlags & SWP_SHOWWINDOW)) return ShowWindow(hwnd, SW_SHOW); if((fuFlags & SWP_HIDEWINDOW)) return ShowWindow(hwnd, SW_HIDE); /* move is relative to parent's client rect for child windows*/ if(hwnd->style & WS_CHILD) { x += hwnd->parent->clirect.left; y += hwnd->parent->clirect.top; } else { x += hwnd->parent->winrect.left; y += hwnd->parent->winrect.top; } bMove = !(fuFlags & SWP_NOMOVE) && (hwnd->winrect.left != x || hwnd->winrect.top != y); bSize = !(fuFlags & SWP_NOSIZE) && ((hwnd->winrect.right - hwnd->winrect.left) != cx || (hwnd->winrect.bottom - hwnd->winrect.top) != cy); bZorder = !(fuFlags & SWP_NOZORDER); if(!bMove && !bSize && !bZorder) return TRUE; /* could optimize to not require redraw when possible*/ hidden = hwnd->unmapcount || (fuFlags & SWP_NOREDRAW); if(bZorder) { switch((int)hwndInsertAfter) { case (int)HWND_TOP: MwRaiseWindow(hwnd); break; case (int)HWND_BOTTOM: MwLowerWindow(hwnd); break; default: /* FIXME for non top/bottom zorder*/ break; } } else { if(!hidden) MwHideWindow(hwnd, FALSE, FALSE); } if(bMove) { offx = x - hwnd->winrect.left; offy = y - hwnd->winrect.top; } if(bMove || bSize) { hwnd->winrect.left = x; hwnd->winrect.top = y; hwnd->winrect.right = x + cx; hwnd->winrect.bottom = y + cy; } if(bMove) MwOffsetChildren(hwnd, offx, offy); if(bMove || bSize) { MwCalcClientRect(hwnd); /* send windowposchanged message*/ /* FIXME: move WM_MOVE, WM_SIZE to defwndproc*/ winpos.hwnd = hwnd; winpos.hwndInsertAfter = hwndInsertAfter; winpos.x = x; winpos.y = y; winpos.cx = cx; winpos.cy = cy; winpos.flags = fuFlags; SendMessage(hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos); MwSendSizeMove(hwnd, bSize, bMove); } ++mwpaintSerial; /* increment paint serial # for alphablending*/ ++mwpaintNC; /* increment paint serial # for NC painting*/ hwnd->nEraseBkGnd++; if(!bZorder && !hidden) MwShowWindow(hwnd, FALSE); return TRUE; }