LRESULT ForcesWindow::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch ( msg ) { case WM_SHOWWINDOW: if ( wParam == TRUE ) { RefreshWindow(); chkd.mapSettingsWindow.SetTitle("Map Settings"); } else { for ( int i=0; i<4; i++ ) CheckReplaceForceName(i); } break; default: { if ( WM_DRAGNOTIFY != WM_NULL && msg == WM_DRAGNOTIFY ) { DRAGLISTINFO* dragInfo = (DRAGLISTINFO*)lParam; switch ( dragInfo->uNotification ) { case DL_BEGINDRAG: { int index = LBItemFromPt(dragInfo->hWnd, dragInfo->ptCursor, FALSE); LRESULT length = SendMessage(dragInfo->hWnd, LB_GETTEXTLEN, index, 0)+1; char* str; try { str = new char[length]; } catch ( std::bad_alloc ) { return FALSE; } length = SendMessage(dragInfo->hWnd, LB_GETTEXT, index, (LPARAM)str); if ( length != LB_ERR && length > 8 && str[7] >= '1' && str[7] <= '8' ) { playerBeingDragged = str[7]-'1'; for ( int id=LB_F1PLAYERS; id<=LB_F4PLAYERS; id++ ) { HWND hForceLb = GetDlgItem(hWnd, id); if ( hForceLb != dragInfo->hWnd && hForceLb != NULL ) SendMessage(GetDlgItem(hWnd, id), LB_SETCURSEL, -1, 0); } return TRUE; } else return FALSE; } break; case DL_CANCELDRAG: playerBeingDragged = 255; return ClassWindow::WndProc(hWnd, msg, wParam, lParam); break; case DL_DRAGGING: { HWND hUnder = WindowFromPoint(dragInfo->ptCursor); if ( hUnder != NULL ) { LONG windowID = GetWindowLong(hUnder, GWL_ID); if ( windowID >= LB_F1PLAYERS && windowID <= LB_F4PLAYERS ) return DL_MOVECURSOR; } return DL_STOPCURSOR; } break; case DL_DROPPED: { HWND hUnder = WindowFromPoint(dragInfo->ptCursor); if ( hUnder != NULL && playerBeingDragged < 8 ) { LONG windowID = GetWindowLong(hUnder, GWL_ID); if ( windowID >= LB_F1PLAYERS && windowID <= LB_F4PLAYERS ) { int force = windowID-LB_F1PLAYERS; GuiMapPtr map = chkd.maps.curr; if ( map != nullptr ) { map->setPlayerForce(playerBeingDragged, force); RefreshWindow(); std::stringstream ssPlayer; ssPlayer << "Player " << playerBeingDragged+1; SendMessage(GetDlgItem(hWnd, LB_F1PLAYERS+force), LB_SELECTSTRING, -1, (LPARAM)ssPlayer.str().c_str()); map->notifyChange(false); chkd.trigEditorWindow.RefreshWindow(); SetFocus(getHandle()); } } } playerBeingDragged = 255; return ClassWindow::WndProc(hWnd, msg, wParam, lParam); } break; default: return ClassWindow::WndProc(hWnd, msg, wParam, lParam); break; } } else return ClassWindow::WndProc(hWnd, msg, wParam, lParam); } break; } return 0; }
LRESULT CALLBACK ArchiveFileChooser(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r, r2; int dx1, dy1, dx2, dy2; static std::map<int,int> s_listToItemsMap; switch(uMsg) { case WM_INITDIALOG: { //Clear_Sound_Buffer(); //if(Full_Screen) //{ // while (ShowCursor(false) >= 0); // while (ShowCursor(true) < 0); //} for(int i = 0; i < numControlLayoutInfos; i++) s_layoutState[i].valid = false; GetWindowRect(AfxGetApp()->m_pMainWnd->GetSafeHwnd(), &r); dx1 = (r.right - r.left) / 2; dy1 = (r.bottom - r.top) / 2; GetWindowRect(hDlg, &r2); dx2 = (r2.right - r2.left) / 2; dy2 = (r2.bottom - r2.top) / 2; //SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); ArchiveFileChooserInfo& info = *(ArchiveFileChooserInfo*)lParam; std::vector<ArchiveFileChooserInfo::FileInfo>& files = info.files; ArchiveFile& archive = info.archive; std::string title = "Choose File in "; title += archive.GetArchiveTypeName(); title += " Archive"; SetWindowText(hDlg, title.c_str()); // populate list for(size_t i = 0; i < files.size(); i++) { int listIndex = SendDlgItemMessage(hDlg, IDC_LIST1, LB_ADDSTRING, (WPARAM) 0, (LONG) (LPTSTR) files[i].name.c_str()); s_listToItemsMap[listIndex] = files[i].itemIndex; } SendDlgItemMessage(hDlg, IDC_LIST1, LB_SETCURSEL, (WPARAM) 0, (LPARAM) 0); { RECT r3; GetClientRect(hDlg, &r3); s_windowWidth = r3.right - r3.left; s_windowHeight = r3.bottom - r3.top; } return true; } break; case WM_SIZING: { // enforce a minimum window size LPRECT r = (LPRECT) lParam; int minimumWidth = 281; int minimumHeight = 117; if(r->right - r->left < minimumWidth) if(wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT) r->left = r->right - minimumWidth; else r->right = r->left + minimumWidth; if(r->bottom - r->top < minimumHeight) if(wParam == WMSZ_TOP || wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOPRIGHT) r->top = r->bottom - minimumHeight; else r->bottom = r->top + minimumHeight; return TRUE; } case WM_SIZE: { // resize or move controls in the window as necessary when the window is resized int prevDlgWidth = s_windowWidth; int prevDlgHeight = s_windowHeight; int dlgWidth = LOWORD(lParam); int dlgHeight = HIWORD(lParam); int deltaWidth = dlgWidth - prevDlgWidth; int deltaHeight = dlgHeight - prevDlgHeight; for(int i = 0; i < numControlLayoutInfos; i++) { ControlLayoutInfo layoutInfo = controlLayoutInfos[i]; ControlLayoutState& layoutState = s_layoutState[i]; HWND hCtrl = GetDlgItem(hDlg,layoutInfo.controlID); int x,y,width,height; if(layoutState.valid) { x = layoutState.x; y = layoutState.y; width = layoutState.width; height = layoutState.height; } else { RECT r; GetWindowRect(hCtrl, &r); POINT p = {r.left, r.top}; ScreenToClient(hDlg, &p); x = p.x; y = p.y; width = r.right - r.left; height = r.bottom - r.top; } switch(layoutInfo.horizontalLayout) { case ControlLayoutInfo::RESIZE_END: width += deltaWidth; break; case ControlLayoutInfo::MOVE_START: x += deltaWidth; break; default: break; } switch(layoutInfo.verticalLayout) { case ControlLayoutInfo::RESIZE_END: height += deltaHeight; break; case ControlLayoutInfo::MOVE_START: y += deltaHeight; break; default: break; } SetWindowPos(hCtrl, 0, x,y, width,height, 0); layoutState.x = x; layoutState.y = y; layoutState.width = width; layoutState.height = height; layoutState.valid = true; } s_windowWidth = dlgWidth; s_windowHeight = dlgHeight; RedrawWindow(hDlg, NULL, NULL, RDW_INVALIDATE); } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_LIST1: if(HIWORD(wParam) == LBN_DBLCLK) { POINT pos; GetCursorPos(&pos); int clickedItem = LBItemFromPt(GetDlgItem(hDlg, IDC_LIST1), pos, FALSE); if(clickedItem != -1) { SendMessage(hDlg, WM_COMMAND, IDOK, 0); } } return TRUE; case IDOK: { int listIndex = SendDlgItemMessage(hDlg, IDC_LIST1, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); s_archiveFileChooserResult = s_listToItemsMap[listIndex]; s_listToItemsMap.clear(); //if(Full_Screen) //{ // while (ShowCursor(true) < 0); // while (ShowCursor(false) >= 0); //} EndDialog(hDlg, false); } return TRUE; case ID_CANCEL: case IDCANCEL: s_archiveFileChooserResult = -1; s_listToItemsMap.clear(); //if(Full_Screen) //{ // while (ShowCursor(true) < 0); // while (ShowCursor(false) >= 0); //} EndDialog(hDlg, false); return TRUE; } case WM_CLOSE: s_archiveFileChooserResult = -1; s_listToItemsMap.clear(); //if(Full_Screen) //{ // while (ShowCursor(true) < 0); // while (ShowCursor(false) >= 0); //} EndDialog(hDlg, false); return TRUE; } return false; }
BOOL plResponderProc::DragListProc(HWND hWnd, DRAGLISTINFO *info) { static int oldIdx = -1; int curIdx = LBItemFromPt(info->hWnd, info->ptCursor, TRUE); switch (info->uNotification) { // Allow the drag case DL_BEGINDRAG: // When you click on an item in the listbox, the rollups are changed and Max can // shift the position of dialog you were just clicking in. Since this happens // before you let go of the mouse button, the listbox thinks you are dragging. // To get around it, we don't allow a selection change and a drag in the same click. if (fIgnoreNextDrop) { SetWindowLong(hWnd, DWL_MSGRESULT, FALSE); } else { oldIdx = curIdx; SetWindowLong(hWnd, DWL_MSGRESULT, TRUE); } return TRUE; case DL_DRAGGING: { if (curIdx < oldIdx) DrawInsert(hWnd, info->hWnd, curIdx); else if (curIdx > oldIdx && ListBox_GetCount(info->hWnd) > curIdx+1) DrawInsert(hWnd, info->hWnd, curIdx+1); else DrawInsert(hWnd, info->hWnd, -1); } return TRUE; case DL_CANCELDRAG: // Clear drag arrow DrawInsert(hWnd, info->hWnd, -1); return TRUE; case DL_DROPPED: { if (fIgnoreNextDrop) { fIgnoreNextDrop = false; return TRUE; } // Clear drag arrow DrawInsert(hWnd, info->hWnd, -1); if (curIdx != -1 && oldIdx != -1 && curIdx != oldIdx) { // Make sure this won't mess up any wait commands, or at least // that the user approves if it does. if (!ResponderWait::ValidateCmdMove(fStatePB, oldIdx, curIdx)) return TRUE; MoveCommand(oldIdx, curIdx); } return TRUE; } } return FALSE; }