//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  MESSAGES:
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//    WM_DISPLAYCHANGE - message sent to Plug & Play systems when the display changes
//    WM_RBUTTONDOWN - Right mouse click -- put up context menu here if appropriate
//    WM_NCRBUTTONUP - User has clicked the right button on the application's system menu
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   int wmId, wmEvent;
   PAINTSTRUCT ps;
   HDC hdc;
   POINT pnt;
   HMENU hMenu;
   BOOL bGotHelp;

   switch (message)
   {
   case WM_CREATE:
      // clear timer flags
      TimerID = 0;
      TimerRunning = FALSE;

      // enable "Start" menu selection
      hAppMenu = GetMenu (hWnd);
      hTestMenu  = GetSubMenu (hAppMenu, 1);
      EnableMenuItem (hTestMenu, IDM_STOP, MF_BYCOMMAND | MF_GRAYED);
      EnableMenuItem (hTestMenu, IDM_START, MF_BYCOMMAND | MF_ENABLED);
      break;

   case WM_COMMAND:
      wmId    = LOWORD(wParam); // Remember, these are...
      wmEvent = HIWORD(wParam); // ...different for Win32!

      //Parse the menu selections:
      switch (wmId)
      {

      case IDM_EXIT:
         DestroyWindow (hWnd);
         break;

      case IDM_START:
         if (!TimerRunning)
         {
            TimerID = SetTimer (hWnd, LEAK_TIMER, TIME_INTERVAL, NULL);
            if (TimerID != 0)
            {
               TimerRunning = TRUE;
               EnableMenuItem (hTestMenu, IDM_START,
                               MF_BYCOMMAND | MF_GRAYED);
               EnableMenuItem (hTestMenu, IDM_STOP,
                               MF_BYCOMMAND | MF_ENABLED);
            }
            else
            {
               //unable to start timer
               MessageBeep (MB_ICONEXCLAMATION);
            }
         }
         InvalidateRect (hWnd, NULL, TRUE);
         break;

      case IDM_STOP:
         if (TimerRunning)
         {
            KillTimer (hWnd, LEAK_TIMER);
            TimerID = 0;
            TimerRunning = FALSE;
            EnableMenuItem (hTestMenu, IDM_STOP,
                            MF_BYCOMMAND | MF_GRAYED);
            EnableMenuItem (hTestMenu, IDM_START,
                            MF_BYCOMMAND | MF_ENABLED);
         }
         InvalidateRect (hWnd, NULL, TRUE);
         break;

      case IDM_RESET:
         FreeAllocatedMemory();
         InvalidateRect (hWnd, NULL, TRUE);
         break;

      case IDM_ABOUT:
         DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)About);
         break;

      case IDM_HELPTOPICS: // Only called in Windows 95
         bGotHelp = WinHelp (hWnd, APPNAME".HLP", HELP_FINDER,(DWORD)0);
         if (!bGotHelp)
         {
            MessageBox (GetFocus(), GetStringRes(IDS_NO_HELP),
                        szAppName, MB_OK|MB_ICONHAND);
         }
         break;

      default:
         return (DefWindowProc(hWnd, message, wParam, lParam));
      }
      break;

   case WM_TIMER:
      {
         PMEMORY_ALLOC_BLOCK     pMab, pNewMab;

         pNewMab = (PMEMORY_ALLOC_BLOCK)G_ALLOC (GPTR, ALLOCATION_SIZE);

         if (pNewMab != NULL)
         {
            // save this pointer
            pNewMab->pNext = NULL;
            if (mabListHead.pNext == NULL)
            {
               // this is the first entry
               mabListHead.pNext = pNewMab;
            }
            else
            {
               // go to end of list
               pMab = mabListHead.pNext;
               while (pMab->pNext != NULL) pMab = pMab->pNext;
               pMab->pNext = pNewMab;
            }
            InvalidateRect (hWnd, NULL, TRUE);
         }
      }
      break;

   case WM_RBUTTONDOWN: // RightClick in windows client area...
      pnt.x = LOWORD(lParam);
      pnt.y = HIWORD(lParam);
      ClientToScreen(hWnd, (LPPOINT) &pnt);
      // This is where you would determine the appropriate 'context'
      // menu to bring up. Since this app has no real functionality,
      // we will just bring up the 'Help' menu:
      hMenu = GetSubMenu (GetMenu (hWnd), 2);
      if (hMenu)
      {
         TrackPopupMenu (hMenu, 0, pnt.x, pnt.y, 0, hWnd, NULL);
      }
      else
      {
         // Couldn't find the menu...
         MessageBeep(0);
      }
      break;


   case WM_DISPLAYCHANGE: // Only comes through on plug'n'play systems
      {
         SIZE  szScreen;
         DWORD dwBitsPerPixel = (DWORD)wParam;

         szScreen.cx = LOWORD(lParam);
         szScreen.cy = HIWORD(lParam);

         MessageBox (GetFocus(), GetStringRes(IDS_DISPLAYCHANGED),
                     szAppName, 0);
      }
      break;

   case WM_PAINT:
      {
         MEMORYSTATUS    MemoryStatusData;
         LONGLONG            llInUse;
         DWORD                   dwPercentUsed;

         int     nX, nY;
         LONG    lTextOutReturn;
         int     nStringLength;
         CHAR            szOutputString[100];

         hdc = BeginPaint (hWnd, &ps);
         // Add any drawing code here...
         GlobalMemoryStatus (& MemoryStatusData);

         llInUse = (LONGLONG)(MemoryStatusData.dwTotalPageFile -
                              MemoryStatusData.dwAvailPageFile + 5 );
         llInUse *= 1000;
         llInUse /= MemoryStatusData.dwTotalPageFile;
         llInUse /= 10;

         dwPercentUsed = (DWORD)llInUse;

         nX = 0;
         nY = 0;
         _snprintf_s(szOutputString, 100, _TRUNCATE, "Reported Memory Load: \t%3.1d%%",
                  MemoryStatusData.dwMemoryLoad);
         nStringLength = lstrlen (szOutputString) * sizeof (CHAR);
         lTextOutReturn = TabbedTextOut (hdc, nX, nY,
                                         szOutputString, nStringLength, 0, NULL, 0);
         nY += HIWORD (lTextOutReturn);

         _snprintf_s(szOutputString, 100, _TRUNCATE, "Page file in use:  \t%3.1d%%",
                  dwPercentUsed);
         nStringLength = lstrlen (szOutputString) * sizeof (CHAR);
         lTextOutReturn = TabbedTextOut(hdc, nX, nY,
                                         szOutputString, nStringLength, 0, NULL, 0);
         nY += HIWORD(lTextOutReturn);

         EndPaint (hWnd, &ps);
      }
      break;

   case WM_DESTROY:
      FreeAllocatedMemory();
      // Tell WinHelp we don't need it any more...
      WinHelp(hWnd, APPNAME".HLP", HELP_QUIT,(DWORD)0);
      PostQuitMessage(0);
      break;

   default:
      return (DefWindowProc(hWnd, message, wParam, lParam));
   }
   return (0);
}
Example #2
0
/******************************************************************************
 * long  APIENTRY FontEditWndProc(hBox, message, wParam, lParam)
 *
 * purpose: Master controller for Fontedit's all-encompassing main window
 *
 * params : same as for all window functions
 *
 * side effects: countless
 *
 *****************************************************************************/
LONG  APIENTRY 
FontEditWndProc(
	HWND   hBox,
	WORD   message,
	WPARAM wParam,
	LONG   lParam
	)
{
	PAINTSTRUCT	ps;
	HMENU	hMenu;
	WORD	mf;
	POINT	pt;
	RECT	BoxRect;

	switch (message) {
	case WM_CLOSE:
		if (!CheckSave())    /* See if any files need saving */
			break;
		/* Window's being destroyed. */
		if (fLoaded)         /* 4/8/87 Linsh added */
			DeleteBitmap(); /* Get rid of memory DC */
		DestroyWindow(hFont);
		DestroyWindow(hBox);
		break;

	case WM_DESTROY:
		PostQuitMessage(0);  /* Cause application to be terminated */
		break;

	case WM_QUERYENDSESSION:
		if (CheckSave())             /* See if any files need saving */
			return TRUE;
		break;

	case WM_ENDSESSION:
		if (fLoaded)
			DeleteBitmap();      /* Get rid of memory DC */
		break;

	case WM_SIZE:
		/* Window's size is changing.  lParam contains the width
        ** and height, in the low and high words, respectively.
        ** wParam contains SIZENORMAL for "normal" size changes,
        ** SIZEICONIC when the window is being made iconic, and
        ** SIZEFULLSCREEN when the window is being made full screen. */
		switch (wParam) {
		case SIZEFULLSCREEN:
		case SIZENORMAL:
			ResizeShow();
			if (kStuff != GetkStuff())	/* Did it change ? */
				ResizeShow();           /* Yes resize again */
			break;
		}
		break;

	case WM_MOVE: /* Tell popup to move with us. */
		if (!IsIconic(hBox))
			ResizeShow();
		break;

	case WM_PAINT:
		/* Time for the window to draw itself. */
		BeginPaint(hBox, (LPPAINTSTRUCT)&ps);
		FontEditPaint(hBox,  ps.hdc);
		EndPaint(hBox, (LPPAINTSTRUCT)&ps);
		break;


	case WM_COMMAND:
		/* A menu item has been selected, or a control is notifying
		 * its parent.  wParam is the menu item value (for menus),
		 * or control ID (for controls).  For controls, the low word
		 * of lParam has the window handle of the control, and the hi
		 * word has the notification code.  For menus, lParam contains
		 * 0L. */
		FontEditCommand(hBox, GET_WM_COMMAND_ID(wParam, lParam));
		break;

		/* Data interchange request. */
	case WM_CUT:
	case WM_COPY:
	case WM_PASTE:
	case WM_CLEAR:
	case WM_UNDO:
	case WM_RENDERFORMAT:
	case WM_RENDERALLFORMATS:
	case WM_DESTROYCLIPBOARD:
	case WM_DRAWCLIPBOARD:
		break;
	case WM_INITMENU:
		hMenu = GetMenu(hBox);  /* Gray menu if no clipboard bitmap */
		mf = (WORD)(IsClipboardFormatAvailable(CF_BITMAP) ? MF_ENABLED : 
				MF_GRAYED);
		EnableMenuItem(hMenu, BOX_PASTE, mf);
		EnableMenuItem(hMenu, FONT_PASTE, mf);
		break;

	/* For each of following mouse window messages, wParam contains
	** bits indicating whether or not various virtual keys are down,
	** and lParam is a POINT containing the mouse coordinates.   The
	** keydown bits of wParam are:  MK_LBUTTON (set if Left Button is
	** down); MK_RBUTTON (set if Right Button is down); MK_SHIFT (set
	** if Shift Key is down); MK_ALTERNATE (set if Alt Key is down);
	** and MK_CONTROL (set if Control Key is down). */

	case WM_LBUTTONDOWN:
		MPOINT2POINT(MAKEMPOINT(lParam), pt);

		if (fStartRubberBand) {
			/* a green signal to rubberband a rectangle for the
			 * Fill menu command rectangle now has null dimensions.
			 * Snap the current mouse point to nearest grid
			 * intersection thus defining upper left corner of
			 * rectangle */

			if (PtInRect((LPRECT)&FontRect, pt)) {
				pt = SnapPointToGrid(pt);
				rectRubber.top    =  pt.y   *scale+ptBox.y+1;
				rectRubber.bottom = (pt.y+1)*scale+ptBox.y-2;
				rectRubber.left   =  pt.x   *scale+ptBox.x+1;
				rectRubber.right  = (pt.x+1)*scale+ptBox.x-2;

				hDst = InitialiseRubberBandingRect(hBox);
				DrawRubberBand(hDst, &rectRubber, R2_XORPEN);
			}
			else {
				fStartRubberBand = fRubberBanding = FALSE;
				ReleaseCapture();
			}
		}
		/* do operation depending upon current active command,
		 * but not if we just added/deleted a row/column. */
		if (!fJustZapped) {
			if (fStartRubberBand) {
				pt.x *= scale;
				pt.y *= scale;
				MouseInBox(hBox, message, pt);
			}
			else {
				MPOINT2POINT(MAKEMPOINT(lParam), pt);
				MouseInBox(hBox, message, pt);
			}
		}

		break;

	case WM_LBUTTONUP:               /* Get other corner of rectangle */
		fJustZapped = FALSE;
		if (fRubberBanding) {
			/* if rubberbanding for the Fill menu command,
			 * terminate proceedings and clean up */
			DrawRubberBand(hDst, &rectRubber, R2_NOT);
			EndRubberBandingRect(hDst);
			if (cursor) {
				ReadRect();
			}
		}
		if (fCaptured ) {
			/* if cursor is + shaped, restore it to default */
			ReleaseCapture();
			SetCursor (hOldCursor);
		}
		break;

	case WM_RBUTTONDOWN:
	case WM_RBUTTONUP:
		break;

	case WM_MOUSEMOVE:                      /* If mouse is down */

		MPOINT2POINT(MAKEMPOINT(lParam), pt);

		if ((fRubberBanding) && (wParam & MK_LBUTTON)) {
			/* if any of Fill menu commands is active
			** (AND the mouse key depressed) draw a rubberband
			** a rectangle with the mouse movements */

			/* get current square number */
			pt = SnapPointToGrid(pt);

			/* calculate grid for new square */
			BoxRect.top    =  pt.y   *scale+ptBox.y+1;
			BoxRect.bottom = (pt.y+1)*scale+ptBox.y-2;
			BoxRect.left   =  pt.x   *scale+ptBox.x+1;
			BoxRect.right  = (pt.x+1)*scale+ptBox.x-2;

			/* erase old mark */
			DrawRubberBand(hDst, &rectRubber, R2_NOT);

			/* limit rubber band to box */
                        if (BoxRect.right > scale * (LONG)wBox + ptBox.x)
				BoxRect.right = scale * wBox + ptBox.x;
                        if (BoxRect.bottom > scale * (LONG)kBox + ptBox.y)
				BoxRect.bottom = scale * kBox + ptBox.y;
			if (BoxRect.top < 0)
				BoxRect.top = 1;
			if (BoxRect.left < 0)
				BoxRect.left = 1;

			if (ptA.x == pt.x) {
				rectRubber.right  = BoxRect.right;
				rectRubber.left   = BoxRect.left;
			}
			if (ptA.y == pt.y) {
				rectRubber.bottom = BoxRect.bottom;
				rectRubber.top    = BoxRect.top;
			}

			/* almost an IntersectRect */
			if (ptA.x >= pt.x)
				rectRubber.left   = BoxRect.left;
			else
				rectRubber.right  = BoxRect.right;

			if (ptA.y >= pt.y)
				rectRubber.top    = BoxRect.top;
			else
				rectRubber.bottom = BoxRect.bottom;

			/* Draw new mark */
			DrawRubberBand(hDst, &rectRubber, R2_XORPEN);
		}
		else {
			/* if not "Fill"ing(AND mouse key depressed,
			 * paint with the mouse movements */
			if ((wParam & MK_LBUTTON) && cursor == FALSE && 
			    fJustZapped == FALSE)
				MouseInBox(hBox, message, pt);
		}
		break;

	case WM_LBUTTONDBLCLK:
	case WM_RBUTTONDBLCLK:
		break;

	default:

		/* Everything else comes here.  This call MUST exist
        ** in your window proc.  */

		return(DefWindowProc(hBox, message, wParam, lParam));
		break;
	}

	/* A window proc should always return something */
	return(0L);
}
Example #3
0
// Altered by Darren Owen (DrO) on 1/10/2003
void Items(HWND hwnd, int on) {
    UINT mf = (!on ? MF_GRAYED : MF_ENABLED);

    if(!on)
        g_sdata.focused_hwnd = GetFocus();
    // Altered by Darren Owen (DrO) on 6/10/2003
    else
        EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),1);

    EnableWindow(GetDlgItem(hwnd,IDC_CLOSE),on);
    // Altered by Darren Owen (DrO) on 6/10/2003
    if((!g_sdata.retcode && on) || !on)
        EnableWindow(GetDlgItem(hwnd,IDC_TEST),on);
    EnableWindow(GetDlgItem(hwnd,IDC_RECOMPILE_TEST),on);

    EnableMenuItem(g_sdata.menu,IDM_SAVE,mf);
    // Altered by Darren Owen (DrO) on 6/10/2003
    if((!g_sdata.retcode && on) || !on)
        EnableMenuItem(g_sdata.menu,IDM_TEST,mf);
    EnableMenuItem(g_sdata.menu,IDM_EXIT,mf);
    EnableMenuItem(g_sdata.menu,IDM_LOADSCRIPT,mf);
    EnableMenuItem(g_sdata.menu,IDM_RECOMPILE,mf);
    EnableMenuItem(g_sdata.menu,IDM_COPY,mf);
    EnableMenuItem(g_sdata.menu,IDM_COPYSELECTED,mf);
    EnableMenuItem(g_sdata.menu,IDM_EDITSCRIPT,mf);
    EnableMenuItem(g_sdata.menu,IDM_CLEARLOG,mf);
    EnableMenuItem(g_sdata.menu,IDM_BROWSESCR,mf);
    EnableMenuItem(g_sdata.menu,IDM_RECOMPILE_TEST,mf);
    EnableMenuItem(g_sdata.menu,IDM_COMPRESSOR,mf);

    EnableToolBarButton(IDM_SAVE,on);
    // Altered by Darren Owen (DrO) on 6/10/2003
    if((!g_sdata.retcode && on) || !on)
        EnableToolBarButton(IDM_TEST,on);
    EnableToolBarButton(IDM_EXIT,on);
    EnableToolBarButton(IDM_LOADSCRIPT,on);
    EnableToolBarButton(IDM_RECOMPILE,on);
    EnableToolBarButton(IDM_COPY,on);
    EnableToolBarButton(IDM_EDITSCRIPT,on);
    EnableToolBarButton(IDM_CLEARLOG,on);
    EnableToolBarButton(IDM_BROWSESCR,on);
    EnableToolBarButton(IDM_RECOMPILE_TEST,on);
    EnableToolBarButton(IDM_COMPRESSOR,on);

    if(!on) {
        if (!IsWindowEnabled(g_sdata.focused_hwnd))
            SetFocus(GetDlgItem(hwnd,IDC_LOGWIN));
    }
    else
        SetFocus(g_sdata.focused_hwnd);
}
Example #4
0
void DesEnableMenuItem(HMENU hMenu, UINT uIDEnableItem, bool enable)
{
	EnableMenuItem(hMenu, uIDEnableItem, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
}
Example #5
0
/*
 * SetDisplayType - changes the heap display type to 'type' unless type is
 *                  'HEAPMENU_DISPLAY_INIT' in which case this is assumed to
 *                  be the first call to SetDisplayType and the heap display
 *                  type is set to 'HeapType'
 */
static void SetDisplayType( HWND hwnd, HWND **title, WORD type ) {

    HMENU       mh;
    char        buf[256];
    char        *typename;

    if( type == HeapType ) return;
    if( type == HEAPMENU_DISPLAY_DPMI && !WDebug386 ) {
        RCMessageBox( HeapWalkMainWindow, STR_INSTALL_WDEBUG,
                      HeapWalkName, MB_OK | MB_ICONEXCLAMATION );
        return;
    }
    mh = GetMenu( hwnd );
    if( type == HEAPMENU_DISPLAY_INIT ) {
        type = HeapType;
        HeapType = HEAPMENU_DISPLAY_INIT;
    } else {
        CheckMenuItem( mh, HeapType, MF_UNCHECKED | MF_BYCOMMAND );
    }

    /* undo anything done for the previous state */
    switch( HeapType ) {
    case HEAPMENU_DISPLAY_DPMI:
        EnableMenuItem( mh, HEAPMENU_ADD, MF_BYCOMMAND | MF_ENABLED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_DISCARD,
                        MF_BYCOMMAND | MF_ENABLED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_OLDEST,
                        MF_BYCOMMAND | MF_ENABLED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_NEWEST,
                        MF_BYCOMMAND | MF_ENABLED );
        EnableMenuItem( mh, HEAPMENU_LOCAL_LOCALWALK,
                        MF_BYCOMMAND | MF_ENABLED );
        EnableMenuItem( mh, HEAPMENU_COMPACT_AND_LOCALWALK,
                        MF_BYCOMMAND | MF_ENABLED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_GET_SELECTOR,
                        MF_BYCOMMAND | MF_ENABLED );
        EnableMenuItem( mh, HEAPMENU_LOCAL_MONITOR,
                        MF_BYCOMMAND | MF_ENABLED );
        ModifyMenu( mh, 2, MF_BYPOSITION | MF_POPUP,
                    (UINT)LoadMenu( Instance, "SORTMENU" ),
                    HWGetRCString( STR_SORT ) );
        KillPushWin( *title );
        *title = SetUpPushWindows( hwnd, HEAPMENU_DISPLAY_ENTIRE );
        if( GSortType == HEAPMENU_SORT_GRAN ||
            GSortType == HEAPMENU_SORT_DPL ) GSortType = HEAPMENU_SORT_HANDLE;
        break;
    case HEAPMENU_DISPLAY_LRU:
        DeleteMenu( mh, HEAPMENU_SORT_LRU, MF_BYCOMMAND );
        if( GSortType == HEAPMENU_SORT_LRU ) GSortType = HEAPMENU_SORT_HANDLE;
        break;
    case HEAPMENU_DISPLAY_INIT:
        if( type != HEAPMENU_DISPLAY_DPMI ) {
            *title = SetUpPushWindows( hwnd, type );
            ModifyMenu( mh, 2, MF_BYPOSITION | MF_POPUP,
                    (UINT)LoadMenu( Instance, "SORTMENU" ),
                    HWGetRCString( STR_SORT ) );
        } else {
            *title = NULL;
        }
        break;
    }
    /* do things for the new state */
    switch( type ) {
    case HEAPMENU_DISPLAY_DPMI:
        ModifyMenu( mh, 2, MF_BYPOSITION | MF_POPUP,
                    (UINT)LoadMenu( Instance, "SORTDPMIMENU" ),
                    HWGetRCString( STR_SORT ) );
        EnableMenuItem( mh, HEAPMENU_ADD, MF_BYCOMMAND | MF_GRAYED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_DISCARD,
                        MF_BYCOMMAND | MF_GRAYED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_OLDEST,
                        MF_BYCOMMAND | MF_GRAYED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_NEWEST,
                        MF_BYCOMMAND | MF_GRAYED );
        EnableMenuItem( mh, HEAPMENU_LOCAL_LOCALWALK,
                        MF_BYCOMMAND | MF_GRAYED );
        EnableMenuItem( mh, HEAPMENU_COMPACT_AND_LOCALWALK,
                        MF_BYCOMMAND | MF_GRAYED );
        EnableMenuItem( mh, HEAPMENU_OBJECT_GET_SELECTOR,
                        MF_BYCOMMAND | MF_GRAYED );
        EnableMenuItem( mh, HEAPMENU_LOCAL_MONITOR,
                        MF_BYCOMMAND | MF_GRAYED );
        if( GSortType == HEAPMENU_SORT_MODULE ||
                GSortType == HEAPMENU_SORT_TYPE ) {
            CheckMenuItem( mh, GSortType, MF_UNCHECKED | MF_BYCOMMAND );
            GSortType = HEAPMENU_SORT_ADDR;
        }
//      SetTitle( HeapDPMITitles, title );
        KillPushWin( *title );
        *title = SetUpPushWindows( hwnd, type );
        typename = HWAllocRCString( STR_SELECTOR_LIST_ITEMS );
        break;
    case HEAPMENU_DISPLAY_LRU:
        InsertMenu( mh, HEAPMENU_SORT_FLAG, MF_BYCOMMAND, HEAPMENU_SORT_LRU,
                   GetRCString( STR_BY_AGE ) );
        typename = HWAllocRCString( STR_LRU_ITEMS );
        break;
    case HEAPMENU_DISPLAY_ENTIRE:
        typename = HWAllocRCString( STR_ENTIRE_HEAP );
        break;
    case HEAPMENU_DISPLAY_FREE:
        typename = HWAllocRCString( STR_FREE_ITEMS );
        break;
    default:
        typename = "";
        break;
    }
    CheckMenuItem( mh, type, MF_CHECKED | MF_BYCOMMAND );
    CheckMenuItem( mh, GSortType, MF_CHECKED | MF_BYCOMMAND );
    DrawMenuBar( hwnd );
    sprintf( buf, "%s - %s", HeapWalkName, typename );
    HWFreeRCString( typename );
    SetWindowText( hwnd, buf );
    HeapType = type;
} /* SetDisplayType */
Example #6
0
static LRESULT
OnNotify(PMAIN_WND_INFO Info,
         LPARAM lParam)
{
    LPNMHDR pnmhdr = (LPNMHDR)lParam;
    LRESULT ret = 0;

    switch (pnmhdr->code)
    {
        case TVN_SELCHANGED:
        {
            LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW)lParam;

            if (Info->Display == DevicesByType)
            {
                if (!TreeView_GetChild(Info->hTreeView,
                                       pnmtv->itemNew.hItem))
                {
                    SendMessage(Info->hTool,
                                TB_SETSTATE,
                                IDC_PROP,
                                (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));

                    EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_ENABLED);
                    EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_ENABLED);
                }
                else
                {
                    SendMessage(Info->hTool,
                                TB_SETSTATE,
                                IDC_PROP,
                                (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));

                    EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
                    EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
                }
            }
            else if (Info->Display == DevicesByConnection)
            {
                if (pnmtv->itemNew.hItem == TreeView_GetRoot(Info->hTreeView))
                {
                    SendMessage(Info->hTool,
                                TB_SETSTATE,
                                IDC_PROP,
                                (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));

                    EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
                    EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
                }
                else
                {
                    SendMessage(Info->hTool,
                                TB_SETSTATE,
                                IDC_PROP,
                                (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));

                    EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_ENABLED);
                    EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_ENABLED);
                }
            }
        }
        break;

        case NM_DBLCLK:
        {
            HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView);
            TV_HITTESTINFO HitTest;

            if (Info->Display == DevicesByType)
            {
                if (!TreeView_GetChild(Info->hTreeView,
                                       hSelected))
                {
                    if (GetCursorPos(&HitTest.pt) &&
                        ScreenToClient(Info->hTreeView, &HitTest.pt))
                    {
                        if (TreeView_HitTest(Info->hTreeView, &HitTest))
                        {
                            if (HitTest.hItem == hSelected)
                            {
                                OpenPropSheet(Info->hTreeView,
                                              hSelected);
                                ret = TRUE;
                            }
                        }
                    }
                }
            }
            else if (Info->Display == DevicesByConnection)
            {
                if (hSelected != TreeView_GetRoot(Info->hTreeView))
                {
                    if (GetCursorPos(&HitTest.pt) &&
                        ScreenToClient(Info->hTreeView, &HitTest.pt))
                    {
                        if (TreeView_HitTest(Info->hTreeView, &HitTest))
                        {
                            if (HitTest.hItem == hSelected)
                            {
                                OpenPropSheet(Info->hTreeView,
                                              hSelected);
                                ret = TRUE;
                            }
                        }
                    }
                }
            }
        }
        break;

        case NM_RCLICK:
        {
            TV_HITTESTINFO HitTest;

            if (GetCursorPos(&HitTest.pt) &&
                ScreenToClient(Info->hTreeView, &HitTest.pt))
            {
                if (TreeView_HitTest(Info->hTreeView, &HitTest))
                    (void)TreeView_SelectItem(Info->hTreeView, HitTest.hItem);
            }
        }
        break;

        case TTN_GETDISPINFO:
        {
            LPTOOLTIPTEXT lpttt;
            UINT idButton;

            lpttt = (LPTOOLTIPTEXT)lParam;

            idButton = (UINT)lpttt->hdr.idFrom;
            switch (idButton)
            {
                case IDC_PROP:
                    lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
                break;

                case IDC_REFRESH:
                    lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
                break;

                case IDC_PROGHELP:
                    lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP);
                break;

                case IDC_EXIT:
                    lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
                break;
            }
        }
        break;
    }

    return ret;
}
Example #7
-1
File: Ui.c Project: kichik/nsis-1
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  if (uMsg == WM_INITDIALOG || uMsg == WM_NOTIFY_OUTER_NEXT)
  {
    page *this_page;
    static DLGPROC winprocs[]=
    {
#ifdef NSIS_CONFIG_LICENSEPAGE
      LicenseProc,
#endif
#ifdef NSIS_CONFIG_COMPONENTPAGE
      SelProc,
#endif
      DirProc,
      InstProc,
#ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
      UninstProc
#endif
    };

    m_delta = wParam;

    if (uMsg == WM_INITDIALOG)
    {
      g_hwnd=hwndDlg;
      m_hwndOK=GetDlgItem(hwndDlg,IDOK);
      m_hwndCancel=GetDlgItem(hwndDlg,IDCANCEL);
      SetDlgItemTextFromLang(hwndDlg,IDC_VERSTR,LANG_BRANDING);
      SetClassLong(hwndDlg,GCL_HICON,(long)g_hIcon);
      // use the following line instead of the above, if .rdata needs shirking
      //SendMessage(hwndDlg,WM_SETICON,ICON_BIG,(LPARAM)g_hIcon);
#if defined(NSIS_SUPPORT_CODECALLBACKS) && defined(NSIS_CONFIG_ENHANCEDUI_SUPPORT)
      g_quit_flag = ExecuteCallbackFunction(CB_ONGUIINIT);
#endif
        //ShowWindow(hwndDlg, SW_SHOW);
      m_delta = 1;
    }

    this_page=g_pages+m_page;

    if (m_page>=0) {
#ifdef NSIS_SUPPORT_CODECALLBACKS
      // Call leave function. If Abort used don't move to the next page.
      // But if quit called we must exit now
      if (m_delta==1) if (ExecuteCodeSegment(this_page->leavefunc,NULL)) {
        SendMessage(m_curwnd, WM_IN_UPDATEMSG, 0, 1);
        return !g_quit_flag;
      }
#endif

      // if the last page was a custom page, wait for it to finish by itself.
      // if it doesn't, it's a BAD plugin.
      // plugins should react to WM_NOTIFY_OUTER_NEXT.
      if (!this_page->dlg_id) return 0;
    }

    NotifyCurWnd(WM_NOTIFY_INIGO_MONTOYA);

nextPage:
    m_page+=m_delta;
    this_page+=m_delta;

#ifdef NSIS_SUPPORT_CODECALLBACKS
    if (m_page==g_blocks[NB_PAGES].num) ExecuteCallbackFunction(CB_ONINSTSUCCESS);
#endif//NSIS_SUPPORT_CODECALLBACKS

    if (g_quit_flag || (unsigned int)m_page >= (unsigned int)g_blocks[NB_PAGES].num)
    {
      DestroyWindow(m_curwnd);
      g_hwnd = 0;
      EndDialog(hwndDlg,m_retcode);
    }
    else
    {
      HWND hwndtmp;

      int pflags = this_page->flags;

      GetNSISString(state_click_next, this_page->clicknext);
      SetDlgItemTextFromLang(hwndDlg, IDOK, this_page->next);
      SetDlgItemTextFromLang(hwndDlg, IDC_BACK, this_page->back);
      SetDlgItemTextFromLang(hwndDlg, IDCANCEL, this_page->cancel);

      hwndtmp = GetDlgItem(hwndDlg, IDC_BACK);

      if (g_exec_flags.abort)
      {
        pflags &= ~(PF_BACK_ENABLE | PF_NEXT_ENABLE);
        pflags |= PF_CANCEL_ENABLE;
      }

      ShowWindow(hwndtmp, pflags & PF_BACK_SHOW);// SW_HIDE = 0, PF_BACK_SHOW = SW_SHOWNA = 8
      EnableWindow(hwndtmp, pflags & PF_BACK_ENABLE);
      EnableNext(pflags & PF_NEXT_ENABLE);
      EnableWindow(m_hwndCancel, pflags & PF_CANCEL_ENABLE);

      if (pflags & PF_CANCEL_ENABLE)
        EnableMenuItem(GetSystemMenu(hwndDlg, FALSE), SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
      else
        EnableMenuItem(GetSystemMenu(hwndDlg, FALSE), SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);

      SendMessage(hwndtmp, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);

      if (g_exec_flags.abort)
      {
        SendMessage(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
        SetActiveCtl(m_hwndCancel);
      }
      else
      {
        SetActiveCtl(m_hwndOK);
      }

      mystrcpy(g_tmp,g_caption);
      GetNSISString(g_tmp+mystrlen(g_tmp),this_page->caption);
      my_SetWindowText(hwndDlg,g_tmp);

#ifdef NSIS_SUPPORT_CODECALLBACKS
      // custom page or user used abort in prefunc
      if (ExecuteCodeSegment(this_page->prefunc, NULL) || !this_page->dlg_id) {
        goto nextPage;
      }
#endif //NSIS_SUPPORT_CODECALLBACKS

      if (this_page->wndproc_id != PWP_COMPLETED)
      {
        DestroyWindow(m_curwnd);
      }
      else {
        if (!g_exec_flags.abort && g_exec_flags.autoclose)
          goto nextPage;
        // no need to go to skipPage because PWP_COMPLETED always follows PWP_INSTFILES
        return FALSE;
      }

      // update g_this_page for the dialog proc
      g_this_page=this_page;

      if (this_page->dlg_id > 0) // NSIS page
      {
        m_curwnd=CreateDialogParam(
          g_hInstance,
          MAKEINTRESOURCE(this_page->dlg_id+dlg_offset),
          hwndDlg,winprocs[this_page->wndproc_id],(LPARAM)this_page
        );
        if (m_curwnd)
        {
          RECT r;

          SetDlgItemTextFromLang(m_curwnd,IDC_INTROTEXT,this_page->parms[0]);

          GetWindowRect(GetDlgItem(hwndDlg,IDC_CHILDRECT),&r);
          ScreenToClient(hwndDlg,(LPPOINT)&r);
          SetWindowPos(m_curwnd,0,r.left,r.top,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
#ifdef NSIS_SUPPORT_CODECALLBACKS
          ExecuteCodeSegment(this_page->showfunc,NULL);
          if (g_quit_flag)
            return FALSE;
#endif //NSIS_SUPPORT_CODECALLBACKS
          ShowWindow(m_curwnd,SW_SHOWNA);
          NotifyCurWnd(WM_NOTIFY_START);
        }
      }
    }

skipPage:

    if (!ui_dlg_visible && m_curwnd)
    {
      ShowWindow(hwndDlg, SW_SHOWDEFAULT);
      ui_dlg_visible = 1;
    }

    return FALSE;
  }

#ifdef NSIS_SUPPORT_BGBG
  if (uMsg == WM_WINDOWPOSCHANGED)
  {
    SetWindowPos(m_bgwnd, hwndDlg, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
  }
  if (uMsg == WM_SIZE) {
    ShowWindow(m_bgwnd, wParam == SIZE_MINIMIZED ? SW_HIDE : SW_SHOW);
  }
#endif //NSIS_SUPPORT_BGBG

  if (uMsg == WM_NOTIFY_CUSTOM_READY) {
    DestroyWindow(m_curwnd);
    m_curwnd = (HWND)wParam;
    goto skipPage;
  }
  if (uMsg == WM_QUERYENDSESSION)
  {
    SetWindowLong(hwndDlg, DWL_MSGRESULT, FALSE);
    return TRUE;
  }
  if (uMsg == WM_COMMAND)
  {
    int id = LOWORD(wParam);
    HWND hCtl = GetDlgItem(hwndDlg, id); // lParam might be NULL
    if (hCtl)
    {
      SendMessage(hCtl, BM_SETSTATE, FALSE, 0);
      if (!IsWindowEnabled(hCtl))
        return 0;
    }

    if (id == IDOK)
    {
      outernotify(1);
    }
    else if (id == IDC_BACK && m_page>0)
    {
      outernotify(-1);
    }
    else if (id == IDCANCEL)
    {
      if (g_exec_flags.abort)
      {
#ifdef NSIS_SUPPORT_CODECALLBACKS
        ExecuteCallbackFunction(CB_ONINSTFAILED);
#endif//NSIS_SUPPORT_CODECALLBACKS
        m_retcode=2;
        outernotify(NOTIFY_BYE_BYE);
      }
      else
      {
#ifdef NSIS_SUPPORT_CODECALLBACKS
        if (!ExecuteCallbackFunction(CB_ONUSERABORT))
#endif//NSIS_SUPPORT_CODECALLBACKS
        {
          m_retcode=1;
          outernotify(NOTIFY_BYE_BYE);
        }
      }
    }
    else
    {
      // Forward WM_COMMANDs to inner dialogs, can be custom ones.
      // Without this, enter on buttons in inner dialogs won't work.
      SendMessage(m_curwnd, WM_COMMAND, wParam, lParam);
    }
  }
  return HandleStaticBkColor();
}