Posted: . At: 6:08 PM. This was 5 months ago. Post ID: 18875
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Looking at the comctl32.dll source code from Windows XP.


I have just been looking at the source code of the comctl32.dll file for Windows XP. This is very interesting.

I have uploaded a copy here: https://www.securitronlinux.com/linuxinfo/comctl32.tar.bz2. Below is the makefile used to build the DLL file using the NT build system.

Makefile
##########################################################################
#
#       Microsoft Confidential
#       Copyright (C) Microsoft Corporation 1991
#       All Rights Reserved.
#
##########################################################################

!ifdef NTMAKEENV    # Prevent NT's build.exe from executing this makefile

clean :

!else  # NTMAKEENV


DIR             = comctl32
ROOT            = ..\..

DIRLIST         = win95

!include ..\shell.mk

default all:    $(DIRLIST)

retail debug:
        cd win95
        nmake $@
        
!endif # NTMAKEENV

The comctl32/v6/listbox.c file is an interesting file, it has listbox and combobox code for Windows XP.

This is a very interesting source code sample. This handles submenus in a menu file.

comctl32/v6/menuhelp.c
#include "ctlspriv.h"

#define MAININSYS

#ifndef WIN32
/* This returns the index of a submenu in a parent menu.  The return is
 * < 0 if the submenu does not exist in the parent menu
 */
int GetMenuIndex(HMENU hMenu, HMENU hSubMenu)
{
  int i;

  if (!hMenu || !hSubMenu)
      return(-1);

  for (i=GetMenuItemCount(hMenu)-1; i>=0; --i)
    {
      if (hSubMenu == GetSubMenu(hMenu, i))
          break;
    }

  return(i);
}
#endif // WIN32


BOOL IsMaxedMDI(HMENU hMenu)
{
  return(GetMenuItemID(hMenu, GetMenuItemCount(hMenu)-1) == SC_RESTORE);
}


/* Note that if iMessage is WM_COMMAND, it is assumed to have come from
 * a header bar or toolbar; do not pass in WM_COMMAND messages from any
 * other controls.
 */

#define MS_ID           GET_WM_MENUSELECT_CMD
#define MS_FLAGS        GET_WM_MENUSELECT_FLAGS
#define MS_MENU         GET_WM_MENUSELECT_HMENU

#define CMD_NOTIFY      GET_WM_COMMAND_CMD
#define CMD_ID          GET_WM_COMMAND_ID
#define CMD_CTRL        GET_WM_COMMAND_HWND


void WINAPI MenuHelp(UINT iMessage, WPARAM wParam, LPARAM lParam,
      HMENU hMainMenu, HINSTANCE hAppInst, HWND hwndStatus, UINT *lpwIDs)
{
  UINT wID;
  UINT *lpwPopups;
  int i;
  TCHAR szString[256];
  BOOL bUpdateNow = TRUE;
#if defined(WINDOWS_ME)
  MENUITEMINFO mii;
#endif

  switch (iMessage)
    {
      case WM_MENUSELECT:
        if ((WORD)MS_FLAGS(wParam, lParam)==(WORD)-1 && MS_MENU(wParam, lParam)==0)
          {
#ifndef WIN32
EndMenuHelp:
#endif
            SendMessage(hwndStatus, SB_SIMPLE, 0, 0L);
            break;
          }

          szString[0] = TEXT('\0');
#if defined(WINDOWS_ME)
          i = MS_ID(wParam, lParam);

          memset(&mii, 0, SIZEOF(MENUITEMINFO ));
          mii.cbSize = sizeof(mii);
          mii.fMask = MIIM_TYPE;
          mii.cch = 0;  //If we ask for MIIM_TYPE, this must be set to zero!
                        //Otherwise, win95 attempts to copy the string too!
          if (GetMenuItemInfo((HMENU)MS_MENU(wParam, lParam), i, TRUE, &mii))
              mii.fState = mii.fType & MFT_RIGHTORDER ?SBT_RTLREADING :0;
#endif
        if (!(MS_FLAGS(wParam, lParam)&MF_SEPARATOR))
          {
            if (MS_FLAGS(wParam, lParam)&MF_POPUP)
              {
                /* We don't want to update immediately in case the menu is
                 * about to pop down, with an item selected.  This gets rid
                 * of some flashing text.
                 */
                bUpdateNow = FALSE;

                /* First check if this popup is in our list of popup menus
                 */
                for (lpwPopups=lpwIDs+2; *lpwPopups; lpwPopups+=2)
                  {
                    /* lpwPopups is a list of string ID/menu handle pairs
                     * and MS_ID(wParam, lParam) is the menu handle of the selected popup
                     */
                    if (*(lpwPopups+1) == (UINT)MS_ID(wParam, lParam))
                      {
                        wID = *lpwPopups;
                        goto LoadTheString;
                      }
                  }

                /* Check if the specified popup is in the main menu;
                 * note that if the "main" menu is in the system menu,
                 * we will be OK as long as the menu is passed in correctly.
                 * In fact, an app could handle all popups by just passing in
                 * the proper hMainMenu.
                 */
                if ((HMENU)MS_MENU(wParam, lParam) == hMainMenu)
                  {
#ifdef  WIN32
                    i = MS_ID(wParam, lParam);
#else   // WIN32
                    i = GetMenuIndex((HMENU)MS_MENU(wParam, lParam), (HMENU)MS_ID(wParam, lParam));
                    if (i >= 0)
#endif  // WIN32
                      {
                        if (IsMaxedMDI(hMainMenu))
                          {
                            if (!i)
                              {
                                wID = IDS_SYSMENU;
                                hAppInst = HINST_THISDLL;
                                goto LoadTheString;
                              }
                            else
                                --i;
                          }
                        wID = (UINT)(i + lpwIDs[1]);
                        goto LoadTheString;
                      }
                  }

                /* This assumes all app defined popups in the system menu
                 * have been listed above
                 */
                if ((MS_FLAGS(wParam, lParam)&MF_SYSMENU))
                  {
                    wID = IDS_SYSMENU;
                    hAppInst = HINST_THISDLL;
                    goto LoadTheString;
                  }

                goto NoString;
              }
            else if (MS_ID(wParam, lParam) >= MINSYSCOMMAND)
              {
                wID = (UINT)(MS_ID(wParam, lParam) + MH_SYSMENU);
                hAppInst = HINST_THISDLL;
              }
            else
              {
                wID = (UINT)(MS_ID(wParam, lParam) + lpwIDs[0]);
              }

LoadTheString:
            if (hAppInst == HINST_THISDLL)
                LocalizedLoadString(wID, szString, ARRAYSIZE(szString));
            else
                LoadString(hAppInst, wID, szString, ARRAYSIZE(szString));
          }

NoString:
#if defined(WINDOWS_ME)
        SendMessage(hwndStatus, SB_SETTEXT, mii.fState|SBT_NOBORDERS|255,
              (LPARAM)(LPSTR)szString);
#else
        SendMessage(hwndStatus, SB_SETTEXT, SBT_NOBORDERS|255,
              (LPARAM)(LPTSTR)szString);
#endif
        SendMessage(hwndStatus, SB_SIMPLE, 1, 0L);

        if (bUpdateNow)
            UpdateWindow(hwndStatus);
        break;

#ifndef WIN32

      case WM_COMMAND:
        switch (CMD_NOTIFY(wParam, lParam))
          {
#ifdef WANT_SUCKY_HEADER
            case HBN_BEGINDRAG:
              bUpdateNow = FALSE;
              wID = IDS_HEADER;
              goto BeginSomething;

            case HBN_BEGINADJUST:
              wID = IDS_HEADERADJ;
              goto BeginSomething;
#endif
            case TBN_BEGINADJUST:
              /* We don't want to update immediately in case the operation is
               * aborted immediately.
               */
              bUpdateNow = FALSE;
              wID = IDS_TOOLBARADJ;
              goto BeginSomething;

BeginSomething:
              SendMessage(hwndStatus, SB_SIMPLE, 1, 0L);
              hAppInst = HINST_THISDLL;
              goto LoadTheString;

            case TBN_BEGINDRAG:
              MenuHelp(WM_MENUSELECT, (WPARAM)CMD_CTRL(wParam, lParam), 0L,
                    hMainMenu, hAppInst, hwndStatus, lpwIDs);
              break;
#ifdef WANT_SUCKY_HEADER
            case HBN_ENDDRAG:
            case HBN_ENDADJUST:
#endif
            case TBN_ENDDRAG:
            case TBN_ENDADJUST:
              goto EndMenuHelp;

            default:
              break;
          }
        break;
#endif  // !WIN32

      default:
        break;
    }
}


BOOL WINAPI ShowHideMenuCtl(HWND hWnd, WPARAM wParam, LPINT lpInfo)
{
  HWND hCtl;
  UINT uTool, uShow = MF_UNCHECKED | MF_BYCOMMAND;
  HMENU hMainMenu;
  BOOL bRet = FALSE;

  hMainMenu = IntToPtr_(HMENU, lpInfo[1]);

  for (uTool=0; ; ++uTool, lpInfo+=2)
    {
      if ((WPARAM)lpInfo[0] == wParam)
          break;
      if (!lpInfo[0])
          goto DoTheCheck;
    }

  if (!(GetMenuState(hMainMenu, (UINT) wParam, MF_BYCOMMAND)&MF_CHECKED))
      uShow = MF_CHECKED | MF_BYCOMMAND;

  switch (uTool)
    {
      case 0:
        bRet = SetMenu(hWnd, (HMENU)((uShow&MF_CHECKED) ? hMainMenu : 0));
        break;

      default:
        hCtl = GetDlgItem(hWnd, lpInfo[1]);
        if (hCtl)
          {
            ShowWindow(hCtl, (uShow&MF_CHECKED) ? SW_SHOW : SW_HIDE);
            bRet = TRUE;
          }
        else
            uShow = MF_UNCHECKED | MF_BYCOMMAND;
        break;
    }

DoTheCheck:
  CheckMenuItem(hMainMenu, (UINT) wParam, uShow);

#ifdef MAININSYS
  hMainMenu = GetSubMenu(GetSystemMenu(hWnd, FALSE), 0);
  if (hMainMenu)
      CheckMenuItem(hMainMenu, (UINT) wParam, uShow);
#endif

  return(bRet);
}


void WINAPI GetEffectiveClientRect(HWND hWnd, LPRECT lprc, LPINT lpInfo)
{
  RECT rc;
  HWND hCtl;

  GetClientRect(hWnd, lprc);

  /* Get past the menu
   */
  for (lpInfo+=2; lpInfo[0]; lpInfo+=2)
    {
      hCtl = GetDlgItem(hWnd, lpInfo[1]);
      /* We check the style bit because the parent window may not be visible
       * yet (still in the create message)
       */
      if (!hCtl || !(GetWindowStyle(hCtl) & WS_VISIBLE))
          continue;

      GetWindowRect(hCtl, &rc);

      //
      // This will do the ScrrenToClient functionality, plus
      // it will return a good rect (left < right) when the
      // hWnd parent is RTL mirrored. [samera]
      //
      MapWindowPoints(HWND_DESKTOP, hWnd, (PPOINT)&rc, 2);

      SubtractRect(lprc, lprc, &rc);
    }
}

Fascinating to see the functionality of the Windows XP Operating System in action. The Windows XP source code is very clean and easy to read.

There are a lot of Linux references in the Windows XP source code, here are a few.

(jcartwright@localhost) 192.168.1.5 XPSP1  $ grep -R -n "Linux" *
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/biblio.lst:616:Most PCI vendor IDs from Linux v1.3.25 include/linux/pci.h by Drew Eckhardt,
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.1st:570: 6/95 Peter Charles Tonoli [email protected] Linux DOSEMU
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:23042: FCh	*	*	02/25/93	Linux DOSEMU (all versions)
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:23226:      Linux's DOSEMU.  Read the Model byte at F000h:FFFEh and BIOS date at
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:31312: 14h	(resulted from using Novell DOS 7.0 FDISK to delete Linux Native part)
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:31357: 81h	Linux
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:31359: 82h	Linux Swap partition
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:31361: 83h	Linux native file system (ext2fs/xiafs)
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:56831: 161	Arabic					[Linux]
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:56832: 162	Arabic					[Linux]
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:56833: 163	Arabic					[Linux]
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:56834: 164	Arabic					[Linux]
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:56835: 165	Arabic					[Linux]
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137582:INT E6 - Linux DOSEMU - INSTALLATION CHECK
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137594:INT E6 - Linux DOSEMU - REGISTER DUMP
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137599:INT E6 - Linux DOSEMU - SET I/O PORT PERMISSIONS
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137608:INT E6 - Linux DOSEMU - STARTUP BANNER
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137613:INT E6 - Linux DOSEMU - SET "HOGTHRESHOLD"
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137620:INT E6 - Linux DOSEMU - GET EMS STATUS
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137625:INT E6 - Linux DOSEMU - SET BOOTDISK FLAG
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137631:INT E6 - Linux DOSEMU - EXECUTE UNIX COMMAND
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137636:INT E6 - Linux DOSEMU - EXECUTE DOS COMMAND FROM UNIX
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137641:INT E6 - Linux DOSEMU - GET CURRENT UNIX DIRECTORY
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137647:INT E6 - Linux DOSEMU - CHANGE CURRENT UNIX DIRECTORY
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst:137653:INT E6 - Linux DOSEMU - TERMINATE
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/intprint.doc:219:-Linux DOSEMU
admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/sample2.flt:15:-Linux DOSEMU
grep: admin/wmi/wbem/valuadd/agents/platinum/setup.exe: binary file matches
base/fs/rdr2/rdbss/ifskit.mrx/smbmrx/sys/smbadmin.c:525:    //  because we know that they handle it correctly.  The version of Linux we have
base/fs/rdr2/rdbss/smb.mrx/smbadmin.c:557:    //  because we know that they handle it correctly.  The version of Linux we have
base/zlib/changelog:153:- fix configure for Linux (Chun-Chung Chen)
base/zlib/changelog:211:- added -soname for Linux in configure (Chun-Chung Chen,
base/zlib/configure:75:  Linux | linux) LDSHARED=${LDSHARED-"gcc -shared -Wl,-soname,libz.so.1"};;
base/zlib/makefile:113:# ldconfig is for Linux
base/zlib/makefile.in:110:# ldconfig is for Linux
com/ole32/stg/ref/readme.txt:70:           Only tested on Solaris, HP-UX, and Linux (2.0.7). 
com/ole32/stg/ref/readme.txt:224:fwrite() function on some versions of Linux overwrites memory in the wrong
drivers/serial/mps/cyclades/z/cyclad-z/zfwint.h:52:#define	C_OS_LINUX		0x00000030	/* generic Linux system */
drivers/serial/mps/cyclades/z/cyzport/zfwint.h:52:#define	C_OS_LINUX		0x00000030	/* generic Linux system */
drivers/storage/port/scsi/miniport/mylex/dac2w2k/sys/mlxtypes.h:173:#define GAMOS_LINUX	0x11 /* Linux */
drivers/tpg/hwx/inferno/src/usa/usa.txt:90721:Linux

There is a comprehensive list of all interrupts for Windows driver programmers.

Here it is.

admin/wmi/wbem/providers/win32provider/tools/references/ralphbrown/interrup.lst

Download the files here. This is a nice archive of code references and interrupts for the Windows XP source code.

https://www.securitronlinux.com/linuxinfo/references.tar.bz2.

I hope someone finds this to be very useful and informative.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.