📄 dialogs.c
字号:
* The value that the dialog proc should return, based on the processing
* of the specific WM_COMMAND message received.
\*****************************************************************************/
BOOL CALLBACK
MessagesDlgProc(
HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam
)
{
switch (msg)
{
case WM_INITDIALOG:
MessagesInit(hwnd);
return TRUE;
case WM_COMMAND:
return MessagesCommand(hwnd, LOWORD(wParam), HIWORD(wParam));
}
return FALSE;
}
/*****************************************************************************\
* MessagesInit
*
* Initializes the messages dialog.
*
* Arguments:
* HWND hwnd - Dialog window handle.
*
* Returns:
* VOID
\*****************************************************************************/
PRIVATE VOID
MessagesInit(
HWND hwnd
)
{
HWND hwndList;
INT i;
INT j;
INT iSel;
PMSGDESC pmd;
for (j = 0; j < gcMsgGroups; j++)
gaMsgGroup[j].cUseCount = 0;
hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
for (i = 0, pmd = gaMsgs; i < gcMessages; i++, pmd++)
{
iSel = (INT)SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)pmd->pszMsg);
SendMessage(hwndList, LB_SETITEMDATA, iSel, (LPARAM)pmd);
if (pmd->Flags & MTF_SELECTED)
{
SendMessage(hwndList, LB_SETSEL, TRUE, iSel);
for (j = 0; j < gcMsgGroups; j++)
{
if (gaMsgGroup[j].flMask & pmd->Flags)
gaMsgGroup[j].cUseCount++;
}
}
}
//
// Set the selection rectangle to the first item in the listbox.
//
SendMessage(hwndList, LB_SETCARETINDEX, 0, FALSE);
//
// Loop through all the message groups.
//
for (j = 0; j < gcMsgGroups; j++)
{
//
// Is at least one message in the group selected?
//
if (gaMsgGroup[j].cUseCount)
{
//
// Check the corresponding checkbox. If all messages
// in the group are selected, the checkbox is checked.
// If only some are selected, the checkbox is set to
// grayed (3-state).
//
CheckDlgButton(hwnd, gaMsgGroup[j].idCheckBox,
(gaMsgGroup[j].cUseCount == gaMsgGroup[j].cMsgs) ? 1 : 2);
}
}
if (gfMsgsUser)
CheckDlgButton(hwnd, DID_MSGSUSER, 1);
if (gfMsgsUnknown)
CheckDlgButton(hwnd, DID_MSGSUNKNOWN, 1);
gcItemsSave = SendMessage(hwndList, LB_GETSELITEMS,
gcMessages, (LPARAM)gaiSelected);
}
/*****************************************************************************\
* MessagesCommand
*
* Handles the WM_COMMAND messages for the Messages dialog.
*
* Arguments:
* HWND hwnd - Window handle of the dialog.
* INT nCmd - Command value.
* INT nNotifyCode - The notify code.
*
* Returns:
* The value that the dialog proc should return, based on the processing
* of the specific WM_COMMAND message received.
*
\*****************************************************************************/
PRIVATE BOOL
MessagesCommand(
HWND hwnd,
INT nCmd,
INT nNotifyCode
)
{
INT i;
INT j;
PMSGGROUP pmg;
PMSGDESC pmd;
BOOL fChecked;
HWND hwndList;
INT cItems;
BOOL fSel;
INT iSel;
INT cSelItemsMax;
INT iTopIndex;
switch (nCmd)
{
case DID_MSGSLIST:
if (nNotifyCode == LBN_SELCHANGE)
{
hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
cItems = SendMessage(hwndList, LB_GETSELITEMS,
gcMessages, (LPARAM)gaiSelected2);
if (cItems == gcItemsSave)
{
//
// Nothing changed except for the selection
// rectangle moving. We are done.
//
break;
}
if (cItems > gcItemsSave)
{
//
// A message was selected. Look for it.
//
for (i = 0; i < gcItemsSave &&
gaiSelected[i] == gaiSelected2[i]; i++)
;
iSel = gaiSelected2[i];
fSel = TRUE;
}
else
{
//
// A message was unselected. Look for it.
//
for (i = 0; i < cItems &&
gaiSelected[i] == gaiSelected2[i]; i++)
;
iSel = gaiSelected[i];
fSel = FALSE;
}
//
// Get the currently selected item. It was either
// just turned on or off.
//
pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA, iSel, 0);
//
// Loop through the message groups and update the use
// counts for all groups that contain this message.
//
for (i = 0; i < gcMsgGroups; i++)
{
if (pmd->Flags & gaMsgGroup[i].flMask)
{
gaMsgGroup[i].cUseCount += fSel ? 1 : -1;
}
}
//
// Be sure that the checkboxes reflect the updated
// status of the message group use counts.
//
MessagesUpdateCheckBoxes(hwnd);
//
// Save away the new selected item array.
//
cSelItemsMax = max(cItems, gcItemsSave);
for (i = 0; i < cSelItemsMax; i++)
{
gaiSelected[i] = gaiSelected2[i];
}
gcItemsSave = cItems;
}
break;
case DID_MSGSALL:
hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
SendMessage(hwndList, LB_SETSEL, TRUE, (LPARAM)-1);
for (i = 0; i < gcMsgGroups; i++)
{
gaMsgGroup[i].cUseCount = gaMsgGroup[i].cMsgs;
CheckDlgButton(hwnd, gaMsgGroup[i].idCheckBox, 1);
}
gcItemsSave = SendMessage(hwndList, LB_GETSELITEMS, gcMessages,
(LPARAM)gaiSelected);
CheckDlgButton(hwnd, DID_MSGSUSER, 1);
CheckDlgButton(hwnd, DID_MSGSUNKNOWN, 1);
break;
case DID_MSGSNONE:
hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
SendMessage(hwndList, LB_SETSEL, FALSE, (LPARAM)-1);
for (i = 0; i < gcMsgGroups; i++)
{
gaMsgGroup[i].cUseCount = 0;
CheckDlgButton(hwnd, gaMsgGroup[i].idCheckBox, 0);
}
gcItemsSave = 0;
CheckDlgButton(hwnd, DID_MSGSUSER, 0);
CheckDlgButton(hwnd, DID_MSGSUNKNOWN, 0);
break;
case DID_MSGSDDE:
case DID_MSGSCLIP:
case DID_MSGSMOUSE:
case DID_MSGSNC:
case DID_MSGSKEYBD:
#ifdef FE_IME
case DID_MSGSIME:
#endif
case DID_MSGSBM:
case DID_MSGSCB:
case DID_MSGSEM:
case DID_MSGSLB:
case DID_MSGSSTM:
for (i = 0; i < gcMsgGroups; i++)
{
if (gaMsgGroup[i].idCheckBox == nCmd)
{
pmg = &gaMsgGroup[i];
break;
}
}
fChecked = IsDlgButtonChecked(hwnd, pmg->idCheckBox);
if (fChecked == 1)
fChecked = FALSE;
else
fChecked = TRUE;
hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
if (fChecked)
{
SendMessage(hwndList, WM_SETREDRAW, FALSE, 0);
iTopIndex = SendMessage(hwndList, LB_GETTOPINDEX, 0, 0);
}
//
// Get the list of currently selected items.
//
cItems = SendMessage(hwndList, LB_GETSELITEMS,
gcMessages, (LPARAM)gaiSelected);
//
// Look for all the messages in this group.
//
for (i = 0, iSel = 0; i < gcMessages; i++)
{
pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA, i, 0);
if (pmd->Flags & pmg->flMask)
{
//
// Bump up through the list of selected items, looking
// to see if this item is currently selected.
//
for (fSel = FALSE; iSel < cItems &&
gaiSelected[iSel] <= i; iSel++)
{
//
// A match was found. The item is selected.
//
if(gaiSelected[iSel] == i)
{
fSel = TRUE;
break;
}
}
//
// Is the current selection state of the item
// different from the desired selection state?
//
if (fSel != fChecked)
{
//
// Update the use counts of all groups that contain
// this message.
//
for (j = 0; j < gcMsgGroups; j++)
{
if (pmd->Flags & gaMsgGroup[j].flMask)
{
gaMsgGroup[j].cUseCount += fChecked ? 1 : -1;
}
}
//
// Select/deselect the message in the list box.
//
SendMessage(hwndList, LB_SETSEL, fChecked, i);
}
}
}
//
// Be sure that the checkboxes reflect the updated
// status of the message group use counts.
//
MessagesUpdateCheckBoxes(hwnd);
if (fChecked)
{
SendMessage(hwndList, LB_SETTOPINDEX, iTopIndex, 0);
SendMessage(hwndList, WM_SETREDRAW, TRUE, 0);
InvalidateRect(hwndList, NULL, FALSE);
}
gcItemsSave = SendMessage(hwndList, LB_GETSELITEMS,
gcMessages, (LPARAM)gaiSelected);
break;
case IDOK:
hwndList = GetDlgItem(hwnd, DID_MSGSLIST);
cItems = SendMessage(hwndList, LB_GETSELITEMS,
gcMessages, (LPARAM)gaiSelected);
//
// Unselect all messages.
//
for (i = 0; i < gcMessages; i++)
gaMsgs[i].Flags &= ~MTF_SELECTED;
//
// Mark all the messages that are selected.
//
for (i = 0; i < cItems; i++)
{
pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA,
gaiSelected[i], 0);
pmd->Flags |= MTF_SELECTED;
}
if (IsDlgButtonChecked(hwnd, DID_MSGSUSER))
gfMsgsUser = TRUE;
else
gfMsgsUser = FALSE;
if (IsDlgButtonChecked(hwnd, DID_MSGSUNKNOWN))
gfMsgsUnknown = TRUE;
else
gfMsgsUnknown = FALSE;
#if 0 //Debug code!
for (i = 0; i < gcMsgGroups; i++)
{
iSel = 0;
for (j = 0; j < cItems; j++)
{
pmd = (PMSGDESC)SendMessage(hwndList, LB_GETITEMDATA,
gaiSelected[j], 0);
if (pmd->Flags & gaMsgGroup[i].flMask)
iSel++;
}
if (iSel != gaMsgGroup[i].cUseCount)
{
DbgPrintf("Use counts are wrong!!!");
for (j = 0; j < gcMsgGroups; j++)
{
DbgPrintf("cMsgs:%d Use:%d", gaMsgGroup[j].cMsgs, gaMsgGroup[j].cUseCount);
}
}
}
#endif // end debug code
EndDialog(hwnd, IDOK);
return TRUE;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
return TRUE;
}
return FALSE;
}
/*****************************************************************************\
* MessagesUpdateCheckBoxes
*
* Updates the message group checkboxes in the Messages dialog.
* This routine should be called when the use counts in the
* message group table are changed, so that the state of the
* checkboxes will get updated also.
*
* Arguments:
* HWND hwnd - Dialog window handle.
*
* Returns:
* VOID
\*****************************************************************************/
PRIVATE VOID
MessagesUpdateCheckBoxes(
HWND hwnd
)
{
INT i;
INT fState;
for (i = 0; i < gcMsgGroups; i++)
{
if (gaMsgGroup[i].cUseCount == gaMsgGroup[i].cMsgs)
fState = 1;
else if (gaMsgGroup[i].cUseCount == 0)
fState = 0;
else
fState = 2;
CheckDlgButton(hwnd, gaMsgGroup[i].idCheckBox, fState);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -