📄 showwnd.c
字号:
MessageBox( 0, "Not a valid queue", 0, MB_OK );
return;
}
if ( pQ->sig2 != 0x5148 ) // 0x5148 == "HQ"
goto error;
SendMessage(HWndDetails, LB_RESETCONTENT, 0, 0);
wsprintf(szBuffer, "Queue: %04X", hQueue );
SendMessage( HWndDetailsDescription, WM_SETTEXT, 0, (LPARAM)szBuffer );
lbprintf( HWndDetails, "+nextQueue: %04X", pQ->nextQueue );
RecordListboxLineTypeAndValue( HWndDetails, LB_ITEM_QUEUE, pQ->nextQueue);
// Get the name of the window's associated task
GetProcessNameFromHQueue( hQueue, szTaskName );
lbprintf( HWndDetails, "hTask: %04X (%s)", pQ->hTask, szTaskName );
lbprintf( HWndDetails, "headMsg: %04X", pQ->headMsg );
lbprintf( HWndDetails, "tailMsg: %04X", pQ->tailMsg );
lbprintf( HWndDetails, "lastMsg: %04X", pQ->lastMsg );
lbprintf( HWndDetails, "cMsgs: %04X", pQ->cMsgs );
lbprintf( HWndDetails, "un1: %02X", pQ->un1 );
lbprintf( HWndDetails, "sig: %-3.3s", pQ->sig );
lbprintf( HWndDetails, "npPerQueueData: %04X", pQ->npPerQueue );
lbprintf( HWndDetails, "un2_5: %04X", pQ->un2_5 );
lbprintf( HWndDetails, "npQueueProcessData: %04X", pQ->npProcess );
lbprintf( HWndDetails, "un3[0]: %08X", pQ->un3[0] );
lbprintf( HWndDetails, "messageTime: %08X", pQ->messageTime);
lbprintf( HWndDetails, "messagePos: %08X", pQ->messagePos);
lbprintf( HWndDetails, "lastMsg2: %04X", pQ->lastMsg2 );
lbprintf( HWndDetails, "extraInfo: %08X", pQ->extraInfo );
lbprintf( HWndDetails, "threadId: %08X", pQ->threadId );
lbprintf( HWndDetails, "un6: %04X", pQ->un6 );
lbprintf( HWndDetails, "expWinVer: %04X", pQ->expWinVer );
lbprintf( HWndDetails, "un7: %08X", pQ->un7 );
lbprintf( HWndDetails, "ChangeBits: %04X", pQ->ChangeBits );
lbprintf( HWndDetails, "WakeBits: %04X", pQ->WakeBits );
lbprintf( HWndDetails, "WakeMask: %04X", pQ->WakeMask );
lbprintf( HWndDetails, "hQueueSend: %04X", pQ->hQueueSend );
lbprintf( HWndDetails, "sig2: %04X", pQ->sig2 );
MBassert( !pQ->un2 );
MBassert( !pQ->un3[1] );
MBassert( !pQ->un3[2] );
MBassert( !pQ->un4 );
MBassert( !pQ->un5[0] );
MBassert( !pQ->un5[1] );
MBassert( !pQ->un8 );
MBassert( !pQ->un9 );
MBassert( (IsSelector(pQ->nextQueue) || !pQ->nextQueue) );
MBassert( Is16BitGlobalHandle(pQ->hTask) );
MBassert( (IsDivisibleBy4(pQ->headMsg) || !pQ->headMsg) );
MBassert( (IsDivisibleBy4(pQ->tailMsg) || !pQ->tailMsg) );
MBassert( IsDivisibleBy4(pQ->npPerQueue) );
MBassert( IsDivisibleBy4(pQ->npProcess) );
MBassert( pQ->sig2 == 0x5148 );
}
DWORD GetUserHeapBase(void)
{
HMODULE hModUser;
hModUser = LoadLibrary16( "USER.EXE" );
if ( !hModUser )
return 0;
FreeLibrary16( hModUser );
return (DWORD)ConvertFar16PtrToFlat( MAKELONG(0, hModUser) );
}
PWND32 HWndToPtr( HWND hWnd )
{
if ( !IsWindow( hWnd ) )
return 0;
return (PWND32)(UserHeapBase +
*(PDWORD)(UserHeapBase + 0x10000 + (DWORD)hWnd) );
}
PWND32 UserPtrToFlatPtr( PWND32 pWnd32 )
{
if ( pWnd32 == 0 )
return 0;
return (PWND32)( UserHeapBase + (DWORD)pWnd32 );
}
#if 0
BOOL GetClassNameFromAtom( WORD atom, PSTR pszBuffer, unsigned cbLen )
{
WORD x;
PBYTE pszString;
// if ( atom < 0xC000 )
// {
wsprintf(pszBuffer, "#%X", atom );
switch ( atom )
{
case 32768: strcat(pszBuffer, " PopupMenu"); break;
case 32769: strcat(pszBuffer, " Desktop"); break;
case 32770: strcat(pszBuffer, " Dialog"); break;
case 32771: strcat(pszBuffer, " WinSwitch"); break;
case 32772: strcat(pszBuffer, " IconTitle"); break;
}
return TRUE;
// }
// GlobalGetAtomName( atom, pszBuffer, cbLen );
return TRUE;
}
#endif
//
// This routine is just modification of the GetProcessNameFromHTask
// function in the WIN32WLK.C program.
//
void GetProcessNameFromHQueue( WORD hQueue, PSTR pszBuffer )
{
pszBuffer[0] = 0;
__try
{
__asm
{
push ds
push ds
pop es
mov ds,word ptr [hQueue] ;; Retrieve the hTask value from
mov ax,ds:[0002h] ;; the hQueue
mov ds, ax
mov esi, 0F2h
mov edi, [pszBuffer]
mov ecx, 2
cld
rep movsd
mov byte ptr es:[edi], 0
pop ds
}
}
__except( 1 ){}
}
BOOL IsWin32Task( WORD hQueue )
{
BOOL retValue = 0;
__try
{
__asm
{
push ds
mov ds,word ptr [hQueue] ;; Retrieve the hTask value from
mov ax,ds:[0002h] ;; the hQueue
mov ds, ax
mov ax, ds:[16h]
test ax, 10h
setnz byte ptr [retValue]
pop ds
}
}
__except( 1 ){}
return retValue;
}
PVOID ConvertFar16PtrToFlat( DWORD far16ptr )
{
LDT_ENTRY selectorEntry;
if ( !GetThreadSelectorEntry(GetCurrentThread(), HIWORD(far16ptr),
&selectorEntry) )
{
return 0;
}
return (PVOID)(
(selectorEntry.HighWord.Bytes.BaseHi << 24) +
(selectorEntry.HighWord.Bytes.BaseMid << 16) +
selectorEntry.BaseLow +
LOWORD(far16ptr));
}
void lbprintf(HWND hWnd, char * format, ...)
{
char szBuffer[512];
va_list argptr;
va_start(argptr, format);
wvsprintf(szBuffer, format, argptr);
va_end(argptr);
SendMessage( hWnd, LB_ADDSTRING, 0, (LPARAM)szBuffer );
}
typedef struct
{
DWORD type;
DWORD value;
} LBITEMDATA, *PLBITEMDATA;
// Records the type (module, process, etc...) of the line that was just
// added to the specified listbox window, along with the value.
void RecordListboxLineTypeAndValue(HWND hWnd, DWORD type, DWORD value)
{
unsigned lastIndex;
PLBITEMDATA plbdata;
lastIndex = SendMessage( hWnd, LB_GETCOUNT, 0, 0 );
if ( !lastIndex )
return;
lastIndex--; // Index is 0 based
plbdata = malloc( sizeof(LBITEMDATA) ); // These will be freed in
if ( plbdata ) // out WM_DELETEITEM handler
{ // in the dlg proc
plbdata->type = type;
plbdata->value = value;
}
SendMessage( hWnd, LB_SETITEMDATA, lastIndex, (LPARAM)plbdata );
}
BOOL RetrieveListboxLineTypeAndValue(HWND hWnd, DWORD *type, DWORD *value)
{
PLBITEMDATA plbdata;
unsigned index = SendMessage( hWnd, LB_GETCURSEL, 0, 0 );
plbdata = (PLBITEMDATA)SendMessage( hWnd, LB_GETITEMDATA, index, 0 );
if ( !plbdata || ((DWORD)plbdata == LB_ERR) )
return FALSE;
*type = plbdata->type;
*value = plbdata->value;
return TRUE;
}
//
// Dialog proc for the main dialog
//
BOOL CALLBACK ShowWndDlgProc(HWND hWndDlg, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch ( msg )
{
case WM_COMMAND:
Handle_WM_COMMAND(hWndDlg, wParam, lParam); return TRUE;
case WM_INITDIALOG:
Handle_WM_INITDIALOG(hWndDlg); return TRUE;
case WM_CLOSE:
EndDialog(hWndDlg, 0); return FALSE;
case WM_DELETEITEM:
Handle_WM_DELETEITEM( hWndDlg, wParam, lParam ); return TRUE;
}
return FALSE;
}
//
// Handle the dialog's WM_COMMAND messages
//
void Handle_WM_COMMAND(HWND hWndDlg, WPARAM wParam, LPARAM lParam)
{
//
// If user hit <enter> see which listbox has the focus, and
// change wParam and lParam to look as if the user performed
// the equivalent dbl-click action.
//
if ( LOWORD(wParam) == IDOK )
{
HWND hWndFocus = GetFocus();
if (hWndFocus == HWndDetails )
{
wParam = IDC_LB_DETAILS; lParam = MAKELONG(0,LBN_DBLCLK);
}
}
switch ( LOWORD(wParam) )
{
case IDC_BUTTON_EXIT:
EndDialog(hWndDlg, 0);
break;
case IDC_BUTTON_REFRESH:
UpdateWndList();
break;
case IDC_LB_MAIN_LIST:
if ( HIWORD(wParam) == LBN_SELCHANGE )
{
DWORD handle, type;
DWORD lbSelectedIndex;
lbSelectedIndex = SendMessage(HWndMainList,LB_GETCURSEL, 0, 0);
RetrieveListboxLineTypeAndValue(HWndMainList, &type, &handle);
ShowWndDetails( (PWND32)handle );
}
break;
case IDC_LB_DETAILS:
if ( HIWORD(wParam) == LBN_DBLCLK )
{
DWORD type, value;
if ( !RetrieveListboxLineTypeAndValue(HWndDetails,
&type, &value) )
break;
switch ( type )
{
case LB_ITEM_WND:
ShowWndDetails( (PWND32)value ); break;
case LB_ITEM_CLASS:
ShowClassDetails( (PUSER_DGROUP_WNDCLASS)value );break;
case LB_ITEM_QUEUE:
ShowQueueDetails( (WORD)value ); break;
}
}
break;
}
return;
}
void Handle_WM_INITDIALOG(HWND hWndDlg)
{
DWORD tabStops=16;
HWndMainList = GetDlgItem(hWndDlg, IDC_LB_MAIN_LIST);
HWndDetails = GetDlgItem(hWndDlg, IDC_LB_DETAILS);
HWndDetailsDescription = GetDlgItem(hWndDlg, IDC_DETAILS_TYPE );
SendMessage( HWndMainList, LB_SETTABSTOPS, 1, (LPARAM)&tabStops );
UserHeapBase = GetUserHeapBase();
UpdateWndList();
}
void Handle_WM_DELETEITEM(HWND hWndDlg, WPARAM wParam, LPARAM lParam)
{
if ( (wParam != IDC_LB_MAIN_LIST) && (wParam != IDC_LB_DETAILS) )
return;
// Free the pointer stored in the item data
free( (PVOID)((LPDELETEITEMSTRUCT)lParam)->itemData );
}
// Our own custom assert for GUI programs
void __cdecl _MBassert(void *pszExp, void *pszFile, unsigned lineNum)
{
char buffer[512];
wsprintf(buffer, "assert: %s (%s line %u)", pszExp, pszFile, lineNum);
MessageBox( 0, buffer, 0, MB_OK );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -