/* free a DC allocated from GetDC*/ int WINAPI ReleaseDC(HWND hwnd, HDC hdc) { /* don't delete a memory dc on release*/ if(!hdc || (hdc->psd->flags&PSF_MEMORY)) return 0; if(hdc == cliphdc) cliphdc = NULL; /* handle private DC's*/ if(hdc->hwnd->owndc && !(hdc->flags & DCX_WINDOW)) return 1; DeleteObject((HBRUSH)hdc->brush); DeleteObject((HPEN)hdc->pen); #if 0 /* don't delete font resources on ReleaseDC... use DeleteObject instead*/ DeleteObject((HFONT)hdc->font); #endif DeleteObject((HRGN)hdc->region); /* * We can only select a bitmap in a memory DC, * so bitmaps aren't released except through DeleteDC. */ DeleteObject((HBITMAP)hdc->bitmap); GdItemFree(hdc); return 1; }
BOOL UnregisterHotKey(HWND hWnd, int id) { MWHOTKEY *pHotkey = MwFindHotkey(id); if (!pHotkey) return FALSE; GdListRemove(&mwHotkeyHead, &pHotkey->link); GdItemFree(pHotkey); return TRUE; }
BOOL WINAPI DeleteObject(HGDIOBJ hObject) { if(!hObject || hObject->hdr.stockobj) return FALSE; if(hObject->hdr.type == OBJ_FONT) GdDestroyFont(((MWFONTOBJ *)hObject)->pfont); if(hObject->hdr.type == OBJ_REGION) GdDestroyRegion(((MWRGNOBJ *)hObject)->rgn); GdItemFree(hObject); return TRUE; }
BOOL WINAPI UnregisterClass(LPCSTR lpClassName, HINSTANCE hInstance) { PWNDCLASS pClass; pClass = MwFindClassByName(lpClassName); if(!pClass) return FALSE; GdListRemove(&mwClassHead, &pClass->link); DeleteObject(pClass->hbrBackground); GdItemFree(pClass); return TRUE; }
/* * Create a new empty region. */ static HRGN REGION_CreateRegion(void) { MWRGNOBJ *obj; obj = GdItemNew(MWRGNOBJ); if(!obj) return NULL; obj->hdr.type = OBJ_REGION; obj->hdr.stockobj = FALSE; if(!(obj->rgn = GdAllocRegion())) { GdItemFree(obj); return NULL; } return (HRGN)obj; }
static BOOL MwRemoveWndFromHotkeys (HWND hWnd) { PMWLIST p, pNext; MWHOTKEY *pHotkey; BOOL bRet = FALSE; for (p=mwHotkeyHead.head; p; p=pNext) { pNext = p->next; pHotkey = GdItemAddr (p, MWHOTKEY, link); if (pHotkey->hWnd == hWnd) { GdListRemove(&mwHotkeyHead, &pHotkey->link); GdItemFree(pHotkey); bRet = TRUE; } } return bRet; }
/** * Destroy an image. * * @param id Image to free. */ void GdFreeImage(int id) { PIMAGEITEM pItem; PMWIMAGEHDR pimage; pItem = findimage(id); if (pItem) { GdListRemove(&imagehead, &pItem->link); pimage = pItem->pimage; /* delete image bits*/ if(pimage->imagebits) free(pimage->imagebits); if(pimage->palette) free(pimage->palette); free(pimage); GdItemFree(pItem); } }
BOOL WINAPI PeekMessage(LPMSG lpMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, UINT wRemoveMsg) { HWND wp; PMSG pNxtMsg; /* check if no messages in queue*/ if(mwMsgHead.head == NULL) { #if PAINTONCE /* check all windows for pending paint messages*/ for(wp=listwp; wp; wp=wp->next) { if(!(wp->style & WS_CHILD)) { if(chkPaintMsg(wp, lpMsg)) return TRUE; } } for(wp=listwp; wp; wp=wp->next) { if(wp->style & WS_CHILD) { if(chkPaintMsg(wp, lpMsg)) return TRUE; } } #endif MwSelect(FALSE); } if(mwMsgHead.head == NULL) return FALSE; pNxtMsg = (PMSG)mwMsgHead.head; if(wRemoveMsg & PM_REMOVE) GdListRemove(&mwMsgHead, &pNxtMsg->link); *lpMsg = *pNxtMsg; if(wRemoveMsg & PM_REMOVE) GdItemFree(pNxtMsg); return TRUE; }
HANDLE WINAPI RemoveProp(HWND hWnd, LPCSTR lpString) { ATOM Atom; PMWLIST p; MWPROP *pProp; HANDLE hRet; if (HIWORD(lpString)) Atom = GlobalFindAtom(lpString); else Atom = LOWORD((DWORD)lpString); for(p=hWnd->props.head; p; p=p->next) { pProp = GdItemAddr(p, MWPROP, link); if (pProp->Atom == Atom) { hRet = pProp->hData; GdListRemove(&hWnd->props, &pProp->link); GdItemFree(pProp); return hRet; } } return NULL; }
/* * Destroy the specified window, and all of its children. * This is a recursive routine. */ void MwDestroyWindow(HWND hwnd,BOOL bSendMsg) { HWND wp = hwnd; HWND prevwp; PMWLIST p; PMSG pmsg; if (wp == rootwp || !IsWindow (hwnd)) return; /* * Unmap the window. */ if (wp->unmapcount == 0) MwHideWindow(wp, FALSE, FALSE); if(bSendMsg) SendMessage(hwnd, WM_DESTROY, 0, 0L); /* * Remove from timers */ MwRemoveWndFromTimers(hwnd); /* * Remove hotkeys */ MwRemoveWndFromHotkeys(hwnd); /* * Disable all sendmessages to this window. */ wp->lpfnWndProc = NULL; /* * Destroy all children, sending WM_DESTROY messages. */ while (wp->children) MwDestroyWindow(wp->children, bSendMsg); wp->pClass = NULL; /* * Free any cursor associated with the window. */ if (wp->cursor->usecount-- == 1) { free(wp->cursor); wp->cursor = NULL; } /* * Remove this window from the child list of its parent. */ prevwp = wp->parent->children; if (prevwp == wp) wp->parent->children = wp->siblings; else { while (prevwp && prevwp->siblings != wp) prevwp = prevwp->siblings; if (prevwp) prevwp->siblings = wp->siblings; } wp->siblings = NULL; /* * Remove this window from the complete list of windows. */ prevwp = listwp; if (prevwp == wp) listwp = wp->next; else { while (prevwp->next && prevwp->next != wp) prevwp = prevwp->next; prevwp->next = wp->next; } wp->next = NULL; /* * Forget various information related to this window. * Then finally free the structure. */ /* Remove all messages from msg queue for this window*/ for(p=mwMsgHead.head; p; ) { pmsg = GdItemAddr(p, MSG, link); if(pmsg->hwnd == wp) { p = p->next; GdListRemove(&mwMsgHead, &pmsg->link); GdItemFree(pmsg); } else p = p->next; } /* * Remove all properties from this window. */ for(p=hwnd->props.head; p; ) { MWPROP *pProp = GdItemAddr(p, MWPROP, link); p = p->next; GdListRemove (&hwnd->props, &pProp->link); GdItemFree (pProp); } /* FIXME: destroy hdc's relating to window?*/ if (wp == capturewp) { capturewp = NULL; MwCheckMouseWindow(); } if (wp == MwGetTopWindow(focuswp)) SetFocus(rootwp->children? rootwp->children: rootwp); /* destroy private DC*/ if(wp->owndc) { HDC hdc = wp->owndc; wp->owndc = NULL; /* force destroy with ReleaseDC*/ ReleaseDC(wp, hdc); } if (wp->szTitle) { free(wp->szTitle); wp->szTitle = NULL; } #if UPDATEREGIONS if (wp->update) { GdDestroyRegion(wp->update); wp->update = NULL; } #endif GdItemFree(wp); }