int main(int argc, char *argv[]) { srand (time(NULL)); // Analyse des arguments et chargement des API S_AIFunctions aiFunctions[2]; InitAIStruct(aiFunctions); E_GameMode gameMode = ParseArgs(argc, argv, aiFunctions); if (gameMode == ERROR) return EXIT_FAILURE; // Chargement de la fenetre SDL_Surface *window = NULL; SDL_Surface *icon = NULL; if (!InitWindow(&window, &icon)) return EXIT_FAILURE; // Affichage du menu DisplayMenu(window, gameMode, aiFunctions); // Liberation des ressources FreeWindow(icon); FreeAIStruct(aiFunctions); return EXIT_SUCCESS; }
void FreeWindowList() { int i; for (i = 0;i < MAXWINDOWS;i++) { FreeWindow(&WindowList[i]); } }
//////////////////////////////////////////////////////////////////////////////////////// /// // /// WindowMonitorThreadProc(LPVOID arg); // /// // //////////////////////////////////////////////////////////////////////////////////////// static DWORD WINAPI WindowMonitorThreadProc(LPVOID arg) { MSG msg ; _tsetlocale(LC_CTYPE, _T("")); MSG_DISPLAY_HOOK = RegisterWindowMessage(DISPLAY_HOOK_MSG); if (EnumWindows(EnumWindowsProc,NULL)==FALSE) { printf("Could not save all previously opened windows\n"); } HookHiddenWindow=AllocateWindow(NULL,WndProc); PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); if (HookHiddenWindow==NULL) { printf("Can't allocate window\n"); return(0); } if (HookDisplayFptr(HookHiddenWindow->WindowHandle)) { BOOL bRet; printf("Display Hooked\n"); fflush(stdout); SetEvent(ThreadReady); SetTimer(HookHiddenWindow->WindowHandle,0xBEEF,1000,(TIMERPROC) NULL); while (1) { bRet=GetMessage (&msg, NULL, 0, 0); if ((bRet != -1) && (bRet!=0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } else if ((bRet==0)&&(msg.wParam==0xDEADBEEF)) break; } KillTimer(HookHiddenWindow->WindowHandle,0xBEEF); if (UnhookDisplayFptr(HookHiddenWindow->WindowHandle)) { printf("Display Unhooked\n"); fflush(stdout); } FreeWindow(HookHiddenWindow); DeleteAllWindows(); } else SetEvent(ThreadReady); // FIX ME should use timeout return 0; }
/* * ResizeWindow - give a window a new size */ vi_rc ResizeWindow( window_id wid, windim x1, windim y1, windim x2, windim y2, bool scrflag ) { window *oldw; // int bt, k; // char *txt, *tptr; // char *ot; // int i, j; oldw = WINDOW_FROM_ID( wid ); AccessWindow( oldw ); if( !ValidDimension( x1, y1, x2, y2, oldw->has_border ) ) { ReleaseWindow( oldw ); return( ERR_WIND_INVALID ); } RestoreOverlap( wid, scrflag ); AllocWindow( wid, x1, y1, x2, y2, oldw->has_border, oldw->has_gadgets, true, oldw->border_color1, oldw->border_color2, oldw->text_color, oldw->background_color ); MarkOverlap( wid ); /* * display the new text */ ClearWindow( wid ); if( oldw->title != NULL ) { WindowTitle( wid, oldw->title ); } else { DrawBorder( wid ); } DCResize( CurrentInfo ); DCDisplayAllLines(); DCUpdate(); FreeWindow( oldw ); ReleaseWindow( WINDOW_FROM_ID( wid ) ); return( ERR_NO_ERR ); } /* ResizeWindow */
/* * ResizeWindow - give a window a new size */ vi_rc ResizeWindow( window_id wn, int x1, int y1, int x2, int y2, int scrflag ) { wind *tmp, *w; int bt, k; // char *txt, *tptr; // char *ot; // int i, j; w = AccessWindow( wn ); if( !ValidDimension( x1, y1, x2, y2, w->has_border ) ) { ReleaseWindow( w ); return( ERR_WIND_INVALID ); } tmp = AllocWindow( x1, y1, x2, y2, w->has_border, w->border_color1, w->border_color2, w->text_color, w->background_color ); tmp->id = wn; tmp->has_gadgets = w->has_gadgets; // txt = MemAlloc( w->width + 1 ); // tptr = txt; RestoreOverlap( wn, scrflag ); Windows[wn] = tmp; tmp->accessed = TRUE; ResetOverlap( tmp ); MarkOverlap( wn ); /* * display the new text */ k = 1; bt = (int) w->has_border; ClearWindow( wn ); if( w->title != NULL ) { WindowTitle( wn, w->title ); } else { DrawBorder( wn ); } #if 0 for( j = bt; j < w->height - bt; j++ ) { ot = &(w->text[(j * w->width) * sizeof( char_info )]); for( i = bt; i < w->width - bt; i++ ) { *txt++ = ot[i * sizeof( char_info )]; } *txt = 0; DisplayLineInWindow( wn, k++, tptr ); txt = tptr; } #else DCResize( CurrentInfo ); DCDisplayAllLines(); DCUpdate(); #endif FreeWindow( w ); ReleaseWindow( tmp ); return( ERR_NO_ERR ); } /* ResizeWindow */
BOOL WINAPI DestroyWindow(HWND hWnd) { HWND32 hWnd32, hWndSib32; HWND hWndSibling, hWndAncestor, hWndFocus, hWndTmp, hWndOwner; DWORD dwStyle; int parent_with_focus; if (!(hWnd32 = CHECKHWND32(hWnd))) { return FALSE; } #ifdef LATER Send WM_CANCELMODE, if caption is active Call RealizeDefaultPalette Send WM_PALETTECHANGED to all windows #endif if ((hWnd32->dwStyle & WS_CHILD) && !(hWnd32->dwExStyle & WS_EX_NOPARENTNOTIFY)) { hWndAncestor = hWnd; do { hWndAncestor = GetParent(hWndAncestor); dwStyle = GetWindowStyle(hWndAncestor); SendMessage(hWndAncestor,WM_PARENTNOTIFY, GET_WM_PARENTNOTIFY_MPS(WM_DESTROY,hWnd32->wChildID,hWnd)); } while (dwStyle & WS_CHILD); } if (!IsWindow(hWnd)) return TRUE; if (hWnd32->dwStyle & WS_VISIBLE) { if (hWnd32->dwStyle & WS_CHILD) ShowWindow(hWnd, SW_HIDE); else /* top-level */ SetWindowPos(hWnd,0,0,0,0,0, SWP_HIDEWINDOW|SWP_NOACTIVATE| SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE); } if (!IsWindow(hWnd)) return TRUE; if (hWnd32->hWndIconTitle) DestroyWindow(hWnd32->hWndIconTitle); if (!(hWnd32->dwStyle & WS_CHILD)) { hWndSibling = GetWindow(hWnd, GW_HWNDFIRST); while (hWndSibling) { /* save the next sibling before this one is destroyed */ hWndSib32 = GETHWND32(hWndSibling); hWndTmp = hWndSib32->hWndSibling; hWndOwner = hWndSib32->hWndOwner; RELEASEWININFO(hWndSib32); if (hWndOwner == hWnd) DestroyWindow(hWndSibling); if (hWndTmp && !IsWindow(hWndTmp)) /* start all over */ hWndSibling = GetWindow(hWnd, GW_HWNDFIRST); else hWndSibling = hWndTmp; } } /* if focus is held by this window or one of it's descendants, revert to the parent */ parent_with_focus= 0; if ((hWndFocus = GetFocus())) if (hWndFocus == hWnd || IsChild(hWnd,hWndFocus)) if(IsWindow(hWnd)) { parent_with_focus= GetParent(hWnd); SetFocus(parent_with_focus); } /* if we are destroying the frame that has the cursor, reset the cursor ownership */ if (!(hWnd32->dwStyle & WS_CHILD)) { if (Get32WindowFrame(hWnd32) == TWIN_GetCursorWindow()) { TWIN_SetCursorWindow((HWND)0); if (parent_with_focus) { int n; POINT FAR lppt; GetCursorPos(&lppt); n=SendMessage(parent_with_focus, WM_NCHITTEST,(WPARAM)0, MAKELPARAM(lppt.x,lppt.y)); SendMessage(parent_with_focus, WM_SETCURSOR, (WPARAM)parent_with_focus, n); } } } SendDestroyMessages(hWnd); RemoveFromList(hWnd32); RELEASEWININFO(hWnd32); FreeWindow(hWnd); return TRUE; }
static void FreeWindow(HWND hWnd) { HWND hWndFree,hWndFreeNext; HWND32 hWnd32; DWORD dwClassStyle; if (!(hWnd32 = GETHWND32(hWnd))) return; hWndFree = hWnd32->hWndChild; while (hWndFree) { hWndFreeNext = GetWindow(hWndFree,GW_HWNDNEXTSIB); FreeWindow(hWndFree); hWndFree = hWndFreeNext; } if (hWnd == GetActiveWindow()) { if (hWnd32->hWndOwner) SetActiveWindow(hWnd32->hWndOwner); else SetActiveWindow(TWIN_FindAnotherOverlapped(hWnd)); } if (hWnd == GetFocus()) SetFocus(0); if (hWnd == GetCapture()) ReleaseCapture(); if (!(hWnd32->dwStyle & WS_CHILD)) if (hWnd32->hMenu) { if (IsMenu(hWnd32->hMenu)) DestroyMenu(hWnd32->hMenu); } if (hWnd32->hSysMenu) { if (IsMenu(hWnd32->hSysMenu)) DestroyMenu(hWnd32->hSysMenu); } /* NOTE: this used to be after releasing OWN/CLASS DC, but */ /* at least one app does a GetDC(hWnd) during the NCDESTROY*/ /* so, don't release it until after. The GetDC code needs */ /* the DC to maintain the hardware DC, (read gc for X11) */ /* send the last message to this window */ SendMessage(hWnd,WM_NCDESTROY,0,0); /* get rid of DCs that may still be gotten */ dwClassStyle = GetClassStyle(hWnd); if ((dwClassStyle & CS_OWNDC) && hWnd32->hDC) TWIN_GdiDestroyDC(hWnd32->hDC); if (!(hWnd32->dwStyle & WS_CHILD)) /* physically destroy the window */ DRVCALL_WINDOWS(PWSH_DESTROYWINDOW,0L,0L, WIN_GETDRVDATA(Get32WindowFrame(hWnd32))); if (hWnd32->UpdateRegion) DRVCALL_REGIONS(PRH_DESTROYREGION,hWnd32->UpdateRegion,0,0); LockClass(hWnd32->hWindowClass32,FALSE); SendMessage(Get32WindowFrame(hWnd32),WM_NCDESTROY,0,0L); FREEHWND(Get32WindowFrame(hWnd32)); if (hWnd32->hWndHZScroll) { SendMessage(hWnd32->hWndHZScroll,WM_DESTROY,0,0L); FREEHWND(hWnd32->hWndHZScroll); } if (hWnd32->hWndVTScroll) { SendMessage(hWnd32->hWndVTScroll,WM_DESTROY,0,0L); FREEHWND(hWnd32->hWndVTScroll); } RELEASEWININFO(hWnd32); TWIN_FlushWindowMessages(hWnd); FREEHWND(hWnd); }