📄 wizard.cpp
字号:
hItem = AddItemToTree(hWnd, lpDPSessionDesc->lpszSessionNameA, (DWORD)lpGuid, 1);
#endif
TreeView_SelectItem(hWnd, hItem);*/
return(TRUE);
}
/*
* EnumPlayer
*
* EnumeratePlayer callback. Inserts player information into the passed in tree view control.
*/
BOOL WINAPI EnumPlayer(DPID pidID, DWORD dwPlayerType, LPCDPNAME lpName,
DWORD dwFlags, LPVOID lpContext)
{
HWND hWnd = (HWND) lpContext;
HTREEITEM hItem;
//here Add Item to tree
/*#ifdef UNICODE
hItem = AddItemToTree(hWnd, lpName->lpszShortName, 0, -1);
#else
hItem = AddItemToTree(hWnd, lpName->lpszShortNameA, 0, -1);
#endif*/
return(TRUE);
}
/*
* DlgProcJoinSession
*
* Dialog procedure for Join Session Dialog
*/
/*BOOL CALLBACK DlgProcJoinSession (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static NM_TREEVIEW nmtv;
static HWND hWndCtl;
static TCHAR tszPlayerName[MAX_PLAYERNAME+1];
static HANDLE dphEvent = NULL;
TV_ITEM tvItem;
TCHAR tszSessionName[MAX_SESSIONNAME+1];
WCHAR wszSPGuid[GUIDSTR_MAX+1];
BYTE szSPGuid[GUIDSTR_MAX+1];
DWORD dwPNameSize;
HRESULT hr;
HTREEITEM htiCur, htiNext;
LPGUID lpGuid;
switch (msg)
{
case WM_NOTIFY:
switch (((NMHDR FAR *) lParam)->code)
{
case PSN_SETACTIVE:
if (hWndCtl) TreeView_DeleteAllItems(hWndCtl);
// enum sessions and let dplay decide the timeout
DPlayEnumSessions(0, EnumSession, (LPVOID) hWndCtl, (DWORD)NULL);
// enumerate players for all sessions
ghtiSession = TreeView_GetFirstVisible(hWndCtl);
while (ghtiSession)
{
// delete previous players from display
if ((htiNext = htiCur = TreeView_GetChild(hWndCtl, ghtiSession))
!= (HTREEITEM)0)
{
do
{
htiNext = TreeView_GetNextSibling(hWndCtl, htiCur);
TreeView_DeleteItem(hWndCtl, htiCur);
htiCur = htiNext;
} while (htiNext);
}
tvItem.hItem = ghtiSession;
tvItem.pszText = tszSessionName;
tvItem.cchTextMax = MAX_SESSIONNAME;
TreeView_GetItem(hWndCtl, &tvItem);
// enumerate players for selected session
DPlayEnumPlayers((LPGUID)tvItem.lParam, EnumPlayer, (LPVOID) hWndCtl, DPENUMPLAYERS_SESSION);
ghtiSession = TreeView_GetNextItem(hWndCtl, ghtiSession, TVGN_NEXTVISIBLE);
}
// set Finish button highlite
if (GetDlgItemText(hDlg, IDC_JOIN_PLAYERNAME, tszPlayerName, MAX_PLAYERNAME) &&
(htiCur = TreeView_GetSelection(hWndCtl)))
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
}
else
{
PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_BACK|PSWIZB_DISABLEDFINISH);
}
SetFocus(hWndCtl);
return(TRUE);
case PSN_WIZFINISH:
// add user selections to registry
if (ghDuelKey)
{
StringFromGUID(&gSPGuid, wszSPGuid);
WideToAnsi(szSPGuid, wszSPGuid, sizeof(wszSPGuid));
RegSetA(TEXT("ServiceProvider"), szSPGuid, sizeof(szSPGuid));
RegSet(TEXT("PlayerName"), (CONST BYTE *)tszPlayerName,
sizeof(tszPlayerName));
}
// get the session guid
if (nmtv.itemNew.lParam)
{
// user selected a session item, so just grab its lParam
lpGuid = (LPGUID)nmtv.itemNew.lParam;
}
else
{
// user selected a player item, so grab its parent's (session) lParam
htiCur = TreeView_GetParent(hWndCtl, nmtv.itemNew.hItem);
if (!htiCur)
{
// fail finish
//initFail("IDS_WIZARD_ERROR_GSG");
SetWindowLong(hDlg, DWL_MSGRESULT, -1);
return (TRUE);
}
tvItem.hItem = htiCur;
tvItem.pszText = tszSessionName;
tvItem.cchTextMax = MAX_SESSIONNAME;
TreeView_GetItem(hWndCtl, &tvItem);
lpGuid = (LPGUID)tvItem.lParam;
}
// open session
if ((hr = DPlayOpenSession(lpGuid)) != DP_OK)
{
// fail finish
//initFail("IDS_DPLAY_ERROR_JS");
SetWindowLong(hDlg, DWL_MSGRESULT, -1);
return (TRUE);
}
// create player
if ((hr = DPlayCreatePlayer(&gOurID, tszPlayerName, NULL, NULL, 0)) != DP_OK)
{
// fail finish
//initFail("IDS_DPLAY_ERROR_CP");
SetWindowLong(hDlg, DWL_MSGRESULT, -1);
return (TRUE);
}
// everything went well, release allocated memory and finish
ReleaseSessionData(hWndCtl);
ReleaseSPData();
return(TRUE);
case PSN_QUERYCANCEL:
ReleaseSPData();
ReleaseSessionData(hWndCtl);
DPlayRelease();
return(TRUE);
case PSN_WIZBACK:
ReleaseSessionData(hWndCtl);
return(TRUE);
case TVN_SELCHANGING:
nmtv = *((NM_TREEVIEW *) lParam);
// set Finish button status
if (GetDlgItemText(hDlg, IDC_JOIN_PLAYERNAME, tszPlayerName, MAX_PLAYERNAME) &&
(htiCur = TreeView_GetSelection(hWndCtl)))
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
}
else
{
PropSheet_SetWizButtons(GetParent(hDlg),PSWIZB_BACK|PSWIZB_DISABLEDFINISH);
}
return(FALSE);
case NM_CLICK:
return(FALSE);
}
break;
case WM_INITDIALOG:
// setup title fonts
SendDlgItemMessage(hDlg, IDC_JOIN_SESSION_TITLE, WM_SETFONT, (WPARAM)ghHeadingFont, MAKELPARAM(TRUE,0));
SendDlgItemMessage(hDlg, IDC_JOIN_PLAYER_TITLE, WM_SETFONT, (WPARAM)ghHeadingFont, MAKELPARAM(TRUE,0));
// setup user's previous data
dwPNameSize = MAX_PLAYERNAME+1;
tszPlayerName[0]=0;
if (ghDuelKey && (RegGet(TEXT("PlayerName"),(LPBYTE)tszPlayerName,&dwPNameSize) == ERROR_SUCCESS))
SetDlgItemText(hDlg, IDC_JOIN_PLAYERNAME, tszPlayerName);
hWndCtl = GetDlgItem(hDlg, IDC_JOIN_SESSION);
if (hWndCtl == NULL) return(TRUE);
InitTreeViewImageLists(hWndCtl);
return(TRUE);
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_JOIN_PLAYERNAME:
if (HIWORD(wParam) == EN_CHANGE)
{
// set Finish button status
if (GetDlgItemText(hDlg, IDC_JOIN_PLAYERNAME, tszPlayerName, MAX_PLAYERNAME) &&
(htiCur = TreeView_GetSelection(hWndCtl)))
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
}
else
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_DISABLEDFINISH);
}
}
break;
}
break;
}
return (FALSE);
} */
/*
* DlgProcHostSession
*
* Dialog proc for Host Session Dialog
*/
/*BOOL CALLBACK DlgProcHostSession(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static TCHAR tszSessionName[MAX_SESSIONNAME+1], tszPlayerName[MAX_PLAYERNAME+1];
HRESULT hr;
WCHAR wszSPGuid[GUIDSTR_MAX+1];
BYTE szSPGuid[GUIDSTR_MAX+1];
DWORD dwPNameSize, dwSNameSize;
switch (msg) {
case WM_NOTIFY:
switch (((NMHDR FAR *) lParam)->code)
{
case PSN_SETACTIVE:
if (GetDlgItemText(hDlg, IDC_HOST_SESSIONNAME, tszSessionName, MAX_SESSIONNAME) &&
GetDlgItemText(hDlg, IDC_HOST_PLAYERNAME, tszPlayerName, MAX_PLAYERNAME))
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
}
else
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_DISABLEDFINISH);
}
return(TRUE);
case PSN_WIZFINISH:
// add user selections to registry
if (ghDuelKey)
{
StringFromGUID(&gSPGuid, wszSPGuid);
WideToAnsi(szSPGuid, wszSPGuid, sizeof(wszSPGuid));
RegSetA(TEXT("ServiceProvider"), szSPGuid, sizeof(szSPGuid));
RegSet(TEXT("PlayerName"), (CONST BYTE *)tszPlayerName, sizeof(tszPlayerName));
RegSet(TEXT("SessionName"), (CONST BYTE *)tszSessionName, sizeof(tszSessionName));
}
// create session
if ((hr = DPlayCreateSession(tszSessionName)) != DP_OK)
{
// fail finish
//initFail("IDS_DPLAY_ERROR_CS");
SetWindowLong(hDlg, DWL_MSGRESULT, -1);
return (TRUE);
}
// create player
if ((hr = DPlayCreatePlayer(&gOurID, tszPlayerName, NULL, NULL, 0)) != DP_OK)
{
//initFail("IDS_DPLAY_ERROR_CP");
SetWindowLong(hDlg, DWL_MSGRESULT, -1);
return (TRUE);
}
// everything went well, release allocated memory and finish
ReleaseSPData();
return(TRUE);
case PSN_WIZBACK:
SetWindowLong(hDlg, DWL_MSGRESULT, IDD_GAMESETUP);
return(TRUE);
case PSN_QUERYCANCEL:
// release allocated memory
ReleaseSPData();
// release dplay
DPlayRelease();
return(TRUE);
}
break;
case WM_INITDIALOG:
// setup title font
SendDlgItemMessage(hDlg, IDC_HOST_TITLE, WM_SETFONT, (WPARAM)ghTitleFont, MAKELPARAM(TRUE,0));
SendDlgItemMessage(hDlg, IDC_HOST_SESSION_TITLE, WM_SETFONT, (WPARAM)ghHeadingFont, MAKELPARAM(TRUE,0));
SendDlgItemMessage(hDlg, IDC_HOST_PLAYER_TITLE, WM_SETFONT, (WPARAM)ghHeadingFont, MAKELPARAM(TRUE,0));
dwPNameSize = MAX_PLAYERNAME+1;
dwSNameSize = MAX_SESSIONNAME+1;
tszPlayerName[0]=0;
tszSessionName[0]=0;
if (ghDuelKey)
{
if (RegGet(TEXT("PlayerName"), (LPBYTE)tszPlayerName, &dwPNameSize) == ERROR_SUCCESS)
SetDlgItemText(hDlg, IDC_HOST_PLAYERNAME, tszPlayerName);
if (RegGet(TEXT("SessionName"), (LPBYTE)tszSessionName, &dwSNameSize) == ERROR_SUCCESS)
SetDlgItemText(hDlg, IDC_HOST_SESSIONNAME, tszSessionName);
}
return(TRUE);
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_HOST_SESSIONNAME:
if (HIWORD(wParam) == EN_CHANGE)
{
if (GetDlgItemText(hDlg, IDC_HOST_SESSIONNAME, tszSessionName, MAX_SESSIONNAME) &&
GetDlgItemText(hDlg, IDC_HOST_PLAYERNAME, tszPlayerName, MAX_PLAYERNAME))
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
}
else
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_DISABLEDFINISH);
}
return TRUE;
}
break;
case IDC_HOST_PLAYERNAME:
if (HIWORD(wParam) == EN_CHANGE)
{
if (GetDlgItemText(hDlg, IDC_HOST_SESSIONNAME, tszSessionName, MAX_SESSIONNAME) &&
GetDlgItemText(hDlg, IDC_HOST_PLAYERNAME, tszPlayerName, MAX_PLAYERNAME))
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_FINISH);
}
else
{
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK|PSWIZB_DISABLEDFINISH);
}
}
break;
}
break;
}
return(FALSE);
}*/
/*
* InitTreeViewImageLists - creates an image list, adds three bitmaps to
* it, and associates the image list with a tree-view control.
* Returns TRUE if successful or FALSE otherwise.
* hwndTV - handle of the tree-view control
*
* Global variables and constants
* gnSession, and gnPlayer - integer variables for
* indexes of the images
* CX_BITMAP and CY_BITMAP - width and height of an icon
* NUM_BITMAPS - number of bitmaps to add to the image list
*/
/*BOOL InitTreeViewImageLists(HWND hwndTV)
{
HIMAGELIST himl; // handle of image list
HBITMAP hbmp; // handle of bitmap
// Create the image list.
if ((himl = ImageList_Create(CX_BITMAP, CY_BITMAP,
FALSE, NUM_BITMAPS, 0)) == NULL)
return FALSE;
// Add the session and player bitmaps.
hbmp = LoadBitmap(ghinst, MAKEINTRESOURCE(IDB_CLOSED_SESSION));
gnSession = ImageList_Add(himl, hbmp, (HBITMAP) NULL);
DeleteObject(hbmp);
hbmp = LoadBitmap(ghinst, MAKEINTRESOURCE(IDB_PLAYER));
gnPlayer = ImageList_Add(himl, hbmp, (HBITMAP) NULL);
DeleteObject(hbmp);
// Fail if not all of the images were added.
if (ImageList_GetImageCount(himl) < 2)
return FALSE;
// Associate the image list with the tree-view control.
TreeView_SetImageList(hwndTV, himl, TVSIL_NORMAL);
return TRUE;
} */
/*
* AddItemToTree - adds items to a tree-view control.
* Returns the handle of the newly added item.
* hwndTV - handle of the tree-view control
* lpszItem - text of the item to add
* nLevel - level at which to add the item
*/
/*HTREEITEM AddItemToTree(HWND hwndTV, LPTSTR lptszItem, DWORD dwData, int nLevel)
{
TV_ITEM tvi;
TV_INSERTSTRUCT tvins;
static HTREEITEM hPrev = (HTREEITEM) TVI_FIRST;
static HTREEITEM hPrevRootItem = NULL;
static HTREEITEM hPrevLev2Item = NULL;
tvi.mask = TVIF_TEXT | TVIF_IMAGE
| TVIF_SELECTEDIMAGE | TVIF_PARAM;
// Set the state
if (nLevel == 1)
{
tvi.mask |= TVIF_STATE;
tvi.state = TVIS_SELECTED;
}
// Set the text of the item.
tvi.pszText = lptszItem;
// Set the image
if (nLevel == 1)
{
tvi.iImage = gnSession;
tvi.iSelectedImage = gnSession;
}
else
{
tvi.iImage = gnPlayer;
tvi.iSelectedImage = gnPlayer;
}
// Save the heading level in the item's application-defined
// data area.
tvi.lParam = (LPARAM) dwData;
tvins.item = tvi;
tvins.hInsertAfter = hPrev;
// Set the parent item based on the specified level.
if (nLevel == -1)
tvins.hParent = ghtiSession;
else if (nLevel == 1)
tvins.hParent = TVI_ROOT;
else if (nLevel == 2)
tvins.hParent = hPrevRootItem;
else
tvins.hParent = hPrevLev2Item;
// Add the item to the tree-view control.
hPrev = (HTREEITEM) SendMessage(hwndTV, TVM_INSERTITEM, 0,
(LPARAM) (LPTV_INSERTSTRUCT) &tvins);
// Save the handle of the item.
if (nLevel == 1)
hPrevRootItem = hPrev;
else if (nLevel == 2)
hPrevLev2Item = hPrev;
return hPrev;
} */
/*
* ReleaseSessionData
*
* Releases the memory allocated for session guids
*/
/*void ReleaseSessionData(HWND hWndCtl)
{
HTREEITEM htiSession;
TV_ITEM tvItem;
TCHAR tszSessionName[MAX_SESSIONNAME+1];
htiSession = TreeView_GetRoot(hWndCtl);
while (htiSession)
{
tvItem.hItem = htiSession;
tvItem.pszText = tszSessionName;
tvItem.cchTextMax = MAX_SESSIONNAME;
TreeView_GetItem(hWndCtl, &tvItem);
if (tvItem.lParam) free((LPVOID)tvItem.lParam);
htiSession = TreeView_GetNextSibling(hWndCtl, htiSession);
}
} */
/*
* ReleaseSPData
*
* Releases the memory allocated for service provider guids
* depends on global variable ghWndSPControl
*/
void ReleaseSPData(void)
{
LPGUID lpGuid;
int count,index;
if (ghWndSPCtl)
{
// count = SendMessage(ghWndSPCtl, LB_GETCOUNT, 0, 0);
// for (index = 0; index < count; index++)
{
*lpGuid =gSPGuid;// (LPGUID) SendMessage(ghWndSPCtl, LB_GETITEMDATA, index, 0);
if (lpGuid) free(lpGuid);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -