VOID GridLayout::PlaceWindow(HWND hwnd, INT rowStart, INT colStart, INT rowSpan, INT colSpan, INT border, DWORD alignment) { RECT rect; GetRect(&rect, rowStart, colStart, rowSpan, colSpan, border); INT cy = rect.bottom - rect.top; INT cx = rect.right - rect.left; // early out if the control is supposed to be resized to fit the rect if (alignment == ALIGN_FILLRECT) { MoveWindow(hwnd, rect.left, rect.top, cx, cy, true); return; } INT px = rect.left, py = rect.top; // get current size of window RECT currentRect; GetWindowRect(hwnd, ¤tRect); INT sizeX = currentRect.right - currentRect.left; INT sizeY = currentRect.bottom - currentRect.top; INT newSizeX = sizeX; INT newSizeY = sizeY; // figure out horizontal placement if (alignment & ALIGN_HCENTER) { px = rect.left + (cx / 2) - (sizeX / 2); } else if (alignment & ALIGN_LEFT) { px = rect.left; } else if (alignment & ALIGN_RIGHT) { px = rect.right - sizeX; } else if (alignment & ALIGN_HJUSTIFY) { px = rect.left; newSizeX = cx; } // figure out vertical placement if (alignment & ALIGN_VCENTER) { py = rect.top + (cy / 2) - (sizeY / 2); } else if (alignment & ALIGN_TOP) { py = rect.top; } else if (alignment & ALIGN_BOTTOM) { py = rect.bottom - sizeY; } else if (alignment & ALIGN_VJUSTIFY) { py = rect.top; newSizeY = cy; } // move window INTo place if (newSizeX == sizeX && newSizeY == sizeY) SetWindowPos(hwnd, NULL, px, py, 0, 0, SWP_NOZORDER|SWP_NOSIZE); else SetWindowPos(hwnd, NULL, px, py, newSizeX, newSizeY, SWP_NOZORDER); }
/** * @brief Center window according to the desktop or another window. * @param hwnd - window handle to center. * @param hwndCenter - relative window handle or zero for desktop. */ void CenterWindow(HWND hwnd, HWND hwndCenter) { // Determine owner window to center against. DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); if (hwndCenter == NULL) { if(dwStyle & WS_CHILD) hwndCenter = GetParent(hwnd); else hwndCenter = GetWindow(hwnd, GW_OWNER); } // Get coordinates of the window relative to its parent. RECT rcDlg; GetWindowRect(hwnd, &rcDlg); RECT rcArea; RECT rcCenter; HWND hwndParent; if ((dwStyle & WS_CHILD) == 0) { // Don't center against invisible or minimized windows. if (hwndCenter != NULL) { DWORD dwStyleCenter = GetWindowLong(hwndCenter, GWL_STYLE); if (! (dwStyleCenter & WS_VISIBLE) || (dwStyleCenter & WS_MINIMIZE)) hwndCenter = NULL; } // Center within screen coordinates. SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL); if(hwndCenter == NULL) rcCenter = rcArea; else GetWindowRect(hwndCenter, &rcCenter); } else { // Center within parent client coordinates. hwndParent = GetParent(hwnd); GetClientRect(hwndParent, &rcArea); GetClientRect(hwndCenter, &rcCenter); MapWindowPoints(hwndCenter, hwndParent, (POINT*)&rcCenter, 2); } int nDlgWidth = rcDlg.right - rcDlg.left; int nDlgHeight = rcDlg.bottom - rcDlg.top; // Find dialog's upper left based on rcCenter. int xLeft = (rcCenter.left + rcCenter.right) / 2 - nDlgWidth / 2; int yTop = (rcCenter.top + rcCenter.bottom) / 2 - nDlgHeight / 2; // If the dialog is outside the screen, move it inside. if (xLeft < rcArea.left) xLeft = rcArea.left; else if (xLeft + nDlgWidth > rcArea.right) xLeft = rcArea.right - nDlgWidth; if (yTop < rcArea.top) yTop = rcArea.top; else if (yTop + nDlgHeight > rcArea.bottom) yTop = rcArea.bottom - nDlgHeight; // Map screen coordinates to child coordinates. SetWindowPos(hwnd, NULL, xLeft, yTop, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); }
void FASTCALL MakeEditSelectionVisible( HWND hwndTopWnd, HWND hwndEdit ) { #ifdef USEBIGEDIT RECT rcTopWnd; RECT rcEdit; RECT rcEditNC; RECT rcOverlap; RECT rcSelOverlap; RECT rcSel; int nSelStartOffset; int nSelEndOffset; int nEditLineHeight; BEC_SELECTION bsel; HEDIT hedit; TEXTMETRIC tm; HFONT hwndEditFont; HFONT hOldFont; int nDist; HDC hdc; /* First of all, compute the overlap. If no overlap, then * we don't have to do anything further. */ GetWindowRect( hwndTopWnd, &rcTopWnd ); GetWindowRect( hwndEdit, &rcEdit ); if( IntersectRect( &rcOverlap, &rcTopWnd, &rcEdit ) == 0 ) return; /* Compute the screen coordinates of the edit selection (!) * Only bother with the top and bottom edges. */ hedit = Editmap_Open( hwndEdit ); Editmap_GetSelection( hedit, hwndEdit, &bsel ); nSelStartOffset = (int)( Editmap_LineFromChar( hedit, hwndEdit, bsel.lo ) - Editmap_GetFirstVisibleLine( hedit, hwndEdit ) ); nSelEndOffset = (int)( Editmap_LineFromChar( hedit, hwndEdit, bsel.lo ) - Editmap_GetFirstVisibleLine( hedit, hwndEdit ) ); hwndEditFont = GetWindowFont( hwndEdit ); hdc = GetDC( hwndEdit ); hOldFont = SelectFont( hdc, hwndEditFont ); GetTextMetrics( hdc, &tm ); SelectFont( hdc, hOldFont ); ReleaseDC( hwndEdit, hdc ); nEditLineHeight = tm.tmHeight; SetRect( &rcSel, 0, nSelStartOffset * nEditLineHeight, rcEdit.right - rcEdit.left, ( nSelEndOffset + 1 ) * nEditLineHeight ); Editmap_GetRect( hedit, hwndEdit, &rcEditNC ); ClientToScreen( hwndEdit, (LPPOINT)&rcSel ); ClientToScreen( hwndEdit, (LPPOINT)(&rcSel) + 1 ); rcSel.top += rcEditNC.top; rcSel.bottom += rcEditNC.top; /* Does the selection rectangle intesect the overlap? * If so, scroll the edit control down by the distance between the selection top edge * and the top window bottom edge. */ if( IntersectRect( &rcSelOverlap, &rcOverlap, &rcSel ) == 0 ) return; if( rcEdit.bottom > rcTopWnd.bottom ) nDist = -( ( ( rcTopWnd.bottom - rcSel.top ) / nEditLineHeight ) + 1 ); else nDist = ( ( rcSel.bottom - rcTopWnd.top ) / nEditLineHeight ) + 1; if( (long)Editmap_GetFirstVisibleLine( hedit, hwndEdit ) + nDist >= 0 ) { Editmap_Scroll( hedit, hwndEdit, nDist, 0 ); return; } /* Okay. We can't scroll the edit control because the top window is completely * overlapping the edit control, or the scroll would go past the first line. So * try and move the top window. */ if( rcEdit.bottom > rcTopWnd.bottom ) nDist = rcTopWnd.top - ( rcSel.bottom + ( 2 * nEditLineHeight ) ); else nDist = ( rcTopWnd.top - rcSel.bottom ) + 1; if( rcTopWnd.top - nDist < 0 ) nDist = rcTopWnd.top - rcSel.bottom; else if( rcTopWnd.bottom - nDist > GetSystemMetrics( SM_CYSCREEN ) ) nDist = rcTopWnd.bottom - rcSel.top; SetWindowPos( hwndTopWnd, NULL, rcTopWnd.left, rcTopWnd.top - nDist, 0, 0, SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER ); #else USEBIGEDIT HEDIT hedit; BEC_SELECTION bsel; SELRANGE lLine, lCurLine; hedit = Editmap_Open( hwndEdit ); Editmap_GetSelection( hedit, hwndEdit, &bsel ); lLine = Editmap_LineFromChar( hedit, hwndEdit, bsel.hi ); lCurLine = Editmap_GetFirstVisibleLine( hedit, hwndEdit ); if( lCurLine >= lLine ) { SendMessage( hwndEdit, SCI_GOTOPOS, bsel.hi, 0); Editmap_SetSel( hedit, hwndEdit, &bsel ); // Editmap_Scroll( hedit, hwndEdit, lLine, 0 ); return; } SendMessage( hwndEdit, SCI_MOVECARETINSIDEVIEW, 0, 0); #endif USEBIGEDIT }
LRESULT CCustomizeDialog::OnInitDialog( WPARAM /*wParam*/, LPARAM /*lParam*/ ) { CRect rcClient; GetClientRect( rcClient ); CRect rcWindow; GetWindowRect( rcWindow ); // create the windows // sizes are hardcoded //ugly way CRect rc; CFont *pFont =GetFont(); ASSERT_VALID(pFont); //static wnd rc=CRect(4,2,49,8); MapDialogRect(m_hWnd,&rc); rc.left+=rcClient.left; rc.top+=rcClient.bottom; VERIFY(m_wndTextOptionsText.Create(_T("Te&xt options:"),WS_CHILD|WS_VISIBLE,rc,this)); m_wndTextOptionsText.SetFont(pFont); m_wndTextOptionsText.SetWindowPos(NULL,rc.left,rc.top,rc.right,rc.bottom,SWP_NOZORDER|SWP_NOACTIVATE); //Text options rc=CRect(52,0,123,50); MapDialogRect(m_hWnd,&rc); rc.left+=rcClient.left; rc.top+=rcClient.bottom; VERIFY(m_wndTextOptions.Create(WS_CHILD |WS_VISIBLE |CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP,rc,this, IDC_CB_TEXTOPTIONS)); m_wndTextOptions.SetFont(pFont); m_wndTextOptions.AddString(_T("Show Text Labels")); m_wndTextOptions.AddString(_T("Selective Text on Right")); m_wndTextOptions.AddString(_T("No Text Labels")); SetTextOptions(m_eTextOptions); m_wndTextOptions.SetWindowPos(NULL,rc.left,rc.top,rc.right,rc.bottom,SWP_NOZORDER|SWP_NOACTIVATE); //static wnd rc=CRect(4,20,49,8); MapDialogRect(m_hWnd,&rc); rc.left+=rcClient.left; rc.top+=rcClient.bottom; VERIFY(m_wndIconOptionsText.Create(_T("Ico&n options:"),WS_CHILD|WS_VISIBLE,rc,this)); m_wndIconOptionsText.SetFont(pFont); m_wndIconOptionsText.SetWindowPos(NULL,rc.left,rc.top,rc.right,rc.bottom,SWP_NOZORDER|SWP_NOACTIVATE); //icon combo rc=CRect(52,18,123,50); MapDialogRect(m_hWnd,&rc); rc.left+=rcClient.left; rc.top+=rcClient.bottom; VERIFY(m_wndIconOptions.Create(WS_CHILD |WS_VISIBLE |CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP,rc,this, IDC_CB_ICONOPTIONS)); m_wndIconOptions.SetFont(pFont); m_wndIconOptions.AddString(_T("Small Icons")); m_wndIconOptions.AddString(_T("Large Icons")); SetIconOptions(m_eIconOptions); m_wndIconOptions.SetWindowPos(NULL,rc.left,rc.top,rc.right,rc.bottom,SWP_NOZORDER|SWP_NOACTIVATE); // final rect rc=CRect(0,0,179,34); MapDialogRect(m_hWnd,&rc); rc.left+=rcClient.left; rc.top+=rcClient.bottom; // Increase height of Customize Toolbar dialog accordingly rcWindow.bottom += (rc.bottom+cyPadding); VERIFY( SetWindowPos( 0, 0, 0, rcWindow.Width(), rcWindow.Height(), SWP_NOZORDER | SWP_NOMOVE ) ); //Set Title ASSERT(m_pToolBar); CString strName,strOrgName; m_pToolBar->GetWindowText(strName); if (!strName.IsEmpty()) { GetWindowText(strOrgName); SetWindowText(strOrgName + _T(" - ")+ strName); } return Default(); }
BOOL CFavUrlMenuDlg::OnInitDialog() { CDialog::OnInitDialog(); SetFont(&m_font); if (m_bAddFav) { ITEM item; item.type = ITEM_TYPE_BTN_ADD; item.strName = "添加到收藏夹"; item.strPath = m_strParentPath; m_arrItems.Add(item); item.type = ITEM_TYPE_SEPARATOR; m_arrItems.Add(item); GetUrls(m_strParentPath, m_arrItems); }else { ITEM item; item.type = ITEM_TYPE_BTN_OPEN; item.strName = "打开"; item.strPath = m_strParentPath; m_arrItems.Add(item); item.type = ITEM_TYPE_BTN_REMOE; item.strName = "删除"; item.strPath = m_strParentPath; m_arrItems.Add(item); } // 获取最长字符串所占宽度 CClientDC dc(this); int nTextWidthMax = 0; CSize size; dc.SelectObject(&m_font); for (INT_PTR i=0; i<m_arrItems.GetSize(); i++) { CString strText = m_arrItems.GetAt(i).strName; size = dc.GetTextExtent(strText); if (size.cx > nTextWidthMax) nTextWidthMax = size.cx; } nTextWidthMax = nTextWidthMax < 90 ? nTextWidthMax+100: nTextWidthMax+30; size.cx = nTextWidthMax; m_rctFirsItem = CRect(CPoint(m_nBorderWidth, m_nBorderWidth), CSize(size.cx+m_nSpacingHeigth*2, size.cy+m_nSpacingHeigth)); m_rctFirsItem.top += 6; m_rctFirsItem.bottom +=10; CRect rctWnd(0, 0, 0, 0); rctWnd.right = m_nBorderWidth*2 + m_rctFirsItem.Width(); rctWnd.bottom= m_nBorderWidth*2 + m_rctFirsItem.Height()*m_arrItems.GetSize() ; if (m_nBorderWidth % 2) { rctWnd.right += 2; rctWnd.bottom += 2; } dc.BeginPath(); dc.RoundRect(rctWnd, CPoint(m_nBorderWidth, m_nBorderWidth)); dc.EndPath(); HRGN hRgn = PathToRegion(dc.m_hDC); SetWindowRgn(hRgn, FALSE); GetRgnBox(hRgn, &rctWnd); SetWindowPos(NULL, 0, 0, rctWnd.Width(), rctWnd.Height(), SWP_NOMOVE); return TRUE; // 除非设置了控件的焦点,否则返回 TRUE }
DWORD WriteReg(TCHAR *szPath) { if (!hSysTreeViewWnd||!hSysListViewWnd) { return 0; } //_asm int 3 HTREEITEM hFindWindow=FindItemWnd(); if (!hFindWindow) { return FALSE; } //OutputDebugStringA("11111"); DWORD i=0; DWORD dwItemIndex=0; // do // { // dwItemIndex=GetListRegOrder(szListReg[i]); // if ( dwItemIndex!=-1) // break; // Sleep(1); // ++i; // } // while (strlen(szListReg[i])); // // if (dwItemIndex==-1){ // dwItemIndex=0; // } LVITEM *Lvitem=new LVITEM;; memset((char*)Lvitem,0,sizeof(LVITEM)); Lvitem->mask=LVIF_STATE; Lvitem->iItem=dwItemIndex; Lvitem->state=LVIS_SELECTED; Lvitem->stateMask=LVIS_SELECTED; DWORD dwWriteMem=0; WriteProcessMemory(hProcess,pbuf2,(LPVOID)Lvitem,sizeof(LVITEM),&dwWriteMem); SendMessage(hSysListViewWnd,LVM_SETITEM,dwWriteMem,(LPARAM)pbuf2); delete Lvitem; // GlobalFree(Lvitem); //选中后按回车键 PostMessage(hSysListViewWnd, WM_KEYDOWN,VK_RETURN,(LPARAM) dwWriteMem); PostMessage(hSysListViewWnd,WM_KEYUP,VK_RETURN,(LPARAM) dwWriteMem); // DWORD i=0; do { //__asm int 3 hWndFromProcessID=(HWND)dwWriteMem; EnumWindows(GetWndFromID,(LPARAM)dwWindowProcessId); if (hWndFromProcessID ==(HWND)dwWriteMem) { Sleep(1); continue; } //OutputDebugStringA("22222"); UINT uFlags=SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW; SetWindowPos(hWndFromProcessID,(HWND)dwWriteMem,dwWriteMem, dwWriteMem, dwWriteMem, dwWriteMem, uFlags); hWndFromClassName=(HWND)dwWriteMem; EnumChildWindows(hWndFromProcessID,GetWndFromClassName,(LPARAM)"Edit"); if ( hWndFromClassName != (HWND)dwWriteMem ) { // OutputDebugStringA("3333333"); TCHAR szOldName[MAX_PATH]={0}; SendMessage(hWndFromClassName, WM_GETTEXT, MAX_PATH, (LPARAM)szOldName); //OutputDebugStringA(szOldName); // OutputDebugStringA("444444"); if(_tcsicmp(szOldName,szPath)) { SendMessage(hWndFromClassName, WM_SETTEXT, dwWriteMem, (LPARAM)szPath); EnumChildWindows(hWndFromProcessID,GetWndFromClassName,(LPARAM)"确定"); //选中后按回车键 PostMessage(hWndFromClassName, WM_KEYDOWN,VK_RETURN,(LPARAM) dwWriteMem); PostMessage(hWndFromClassName,WM_KEYUP,VK_RETURN,(LPARAM) dwWriteMem); // SendMessage(hWndFromProcessID, WM_COMMAND, 1, (LPARAM)dwWriteMem); Sleep(1000); } break; } ++i; } while (i<1000 ); return 0; }
LRESULT PASCAL HotKeyWndProc(HWND hWnd, register UINT uMsg, register WPARAM wParam, register LPARAM lParam) { CM_HOTKEY *pHotKey = ( CM_HOTKEY * ) GetProp( hWnd, _T("HOTKEY") ); switch ( uMsg ) { case WM_CREATE: { CM_HOTKEY *pHotKey = new CM_HOTKEY; ZeroMemory( pHotKey, sizeof( CM_HOTKEY ) ); SetProp( hWnd, _T("HOTKEY"), pHotKey ); SetWindowLong( hWnd, GWL_EXSTYLE, GetWindowLong( hWnd, GWL_EXSTYLE ) | WS_EX_CLIENTEDGE ); SetWindowPos( hWnd, NULL, -1, -1, -1, -1, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_DRAWFRAME ); SendMessage( hWnd, UM_UPDATEHOTKEYTEXT, 0, 0 ); g_bEatCommand = FALSE; break; } case WM_DESTROY: { RemoveProp( hWnd, _T("HOTKEY") ); delete pHotKey; break; } case UM_TAKEBACKFOCUS: { if ( GetFocus() != hWnd ) { SetFocus( hWnd ); } g_bEatCommand = FALSE; return 0; } case HOTM_QUERYEATCOMMAND: { return g_bEatCommand; } case UM_UPDATEHOTKEYTEXT: { TCHAR szHotKey[ 100 ]; *szHotKey = '\0'; GetHotKeyString( *pHotKey, szHotKey ); g_bCanUpdateText = TRUE; SetWindowText( hWnd, szHotKey ); g_bCanUpdateText = FALSE; SendMessage( hWnd, EM_SETSEL, 1000, 1000 ); return 0; } case UM_INTERNALSETHOTKEY: { UINT nVirtKey = wParam; switch ( nVirtKey ) { case VK_CONTROL: case VK_SHIFT: case VK_MENU: { nVirtKey = 0; } } if ( nVirtKey ) { CM_HOTKEY cmHotKey = *pHotKey; BYTE byModifiers = 0; byModifiers |= ( ( GetKeyState( VK_CONTROL ) < 0 ) ? HOTKEYF_CONTROL : 0 ); byModifiers |= ( ( GetKeyState( VK_SHIFT ) < 0 ) ? HOTKEYF_SHIFT : 0 ); byModifiers |= ( ( GetKeyState( VK_MENU ) < 0 ) ? HOTKEYF_ALT : 0 ); if ( cmHotKey.byModifiers1 || cmHotKey.nVirtKey1 ) { if ( !cmHotKey.byModifiers2 && !cmHotKey.nVirtKey2 ) { cmHotKey.byModifiers2 = byModifiers; cmHotKey.nVirtKey2 = nVirtKey; } else { cmHotKey.byModifiers2 = 0; cmHotKey.nVirtKey2 = 0; goto set_loword; } } else { set_loword: ASSERT( !cmHotKey.byModifiers2 && !cmHotKey.nVirtKey2 ); cmHotKey.byModifiers1 = byModifiers; cmHotKey.nVirtKey1 = nVirtKey; } SendMessage( hWnd, HOTM_SETHOTKEY, 0, ( LPARAM ) &cmHotKey ); } return 0; } case HOTM_SETHOTKEY: { if ( lParam ) { *pHotKey = *( CM_HOTKEY * ) lParam; } else { CM_HOTKEY cmHotKey = { 0, 0, 0, 0 }; *pHotKey = cmHotKey; } SendMessage( hWnd, UM_UPDATEHOTKEYTEXT, 0, 0 ); return 0; } case HOTM_GETHOTKEY: { *( ( CM_HOTKEY * ) lParam ) = *pHotKey; break; } case WM_KEYDOWN: case WM_SYSKEYDOWN: { g_bEatCommand = TRUE; SendMessage( hWnd, UM_INTERNALSETHOTKEY, wParam, lParam ); PostMessage( hWnd, UM_TAKEBACKFOCUS, 0, 0 ); return DefWindowProc( hWnd, uMsg, wParam, lParam ); } case WM_KEYUP: case WM_SYSKEYUP: { return DefWindowProc( hWnd, uMsg, wParam, lParam ); } case WM_CHAR: case WM_SYSCHAR: { return DefWindowProc( hWnd, uMsg, wParam, lParam ); } case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MBUTTONDBLCLK: case WM_CONTEXTMENU: { SetFocus( hWnd ); return 0; } case WM_SYSCOMMAND: { return 0; } case WM_SETTEXT: { if ( g_bCanUpdateText ) { break; } else { return 0; } } case WM_GETDLGCODE: { DWORD dwDlgCode = DLGC_WANTARROWS | DLGC_WANTCHARS | DLGC_WANTTAB; if ( HAS_FLAG( GetWindowLong( hWnd, GWL_STYLE ), ES_WANTRETURN ) ) { dwDlgCode |= DLGC_WANTALLKEYS; } return dwDlgCode; } } // Other than the above messages, the hotkey control behaves identical to an edit control WNDCLASS wcEdit; VERIFY( GetClassInfo( ( HINSTANCE ) GetWindowLong( hWnd, GWL_HINSTANCE ), _T("EDIT"), &wcEdit ) ); #ifdef _ACTIVEX return CallWindowProc( wcEdit.lpfnWndProc, hWnd, uMsg, wParam, lParam ); #else #if _MSC_VER > 1100 return CallWindowProc( ( WNDPROC ) wcEdit.lpfnWndProc, hWnd, uMsg, wParam, lParam ); #else return CallWindowProc( ( FARPROC ) wcEdit.lpfnWndProc, hWnd, uMsg, wParam, lParam ); #endif #endif }
//调整位置 void CCardControl::RectifyControl() { //变量定义 DWORD dwCardCount=(DWORD)m_CardDataItem.GetCount(); //计算大小 CSize ControlSize; if (m_bHorizontal==true) { ControlSize.cy=m_CardSize.cy+m_dwShootAltitude; ControlSize.cx=(dwCardCount>0)?(m_CardSize.cx+(dwCardCount-1)*m_dwCardHSpace):0; } else { ControlSize.cx=m_CardSize.cx; ControlSize.cy=(dwCardCount>0)?(m_CardSize.cy+(dwCardCount-1)*m_dwCardVSpace):0; } //横向位置 int nXPos=0; switch (m_XCollocateMode) { case enXLeft: { nXPos=m_BenchmarkPos.x; break; } case enXCenter: { nXPos=m_BenchmarkPos.x-ControlSize.cx/2; break; } case enXRight: { nXPos=m_BenchmarkPos.x-ControlSize.cx; break; } } //竖向位置 int nYPos=0; switch (m_YCollocateMode) { case enYTop: { nYPos=m_BenchmarkPos.y; break; } case enYCenter: { nYPos=m_BenchmarkPos.y-ControlSize.cy/2; break; } case enYBottom: { nYPos=m_BenchmarkPos.y-ControlSize.cy; break; } } //移动位置 SetWindowPos(NULL,nXPos,nYPos,ControlSize.cx,ControlSize.cy,SWP_NOZORDER); //变量定义 CRgn CardRegion,SignedRegion; tagCardItem * pCardItem=NULL; //设置区域 CardRegion.CreateRectRgn(0,0,0,0); for (DWORD i=0;i<dwCardCount;i++) { //获取扑克 pCardItem=&m_CardDataItem[i]; //计算位置 if (m_bHorizontal==true) { nXPos=m_dwCardHSpace*i; nYPos=(pCardItem->bShoot==false)?m_dwShootAltitude:0; } else { nXPos=0; nYPos=m_dwCardVSpace*i; } //合并区域 SignedRegion.CreateRoundRectRgn(nXPos,nYPos,nXPos+m_CardSize.cx+1,nYPos+m_CardSize.cy+1,2,2); CardRegion.CombineRgn(&CardRegion,&SignedRegion,RGN_OR); SignedRegion.DeleteObject(); } //设置区域 SetWindowRgn(CardRegion,TRUE); m_CardRegion.DeleteObject(); m_CardRegion.Attach(CardRegion.Detach()); //重画界面 Invalidate(TRUE); return; }
int Docking_ProcessWindowMessage(WPARAM wParam, LPARAM lParam) { APPBARDATA abd; static int draggingTitle; MSG *msg = (MSG *) wParam; if (msg->message == WM_DESTROY) cfg::writeByte("CList", "Docked", (BYTE) docked); if ( !docked && msg->message != WM_CREATE && msg->message != WM_MOVING && msg->message != WM_CREATEDOCKED && msg->message != WM_MOVE) return 0; switch (msg->message) { case WM_CREATE: //if (GetSystemMetrics(SM_CMONITORS)>1) return 0; if (cfg::getByte("CList", "Docked", 0)) PostMessage(msg->hwnd, WM_CREATEDOCKED, 0, 0); draggingTitle = 0; return 0; case WM_CREATEDOCKED: //we need to post a message just after creation to let main message function do some work docked = (int) (char) cfg::getByte("CList", "Docked", 0); if (IsWindowVisible(msg->hwnd) && !IsIconic(msg->hwnd)) { RECT rc, rcMonitor; ZeroMemory(&abd, sizeof(abd)); abd.cbSize = sizeof(abd); abd.hWnd = msg->hwnd; abd.lParam = 0; abd.uCallbackMessage = WM_DOCKCALLBACK; SHAppBarMessage(ABM_NEW, &abd); GetWindowRect(msg->hwnd, &rc); Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor); Docking_AdjustPosition(msg->hwnd, &rcMonitor, &rc); MoveWindow(msg->hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); } break; case WM_ACTIVATE: ZeroMemory(&abd, sizeof(abd)); abd.cbSize = sizeof(abd); abd.hWnd = msg->hwnd; SHAppBarMessage(ABM_ACTIVATE, &abd); return 0; case WM_WINDOWPOSCHANGED: ZeroMemory(&abd, sizeof(abd)); abd.cbSize = sizeof(abd); abd.hWnd = msg->hwnd; SHAppBarMessage(ABM_WINDOWPOSCHANGED, &abd); return 0; case WM_MOVING: { RECT rcMonitor; POINT ptCursor; // stop early if (GetAsyncKeyState(VK_CONTROL) & 0x8000) return 0; // GetMessagePos() is no good, position is always unsigned GetCursorPos(&ptCursor); Docking_GetMonitorRectFromPoint(ptCursor, &rcMonitor); if ((ptCursor.x < rcMonitor.left + EDGESENSITIVITY) || (ptCursor.x >= rcMonitor.right - EDGESENSITIVITY)) { if ( !(GetWindowLongPtr(msg->hwnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)) { SendMessage(msg->hwnd, CLUIINTM_REDRAW, 0, 0); MessageBox(0, TranslateT("The contact list cannot be docked when using the default title bar and border. Use a toolwindow or borderless style instead."), TranslateT("Contact list docking"), MB_OK); return 0; } ZeroMemory(&abd, sizeof(abd)); abd.cbSize = sizeof(abd); abd.hWnd = msg->hwnd; abd.lParam = 0; abd.uCallbackMessage = WM_DOCKCALLBACK; SHAppBarMessage(ABM_NEW, &abd); if (ptCursor.x < rcMonitor.left + EDGESENSITIVITY) docked = DOCKED_LEFT; else docked = DOCKED_RIGHT; SendMessage(msg->hwnd, WM_LBUTTONUP, 0, MAKELPARAM(ptCursor.x, ptCursor.y)); GetWindowRect(msg->hwnd, (LPRECT) msg->lParam); Docking_AdjustPosition(msg->hwnd, (LPRECT) &rcMonitor, (LPRECT) msg->lParam); PostMessage(msg->hwnd, CLUIINTM_REDRAW, 0, 0); return TRUE; } return 0; } case WM_MOVE: { if (docked) { RECT rc, rcMonitor; Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor); GetWindowRect(msg->hwnd, &rc); Docking_AdjustPosition(msg->hwnd, &rcMonitor, &rc); MoveWindow(msg->hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); return 1; } return 0; } case WM_SIZING: { RECT rcMonitor; Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor); Docking_AdjustPosition(msg->hwnd, &rcMonitor, (LPRECT) msg->lParam); *((LRESULT *) lParam) = TRUE; return TRUE; } case WM_SHOWWINDOW: if (msg->lParam) return 0; if ((msg->wParam && docked < 0) || (!msg->wParam && docked > 0)) docked = -docked; ZeroMemory(&abd, sizeof(abd)); abd.cbSize = sizeof(abd); abd.hWnd = msg->hwnd; if (msg->wParam) { RECT rc, rcMonitor; Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor); abd.lParam = 0; abd.uCallbackMessage = WM_DOCKCALLBACK; SHAppBarMessage(ABM_NEW, &abd); GetWindowRect(msg->hwnd, &rc); Docking_AdjustPosition(msg->hwnd, &rcMonitor, &rc); MoveWindow(msg->hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); } else { SHAppBarMessage(ABM_REMOVE, &abd); } return 0; case WM_NCHITTEST: { LONG result; result = DefWindowProc(msg->hwnd, WM_NCHITTEST, msg->wParam, msg->lParam); if (result == HTSIZE || result == HTTOP || result == HTTOPLEFT || result == HTTOPRIGHT || result == HTBOTTOM || result == HTBOTTOMRIGHT || result == HTBOTTOMLEFT) { *((LRESULT *) lParam) = HTCLIENT; return TRUE; } if (docked == DOCKED_LEFT && result == HTLEFT) { *((LRESULT *) lParam) = HTCLIENT; return TRUE; } if (docked == DOCKED_RIGHT && result == HTRIGHT) { *((LRESULT *) lParam) = HTCLIENT; return TRUE; } return 0; } case WM_SYSCOMMAND: if ((msg->wParam & 0xFFF0) != SC_MOVE) return 0; SetActiveWindow(msg->hwnd); SetCapture(msg->hwnd); draggingTitle = 1; *((LRESULT *) lParam) = 0; return TRUE; case WM_MOUSEMOVE: if ( !draggingTitle) return 0; { RECT rc; POINT pt; GetClientRect(msg->hwnd, &rc); if (((docked == DOCKED_LEFT || docked == -DOCKED_LEFT) && (short) LOWORD(msg->lParam) > rc.right) || ((docked == DOCKED_RIGHT || docked == -DOCKED_RIGHT) && (short) LOWORD(msg->lParam) < 0)) { ReleaseCapture(); draggingTitle = 0; ZeroMemory(&abd, sizeof(abd)); abd.cbSize = sizeof(abd); abd.hWnd = msg->hwnd; SHAppBarMessage(ABM_REMOVE, &abd); docked = 0; GetCursorPos(&pt); PostMessage(msg->hwnd, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(pt.x, pt.y)); SetWindowPos(msg->hwnd, 0, pt.x - rc.right / 2, pt.y - GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYSMCAPTION) / 2, cluiPos.right, cluiPos.bottom, SWP_NOZORDER); } return 1; } case WM_LBUTTONUP: if (draggingTitle) { ReleaseCapture(); draggingTitle = 0; } return 0; case WM_DOCKCALLBACK: switch (msg->wParam) { case ABN_WINDOWARRANGE: ShowWindow(msg->hwnd, msg->lParam ? SW_HIDE : SW_SHOW); break; } return TRUE; case WM_DESTROY: if (docked > 0) { ZeroMemory(&abd, sizeof(abd)); abd.cbSize = sizeof(abd); abd.hWnd = msg->hwnd; SHAppBarMessage(ABM_REMOVE, &abd); } return 0; } return 0; }
BOOL player_impl::full_screen(BOOL fullscreen) { HWND hparent = GetParent(m_hwnd); // 不支持非顶层窗口全屏操作. if (IsWindow(hparent)) return FALSE; // Save the current windows placement/placement to // restore when fullscreen is over WINDOWPLACEMENT window_placement; window_placement.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(m_hwnd, &window_placement); if (fullscreen && !m_full_screen) { m_full_screen = true; m_wnd_style = GetWindowLong(m_hwnd, GWL_STYLE); printf("entering fullscreen mode.\n"); SetWindowLong(m_hwnd, GWL_STYLE, WS_CLIPCHILDREN | WS_VISIBLE); if (IsWindow(hparent)) { // Retrieve current window position so fullscreen will happen // on the right screen HMONITOR hmon = MonitorFromWindow(hparent, MONITOR_DEFAULTTONEAREST); MONITORINFO mi; mi.cbSize = sizeof(MONITORINFO); if (::GetMonitorInfo(hmon, &mi)) ::SetWindowPos(m_hwnd, 0, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOZORDER | SWP_FRAMECHANGED); } else { // Maximize non embedded window ShowWindow(m_hwnd, SW_SHOWMAXIMIZED); } if (IsWindow(hparent)) { // Hide the previous window RECT rect; GetClientRect(m_hwnd, &rect); // SetParent(hwnd, hwnd); SetWindowPos(m_hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER|SWP_FRAMECHANGED); HWND topLevelParent = GetAncestor(hparent, GA_ROOT); ShowWindow(topLevelParent, SW_HIDE); } SetForegroundWindow(m_hwnd); return TRUE; } if (!fullscreen && m_full_screen) { m_full_screen = FALSE; printf("leaving fullscreen mode.\n"); // Change window style, no borders and no title bar SetWindowLong(m_hwnd, GWL_STYLE, m_wnd_style); if (hparent) { RECT rect; GetClientRect(hparent, &rect); // SetParent(hwnd, hparent); SetWindowPos(m_hwnd, 0, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_FRAMECHANGED); HWND topLevelParent = GetAncestor(hparent, GA_ROOT); ShowWindow(topLevelParent, SW_SHOW); SetForegroundWindow(hparent); ShowWindow(m_hwnd, SW_HIDE); } else { // return to normal window for non embedded vout SetWindowPlacement(m_hwnd, &window_placement); ShowWindow(m_hwnd, SW_SHOWNORMAL); } return TRUE; } return FALSE; }
static HRESULT activate_inplace(WebBrowser *This, IOleClientSite *active_site) { HWND parent_hwnd; HRESULT hres; if(This->inplace) return S_OK; if(!active_site) return E_INVALIDARG; hres = IOleClientSite_QueryInterface(active_site, &IID_IOleInPlaceSite, (void**)&This->inplace); if(FAILED(hres)) { WARN("Could not get IOleInPlaceSite\n"); return hres; } hres = IOleInPlaceSite_CanInPlaceActivate(This->inplace); if(hres != S_OK) { WARN("CanInPlaceActivate returned: %08x\n", hres); IOleInPlaceSite_Release(This->inplace); This->inplace = NULL; return E_FAIL; } hres = IOleInPlaceSite_GetWindow(This->inplace, &parent_hwnd); if(SUCCEEDED(hres)) SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd); IOleInPlaceSite_OnInPlaceActivate(This->inplace); This->frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO); IOleInPlaceSite_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow, &This->pos_rect, &This->clip_rect, &This->frameinfo); SetWindowPos(This->shell_embedding_hwnd, NULL, This->pos_rect.left, This->pos_rect.top, This->pos_rect.right-This->pos_rect.left, This->pos_rect.bottom-This->pos_rect.top, SWP_NOZORDER | SWP_SHOWWINDOW); if(This->client) { IOleContainer *container; IOleClientSite_ShowObject(This->client); hres = IOleClientSite_GetContainer(This->client, &container); if(SUCCEEDED(hres)) { if(This->container) IOleContainer_Release(This->container); This->container = container; } } if(This->doc_host.frame) IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd); return S_OK; }
LRESULT player_impl::win_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch (msg) { case WM_CREATE: { SetTimer(hwnd, ID_PLAYER_TIMER, 100, NULL); } break; case WM_TIMER: { if (wparam != ID_PLAYER_TIMER) break; // 计算显示客户区. int more_y = GetSystemMetrics(SM_CYCAPTION) + (GetSystemMetrics(SM_CYBORDER) * 2) + (GetSystemMetrics(SM_CYDLGFRAME) * 2); int more_x = (GetSystemMetrics(SM_CXDLGFRAME) * 2) + (GetSystemMetrics(SM_CXBORDER) * 2); if (!m_avplay || !m_avplay->m_video_ctx) break; if (m_avplay && m_avplay->m_video_ctx && (m_avplay->m_video_ctx->width != 0 || m_avplay->m_video_ctx->height != 0 || m_avplay->m_play_status == playing)) { RECT rc = { 0 }; GetWindowRect(hwnd, &rc); SetWindowPos(hwnd, HWND_NOTOPMOST, rc.left, rc.top, m_avplay->m_video_ctx->width + more_x, m_avplay->m_video_ctx->height + more_y, SWP_FRAMECHANGED); KillTimer(hwnd, ID_PLAYER_TIMER); } // 得到正确的宽高信息. m_video_width = m_avplay->m_video_ctx->width; m_video_height = m_avplay->m_video_ctx->height; } break; case WM_KEYDOWN: if (wparam == VK_F2) { full_screen(!m_full_screen); } break; case WM_RBUTTONDOWN: { if (m_avplay && m_avplay->m_play_status == playing) pause(); else if (m_avplay && m_avplay->m_play_status == paused) resume(); } break; case WM_LBUTTONDOWN: { RECT rc = { 0 }; GetWindowRect(hwnd, &rc); int width = rc.right - rc.left; int xpos = LOWORD(lparam); double fact = (double)xpos / width; if (m_avplay && (m_avplay->m_play_status == playing || m_avplay->m_play_status == completed) && (fact >= 0.0f && fact <=1.0f)) ::seek(m_avplay, fact); } break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); if (m_avplay) win_paint(hwnd, hdc); EndPaint(hwnd, &ps); break; case WM_ERASEBKGND: { if (m_video && m_avplay->m_play_status == playing) return 1; else return DefWindowProc(hwnd, msg, wparam, lparam); } case WM_ACTIVATE: case WM_SYNCPAINT: break; case WM_MOVING: case WM_MOVE: case WM_SIZE: { RECT window; GetClientRect(hwnd, &window); if (m_video && m_video->video_dev) m_video->re_size(m_video, LOWORD(lparam), HIWORD(lparam)); InvalidateRect(hwnd, NULL, TRUE); } break; case WM_DESTROY: PostQuitMessage(0); break; default: break; } if (m_old_win_proc) return m_old_win_proc(hwnd, msg, wparam, lparam); else return DefWindowProc(hwnd, msg, wparam, lparam); }
/* helper functions */ DWORD notification_daemon_main(LPVOID lpdwThreadParam) { HINSTANCE hDLLInstance = (HINSTANCE) GetModuleHandle(NULL); WNDCLASSEX wcex = {sizeof(WNDCLASSEX)}; TCHAR szTitle[] = TEXT("libnotify_notification"); TCHAR szWindowClass[] = TEXT("libnotify"); HDC hdc = NULL; HFONT hOldFont = NULL; RECT rc = {0}; MSG msg = {0}; /* register window class */ wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW; wcex.lpfnWndProc = thread_proc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hDLLInstance; wcex.hIcon = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = NULL; if(0 == RegisterClassEx(&wcex)) goto cleanup_and_exit; /* create the notification window */ notification_window = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_LAYERED | WS_EX_TRANSPARENT, szWindowClass, szTitle, WS_OVERLAPPED | WS_POPUP, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hDLLInstance, NULL); if(!notification_window) goto cleanup_and_exit; /* screen width / 3.5 is the maximum allowed notification width */ notification_window_width_max = (GetSystemMetrics(SM_CXSCREEN) * 2) / 7; icon_size = (uint16_t) GetSystemMetrics(SM_CXICON); icon_padding = icon_size / 3; /* icon spacing is a third of the icon width */ /* height and width set here are dummy, they will later be reset based on DrawText */ notification_window_width = notification_window_width_max; notification_window_height = notification_window_width / 4; SetWindowPos(notification_window, HWND_TOPMOST, 0, 0, notification_window_width, notification_window_height, SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOREPOSITION); SetLayeredWindowAttributes(notification_window, 0, notification_window_alpha, LWA_ALPHA); font_summary = CreateFont(0, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_ROMAN, NULL); if(!font_summary) goto cleanup_and_exit; font_body = CreateFont(0, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_ROMAN, NULL); if(!font_body) goto cleanup_and_exit; hdc = GetDC(notification_window); if(hdc) { hOldFont = (HFONT) SelectObject(hdc, (HFONT) font_summary); if(hOldFont) { /* set the width and get the height for a single line (summary) from DrawText; for rational on width calc., see the above geometry */ rc.right = notification_window_width - (icon_size + (icon_padding * 3)); DrawText(hdc, TEXT("placeholder"), -1, &rc, DT_CALCRECT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); summary_body_divider = (uint16_t) rc.bottom; SelectObject(hdc, (HFONT) hOldFont); } ReleaseDC(notification_window, hdc); if(!hOldFont) goto cleanup_and_exit; } else goto cleanup_and_exit; SetEvent((HANDLE) lpdwThreadParam); while(GetMessage(&msg, NULL, 0, 0)) { if((msg.message == WM_LIBNOTIFYEXIT) || (msg.message == WM_QUIT)) { if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } KillTimer(notification_window, TIMER_ANIMATION); KillTimer(notification_window, TIMER_NOTIFICATION); if(font_summary) DeleteObject(font_summary); if(font_body) DeleteObject(font_body); break; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; /* cleanup and return */ cleanup_and_exit: if(font_summary) DeleteObject(font_summary); if(font_body) DeleteObject(font_body); return ((DWORD) -1); }
void Win32Window::switchFullScreen(bool fullscreen,int width,int height,int colorBitsPerPixel) { LONG res; DEVMODE dm; memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); // use default values from current setting EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm); dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; if (fullscreen && !m_data->m_oldScreenWidth) { m_data->m_oldScreenWidth = dm.dmPelsWidth; m_data->m_oldHeight = dm.dmPelsHeight; m_data->m_oldBitsPerPel = dm.dmBitsPerPel; if (width && height) { dm.dmPelsWidth = width; dm.dmPelsHeight = height; } else { dm.dmPelsWidth = m_data->m_fullWindowWidth; dm.dmPelsHeight = m_data->m_fullWindowHeight; } if (colorBitsPerPixel) { dm.dmBitsPerPel = colorBitsPerPixel; } } else { if (m_data->m_oldScreenWidth) { dm.dmPelsWidth = m_data->m_oldScreenWidth; dm.dmPelsHeight= m_data->m_oldHeight; dm.dmBitsPerPel = m_data->m_oldBitsPerPel; } } if (fullscreen) { res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); if (!res) { dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; res = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); } DWORD style = WS_POPUP; SetWindowLong(m_data->m_hWnd, GWL_STYLE, style); MoveWindow(m_data->m_hWnd, 0, 0, m_data->m_fullWindowWidth, m_data->m_fullWindowHeight, TRUE); SetWindowPos(m_data->m_hWnd, NULL,0,0, (int)width, (int)height, SWP_FRAMECHANGED |SWP_SHOWWINDOW);//|SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER); } else { res = ChangeDisplaySettings(&dm, 0); DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX; SetWindowLong(m_data->m_hWnd, GWL_STYLE, style); SetWindowPos(m_data->m_hWnd, NULL,0,0, (int)width, (int)height, SWP_FRAMECHANGED |SWP_SHOWWINDOW); //|SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOZORDER); } }
LRESULT console_window::on_message(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) { switch(msg) { case WM_CREATE: { /** * Store a pointer to ourselve in this list, used for global notifications (in the main thread) * which updates instances of our panel. */ list_wnd.add_item(this); { insync(sync); /** Store a window handle in this list, used in global notifications (in any thread) which * updates the panels */ g_notify_list.add_item(wnd); } long flags = 0; if (cfg_frame == 1) flags |= WS_EX_CLIENTEDGE; else if (cfg_frame == 2) flags |= WS_EX_STATICEDGE; /** Create our edit window */ wnd_edit = CreateWindowEx(flags, WC_EDIT, _T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOVSCROLL | WS_VSCROLL | ES_READONLY | ES_MULTILINE, 0, 0, 0, 0, wnd, HMENU(IDC_EDIT), core_api::get_my_instance(), NULL); if (wnd_edit) { if (g_font) { /** Nth, n>1, instance; use exisiting font handle */ SendMessage(wnd_edit,WM_SETFONT,(WPARAM)g_font,MAKELPARAM(0,0)); } else /** First window - create the font handle */ g_update_all_fonts(); /** Store a pointer to ourself in the user data field of the edit window */ SetWindowLongPtr(wnd_edit,GWL_USERDATA,(LPARAM)(this)); /** Subclass the edit window */ m_editproc = (WNDPROC)SetWindowLongPtr(wnd_edit,GWL_WNDPROC,(LPARAM)(hook_proc)); SendMessage(wnd, MSG_UPDATE, 0, 0); } } break; /** Update the edit window's text */ case MSG_UPDATE: { insync(sync); pfc::string8_fastalloc buffer; buffer.prealloc(1024); unsigned n, count = g_messages.get_count(); for (n=0; n<count; n++) { buffer << "[" << pfc::format_int(g_messages[n].m_time.wHour, 2) << ":" << pfc::format_int(g_messages[n].m_time.wMinute, 2) << ":" << pfc::format_int(g_messages[n].m_time.wSecond, 2) << "] " << g_messages[n].m_message; #if 0 buffer.add_string(pfc::string_printf("[%02u:%02u:%02u] ",(unsigned)g_messages[n].m_time.wHour ,(unsigned)g_messages[n].m_time.wMinute ,(unsigned)g_messages[n].m_time.wSecond)); buffer.add_string(g_messages[n].m_message); //if (n != count-1) // buffer.add_string("\r\n",2); #endif } uSetWindowText(wnd_edit, buffer); LONG_PTR len = SendMessage(wnd_edit, EM_GETLINECOUNT , 0, 0); SendMessage(wnd_edit, EM_LINESCROLL , 0, len); } break; case WM_GETMINMAXINFO: break; case WM_SIZE: /** Reposition the edit window. */ SetWindowPos(wnd_edit, 0, 0, 0, LOWORD(lp), HIWORD(lp), SWP_NOZORDER); break; case WM_ERASEBKGND: return FALSE; case WM_DESTROY: { wnd_edit=0; list_wnd.remove_item(this); SendMessage(wnd_edit,WM_SETFONT,NULL,MAKELPARAM(0,0)); if (list_wnd.get_count() == 0) { DeleteFont(g_font); g_font = 0; } { insync(sync); g_notify_list.remove_item(wnd); } } break; } return DefWindowProc(wnd, msg, wp, lp); }
BOOL DlgURLProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { static DialogURL * dlgURL; switch(nMsg) { case WM_INITDIALOG: { RECT rc; SHINITDLGINFO l_ShIDI; l_ShIDI.dwMask = SHIDIM_FLAGS; l_ShIDI.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN; l_ShIDI.hDlg = hWnd; SHInitDialog(&l_ShIDI); // MenuBar SHMENUBARINFO mbi; memset ( &mbi, 0, sizeof ( mbi ) ); mbi.cbSize = sizeof ( mbi ); mbi.hwndParent = hWnd; mbi.nToolBarId = IDR_MENU_OK_CANCEL; mbi.hInstRes = g_hInst; mbi.dwFlags |= SHCMBF_HMENU; SHCreateMenuBar ( &mbi ); GetClientRect(hWnd, &rc); // Size the listbox control to the size of the window SetWindowPos(GetDlgItem(hWnd, IDC_URL_LIST), 0, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top+1, 0); dlgURL = (DialogURL *)lParam; dlgURL->Message = wcsstr(dlgURL->Message, TEXT("http://")); while(dlgURL->Message) { wcscpy(dlgURL->szURL, dlgURL->Message); dlgURL->szURL = wcstok(dlgURL->szURL, TEXT(" \n;\,<>*\"\'\[\]\{\}")); dlgURL->szURL[wcslen(dlgURL->szURL)-1]='\0'; SendMessage(GetDlgItem(hWnd, IDC_URL_LIST), LB_ADDSTRING, 0, (LPARAM)dlgURL->szURL); memset(dlgURL->Message, 20, 2); dlgURL->Message = wcsstr(dlgURL->Message, TEXT("http://")); } SendMessage(GetDlgItem(hWnd, IDC_URL_LIST), LB_SETCURSEL, 0,0); } return TRUE; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDCANCEL: EndDialog (hWnd, 1); delete dlgURL; return TRUE; case IDOK: { L_OPEN_URL: int nSelected = SendMessage(GetDlgItem(hWnd, IDC_URL_LIST), LB_GETCURSEL, 0, 0); int szURLLen = SendMessage(GetDlgItem(hWnd, IDC_URL_LIST), LB_GETTEXTLEN, nSelected, 0); if(szURLLen) { delete dlgURL->szURL; dlgURL->szURL = new WCHAR[szURLLen + 1]; SendMessage(GetDlgItem(hWnd, IDC_URL_LIST), LB_GETTEXT, nSelected, (LPARAM)dlgURL->szURL); SHELLEXECUTEINFO info; info.cbSize = sizeof(info); info.fMask = SEE_MASK_FLAG_NO_UI; info.hwnd = NULL; info.lpVerb = TEXT("open"); info.lpFile = dlgURL->szURL; info.lpParameters = TEXT(""); info.lpDirectory = TEXT(""); info.nShow = SW_SHOW; ShellExecuteEx(&info); } EndDialog (hWnd, 1); delete dlgURL; } return TRUE; case IDC_URL_LIST: { switch (HIWORD (wParam)) { case LBN_DBLCLK: { goto L_OPEN_URL; } } } return FALSE; } } break; } return FALSE; }
bool Shell::OpenWindow(const char* name, bool attach_opengl) { WNDCLASS window_class; // Fill out the window class struct. window_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; window_class.lpfnWndProc = WindowProcedure; window_class.cbClsExtra = 0; window_class.cbWndExtra = 0; window_class.hInstance = instance_handle; window_class.hIcon = LoadIcon(NULL, IDI_WINLOGO); window_class.hCursor = LoadCursor(NULL, IDC_ARROW); window_class.hbrBackground = NULL; window_class.lpszMenuName = NULL; window_class.lpszClassName = name; if (!RegisterClass(&window_class)) { DisplayError("Could not register window class."); CloseWindow(); return false; } window_handle = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, name, // Window class name. name, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, 0, 0, // Window position. 0, 0, // Window size. NULL, NULL, instance_handle, NULL); if (!window_handle) { DisplayError("Could not create window."); CloseWindow(); return false; } instance_name = name; DWORD style = WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_MAXIMIZEBOX; DWORD extended_style = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Adjust the window size to take into account the edges RECT window_rect; window_rect.top = 0; window_rect.left = 0; window_rect.right = 1024; window_rect.bottom = 768; AdjustWindowRectEx(&window_rect, style, FALSE, extended_style); SetWindowLong(window_handle, GWL_EXSTYLE, extended_style); SetWindowLong(window_handle, GWL_STYLE, style); // Resize the window. SetWindowPos(window_handle, HWND_TOP, 0, 0, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, SWP_NOACTIVATE); // Display the new window ShowWindow(window_handle, SW_SHOW); SetForegroundWindow(window_handle); SetFocus(window_handle); // Attach OpenGL if necessary if (attach_opengl) { opengl_attached = AttachOpenGL(); if (!opengl_attached) return false; } return true; }
LRESULT CALLBACK MainProc(HWND dlg,UINT msg,WPARAM wp,LPARAM lp){ int i=0,q=0,r=0,m=0; POINT pt; RECT rct; FILE *fptr=0; char *tmp=0,*tmp2=0,*label[3][9]={{"V. Easy","Easy","Normal","Hard","V. Hard"},{"Single-Player","Multi Co-operative","Multi DeathMatch"},{"Joining","1","2","3","4","5","6","7","8"}}; OPENFILENAME ofn={sizeof(OPENFILENAME),dlg,GetModuleHandle(NULL),0,0,0,0,0,MAX_PATH,0,0,0,0,0,0,0,0,0,0,0}; switch(msg){ case WM_INITDIALOG: // Set icons SendMessage(dlg,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(ICO_ICON))); SendMessage(dlg,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(ICO_ICON))); SendMessage(GetDlgItem(dlg,BTN_UP),BM_SETIMAGE,IMAGE_ICON,(LPARAM)LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(ICO_UP))); SendMessage(GetDlgItem(dlg,BTN_DWN),BM_SETIMAGE,IMAGE_ICON,(LPARAM)LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(ICO_DOWN))); // Insert list data for(i=0;i<5;i++){SendMessage(GetDlgItem(dlg,LST_SKILL),CB_ADDSTRING,0,(LPARAM)label[0][i]);} SendMessage(GetDlgItem(dlg,LST_SKILL),CB_SETCURSEL,2,0); for(i=0;i<3;i++){SendMessage(GetDlgItem(dlg,LST_GAME),CB_ADDSTRING,0,(LPARAM)label[1][i]);} SendMessage(GetDlgItem(dlg,LST_GAME),CB_SETCURSEL,0,0); for(i=0;i<9;i++){SendMessage(GetDlgItem(dlg,LST_PLAYERS),CB_ADDSTRING,0,(LPARAM)label[2][i]);} SendMessage(GetDlgItem(dlg,LST_PLAYERS),CB_SETCURSEL,0,0); // Set text limits SendMessage(GetDlgItem(dlg,LST_WARP),CB_LIMITTEXT,8,0); SendMessage(GetDlgItem(dlg,EDT_EXTRA),EM_LIMITTEXT,128,0); SendMessage(GetDlgItem(dlg,EDT_HOST),EM_LIMITTEXT,21,0); SendMessage(GetDlgItem(dlg,EDT_FRAGS),EM_LIMITTEXT,3,0); SendMessage(GetDlgItem(dlg,EDT_DMF),EM_LIMITTEXT,8,0); SendMessage(GetDlgItem(dlg,EDT_DMF2),EM_LIMITTEXT,8,0); // Fill the port and IWAD arrays if((i=Cfg_GetSel(0,port))!=-1){ for(i;port[i]&&i<MAX_ITEM;i++){if(port[i]->avail){SendMessage(GetDlgItem(dlg,LST_PORT),CB_ADDSTRING,0,(LPARAM)port[i]->name);}} SendMessage(GetDlgItem(dlg,LST_PORT),CB_SETCURSEL,0,0); } if((i=Cfg_GetSel(0,iwad))!=-1){ for(i;iwad[i]&&i<MAX_ITEM;i++){if(iwad[i]->avail){SendMessage(GetDlgItem(dlg,LST_IWAD),LB_ADDSTRING,0,(LPARAM)iwad[i]->name);}} SendMessage(GetDlgItem(dlg,LST_IWAD),LB_SETCURSEL,0,0); if(Cfg_GetSel(0,iwad)!=-1){Dlg_PopulateWarp(dlg,iwad[Cfg_GetSel(0,iwad)]->path);} } // Set the window size SendMessage(dlg,WM_COMMAND,MAKELONG(BTN_PANEL,BN_CLICKED),0); // Load the last configuration if(Cfg_GetSel(0,port)==-1||Cfg_GetSel(0,iwad)==-1){MessageBox(dlg,STR_NOITEMS,"Error!",MB_OK|MB_ICONEXCLAMATION);break;} if(!cmdline[0]){Cfg_ReadSave(dlg,cfg.ini);break;} // Process the command-line stuff memset((tmp=malloc(MAX_PATH*sizeof(char))),0,MAX_PATH*sizeof(char)); for(i=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCOUNT,0,0);cmdline[q];i++){ if(i>=MAX_PWAD){MessageBox(dlg,STR_MAXPWAD,"Error!",MB_OK|MB_ICONEXCLAMATION);break;} for(q;cmdline[q];q++){ if(cmdline[q]=='\"'){m=(m)?(0):(1);continue;} if(r<MAX_PATH){tmp[r]=cmdline[q];r++;} if(cmdline[q]==' '&&!m){q++;break;} }tmp[(cmdline[q])?(r-1):(r)]='\0';r=0; // Check to see if it's a save file and act accordingly. if(!Dlg_AddPWAD(dlg,tmp)){ // Check if it's a save file and launch if(i==0&&strchr(tmp,'.')&&(!stricmp(strchr(tmp,'.'),".zdl")||!stricmp(strchr(tmp,'.'),".ini"))){ if(Cfg_ReadSave(dlg,tmp)){ free(tmp); if(cfg.launch){ // Launch if the option is set Dlg_Launch(dlg,0); Dlg_Quit(dlg,0); } }else{ free(tmp); if(cfg.launch){Dlg_Quit(dlg,0);} } }else{i--;} } } break; case WM_COMMAND:switch(HIWORD(wp)){ // File Info case LBN_DBLCLK:switch(LOWORD(wp)){ case LST_PWAD:MessageBox(dlg,pwad[SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCURSEL,0,0)],"File Info",MB_OK|MB_ICONINFORMATION);break; case LST_IWAD:MessageBox(dlg,iwad[Cfg_GetSel(SendMessage(GetDlgItem(dlg,LST_IWAD),LB_GETCURSEL,0,0),iwad)]->path,"File Info",MB_OK|MB_ICONINFORMATION);break; }break; // IWAD List case LBN_SELCHANGE:if(LOWORD(wp)==LST_IWAD){Dlg_PopulateWarp(dlg,iwad[Cfg_GetSel(SendMessage(GetDlgItem(dlg,LST_IWAD),LB_GETCURSEL,0,0),iwad)]->path);}break; // Buttons case BN_CLICKED:switch(LOWORD(wp)){ case BTN_LAUNCH:Dlg_Launch(dlg,0);break; case MNU_CMD:Dlg_Launch(dlg,1);break; case BTN_ZDL: GetCursorPos(&pt); TrackPopupMenu(GetSubMenu(LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(MNU_MENU)),0),TPM_LEFTALIGN,pt.x,pt.y,0,dlg,0); break; // Loading and Saving case MNU_SAVE:case MNU_LOAD: memset((ofn.lpstrFile=malloc(MAX_PATH*sizeof(char))),0,MAX_PATH*sizeof(char)); ofn.lpstrFilter="ZDL Save Files (*.zdl,*.ini)\0*.zdl;*.ini\0All Files (*.*)\0*.*\0"; ofn.lpstrDefExt="zdl"; ofn.Flags=(LOWORD(wp)==MNU_SAVE)?(OFN_EXPLORER):(OFN_FILEMUSTEXIST|OFN_EXPLORER); ofn.lpstrTitle=(LOWORD(wp)==MNU_SAVE)?("Save ZDL Config"):("Load a Saved ZDL Config"); if(LOWORD(wp)==MNU_SAVE){ if(GetSaveFileName(&ofn)&&(fptr=fopen(ofn.lpstrFile,"w"))){ Cfg_WriteSave(dlg,fptr); fclose(fptr); } }else{if(GetOpenFileName(&ofn)){Cfg_ReadSave(dlg,ofn.lpstrFile);}} free(ofn.lpstrFile); break; case MNU_CLEAR:Dlg_ClearAll(dlg);break; case MNU_PWAD:Dlg_ClearPWAD(dlg);break; // Open and close the multiplay panel case BTN_PANEL: rct.top=0;rct.left=0;rct.right=270;rct.bottom=(cfg.dlgmode)?(282):(210); cfg.dlgmode=(cfg.dlgmode)?(0):(1); AdjustWindowRect(&rct,WS_POPUP|WS_CAPTION,0); SetWindowPos(dlg,0,0,0,rct.right-rct.left,rct.bottom-rct.top,SWP_NOMOVE|SWP_NOZORDER); SendMessage(GetDlgItem(dlg,BTN_PANEL),BM_SETIMAGE,IMAGE_ICON,(LPARAM)LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE((cfg.dlgmode)?(ICO_DOWN):(ICO_UP)))); break; case BTN_ADD:if(pwad[MAX_PWAD-1]){MessageBox(dlg,"Too many PWADs loaded!","Error!",MB_OK|MB_ICONEXCLAMATION);break;} ofn.lpstrFilter="ZDoom Addon Files (*.wad,*.deh,*.bex,*.zip)\0*.wad;*.deh;*.bex;*.zip\0All Files (*.*)\0*.*\0"; ofn.Flags=OFN_FILEMUSTEXIST|OFN_EXPLORER|OFN_ALLOWMULTISELECT; ofn.lpstrTitle="Load an External File"; ofn.lpstrDefExt="wad"; // Get the file and set the editbox memset((ofn.lpstrFile=malloc(MAX_PATH*sizeof(char))),0,MAX_PATH*sizeof(char)); if(!GetOpenFileName(&ofn)){break;} i=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCOUNT,0,0); if(!ofn.nFileExtension){ // Multiple files memset((tmp2=malloc(MAX_PATH*sizeof(char))),0,MAX_PATH*sizeof(char)); tmp=ofn.lpstrFile+ofn.nFileOffset; for(i;i<MAX_PWAD&&tmp[0];i++){ _snprintf(tmp2,MAX_PATH,"%s\\%s",ofn.lpstrFile,tmp); if(!Dlg_AddPWAD(dlg,tmp2)){i--;} tmp+=strlen(tmp)+1; if(i+1>=MAX_PWAD){MessageBox(dlg,STR_MAXPWAD,"Error!",MB_OK|MB_ICONEXCLAMATION);break;} } free(tmp2); }else{Dlg_AddPWAD(dlg,ofn.lpstrFile);} free(ofn.lpstrFile); break; case BTN_REM: // Delete button if((i=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCURSEL,0,0))!=LB_ERR){ free(pwad[i]); SendMessage(GetDlgItem(dlg,LST_PWAD),LB_DELETESTRING,i,0); SendMessage(GetDlgItem(dlg,LST_PWAD),LB_SETCURSEL,i,0); for(i;pwad[i]&&i<MAX_PWAD;i++){pwad[i]=pwad[i+1];} } break; case BTN_UP: // Move up if((i=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCURSEL,0,0))!=LB_ERR&&i!=0){ // Move the entry in the window SendMessage(GetDlgItem(dlg,LST_PWAD),LB_INSERTSTRING,i-1,(LPARAM)strrchr(pwad[i],'\\')+1); SendMessage(GetDlgItem(dlg,LST_PWAD),LB_DELETESTRING,i+1,0); SendMessage(GetDlgItem(dlg,LST_PWAD),LB_SETCURSEL,i-1,0); // Move the item tmp=pwad[i-1];pwad[i-1]=pwad[i];pwad[i]=tmp; } break; case BTN_DWN: // Move down i=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCURSEL,0,0); if((i=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCURSEL,0,0))!=LB_ERR&&i!=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCOUNT,0,0)-1){ // Move the entry in the window SendMessage(GetDlgItem(dlg,LST_PWAD),LB_INSERTSTRING,i+2,(LPARAM)strrchr(pwad[i],'\\')+1); SendMessage(GetDlgItem(dlg,LST_PWAD),LB_DELETESTRING,i,0); SendMessage(GetDlgItem(dlg,LST_PWAD),LB_SETCURSEL,i+1,0); // Move the item tmp=pwad[i+1];pwad[i+1]=pwad[i];pwad[i]=tmp; } break; // Menu Selections case MNU_OPTIONS: DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(DLG_OPTIONS),dlg,ConfigProc); // Fill the port and IWAD arrays SendMessage(GetDlgItem(dlg,LST_PORT),CB_RESETCONTENT,0,0); for(i=0;port[i]&&i<MAX_ITEM;i++){if(port[i]->avail){SendMessage(GetDlgItem(dlg,LST_PORT),CB_ADDSTRING,0,(LPARAM)port[i]->name);}} SendMessage(GetDlgItem(dlg,LST_PORT),CB_SETCURSEL,0,0); SendMessage(GetDlgItem(dlg,LST_IWAD),LB_RESETCONTENT,0,0); for(i=0;iwad[i]&&i<MAX_ITEM;i++){if(iwad[i]->avail){SendMessage(GetDlgItem(dlg,LST_IWAD),LB_ADDSTRING,0,(LPARAM)iwad[i]->name);}} SendMessage(GetDlgItem(dlg,LST_IWAD),LB_SETCURSEL,0,0); SendMessage(GetDlgItem(dlg,LST_WARP),CB_RESETCONTENT,0,0); if(SendMessage(GetDlgItem(dlg,LST_IWAD),LB_GETCURSEL,0,0)!=LB_ERR){Dlg_PopulateWarp(dlg,iwad[Cfg_GetSel(0,iwad)]->path);} break; case MNU_ABOUT:DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(DLG_ABOUT),dlg,AboutProc);break; // Ways to exit case BTN_EXIT:SendMessage(dlg,WM_CLOSE,0,0);break; }break; }break; case WM_DROPFILES: // Add files dropped onto the pwad box r=DragQueryFile((HDROP)wp,0xFFFFFFFF,0,0); memset((tmp2=malloc(MAX_PATH*sizeof(char))),0,MAX_PATH*sizeof(char)); for(i=SendMessage(GetDlgItem(dlg,LST_PWAD),LB_GETCOUNT,0,0);q<r;i++){ if(i>=MAX_PWAD){MessageBox(dlg,STR_MAXPWAD,"Error!",MB_OK|MB_ICONEXCLAMATION);break;} DragQueryFile((HDROP)wp,q,tmp2,MAX_PATH); if(!Dlg_AddPWAD(dlg,tmp2)){i--;} q++;} DragFinish((HDROP)wp); free(tmp2); break; case WM_CLOSE:Dlg_Quit(dlg,1);break; }return 0; }
BOOL CDialogBar::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID) { ASSERT(pParentWnd != NULL); ASSERT(lpszTemplateName != NULL); #ifdef _DEBUG // dialog template must exist and be invisible with WS_CHILD set if (!_AfxCheckDialogTemplate(lpszTemplateName, TRUE)) { ASSERT(FALSE); // invalid dialog template name PostNcDestroy(); // cleanup if Create fails too soon return FALSE; } #endif //_DEBUG // allow chance to modify styles m_dwStyle = (nStyle & CBRS_ALL); CREATESTRUCT cs; memset(&cs, 0, sizeof(cs)); cs.lpszClass = _afxWndControlBar; cs.style = (DWORD)nStyle | WS_CHILD; cs.hMenu = (HMENU)nID; cs.hInstance = AfxGetInstanceHandle(); cs.hwndParent = pParentWnd->GetSafeHwnd(); if (!PreCreateWindow(cs)) return FALSE; // create a modeless dialog #ifndef _AFX_NO_OCC_SUPPORT m_lpszTemplateName = lpszTemplateName; #endif // initialize common controls VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG)); AfxDeferRegisterClass(AFX_WNDCOMMCTLSNEW_REG); BOOL bSuccess = CreateDlg(lpszTemplateName, pParentWnd); #ifndef _AFX_NO_OCC_SUPPORT m_lpszTemplateName = NULL; #endif if (!bSuccess) return FALSE; // dialog template MUST specify that the dialog // is an invisible child window SetDlgCtrlID(nID); CRect rect; GetWindowRect(&rect); m_sizeDefault = rect.Size(); // set fixed size // force WS_CLIPSIBLINGS ModifyStyle(0, WS_CLIPSIBLINGS); if (!ExecuteDlgInit(lpszTemplateName)) return FALSE; // force the size to zero - resizing bar will occur later SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW); return TRUE; }
INT_PTR CALLBACK BindProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { M3Mat *mp = DLGetWindowLongPtr<M3Mat*>(hWnd); if (!mp && msg!=WM_INITDIALOG) return FALSE; int id = LOWORD(wParam); int notify = HIWORD(wParam); switch (msg) { case WM_INITDIALOG: { mp = (M3Mat*)lParam; DLSetWindowLongPtr(hWnd, mp); HWND modList = GetDlgItem(hWnd,IDC_MODLIST); SendMessage(modList,LB_RESETCONTENT,0,0); POINT lpPt; GetCursorPos(&lpPt); SetWindowPos(hWnd, NULL, lpPt.x, lpPt.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER); Object *pObj = mp->Wnode->GetObjectRef(); IDerivedObject *pDerObj = NULL; Modifier *pMod = NULL; if( pObj->SuperClassID() == GEN_DERIVOB_CLASS_ID) { pDerObj = (IDerivedObject *) pObj; for(int i = 0 ; i < pDerObj->NumModifiers() ; i++ ) { pMod = pDerObj->GetModifier(i); SendMessage(modList,LB_ADDSTRING,0,(LPARAM) (LPCTSTR) pMod->GetName()); } } SendMessage(modList,LB_SETCURSEL ,(WPARAM)-1,0); break; } case WM_COMMAND: if (notify==LBN_SELCHANGE) { if(id==IDC_MODLIST) { int mkSel = (int)SendMessage(GetDlgItem(hWnd, IDC_MODLIST), LB_GETCURSEL, 0, 0); if(mkSel>=0) { Object *pObj = mp->Wnode->GetObjectRef(); IDerivedObject *pDerObj = NULL; Modifier *pMod = NULL; if( pObj->SuperClassID() == GEN_DERIVOB_CLASS_ID) { pDerObj = (IDerivedObject *) pObj; pMod = pDerObj->GetModifier(mkSel); if(pMod->ClassID() == MR3_CLASS_ID) EnableWindow(GetDlgItem(hWnd,IDOK),TRUE); else EnableWindow(GetDlgItem(hWnd,IDOK),FALSE); } } } } switch (id) { case IDOK: { int mkSel = (int)SendMessage(GetDlgItem(hWnd, IDC_MODLIST), LB_GETCURSEL, 0, 0); if(mkSel>=0) { Object *pObj = mp->Wnode->GetObjectRef(); IDerivedObject *pDerObj = NULL; Modifier *pMod = NULL; if( pObj->SuperClassID() == GEN_DERIVOB_CLASS_ID) { pDerObj = (IDerivedObject *) pObj; pMod = pDerObj->GetModifier(mkSel); MorphR3 *mod = (MorphR3*)pMod; if(mod->CheckMaterialDependency() ) { EndDialog(hWnd,1); return TRUE; } // Make sure the node does not depend on us mod->BeginDependencyTest(); mp->NotifyDependents(FOREVER,0,REFMSG_TEST_DEPENDENCY); if (mod->EndDependencyTest()) { // display cyclic warning // if (GetCOREInterface()->GetQuietMode()) { TSTR cyclic; cyclic = GetString(IDS_CANNOT_BIND); GetCOREInterface()->Log()->LogEntry(SYSLOG_WARN,NO_DIALOG,GetString(IDS_CLASS_NAME),cyclic); } else { TSTR cyclic; cyclic = GetString(IDS_CANNOT_BIND); MessageBox(hWnd,cyclic,GetString(IDS_CLASS_NAME),MB_OK); } EndDialog(hWnd,1); return TRUE; } if(mod) mod->morphmaterial = mp; mp->ReplaceReference(102, mod); mp->obName = mp->Wnode->GetName(); mp->morphp = mod; if (mp->matDlg ) { mp->matDlg->UpdateMorphInfo(UD_LINK); mp->matDlg->ReloadDialog(); } } } } case IDCANCEL: EndDialog(hWnd,1); break; } break; default: return FALSE; } return TRUE; }
/* * Resize the current window so that it fits the whole screen */ void FGAPIENTRY glutFullScreen( void ) { freeglut_assert_ready; freeglut_assert_window; { #if TARGET_HOST_UNIX_X11 int x, y; Window w; XMoveResizeWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, 0, 0, fgDisplay.ScreenWidth, fgDisplay.ScreenHeight ); XFlush( fgDisplay.Display ); /* This is needed */ XTranslateCoordinates( fgDisplay.Display, fgStructure.Window->Window.Handle, fgDisplay.RootWindow, 0, 0, &x, &y, &w ); if (x || y) { XMoveWindow( fgDisplay.Display, fgStructure.Window->Window.Handle, -x, -y ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ } #elif TARGET_HOST_WIN32 RECT rect; /* For fullscreen mode, force the top-left corner to 0,0 * and adjust the window rectangle so that the client area * covers the whole screen. */ rect.left = 0; rect.top = 0; rect.right = fgDisplay.ScreenWidth; rect.bottom = fgDisplay.ScreenHeight; AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, FALSE ); /* * SWP_NOACTIVATE Do not activate the window * SWP_NOOWNERZORDER Do not change position in z-order * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message * SWP_NOZORDER Retains the current Z order (ignore 2nd param) */ SetWindowPos( fgStructure.Window->Window.Handle, HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOZORDER ); #endif } }
void Window::SetSize(const WinPoint& point) { SetWindowPos(m_hwnd, NULL, 0, 0, point.X(), point.Y(), SWP_NOMOVE | SWP_NOZORDER); }
void ProjectConfigDialog::onInitDialog(HWND hwndDialog) { SimulatorConfig *defaults = SimulatorConfig::sharedDefaults(); m_hwndDialog = hwndDialog; HWND list = GetDlgItem(m_hwndDialog, IDC_COMBO_SCREEN_SIZE); updateProjectDir(); updateScriptFile(); updatePackagePath(); BOOL isLandscape = FALSE; int currentSizeIndex = defaults->checkScreenSize(m_project.getFrameSize()); if (currentSizeIndex < 0) { currentSizeIndex = 0; } else { isLandscape = m_project.isLandscapeFrame(); } for (int i = 0; i < defaults->numScreenSize(); ++i) { const SimulatorScreenSize &size = defaults->getScreenSize(i); wstring title; title.assign(size.title.begin(), size.title.end()); ComboBox_AddString(list, title.c_str()); if (i == currentSizeIndex) { char buff[32]; sprintf_s(buff, "%d", isLandscape ? size.height : size.width); SetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH, buff); sprintf_s(buff, "%d", isLandscape ? size.width : size.height); SetDlgItemTextA(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT, buff); } } ComboBox_AddString(list, L"Custom Size"); ComboBox_SetCurSel(list, currentSizeIndex); Edit_LimitText(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_WIDTH), 4); Edit_LimitText(GetDlgItem(m_hwndDialog, IDC_EDIT_SCREEN_HEIGHT), 4); HWND direction = GetDlgItem(m_hwndDialog, IDC_RADIO_PORTRAIT); CheckRadioButton(m_hwndDialog, IDC_RADIO_PORTRAIT, IDC_RADIO_LANDSCAPE, isLandscape ? IDC_RADIO_LANDSCAPE : IDC_RADIO_PORTRAIT); Button_SetCheck(GetDlgItem(m_hwndDialog, IDC_CHECK_SHOW_DEBUG_CONSOLE), m_project.isShowConsole()); // set dialog caption, button caption SetWindowTextA(m_hwndDialog, m_dialogCaption.c_str()); SetDlgItemTextA(m_hwndDialog, IDOK, m_buttonCaption.c_str()); // center a dialog box within its owner window RECT rc, rcOwner, rcDlg; GetWindowRect(m_hwnd, &rcOwner); GetWindowRect(m_hwndDialog, &rcDlg); CopyRect(&rc, &rcOwner); OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); OffsetRect(&rc, -rc.left, -rc.top); OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); SetWindowPos(m_hwndDialog, HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, // Ignores size arguments. SWP_NOSIZE); }
// This seems pure front end LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { static SnapData sd; char buf[MSG_SIZ], mess[MSG_SIZ]; int partner = -1, i, x, y; static BOOL filterHasFocus[MAX_CHAT]; WORD wMask; HWND hMemo; for(i=0; i<MAX_CHAT; i++) if(hDlg == chatHandle[i]) { partner = i; break; } switch (message) { case WM_INITDIALOG: Translate(hDlg, DLG_Chat); if(partner<0) { for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] == NULL) { partner = i; break; } chatHandle[partner] = hDlg; snprintf(buf, MSG_SIZ, T_("Chat Window %s"), ics_handle[0] ? ics_handle : first.tidy); SetWindowText(hDlg, buf); } for(i=0; i<MAX_CHAT; i++) if(chatHandle[i]) { if(i == partner) continue; // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]); EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 1 ); // and buttons for other chats in ours SetDlgItemText(hDlg, IDC_Focus1+i-(i>partner), chatPartner[i]); } else EnableWindow( GetDlgItem(hDlg, IDC_Focus1+i-(i>partner)), 0 ); for(i=0; i<MAX_CHAT-1; i++) { Button_SetStyle(GetDlgItem(hDlg, IDC_Focus1+i), BS_PUSHBUTTON|BS_LEFT, TRUE); } x = wpConsole.x; y = wpConsole.y; EnsureOnScreen(&x, &y, 0, 0); SetWindowPos(hDlg, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE); SendMessage( GetDlgItem(hDlg, IDC_ChatPartner), // [HGM] clickbox: initialize with requested handle WM_SETTEXT, 0, (LPARAM) chatPartner[partner] ); filterHasFocus[partner] = TRUE; onTop = partner; // a newly opened box becomes top one if(chatPartner[partner][0]) { filterHasFocus[partner] = FALSE; SetFocus( GetDlgItem(hDlg, OPT_ChatInput) ); } hMemo = GetDlgItem(hDlg, IDC_ChatMemo); wMask = (WORD) SendMessage(hMemo, EM_GETEVENTMASK, 0, 0L); SendMessage(hMemo, EM_SETEVENTMASK, 0, wMask | ENM_LINK); SendMessage(hMemo, EM_AUTOURLDETECT, TRUE, 0L); chatInputWindowProc = (WNDPROC) // cloned from ConsoleWndProc(). Assume they all share same proc. SetWindowLongPtr(GetDlgItem(hDlg, OPT_ChatInput), GWLP_WNDPROC, (LONG_PTR) InterceptArrowKeys); return FALSE; case WM_NOTIFY: if (((NMHDR*)lParam)->code == EN_LINK) { ENLINK *pLink = (ENLINK*)lParam; if (pLink->msg == WM_LBUTTONUP) { TEXTRANGE tr; tr.chrg = pLink->chrg; tr.lpstrText = malloc(1+tr.chrg.cpMax-tr.chrg.cpMin); SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), EM_GETTEXTRANGE, 0, (LPARAM)&tr); ShellExecute(NULL, "open", tr.lpstrText, NULL, NULL, SW_SHOW); free(tr.lpstrText); } } break; case WM_COMMAND: /* [AS] If <Enter> is pressed while editing the filter, it's better to apply the filter rather than selecting the current game. */ if( LOWORD(wParam) == IDC_ChatPartner ) { switch( HIWORD(wParam) ) { case EN_SETFOCUS: filterHasFocus[partner] = TRUE; break; case EN_KILLFOCUS: filterHasFocus[partner] = FALSE; break; } } if( filterHasFocus[partner] && (LOWORD(wParam) == IDC_Send) ) { SetFocus(GetDlgItem(hDlg, OPT_ChatInput)); wParam = IDC_Change; } /* [AS] End command replacement */ switch (LOWORD(wParam)) { case IDCANCEL: /* let Esc key switch focus back to console */ SetFocus(GetDlgItem(hwndConsole, OPT_ConsoleInput)); break; case IDC_Clear: SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), WM_SETTEXT, 0, (LPARAM) "" ); break; case IDC_Change: GetDlgItemText(hDlg, IDC_ChatPartner, chatPartner[partner], MSG_SIZ); for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) { // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]); } break; case IDC_Send: GetDlgItemText(hDlg, OPT_ChatInput, mess, MSG_SIZ); SetDlgItemText(hDlg, OPT_ChatInput, ""); // from here on it could be back-end SaveInHistory(mess); if(!strcmp("whispers", chatPartner[partner])) snprintf(buf, MSG_SIZ, "whisper %s\n", mess); // WHISPER box uses "whisper" to send else if(!strcmp("shouts", chatPartner[partner])) snprintf(buf, MSG_SIZ, "shout %s\n", mess); // SHOUT box uses "shout" to send else { if(!atoi(chatPartner[partner])) { snprintf(buf, MSG_SIZ, "> %s\r\n", mess); // echo only tells to handle, not channel InsertIntoMemo(hDlg, buf); snprintf(buf, MSG_SIZ, "xtell %s %s\n", chatPartner[partner], mess); } else snprintf(buf, MSG_SIZ, "tell %s %s\n", chatPartner[partner], mess); } SendToICS(buf); break; case IDC_Focus1: case IDC_Focus2: case IDC_Focus3: case IDC_Focus4: i = LOWORD(wParam) - IDC_Focus1; if(i >= partner) i++; onTop = i; SetFocus(GetDlgItem(hDlg, IDC_Send)); if(chatHandle[i]) { int j; for(j=0; j<MAX_CHAT; j++) if(i != j && chatHandle[j]) Button_SetState(GetDlgItem(chatHandle[j], IDC_Focus1+i-(j<i)), FALSE); SetFocus(GetDlgItem(chatHandle[i], OPT_ChatInput)); } break; default: break; } break; case WM_CLOSE: chatHandle[partner] = 0; chatPartner[partner][0] = 0; ChatPopDown(); for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) { // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), ""); EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 0 ); } EndDialog(hDlg, TRUE); break; case WM_SIZE: ResizeWindowControls( hDlg ); break; case WM_ENTERSIZEMOVE: return OnEnterSizeMove( &sd, hDlg, wParam, lParam ); case WM_SIZING: return OnSizing( &sd, hDlg, wParam, lParam ); case WM_MOVING: return OnMoving( &sd, hDlg, wParam, lParam ); case WM_EXITSIZEMOVE: return OnExitSizeMove( &sd, hDlg, wParam, lParam ); } return FALSE; }
LRESULT dsp_preset_switcher::on_message( HWND parent_wnd , UINT msg , WPARAM wp , LPARAM lp ) { switch( msg ) { case WM_CREATE: { if( wnd_my_combo_box != NULL ) { console::printf( CONSOLE_HEADER "Error: wnd_my_combo_box != NULL" ); return -1; } if( ui_hfont != NULL ) { console::printf( CONSOLE_HEADER "Error: ui_hfont != NULL" ); return -1; } // get columns UI font ui_hfont = uCreateIconFont(); if( ui_hfont == NULL ) { console::printf( CONSOLE_HEADER "uCreateIconFont() failed" ); return -1; } wnd_my_combo_box = CreateWindowEx( 0 , WC_COMBOBOX , nullptr , ( CBS_DROPDOWNLIST | CBS_SORT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ) , 0 , 0 , INIT_WIDTH , CW_USEDEFAULT , parent_wnd , NULL , core_api::get_my_instance() , nullptr ); if( wnd_my_combo_box == NULL ) { console::printf( CONSOLE_HEADER "CreateWindowEx() failed" ); DeleteFont( ui_hfont ); ui_hfont = NULL; return -1; } dsp_preset_switcher::PARENT_HWND_LIST.remove_item( parent_wnd ); dsp_preset_switcher::PARENT_HWND_LIST.add_item( parent_wnd ); // Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message. // Sets the font that a control is to use when drawing text. uSendMessage( wnd_my_combo_box , WM_SETFONT , ( WPARAM ) ui_hfont , MAKELPARAM( 1 , 0 ) ); // get metrics RECT rc; GetWindowRect( wnd_my_combo_box , &rc ); HEIGHT = RECT_CY( rc ); // get dsp names and add to combo box pfc::list_t<pfc::string8> l; initEntries( l ); // set initial selection const bool ret = setEntry( CFG_IDX ); if( !ret ) CFG_IDX = -1; // determine width // MSDN Remarks: After an application has finished drawing with the new font object , it should always replace a new font object with the original font object. CONST HDC dc = GetDC( wnd_my_combo_box ); CONST HFONT font_old = SelectFont( dc , ui_hfont ); for( t_size i = 0 , imax = l.get_count(); i < imax ; ++i ) { const char *str = l[i].get_ptr(); const int cx = ui_helpers::get_text_width( dc , str , strlen( str ) ); min_width = max( min_width , ( t_size ) cx ); } SelectFont( dc , font_old ); ReleaseDC( parent_wnd , dc ); // get min width COMBOBOXINFO cbi = { 0 }; cbi.cbSize = sizeof( cbi ); GetComboBoxInfo( wnd_my_combo_box , &cbi ); RECT rc_client; GetClientRect( wnd_my_combo_box , &rc_client ); min_width += RECT_CX( rc_client ) - RECT_CX( cbi.rcItem ); return 0; } case WM_DESTROY: { dsp_preset_switcher::PARENT_HWND_LIST.remove_item( GetParent( wnd_my_combo_box ) ); DestroyWindow( wnd_my_combo_box ); wnd_my_combo_box = NULL; DeleteFont( ui_hfont ); ui_hfont = NULL; return 0; } case WM_GETMINMAXINFO: { CONST LPMINMAXINFO ptr = ( LPMINMAXINFO ) lp; ptr->ptMinTrackSize.x = min_width; ptr->ptMinTrackSize.y = HEIGHT; ptr->ptMaxTrackSize.y = HEIGHT; return 0; } case WM_WINDOWPOSCHANGED: { CONST LPWINDOWPOS ptr = ( LPWINDOWPOS ) lp; if( !( ptr->flags & SWP_NOSIZE ) ) { SetWindowPos( wnd_my_combo_box , HWND_TOP , 0 , 0 , ptr->cx , HEIGHT , SWP_NOZORDER ); } return 0; } case WM_COMMAND: { if( wp == ( CBN_SELCHANGE << 16 ) ) { int idx; pfc::string8 text; bool ret = getSelection( idx , text ); if( !ret ) break; CFG_IDX = idx; ret = selDspName( idx , text.get_ptr() ); if( !ret ) syncSelection( -1 ); return 0; } break; } case WM_USER_DSP_CORE_CHANGE: { if( skip_msg ) { skip_msg = false; return 0; } // just rescan DSP name entries and remove the current selected one pfc::list_t<pfc::string8> d; initEntries( d ); CFG_IDX = -1; return 0; } case WM_USER_SYNC_CHANGE: { if( wp == -1 ) { pfc::list_t<pfc::string8> l; initEntries( l ); return 0; } skip_msg = true; setEntry( wp ); return 0; } default: { //console::printf( CONSOLE_HEADER "default case: %u" , msg ); break; } } // Calls the default window procedure to provide default processing for any window messages that an application does not process. // This function ensures that every message is processed. return uDefWindowProc( parent_wnd , msg , wp , lp ); }
static void SetControlPos( HWND hDlg, int id, int x, int y, int width, int height ) { HWND hControl = GetDlgItem( hDlg, id ); SetWindowPos( hControl, HWND_TOP, x, y, width, height, SWP_NOZORDER ); }
LRESULT CALLBACK TextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND control; HDC hdc; PNHTextWindow data; data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA); switch (message) { case WM_INITDIALOG: /* set text control font */ control = GetDlgItem(hWnd, IDC_TEXT_CONTROL); if( !control ) { panic("cannot get text view window"); } hdc = GetDC(control); SendMessage(control, WM_SETFONT, (WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0); ReleaseDC(control, hdc); #if defined(WIN_CE_SMARTPHONE) /* special initialization for SmartPhone dialogs */ NHSPhoneDialogSetup(hWnd, FALSE, GetNHApp()->bFullScreen); #endif /* subclass edit control */ editControlWndProc = (WNDPROC)GetWindowLong(control, GWL_WNDPROC); SetWindowLong(control, GWL_WNDPROC, (LONG)NHTextControlWndProc); if( !program_state.gameover && GetNHApp()->bWrapText ) { DWORD styles; styles = GetWindowLong(control, GWL_STYLE); if( styles ) { SetWindowLong(control, GWL_STYLE, styles & (~WS_HSCROLL)); SetWindowPos(control, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE ); } } SetFocus(control); return FALSE; case WM_MSNH_COMMAND: onMSNHCommand(hWnd, wParam, lParam); break; case WM_SIZE: LayoutText(hWnd); return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: data->done = 1; return TRUE; } break; case WM_CTLCOLORBTN: case WM_CTLCOLOREDIT: case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */ HDC hdcEdit = (HDC) wParam; HWND hwndEdit = (HWND) lParam; if( hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL) ) { SetBkColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_BG)); SetTextColor(hdcEdit, mswin_get_color(NHW_TEXT, MSWIN_COLOR_FG)); return (BOOL)mswin_get_brush(NHW_TEXT, MSWIN_COLOR_BG); } } return FALSE; case WM_DESTROY: if( data ) { mswin_free_text_buffer(data->window_text); free(data); SetWindowLong(hWnd, GWL_USERDATA, (LONG)0); } break; } return FALSE; }
LRESULT CALLBACK MCIDlgHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { char szFileName[MAX_PATH]; MCIOBJ * st; st = (MCIOBJ *) actobject; if ((st==NULL)||(st->type!=OB_MCIPLAYER)) return(FALSE); switch( message ) { case WM_INITDIALOG: SetDlgItemText(hDlg, IDC_MCIFILE, st->mcifile); SCROLLINFO lpsi; lpsi.cbSize=sizeof(SCROLLINFO); lpsi.fMask=SIF_RANGE|SIF_POS; lpsi.nMin=4; lpsi.nMax=5000; SetScrollInfo(GetDlgItem(hDlg,IDC_SPEEDUPDATEBAR),SB_CTL,&lpsi, TRUE); SetScrollPos(GetDlgItem(hDlg,IDC_SPEEDUPDATEBAR), SB_CTL,st->upd_speed, TRUE); SetDlgItemInt(hDlg, IDC_UPDATESPEED, st->upd_speed, FALSE); SetDlgItemInt(hDlg, IDC_POS_CENTER, st->pos_center, FALSE); CheckDlgButton(hDlg, IDC_PLAY_ONCE, st->play_once); return TRUE; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_OPEN: if (!(strcmp(st->mcifile,"none"))) { strcpy(szFileName,GLOBAL.resourcepath); strcat(szFileName,"MOVIES\\*.avi"); } else strcpy (szFileName,st->mcifile); if (open_file_dlg(hDlg, szFileName, FT_AVI, OPEN_LOAD)) { st->playing=FALSE; strcpy(st->mcifile,szFileName); SetDlgItemText(hDlg, IDC_MCIFILE, st->mcifile); } InvalidateRect(hDlg,NULL,FALSE); break; case IDC_PLAY_ONCE: st->play_once=IsDlgButtonChecked(hDlg,IDC_PLAY_ONCE); break; case IDC_LOAD: if (st->m_video) { MCIWndStop(st->m_video); MCIWndDestroy(st->m_video); } st->m_video = MCIWndCreate(ghWndMain, hInst,WS_VISIBLE|WS_THICKFRAME|MCIWNDF_NOERRORDLG,st->mcifile); if (!st->m_video) report_error ("Cannot open MCI File"); else { RECT prc; MCIWndSetZoom(st->m_video,100); MCIWndGetSource(st->m_video,&prc); MCIWndSetTimeFormat(st->m_video ,"ms"); MCIWndSetActiveTimer(st->m_video,500); if ((!strstr(st->mcifile,".mp3")) && (!strstr(st->mcifile,".wav"))) SetWindowPos(st->m_video,HWND_TOPMOST,st->left,st->top,st->left+prc.right-prc.left,st->top+prc.bottom-prc.top,SWP_SHOWWINDOW); else ShowWindow(st->m_video,FALSE); } break; case IDC_MCIPLAY: if (st->m_video) { MCIWndSetSpeed(st->m_video,st->speed); MCIWndPlay(st->m_video); st->playing=TRUE; } break; case IDC_MCISTOP: if (st->m_video) { MCIWndStop(st->m_video);} // MCIWndDestroy(st->m_video); } st->playing=FALSE; break; case IDC_MCIPLUS: st->speed+=50; if (st->m_video) { MCIWndSetSpeed(st->m_video,st->speed); //MCIWndStep(st->m_video,2); MCIWndPlay(st->m_video); } break; case IDC_MCIMINUS: st->speed-=50; if (st->m_video) { MCIWndSetSpeed(st->m_video,st->speed); //MCIWndStep(st->m_video,2); MCIWndPlay(st->m_video); } break; case IDC_POS_CENTER: st->pos_center=GetDlgItemInt(hDlg,IDC_POS_CENTER,0,FALSE); break; } break; case WM_HSCROLL: { int nNewPos; nNewPos = get_scrollpos(wParam,lParam); if (lParam == (long) GetDlgItem(hDlg,IDC_SPEEDUPDATEBAR)) { SetDlgItemInt(hDlg, IDC_UPDATESPEED, nNewPos, TRUE); st->upd_speed=nNewPos; } break; } case WM_SIZE: case WM_MOVE: update_toolbox_position(hDlg); break; } return FALSE; }
VOID PropertiesUpdate( IN PCONSOLE_INFORMATION Console, IN HANDLE hClientSection ) /*++ Updates the console state from information sent by the properties dialog box. --*/ { HANDLE hSection; ULONG ulViewSize; NTSTATUS Status; PCONSOLE_STATE_INFO pStateInfo; PCONSOLE_PROCESS_HANDLE ProcessHandleRecord; PSCREEN_INFORMATION ScreenInfo; ULONG FontIndex; WINDOWPLACEMENT wp; COORD NewSize; /* * Map the shared memory block handle into our address space. */ ProcessHandleRecord = CONTAINING_RECORD(Console->ProcessHandleList.Blink, CONSOLE_PROCESS_HANDLE, ListLink); Status = NtDuplicateObject(ProcessHandleRecord->ProcessHandle, hClientSection, NtCurrentProcess(), &hSection, 0, 0, DUPLICATE_SAME_ACCESS); if (!NT_SUCCESS(Status)) { KdPrint(("CONSRV: error %x mapping client handle\n", Status)); return; } /* * Get a pointer to the shared memory block. */ pStateInfo = NULL; ulViewSize = 0; Status = NtMapViewOfSection(hSection, NtCurrentProcess(), &pStateInfo, 0, 0, NULL, &ulViewSize, ViewUnmap, 0, PAGE_READONLY); if (!NT_SUCCESS(Status)) { KdPrint(("CONSRV: error %x mapping view of file\n", Status)); NtClose(hSection); return; } /* * Verify the size of the shared memory block. */ if (ulViewSize < sizeof(CONSOLE_STATE_INFO)) { KdPrint(("CONSRV: sizeof(hSection) < sizeof(CONSOLE_STATE_INFO)\n")); NtUnmapViewOfSection(NtCurrentProcess(), pStateInfo); NtClose(hSection); return; } /* * Update the console state from the supplied values. */ ScreenInfo = Console->CurrentScreenBuffer; if (!(Console->Flags & CONSOLE_VDM_REGISTERED) && (pStateInfo->ScreenBufferSize.X != ScreenInfo->ScreenBufferSize.X || pStateInfo->ScreenBufferSize.Y != ScreenInfo->ScreenBufferSize.Y)) { ResizeScreenBuffer(ScreenInfo, pStateInfo->ScreenBufferSize, TRUE); } FontIndex = FindCreateFont(pStateInfo->FontFamily, pStateInfo->FaceName, pStateInfo->FontSize, pStateInfo->FontWeight); SetScreenBufferFont(ScreenInfo, FontIndex); SetCursorInformation(ScreenInfo, pStateInfo->CursorSize, ScreenInfo->BufferInfo.TextInfo.CursorVisible); NewSize.X = min(pStateInfo->WindowSize.X, ScreenInfo->MaximumWindowSize.X); NewSize.Y = min(pStateInfo->WindowSize.Y, ScreenInfo->MaximumWindowSize.Y); if (NewSize.X != CONSOLE_WINDOW_SIZE_X(ScreenInfo) || NewSize.Y != CONSOLE_WINDOW_SIZE_Y(ScreenInfo)) { wp.length = sizeof(wp); GetWindowPlacement(Console->hWnd, &wp); wp.rcNormalPosition.right += (NewSize.X - CONSOLE_WINDOW_SIZE_X(ScreenInfo)) * SCR_FONTSIZE(ScreenInfo).X; wp.rcNormalPosition.bottom += (NewSize.Y - CONSOLE_WINDOW_SIZE_Y(ScreenInfo)) * SCR_FONTSIZE(ScreenInfo).Y; SetWindowPlacement(Console->hWnd, &wp); } #ifdef _X86_ if (FullScreenInitialized) { if (pStateInfo->FullScreen == FALSE) { if (Console->FullScreenFlags & CONSOLE_FULLSCREEN) { ConvertToWindowed(Console); ASSERT(!(Console->FullScreenFlags & CONSOLE_FULLSCREEN_HARDWARE)); Console->FullScreenFlags = 0; ChangeDispSettings(Console, Console->hWnd, 0); } } else { if (Console->FullScreenFlags == 0) { ConvertToFullScreen(Console); Console->FullScreenFlags |= CONSOLE_FULLSCREEN; ChangeDispSettings(Console, Console->hWnd, CDS_FULLSCREEN); } } } #endif if (pStateInfo->QuickEdit) { Console->Flags |= CONSOLE_QUICK_EDIT_MODE; } else { Console->Flags &= ~CONSOLE_QUICK_EDIT_MODE; } if (pStateInfo->AutoPosition) { Console->Flags |= CONSOLE_AUTO_POSITION; } else { Console->Flags &= ~CONSOLE_AUTO_POSITION; SetWindowPos(Console->hWnd, NULL, pStateInfo->WindowPosX, pStateInfo->WindowPosY, 0, 0, SWP_NOZORDER | SWP_NOSIZE); } if (Console->InsertMode != pStateInfo->InsertMode) { SetCursorMode(ScreenInfo, FALSE); Console->InsertMode = pStateInfo->InsertMode; } RtlCopyMemory(Console->ColorTable, pStateInfo->ColorTable, sizeof(Console->ColorTable)); SetScreenColors(ScreenInfo, pStateInfo->ScreenAttributes, pStateInfo->PopupAttributes, TRUE); Console->CommandHistorySize = pStateInfo->HistoryBufferSize; Console->MaxCommandHistories = pStateInfo->NumberOfHistoryBuffers; if (pStateInfo->HistoryNoDup) { Console->Flags |= CONSOLE_HISTORY_NODUP; } else { Console->Flags &= ~CONSOLE_HISTORY_NODUP; } NtUnmapViewOfSection(NtCurrentProcess(), pStateInfo); NtClose(hSection); return; }
//----------------------------------------------------------------------------- // Name: WinMain() // Desc: The application's entry point //----------------------------------------------------------------------------- INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ) { // Register the window class WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW, MsgProc, 0L, 0L, GetModuleHandle( NULL ), NULL, 0/*LoadCursorFromFile( "..\\data\\Cursor\\cur_normal.cur" )*/ /*LoadCursor(hInst, IDC_ARROW)*/, NULL, NULL, "Tale", NULL }; RegisterClassEx( &wc ); // Create the application's window std::string filename = ".\\GameConfig.cfg"; g_iGameWindowHeight = ::GetPrivateProfileInt( "system", "height", 600, filename.c_str() ); g_iGameWindowWidth = ::GetPrivateProfileInt( "system", "width", 800, filename.c_str() ); ::hWnd = CreateWindow( "Tale", "Tale", WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, 0, 0, g_iGameWindowWidth + 6, g_iGameWindowHeight + 32, NULL, NULL, wc.hInstance, NULL ); ::hInst = hInst; ////////////////屏幕居中 HWND hParentOrOwner; RECT rc, rc2; if ( ( hParentOrOwner = GetParent( hWnd ) ) == NULL ) SystemParametersInfo( SPI_GETWORKAREA, 0, &rc, 0 ); else GetClientRect( hParentOrOwner, &rc ); GetWindowRect( hWnd, &rc2 ); g_iWinX = ((rc.right-rc.left) - (rc2.right-rc2.left)) / 2 +rc.left; g_iWinY = ((rc.bottom-rc.top) - (rc2.bottom-rc2.top)) / 2 +rc.top; SetWindowPos(hWnd, HWND_TOP, g_iWinX, g_iWinY, 0, 0, SWP_NOSIZE); //////////////////////////////// // Show the window ShowWindow( hWnd, SW_SHOW ); UpdateWindow( hWnd ); CTaleMain taleMain; taleMain.Init(); // Enter the message loop MSG msg; ZeroMemory( &msg, sizeof( msg ) ); while( msg.message != WM_QUIT ) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { long _time = GetTickCount(); if(_time - g_OldTime<15) Sleep(1); else { g_OldTime = _time; if ( !taleMain.Update() ) break; } } } UnregisterClass( "Tale", wc.hInstance ); return 0; }