int cdecl Message (UINT type, LPCTSTR title, LPCTSTR text, LPCTSTR fmt, ...)
{
   va_list  arg;
   // if (fmt != NULL)
      va_start (arg, fmt);
   return vMessage (type, PtrToLong(title), PtrToLong(text), fmt, arg);
}
Exemple #2
0
Debugstr & Debugstr::operator<< (void *addr)
{
   char  szTemp[40];
   if (HIWORD(addr) == 0x0000)
      wsprintf (szTemp, "0x%04X", (ushort)LOWORD(PtrToLong(addr)));
   else
      wsprintf (szTemp, "0x%08lX", PtrToLong(addr));
   return (*this << szTemp);
}
// Create Console View as child of Main Window
void CreateConsoleView(HWND hwndParent, int x, int y, int width, int height)
{
    ASSERT(hwndParent != NULL);

    g_hwndConsole = CreateWindow(
            CLASSNAME_TOOLWINDOW, NULL,
            WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
            x, y, width, height,
            hwndParent, NULL, g_hInst, NULL);
    SetWindowText(g_hwndConsole, _T("Debug Console"));

    // ToolWindow subclassing
    m_wndprocConsoleToolWindow = (WNDPROC) LongToPtr( SetWindowLongPtr(
            g_hwndConsole, GWLP_WNDPROC, PtrToLong(ConsoleViewWndProc)) );

    RECT rcConsole;  GetClientRect(g_hwndConsole, &rcConsole);

    m_hwndConsoleEdit = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            _T("EDIT"), NULL,
            WS_CHILD | WS_VISIBLE,
            90, rcConsole.bottom - 20,
            rcConsole.right - 90, 20,
            g_hwndConsole, NULL, g_hInst, NULL);
    m_hwndConsoleLog = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            _T("EDIT"), NULL,
            WS_CHILD | WS_VSCROLL | WS_VISIBLE | ES_READONLY | ES_MULTILINE,
            0, 0,
            rcConsole.right, rcConsole.bottom - 20,
            g_hwndConsole, NULL, g_hInst, NULL);
    m_hwndConsolePrompt = CreateWindowEx(
            0,
            _T("STATIC"), NULL,
            WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE | SS_CENTER | SS_NOPREFIX,
            0, rcConsole.bottom - 20,
            90, 20,
            g_hwndConsole, NULL, g_hInst, NULL);

    m_hfontConsole = CreateMonospacedFont();
    SendMessage(m_hwndConsolePrompt, WM_SETFONT, (WPARAM) m_hfontConsole, 0);
    SendMessage(m_hwndConsoleEdit, WM_SETFONT, (WPARAM) m_hfontConsole, 0);
    SendMessage(m_hwndConsoleLog, WM_SETFONT, (WPARAM) m_hfontConsole, 0);

    // Edit box subclassing
    m_wndprocConsoleEdit = (WNDPROC) LongToPtr( SetWindowLongPtr(
            m_hwndConsoleEdit, GWLP_WNDPROC, PtrToLong(ConsoleEditWndProc)) );

    ShowWindow(g_hwndConsole, SW_SHOW);
    UpdateWindow(g_hwndConsole);

    ConsoleView_Print(_T("Use 'h' command to show help.\r\n\r\n"));
    PrintConsolePrompt();
    SetFocus(m_hwndConsoleEdit);
}
Exemple #4
0
void
SWindow::SetSubClass(void)
{
	OriginalWndProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(GWLP_WNDPROC));

	SetWindowLongPtr(GWLP_USERDATA, PtrToLong(this));
	SetWindowLongPtr(
				GWLP_WNDPROC,
				(ControlMode == ControlMode_Dialog) ? PtrToLong(SDialogProc) : PtrToLong(SWindowProc));

	SetupWindow();
}
Exemple #5
0
void MemoryMapView_Create(HWND hwndParent, int x, int y)
{
    int cxScroll = ::GetSystemMetrics(SM_CXVSCROLL);
    int cyCaption = TOOLWINDOW_CAPTION_HEIGHT;

    int width = m_nMemoryMap_ViewCX + cxScroll;
    int height = m_nMemoryMap_ViewCY + cyCaption;
    g_hwndMemoryMap = CreateWindow(
            CLASSNAME_TOOLWINDOW, _T("Memory Map"),
            WS_CHILD | WS_VISIBLE,
            x, y, width, height,
            hwndParent, NULL, g_hInst, NULL);

    // ToolWindow subclassing
    m_wndprocMemoryMapToolWindow = (WNDPROC) LongToPtr( SetWindowLongPtr(
            g_hwndMemoryMap, GWLP_WNDPROC, PtrToLong(MemoryMapViewWndProc)) );

    RECT rcClient;  GetClientRect(g_hwndMemoryMap, &rcClient);

    m_hwndMemoryMapViewer = CreateWindow(
            CLASSNAME_MEMORYMAPVIEW, NULL,
            WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP,
            0, 0, rcClient.right, rcClient.bottom,
            g_hwndMemoryMap, NULL, g_hInst, NULL);

    MemoryMapView_InitBitmap();
    MemoryMapView_UpdateScrollPos();
}
Exemple #6
0
VOID UnHookWindowProcedure()
{
    DWORD dwWindowPId, dwMyPId = GetCurrentProcessId();
    HWND hwndCurrent = NULL;

    if(g_wpOrigWndProc)
    {
        if(g_hWaitProc)
		{
            TerminateThread(g_hWaitProc, 0);
			g_hWaitProc = NULL;
		}

        do
        {
            hwndCurrent = FindWindowEx(NULL, hwndCurrent, "GxWindowClassD3d", NULL);
            GetWindowThreadProcessId(hwndCurrent, &dwWindowPId);
            if(dwWindowPId == dwMyPId)
            {
                SetWindowLong(hwndCurrent, GWL_WNDPROC, PtrToLong(g_wpOrigWndProc));
                g_wpOrigWndProc = NULL;
                return;
            }
        } while(hwndCurrent);
    }
}
CString COXShortkeysOrganizer::GetAccelKeyString(ACCEL* pAccel)
{
	ASSERT(pAccel!=NULL);

	CString sKey(_T(""));
	if(pAccel->fVirt&FSHIFT)
		sKey+=_T("Shift+");
	if(pAccel->fVirt&FCONTROL)
		sKey+=_T("Ctrl+");
	if(pAccel->fVirt&FALT)
		sKey+=_T("Alt+");
	if(pAccel->fVirt&FVIRTKEY)
	{
		TCHAR szKeyName[10];
		LPARAM lParam=MAKELPARAM(0,::MapVirtualKey(pAccel->key,0)) | 
			(pAccel->key<0x0030 ? 0x01000000 : 0);
		if(pAccel->key!=0xbf)
		{
			::GetKeyNameText(PtrToLong(lParam),szKeyName,10);
		}
		else
		{
			lstrcpy(szKeyName,_T("Slash"));
		}
		sKey+=szKeyName;
	}
	else
	{
		sKey+=(TCHAR)pAccel->key;
	}

	return sKey;
}
Exemple #8
0
void CreateMemoryView(HWND hwndParent, int x, int y, int width, int height)
{
    ASSERT(hwndParent != NULL);

    g_hwndMemory = CreateWindow(
            CLASSNAME_TOOLWINDOW, NULL,
            WS_CHILD | WS_VISIBLE,
            x, y, width, height,
            hwndParent, NULL, g_hInst, NULL);
    MemoryView_UpdateWindowText();

    // ToolWindow subclassing
    m_wndprocMemoryToolWindow = (WNDPROC) LongToPtr( SetWindowLongPtr(
            g_hwndMemory, GWLP_WNDPROC, PtrToLong(MemoryViewWndProc)) );

    RECT rcClient;  GetClientRect(g_hwndMemory, &rcClient);

    m_hwndMemoryViewer = CreateWindowEx(
            WS_EX_STATICEDGE,
            CLASSNAME_MEMORYVIEW, NULL,
            WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP,
            0, 0, rcClient.right, rcClient.bottom,
            g_hwndMemory, NULL, g_hInst, NULL);

    MemoryView_ScrollTo(0);
}
Exemple #9
0
void CreateMemoryMapView(int x, int y)
{
    int cxBorder = ::GetSystemMetrics(SM_CXDLGFRAME);
    int cyBorder = ::GetSystemMetrics(SM_CYDLGFRAME);
    int cxScroll = ::GetSystemMetrics(SM_CXVSCROLL);
    int cyScroll = ::GetSystemMetrics(SM_CYHSCROLL);
    int cyCaption = ::GetSystemMetrics(SM_CYSMCAPTION);

    int width = 256 * 2 + cxScroll + cxBorder * 2;
    int height = 256 * 2 + cyScroll + cyBorder * 2 + cyCaption;
    g_hwndMemoryMap = CreateWindowEx(
            WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
            CLASSNAME_OVERLAPPEDWINDOW, _T("BK Memory Map"),
            WS_POPUPWINDOW | WS_CAPTION | WS_VISIBLE,
            x, y, width, height,
            NULL, NULL, g_hInst, NULL);

    // ToolWindow subclassing
    m_wndprocMemoryMapToolWindow = (WNDPROC) LongToPtr( SetWindowLongPtr(
            g_hwndMemoryMap, GWLP_WNDPROC, PtrToLong(MemoryMapViewWndProc)) );

    RECT rcClient;  GetClientRect(g_hwndMemoryMap, &rcClient);

    m_hwndMemoryMapViewer = CreateWindow(
            CLASSNAME_MEMORYMAPVIEW, NULL,
            WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_TABSTOP,
            0, 0, rcClient.right, rcClient.bottom,
            g_hwndMemoryMap, NULL, g_hInst, NULL);

    MemoryMapView_InitBitmap();
    MemoryMapView_UpdateScrollPos();
    ::SetFocus(m_hwndMemoryMapViewer);
}
Exemple #10
0
SWindow::~SWindow(void)
{
	if(IsWindow()) {
		SetWindowLongPtr(GWLP_USERDATA, NULL);
		if(OriginalWndProc) SetWindowLongPtr(GWLP_WNDPROC, PtrToLong(OriginalWndProc));
	} else {
		if(ControlMode == ControlMode_Normal) ::UnregisterClass(ClassName, WSLhInstance);
	}
}
Exemple #11
0
//! Removes subclassing from all windows.
void BlueWindow::RemoveSubclassing(void)
{
    for (hwndprocmap_t::const_iterator lpfnit = OldWindowProcs.begin();
        lpfnit != OldWindowProcs.end(); lpfnit++)
    {
		SetWindowLongPtr(lpfnit->first, GWL_WNDPROC, PtrToLong(lpfnit->second));
        ForceNonclientRepaint(lpfnit->first);
    }
    OldWindowProcs.clear();
}
Exemple #12
0
void CreateDebugView(HWND hwndParent, int x, int y, int width, int height)
{
    ASSERT(hwndParent != NULL);

    g_hwndDebug = CreateWindow(
            CLASSNAME_TOOLWINDOW, NULL,
            WS_CHILD | WS_VISIBLE,
            x, y, width, height,
            hwndParent, NULL, g_hInst, NULL);
    DebugView_UpdateWindowText();

    // ToolWindow subclassing
    m_wndprocDebugToolWindow = (WNDPROC) LongToPtr( SetWindowLongPtr(
            g_hwndDebug, GWLP_WNDPROC, PtrToLong(DebugViewWndProc)) );

    RECT rcClient;  GetClientRect(g_hwndDebug, &rcClient);

    m_hwndDebugViewer = CreateWindowEx(
            WS_EX_STATICEDGE,
            CLASSNAME_DEBUGVIEW, NULL,
            WS_CHILD | WS_VISIBLE,
            0, 0, rcClient.right, rcClient.bottom,
            g_hwndDebug, NULL, g_hInst, NULL);

    m_hwndDebugToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
            WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_TOOLTIPS | CCS_NOPARENTALIGN | CCS_NODIVIDER | CCS_VERT,
            4, 4, 32, rcClient.bottom, m_hwndDebugViewer,
            (HMENU) 102,
            g_hInst, NULL);

    TBADDBITMAP addbitmap;
    addbitmap.hInst = g_hInst;
    addbitmap.nID = IDB_TOOLBAR;
    SendMessage(m_hwndDebugToolbar, TB_ADDBITMAP, 2, (LPARAM) &addbitmap);

    SendMessage(m_hwndDebugToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
    SendMessage(m_hwndDebugToolbar, TB_SETBUTTONSIZE, 0, (LPARAM) MAKELONG (26, 26));

    TBBUTTON buttons[3];
    ZeroMemory(buttons, sizeof(buttons));
    for (int i = 0; i < sizeof(buttons) / sizeof(TBBUTTON); i++)
    {
        buttons[i].fsState = TBSTATE_ENABLED | TBSTATE_WRAP;
        buttons[i].fsStyle = BTNS_BUTTON;
        buttons[i].iString = -1;
    }
    buttons[0].idCommand = ID_DEBUG_CPUPPU;
    buttons[0].iBitmap = 17;
    buttons[1].idCommand = ID_DEBUG_STEPINTO;
    buttons[1].iBitmap = 15;
    buttons[2].idCommand = ID_DEBUG_STEPOVER;
    buttons[2].iBitmap = 16;

    SendMessage(m_hwndDebugToolbar, TB_ADDBUTTONS, (WPARAM) sizeof(buttons) / sizeof(TBBUTTON), (LPARAM) &buttons);
}
Exemple #13
0
__inline
VOID
PackNBQPointer (
    IN PNBQUEUE_POINTER Entry,
    IN PNBQUEUE_NODE Node
    )

{
    Entry->Node = PtrToLong(Node);
    return;
}
void 
CMainFrame::pWarnUninitalizedDisks(
	NDAS_LOGICALDEVICE_ID LogicalDeviceId)
{
	ATLTRACE("Logical Unit does not seem to be initialized.\n");

	TASKDIALOG_BUTTON buttons[] = {
		IDOK, MAKEINTRESOURCE(IDS_LAUNCH_DISKMGMT),
	};

	TASKDIALOGCONFIG config = {0};
	config.cbSize = sizeof(TASKDIALOGCONFIG);
	config.hwndParent = m_hWnd;
	config.hInstance = _AtlBaseModule.GetResourceInstance();
	config.dwFlags = 
		TDF_ALLOW_DIALOG_CANCELLATION |
		TDF_USE_COMMAND_LINKS;
	config.dwCommonButtons = TDCBF_CLOSE_BUTTON;
	config.pszWindowTitle = MAKEINTRESOURCE(IDS_MAIN_TITLE);
	config.pszMainIcon = TD_INFORMATION_ICON;
	config.pszMainInstruction;
	config.pszContent = MAKEINTRESOURCE(IDS_MOUNTED_DISK_WITH_NO_PARTITION);
	config.cButtons = RTL_NUMBER_OF(buttons);
	config.pButtons = buttons;
	config.nDefaultButton = IDOK;

	int selected;
	BOOL verify;
	HRESULT hr = xTaskDialogIndirect(&config, &selected, NULL, &verify);
	if (FAILED(hr))
	{
		ATLTRACE("xTaskDialogIndirect failed, hr=0x%X\n", hr);
	}
	else
	{
		if (IDOK == selected)
		{
			int ret = PtrToLong(ShellExecute(
				m_hWnd,
				_T("open"),
				_T("diskmgmt.msc"),
				NULL,
				NULL,
				SW_SHOWNORMAL));
			if (ret <= 32)
			{
				ATLTRACE("ShellExecute(diskmgmt.msc) failed, ret=%d\n", ret);
			}
		}
	}
}
Exemple #15
0
/* Builds the individual elements of the GUI.
 ******************************************************************************/
void BuildGUI()
{
  int i, j;

  // minimize button
  hMinButton = CreateWindow( "BUTTON", "M", WS_VISIBLE | WS_CHILD |
                               BS_OWNERDRAW, 227, 3, 7, 7, hWnd,
                               ( HMENU )IDB_MIN, hInstance, NULL );

  // close button
  hCloseButton = CreateWindow( "BUTTON", "C", WS_VISIBLE | WS_CHILD |
                                 BS_OWNERDRAW, 235, 3, 7, 7, hWnd,
                                 ( HMENU )IDB_CLOSE, hInstance, NULL );

  // new game button
  hNewButton = CreateWindow( "BUTTON", "N", WS_VISIBLE | WS_CHILD |
                               BS_OWNERDRAW, 131, 3, 7, 7, hWnd,
                               ( HMENU )IDB_NEW, hInstance, NULL );

  // number of mines left display
  for( i = 0; i < 2; i++ )
    hScore[ i ] = CreateWindow( "STATIC", "0", WS_VISIBLE | WS_CHILD |
                                SS_BITMAP, 117 - ( 5 * i ), 3, 7, 7, hWnd,
                                ( HMENU )( IDS_SCORE + i ), hInstance, NULL );

  // timer display
  for( i = 0; i < 3; i++ )
    hTime[ i ] = CreateWindow( "STATIC", "0", WS_VISIBLE | WS_CHILD |
                                SS_BITMAP, 155 - ( 5 * i ), 3, 7, 7, hWnd,
                                ( HMENU )( IDS_TIME + i ), hInstance, NULL );

  // subclassed minefield position buttons
  for( i = 0; i < COLS; i++ )
    for( j = 0; j < ROWS; j++ )
    {
      hField[ i ][ j ] = CreateWindow( "BUTTON", "x", WS_VISIBLE |
                                       WS_CHILD | BS_OWNERDRAW,
                                       ( 3 + 8 * i ), ( 14 + 8 * j ), 7, 7,
                                       hWnd,
                                       ( HMENU )( IDB_MINE + i + COLS * j ),
                                       hInstance, NULL );
      mainProc = ( WNDPROC )SetWindowLongPtr( hField[ i ][ j ], GWLP_WNDPROC,
                   PtrToLong( BtnSubclassProc ) );
    }

  SkinBmpa = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_WINDOW ) );
  ButtonBmpa = LoadBitmap( hInstance, MAKEINTRESOURCE( IDB_ELEMENTS ) );
}
    MyWinMsg(const char *app)
    {
#ifdef WIN32
        mHwnd = 0;
		mCurrent = 0;
        if ( app )
        {
     		HWND msgWindow = 0;

            WNDCLASSEX wcex;
            wcex.cbSize         = sizeof(WNDCLASSEX);
            wcex.style          = 0;
            wcex.lpfnWndProc    = (WNDPROC)_MsgWindowProc;
            wcex.cbClsExtra     = 0;
            wcex.cbWndExtra     = sizeof(void*);
            wcex.hInstance      = 0;
            wcex.hIcon          = 0;
            wcex.hCursor        = 0;
            wcex.hbrBackground  = 0;
            wcex.lpszMenuName   = 0;
            #ifdef UNICODE
            wcex.lpszClassName  = L"WinMsg";
            #else
            wcex.lpszClassName  = "WinMsg";
            #endif
            wcex.hIconSm        = 0;
            RegisterClassEx(&wcex);

            #ifdef UNICODE
         	wchar_t wapp[512];
        	mbstowcs(wapp,app,512);
            msgWindow = ::CreateWindow(L"WinMsg",wapp, 0, 0, 0, 0, 0, 0, 0, 0, this);
            #else
            msgWindow = ::CreateWindow("WinMsg",app, 0, 0, 0, 0, 0, 0, 0, 0, this);
            #endif

            if(msgWindow)
            {
              SetWindowLongPtr(msgWindow, GWLP_USERDATA, PtrToLong(this));
              mHwnd = msgWindow;
            }
      }
#endif
    }
Exemple #17
0
//! Entrypoint used to make another window become subclassed.
bool BlueWindow::SubclassNewWindow(HWND hwnd)
{
    DWORD windowpid;
    
    if (hwnd != NULL && IsWindow(hwnd) && 
        GetWindowThreadProcessId(hwnd, &windowpid) && 
        windowpid == GetCurrentProcessId() &&
        OldWindowProcs.find(hwnd) == OldWindowProcs.end())
    {
        // Found the window that is from our process.  Subclass it.
        WNDPROC lpfnOldWindowProc = (WNDPROC) LongToPtr(GetWindowLongPtr(hwnd, GWL_WNDPROC));
        OldWindowProcs.insert(std::make_pair<HWND, WNDPROC>(hwnd, lpfnOldWindowProc));
        SetWindowLongPtr(hwnd, GWL_WNDPROC, PtrToLong(BlueWindow::SubclassProc));
        ForceNonclientRepaint(hwnd);
        return true;
    }

    return false;       // could not successfully subclass specified window.
}
Exemple #18
0
INT_PTR CALLBACK
SWindow::SDialogPropertySheetPageProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	SWindow*	SWindowClass;

	if(uMsg == WM_INITDIALOG) {
		SWindowClass = reinterpret_cast<SWindow*>(reinterpret_cast<PROPSHEETPAGE*>(lParam)->lParam);
		::SetWindowLongPtr(hwnd, GWLP_USERDATA, PtrToLong(SWindowClass));
	} else {
		SWindowClass = reinterpret_cast<SWindow*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
	}

	INT_PTR	RetCode;

	if(SWindowClass) {
		RetCode = SWindowClass->WndProc(hwnd, uMsg, wParam, lParam);
	} else {
		RetCode = false;
	}

	return RetCode;
}
Exemple #19
0
BOOL WINAPI HookHotPatch(void **pTarget, const void *pDetour)
{
#pragma pack(push, 1)
	typedef struct
	{
		unsigned char	nJumpInst;
		unsigned long	nRelativeAddr;
		unsigned short	nHotPatch;
	} HOT_PATCH;
#pragma pack(pop)

	HOT_PATCH *pPatch;
	DWORD op = 0;
	const unsigned char *pHook;
	const unsigned char *pDestination;

	static const unsigned char nJumpBack[] = { 0xEB, 0xF9 };

	pHook = (const unsigned char *)(*pTarget);

	if (HOTPATCH_HEAD != *((const unsigned short *)pHook))
		return FALSE;

	pDestination	= (const unsigned char *)(pDetour);
	pPatch			= (HOT_PATCH *)(pHook - JMP_SIZE);

	if (FALSE == VirtualProtect(pPatch, sizeof(HOT_PATCH), PAGE_EXECUTE_READWRITE, &op))
		return FALSE;

	pPatch->nJumpInst		= JMP_INSTR;
	pPatch->nRelativeAddr	= PtrToLong(pDestination - pHook);
	pPatch->nHotPatch		= *(const unsigned short *)nJumpBack;

	(*pTarget) = (void *)(pHook + 2);

	VirtualProtect(pPatch, sizeof(HOT_PATCH), op, &op);

	return TRUE;
}
Exemple #20
0
LRESULT CALLBACK
SWindow::SWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	SWindow*	SWindowClass;

	if(uMsg == WM_CREATE) {
		SWindowClass = reinterpret_cast<SWindow*>
							(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams);
		::SetWindowLongPtr(hwnd, GWLP_USERDATA, PtrToLong(SWindowClass));
	} else {
		SWindowClass = reinterpret_cast<SWindow*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
	}

	LRESULT	RetCode;

	if(SWindowClass) {
		RetCode = SWindowClass->WndProc(hwnd, uMsg, wParam, lParam);
	} else {
		RetCode = ::DefWindowProc(hwnd, uMsg, wParam, lParam);
	}

	return RetCode;
}
Exemple #21
0
void CreateDisasmView(HWND hwndParent, int x, int y, int width, int height)
{
    ASSERT(hwndParent != NULL);

    g_hwndDisasm = CreateWindow(
            CLASSNAME_TOOLWINDOW, NULL,
            WS_CHILD | WS_VISIBLE,
            x, y, width, height,
            hwndParent, NULL, g_hInst, NULL);
    DisasmView_UpdateWindowText();

    // ToolWindow subclassing
    m_wndprocDisasmToolWindow = (WNDPROC) LongToPtr( SetWindowLongPtr(
            g_hwndDisasm, GWLP_WNDPROC, PtrToLong(DisasmViewWndProc)) );

    RECT rcClient;  GetClientRect(g_hwndDisasm, &rcClient);

    m_hwndDisasmViewer = CreateWindowEx(
            WS_EX_STATICEDGE,
            CLASSNAME_DISASMVIEW, NULL,
            WS_CHILD | WS_VISIBLE,
            0, 0, rcClient.right, rcClient.bottom,
            g_hwndDisasm, NULL, g_hInst, NULL);
}
Exemple #22
0
VOID
NTAPI
KiTimerExpiration(IN PKDPC Dpc,
                  IN PVOID DeferredContext,
                  IN PVOID SystemArgument1,
                  IN PVOID SystemArgument2)
{
    ULARGE_INTEGER SystemTime, InterruptTime;
    LARGE_INTEGER Interval;
    LONG Limit, Index, i;
    ULONG Timers, ActiveTimers, DpcCalls;
    PLIST_ENTRY ListHead, NextEntry;
    KIRQL OldIrql;
    PKTIMER Timer;
    PKDPC TimerDpc;
    ULONG Period;
    DPC_QUEUE_ENTRY DpcEntry[MAX_TIMER_DPCS];
    PKSPIN_LOCK_QUEUE LockQueue;
#ifdef CONFIG_SMP
    PKPRCB Prcb = KeGetCurrentPrcb();
#endif

    /* Disable interrupts */
    _disable();

    /* Query system and interrupt time */
    KeQuerySystemTime((PLARGE_INTEGER)&SystemTime);
    InterruptTime.QuadPart = KeQueryInterruptTime();
    Limit = KeTickCount.LowPart;

    /* Bring interrupts back */
    _enable();

    /* Get the index of the timer and normalize it */
    Index = PtrToLong(SystemArgument1);
    if ((Limit - Index) >= TIMER_TABLE_SIZE)
    {
        /* Normalize it */
        Limit = Index + TIMER_TABLE_SIZE - 1;
    }

    /* Setup index and actual limit */
    Index--;
    Limit &= (TIMER_TABLE_SIZE - 1);

    /* Setup accounting data */
    DpcCalls = 0;
    Timers = 24;
    ActiveTimers = 4;

    /* Lock the Database and Raise IRQL */
    OldIrql = KiAcquireDispatcherLock();

    /* Start expiration loop */
    do
    {
        /* Get the current index */
        Index = (Index + 1) & (TIMER_TABLE_SIZE - 1);

        /* Get list pointers and loop the list */
        ListHead = &KiTimerTableListHead[Index].Entry;
        while (ListHead != ListHead->Flink)
        {
            /* Lock the timer and go to the next entry */
            LockQueue = KiAcquireTimerLock(Index);
            NextEntry = ListHead->Flink;

            /* Get the current timer and check its due time */
            Timers--;
            Timer = CONTAINING_RECORD(NextEntry, KTIMER, TimerListEntry);
            if ((NextEntry != ListHead) &&
                (Timer->DueTime.QuadPart <= InterruptTime.QuadPart))
            {
                /* It's expired, remove it */
                ActiveTimers--;
                KiRemoveEntryTimer(Timer);

                /* Make it non-inserted, unlock it, and signal it */
                Timer->Header.Inserted = FALSE;
                KiReleaseTimerLock(LockQueue);
                Timer->Header.SignalState = 1;

                /* Get the DPC and period */
                TimerDpc = Timer->Dpc;
                Period = Timer->Period;

                /* Check if there's any waiters */
                if (!IsListEmpty(&Timer->Header.WaitListHead))
                {
                    /* Check the type of event */
                    if (Timer->Header.Type == TimerNotificationObject)
                    {
                        /* Unwait the thread */
                        KxUnwaitThread(&Timer->Header, IO_NO_INCREMENT);
                    }
                    else
                    {
                        /* Otherwise unwait the thread and signal the timer */
                        KxUnwaitThreadForEvent((PKEVENT)Timer, IO_NO_INCREMENT);
                    }
                }

                /* Check if we have a period */
                if (Period)
                {
                    /* Calculate the interval and insert the timer */
                    Interval.QuadPart = Int32x32To64(Period, -10000);
                    while (!KiInsertTreeTimer(Timer, Interval));
                }

                /* Check if we have a DPC */
                if (TimerDpc)
                {
#ifdef CONFIG_SMP
                    /* 
                     * If the DPC is targeted to another processor,
                     * then insert it into that processor's DPC queue
                     * instead of delivering it now.
                     * If the DPC is a threaded DPC, and the current CPU
                     * has threaded DPCs enabled (KiExecuteDpc is actively parsing DPCs),
                     * then also insert it into the DPC queue for threaded delivery,
                     * instead of doing it here.
                     */
                    if (((TimerDpc->Number >= MAXIMUM_PROCESSORS) &&
                        ((TimerDpc->Number - MAXIMUM_PROCESSORS) != Prcb->Number)) ||
                        ((TimerDpc->Type == ThreadedDpcObject) && (Prcb->ThreadDpcEnable)))
                    {
                        /* Queue it */
                        KeInsertQueueDpc(TimerDpc,
                                         UlongToPtr(SystemTime.LowPart),
                                         UlongToPtr(SystemTime.HighPart));
                    }
                    else
#endif
                    {
                        /* Setup the DPC Entry */
                        DpcEntry[DpcCalls].Dpc = TimerDpc;
                        DpcEntry[DpcCalls].Routine = TimerDpc->DeferredRoutine;
                        DpcEntry[DpcCalls].Context = TimerDpc->DeferredContext;
                        DpcCalls++;
                        ASSERT(DpcCalls < MAX_TIMER_DPCS);
                    }
                }

                /* Check if we're done processing */
                if (!(ActiveTimers) || !(Timers))
                {
                    /* Release the dispatcher while doing DPCs */
                    KiReleaseDispatcherLock(DISPATCH_LEVEL);

                    /* Start looping all DPC Entries */
                    for (i = 0; DpcCalls; DpcCalls--, i++)
                    {
                        /* Call the DPC */
                        DpcEntry[i].Routine(DpcEntry[i].Dpc,
                                            DpcEntry[i].Context,
                                            UlongToPtr(SystemTime.LowPart),
                                            UlongToPtr(SystemTime.HighPart));
                    }

                    /* Reset accounting */
                    Timers = 24;
                    ActiveTimers = 4;

                    /* Lock the dispatcher database */
                    KiAcquireDispatcherLock();
                }
            }
            else
            {
                /* Check if the timer list is empty */
                if (NextEntry != ListHead)
                {
                    /* Sanity check */
                    ASSERT(KiTimerTableListHead[Index].Time.QuadPart <=
                           Timer->DueTime.QuadPart);

                    /* Update the time */
                    _disable();
                    KiTimerTableListHead[Index].Time.QuadPart =
                        Timer->DueTime.QuadPart;
                    _enable();
                }

                /* Release the lock */
                KiReleaseTimerLock(LockQueue);

                /* Check if we've scanned all the timers we could */
                if (!Timers)
                {
                    /* Release the dispatcher while doing DPCs */
                    KiReleaseDispatcherLock(DISPATCH_LEVEL);

                    /* Start looping all DPC Entries */
                    for (i = 0; DpcCalls; DpcCalls--, i++)
                    {
                        /* Call the DPC */
                        DpcEntry[i].Routine(DpcEntry[i].Dpc,
                                            DpcEntry[i].Context,
                                            UlongToPtr(SystemTime.LowPart),
                                            UlongToPtr(SystemTime.HighPart));
                    }

                    /* Reset accounting */
                    Timers = 24;
                    ActiveTimers = 4;

                    /* Lock the dispatcher database */
                    KiAcquireDispatcherLock();
                }

                /* Done looping */
                break;
            }
        }
    } while (Index != Limit);

    /* Verify the timer table, on debug builds */
    if (KeNumberProcessors == 1) KiCheckTimerTable(InterruptTime);

    /* Check if we still have DPC entries */
    if (DpcCalls)
    {
        /* Release the dispatcher while doing DPCs */
        KiReleaseDispatcherLock(DISPATCH_LEVEL);

        /* Start looping all DPC Entries */
        for (i = 0; DpcCalls; DpcCalls--, i++)
        {
            /* Call the DPC */
            DpcEntry[i].Routine(DpcEntry[i].Dpc,
                                DpcEntry[i].Context,
                                UlongToPtr(SystemTime.LowPart),
                                UlongToPtr(SystemTime.HighPart));
        }

        /* Lower IRQL if we need to */
        if (OldIrql != DISPATCH_LEVEL) KeLowerIrql(OldIrql);
    }
    else
    {
        /* Unlock the dispatcher */
        KiReleaseDispatcherLock(OldIrql);
    }
}
Exemple #23
0
void kuhl_m_sekurlsa_krbtgt_keys(PVOID addr, PCWSTR prefix)
{
	DWORD sizeForCreds, i;
	KIWI_KRBTGT_CREDENTIALS_6 tmpCred6, *creds6;
	KIWI_KRBTGT_CREDENTIALS_5 tmpCred5, *creds5;
	KULL_M_MEMORY_HANDLE hLocalMemory = {KULL_M_MEMORY_TYPE_OWN, NULL};
	KULL_M_MEMORY_ADDRESS aLsass = {addr, cLsass.hLsassMem}, aLocal = {&tmpCred6, &hLocalMemory};

	if(addr)
	{
		kprintf(L"\n%s krbtgt: ", prefix);
		if(cLsass.osContext.MajorVersion < 6)
		{
			aLocal.address = &tmpCred5;
			if(kull_m_memory_copy(&aLocal, &aLsass, sizeof(KIWI_KRBTGT_CREDENTIALS_5) - sizeof(KIWI_KRBTGT_CREDENTIAL_5)))
			{
				sizeForCreds = sizeof(KIWI_KRBTGT_CREDENTIALS_5) + (tmpCred5.cbCred - 1) * sizeof(KIWI_KRBTGT_CREDENTIAL_5);
				if(creds5 = (PKIWI_KRBTGT_CREDENTIALS_5) LocalAlloc(LPTR, sizeForCreds))
				{
					aLocal.address = creds5;
					if(kull_m_memory_copy(&aLocal, &aLsass, sizeForCreds))
					{
						kprintf(L"%u credentials\n", creds5->cbCred);
						for(i = 0; i < creds5->cbCred; i++)
						{
							kprintf(L"\t * %s : ", kuhl_m_kerberos_ticket_etype(PtrToLong(creds5->credentials[i].type)));
							aLsass.address = creds5->credentials[i].key;
							if(aLocal.address = LocalAlloc(LPTR, PtrToUlong(creds5->credentials[i].size)))
							{
								if(kull_m_memory_copy(&aLocal, &aLsass, PtrToUlong(creds5->credentials[i].size)))
									kull_m_string_wprintf_hex(aLocal.address, PtrToUlong(creds5->credentials[i].size), 0);
								LocalFree(aLocal.address);
							}
							kprintf(L"\n");
						}
					}
					LocalFree(creds5);
				}
			}
		}
		else
		{
			aLocal.address = &tmpCred6;
			if(kull_m_memory_copy(&aLocal, &aLsass, sizeof(KIWI_KRBTGT_CREDENTIALS_6) - sizeof(KIWI_KRBTGT_CREDENTIAL_6)))
			{
				sizeForCreds = sizeof(KIWI_KRBTGT_CREDENTIALS_6) + (tmpCred6.cbCred - 1) * sizeof(KIWI_KRBTGT_CREDENTIAL_6);
				if(creds6 = (PKIWI_KRBTGT_CREDENTIALS_6) LocalAlloc(LPTR, sizeForCreds))
				{
					aLocal.address = creds6;
					if(kull_m_memory_copy(&aLocal, &aLsass, sizeForCreds))
					{
						kprintf(L"%u credentials\n", creds6->cbCred);
						for(i = 0; i < creds6->cbCred; i++)
						{
							kprintf(L"\t * %s : ", kuhl_m_kerberos_ticket_etype(PtrToLong(creds6->credentials[i].type)));
							aLsass.address = creds6->credentials[i].key;
							if(aLocal.address = LocalAlloc(LPTR, PtrToUlong(creds6->credentials[i].size)))
							{
								if(kull_m_memory_copy(&aLocal, &aLsass, PtrToUlong(creds6->credentials[i].size)))
									kull_m_string_wprintf_hex(aLocal.address, PtrToUlong(creds6->credentials[i].size), 0);
								LocalFree(aLocal.address);
							}
							kprintf(L"\n");
						}
					}
					LocalFree(creds6);
				}
			}
		}
	}
}
Exemple #24
0
    bool DiWin32EGLWindow::_Create(uint32& width, uint32& height, const DiString& title, bool fullscreen)
    {
        bool ok = false;
        DI_ASSERT(!mWndHandle);

        registerWindowClass((HINSTANCE)::GetModuleHandle(0));
        RECT winRect;
        winRect.left = 0;
        winRect.top = 0;
        winRect.right = width;
        winRect.bottom = height;
        DWORD dwstyle = (fullscreen ? gFullscreenStyle : gWindowStyle);
        uint32  offset = fullscreen ? 0 : 50;
        ::AdjustWindowRect(&winRect, dwstyle, 0);
        mWndHandle = ::CreateWindowA(gWindowClass, title.c_str(), dwstyle,
            offset, offset,
            winRect.right - winRect.left, winRect.bottom - winRect.top,
            0, 0, 0, 0);
        DI_ASSERT(mWndHandle);
        mWindow = (NativeWindowType)mWndHandle;

        if (mWndHandle)
        {
            ok = true;
            ShowWindow((HWND)mWndHandle, SW_SHOWNORMAL);
            ::SetFocus((HWND)mWndHandle);
            SetWindowLongPtr((HWND)mWndHandle, GWLP_USERDATA, PtrToLong(this));

            mHDC = ::GetDC((HWND)mWndHandle);
        }

        RAWINPUTDEVICE rawInputDevice;
        rawInputDevice.usUsagePage = 1;
        rawInputDevice.usUsage = 6;
        rawInputDevice.dwFlags = 0;
        rawInputDevice.hwndTarget = NULL;

        BOOL status = RegisterRawInputDevices(&rawInputDevice, 1, sizeof(rawInputDevice));
        if (status != TRUE)
        {
            DI_ERROR("RegisterRawInputDevices failed: %d", GetLastError());
        }

        mNativeDisplay = GetDC(mWindow);
        mEglDisplay = eglGetDisplay(mNativeDisplay);

        // fallback for some emulations 
        if (mEglDisplay == EGL_NO_DISPLAY)
        {
            mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        }

        eglInitialize(mEglDisplay, NULL, NULL);

        eglBindAPI(EGL_OPENGL_ES_API);

        mGLSupport->SetGLDisplay(mEglDisplay);
        mEglSurface = CreateSurfaceFromWindow(mEglDisplay, mWindow);

        return ok;
    }
int cdecl vMessage (UINT type, int title, LPCTSTR text, LPCTSTR fmt, va_list arg)
{
   return vMessage (type, (LONG)title, PtrToLong(text), fmt, arg);
}
Exemple #26
0
BOOL HookWindowProcedure(PFNWINDOWPROC pfnWindowProc)
{
    DWORD dwWindowPId, dwMyPId = GetCurrentProcessId();
	HWND hwndCurrent = NULL;
    
	if(g_wpOrigWndProc == NULL)
    {
        do
        {
            hwndCurrent = FindWindowEx(NULL, hwndCurrent, "GxWindowClassD3d", NULL);
            GetWindowThreadProcessId(hwndCurrent, &dwWindowPId);
            if(dwWindowPId == dwMyPId)
            {
                g_wpOrigWndProc = (WNDPROC)LongToPtr(SetWindowLong(hwndCurrent, GWL_WNDPROC, PtrToLong(HookedWindowProcedure)));
                g_pfnWindowProc = pfnWindowProc;
				g_hwndHook = hwndCurrent;
				if(g_wpOrigWndProc)
                    return TRUE;
                else
                    return FALSE;
            }
        } while(hwndCurrent);
    }
    return FALSE;
}
UINT COXFileWatcher::FileWatchThreadFunction(LPVOID pParam)
// --- In  : pParam: a pointer to the current COXFileWatcher object 
	// --- Out : 
	// --- Returns :
	// --- Effect : Used as a worker thread function
{
#if defined (_WINDLL)
#if defined (_AFXDLL)
	AFX_MANAGE_STATE(AfxGetAppModuleState());
#else
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
#endif

	ASSERT(pParam!=NULL);

	COXFileWatcher* pThis=(COXFileWatcher*)pParam;
	HANDLE*			pHandles=pThis->m_pHandles;
	
	pThis->m_bThreadIsRunning = TRUE;

	VERIFY(pThis->m_eventStartThread.SetEvent());

#if defined(_UNICODE) && (_WIN32_WINNT >= 0x400)
// Extended info is supported

	static TCHAR	szFileName[_MAX_PATH];
	// --- the name of the file if extended info is available
	static TCHAR	szNewFileName[_MAX_PATH];
	// --- the name of the new file if extended info is available and action is rename
	
	FILE_NOTIFY_INFORMATION* pfnInfo=NULL;
	// -- pointer to a buffer with extended information (if available)

#endif // defined(_UNICODE) && (_WIN32_WINNT >= 0x400)

	COXFileWatchNotifier* pfwnNotifier;
	// --- the notifier object that will be posted/sended

	DWORD nCount=PtrToLong(pThis->m_arWatchedDirs.GetSize()+1);
	
	// Exit from the loop only when the StartStopEvent as signaled
	while(TRUE)
	{
		DWORD dwRetValue = WaitForMultipleObjects(nCount, pHandles, 
			FALSE, INFINITE);

		// Check for error
		if(dwRetValue == WAIT_FAILED || dwRetValue<WAIT_OBJECT_0 || 
			dwRetValue > (WAIT_OBJECT_0 + nCount - 1))
		{
			pThis->m_hrError = HRESULT_FROM_WIN32(::GetLastError());
			break;
		}
		else  
		{
			// To stop the thread or a notification is signaled
			if(dwRetValue == WAIT_OBJECT_0)
			{
				VERIFY(pThis->m_mxThreadShouldStop.Unlock());
				// Informs the main thread that we are waiting
//				VERIFY(pThis->m_mxThreadStopped.Unlock());
				pThis->m_mxThreadStopped.Unlock();
				// Wait for the main thread
				VERIFY(pThis->m_mxThreadCanContinue.Lock());
				VERIFY(pThis->m_mxThreadStopped.Lock());
				VERIFY(pThis->m_mxThreadCanContinue.Unlock());

				// In this point the main thread should prepare the handles

				if(pThis->m_pNewHandles==NULL) 
				{
					break; // Stops the thread
				}

				// Set new handles
				pHandles=pThis->m_pNewHandles;
				nCount = PtrToLong(pThis->m_arWatchedDirs.GetSize()+1);

				continue;
			}
			else
			{ 
				// ... OK. New notification

				//if notification comes in the period of the time
				//that this thread is to be deleted, so do not
				//process the notification.
				if (pThis->m_bDeletingThread)
					break;
				
				// Find the directory entry
				int nSignaledPath=dwRetValue-WAIT_OBJECT_0-1;
				
				COXWatchedDir* pwdPath = (pThis->m_arWatchedDirs)[nSignaledPath];

#if defined(_UNICODE) && (_WIN32_WINNT >= 0x400)
// Extended info is supported
				DWORD dwNumberOfBytesTransferred;
				BOOL bValid;

				if(pwdPath->m_bExtended)
				{
					// ... OK. We have extended info. Take a pointer to it.
					pfnInfo=(FILE_NOTIFY_INFORMATION*)pwdPath->m_lpBuffer;

					// ... we have to check if the notification is valid or not
					// The check must be done before FindNextHandle()
					bValid= ::GetOverlappedResult(pwdPath->m_hDirectory,      // handle of the directory
								  				  pwdPath->m_pOverlapped,	  // address of overlapped structure 
 												  &dwNumberOfBytesTransferred, // address of actual bytes count 
												  FALSE);					  /// wait flag 

					if(bValid == FALSE || dwNumberOfBytesTransferred == 0) 
					{
						// Something is wrong
#ifdef _DEBUG
						if(bValid == FALSE)
						{
							pThis->m_hrError = HRESULT_FROM_WIN32(::GetLastError());
							CONDITIONAL_TRACE_RESULT("COXFileWatcher::FileWatchThreadFunction", pThis->m_hrError)
						}
						else // dwNumberOfBytesTransferred == 0
						{
							TRACE(_T("\nThe buffer passed to ReadDirectoryChangesW() is too small!\n"));
						}
#endif // _DEBUG

						// ... update the handle
						if(!pwdPath->FindNextHandle((pThis->m_pHandles)[nSignaledPath+1]))
						{
							pThis->m_hrError=
								HRESULT_FROM_WIN32(::GetLastError());
							break;
						}

						// The extended information is available, but it is not valid
						continue;
					}
				}

				while(TRUE)
				{
					if(pwdPath->m_bExtended)
					{
						// Extended information is available
						memcpy(szFileName,(LPCTSTR)&pfnInfo->FileName[0], 
							pfnInfo->FileNameLength);
						szFileName[pfnInfo->
							FileNameLength/sizeof(TCHAR)]=_T('\0');

						if(pfnInfo->Action == FILE_ACTION_RENAMED_OLD_NAME) 
						{
							pfnInfo=(FILE_NOTIFY_INFORMATION*)(((char*)pfnInfo)+
								pfnInfo->NextEntryOffset);
							memcpy(szNewFileName, (LPCTSTR)&pfnInfo->FileName[0],
								pfnInfo->FileNameLength);
							szNewFileName[pfnInfo->
								FileNameLength/sizeof(TCHAR)]=_T('\0');
						}
						else
						{
							szNewFileName[0]=_T('\0');
						}
						pfwnNotifier= new COXFileWatchNotifier(pwdPath->m_sPath,
							pwdPath->m_bWatchSubTree,pwdPath->m_dwWatchFilter, 
							TRUE,pfnInfo->Action,szFileName,szNewFileName);
					}
					else
#endif // defined(_UNICODE) && (_WIN32_WINNT >= 0x400)
					{
						// ... there is no extended information
						pfwnNotifier= new COXFileWatchNotifier(pwdPath->m_sPath,
							pwdPath->m_bWatchSubTree,pwdPath->m_dwWatchFilter, 
							FALSE,0,NULL,NULL);
					}

					// Notify the derived class or ...
					if(!pThis->OnNotify(*pfwnNotifier) && 
						pwdPath->m_hwndWindowToNotify!=NULL)
					{
						// ... post/send message
						UINT nItemIndex=pThis->m_arFileWatchNotifiers.
							AddItem(pfwnNotifier);
						if(pwdPath->m_bPost)
						{
							::PostMessage(pwdPath->m_hwndWindowToNotify, 
								WM_OX_FILE_NOTIFY,nItemIndex,LPARAM(0));
						}
						else
						{
							::SendMessage(pwdPath->m_hwndWindowToNotify, 
								WM_OX_FILE_NOTIFY,nItemIndex,LPARAM(0));
						}
					}
					else 
					{
						// the notifier object is not queued so delete it
						delete pfwnNotifier;
					}

#if defined(_UNICODE) && (_WIN32_WINNT >= 0x400)
// Extended info is supported
					if(!pwdPath->m_bExtended || pfnInfo->NextEntryOffset == 0) 
					{
						break;
					}
					else
					{
						// ... go to the next entry in the buffer...
						pfnInfo = (FILE_NOTIFY_INFORMATION*)(((char*)pfnInfo)+
							pfnInfo->NextEntryOffset);
					}
				} // while(TRUE);

#endif // defined(_UNICODE) && (_WIN32_WINNT >= 0x400)

				// ... update the handle
				if(!pwdPath->FindNextHandle((pThis->m_pHandles)[nSignaledPath+1]))
				{
					pThis->m_hrError = HRESULT_FROM_WIN32(::GetLastError());
					break;
				}

			}
Exemple #28
0
INT_PTR CALLBACK AssignProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
	case WM_INITDIALOG:
		g_bCtrlDown = FALSE;
		g_bAltDown = FALSE;
		g_OrigButtonProc = (WNDPROC)LongToPtr(SetWindowLong(GetDlgItem(hwndDlg, IDC_DUMMY), GWL_WNDPROC, PtrToLong(SubclassedButtonProc)));
		break;
    default:
        return FALSE;
        break;
    }
    return TRUE;
}
BOOL COXHistoryCombo::SaveContentsToRegistry(HKEY hKeyRoot, LPCTSTR pszCompany, 
											 LPCTSTR pszApplication,
											 LPCTSTR pszValueName, LPCTSTR pszValue)
{
	ASSERT(hKeyRoot != NULL);
	ASSERT((pszCompany != NULL) && (*pszCompany != _T('\0')));
	ASSERT((pszApplication != NULL) && (*pszApplication != _T('\0')));
	ASSERT((pszValueName != NULL) && (*pszValueName != _T('\0')));
	// ... Value may be empty string
	ASSERT((pszValue != NULL));

	// Open key for hKeyRoot\<szSoftware>\<pszCompany>\<pszApplication>\<szHistoryCombo>
	HKEY hSoftwareKey = NULL;
	HKEY hCompanyKey = NULL;
	HKEY hApplicationKey = NULL;
	HKEY hHistoryKey = NULL;
	if (::RegOpenKeyEx(hKeyRoot, szSoftware, 0, KEY_WRITE | KEY_READ,
		&hSoftwareKey) == ERROR_SUCCESS)
	{
		DWORD dw;
		if (::RegCreateKeyEx(hSoftwareKey, pszCompany, 0, REG_NONE,
			REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL,
			&hCompanyKey, &dw) == ERROR_SUCCESS)
		{
			if (::RegCreateKeyEx(hCompanyKey, pszApplication, 0, REG_NONE,
				REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL,
				&hApplicationKey, &dw) == ERROR_SUCCESS)
			{
				::RegCreateKeyEx(hApplicationKey, szHistoryCombo, 0, REG_NONE,
					REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL,
					&hHistoryKey, &dw);
			}
		}
	}
	if (hSoftwareKey != NULL)
		::RegCloseKey(hSoftwareKey);
	if (hCompanyKey != NULL)
		::RegCloseKey(hCompanyKey);
	if (hApplicationKey != NULL)
		::RegCloseKey(hApplicationKey);

	if (hHistoryKey == NULL)
	{
		TRACE0("COXHistoryCombo::SaveContentsToRegistry : Failed to open history key\n");
		return FALSE;
	}

	// Set value
	LONG nResult;
	if (*pszValue == _T('\0'))
		// ... Necessary to cast away const 
		nResult = ::RegDeleteValue(hHistoryKey, (LPTSTR)pszValueName);
	else
		nResult = RegSetValueEx(hHistoryKey, pszValueName, NULL, REG_SZ,
			(LPBYTE)pszValue, PtrToLong((_tcslen(pszValue) + 1) * sizeof(TCHAR)));
	::RegCloseKey(hHistoryKey);

#ifdef _DEBUG
	if (nResult != ERROR_SUCCESS)
		TRACE0("COXHistoryCombo::SaveContentsToRegistry : Failed to set value\n");
#endif // _DEBUG

	return (nResult == ERROR_SUCCESS);
}
BOOL COXCustomizeManager::InsertPage(COXCustomizePage* pCustomizePage, 
									 int nPageIndex)
{
	ASSERT(pCustomizePage!=NULL);

	CString sTitle=pCustomizePage->GetTitle();
	LPCTSTR lpszImageResource=pCustomizePage->GetImageResource(); 
	COLORREF clrMask=pCustomizePage->GetImageMask();
	CString sTooltip=pCustomizePage->GetTooltip();
	CString sGroup=pCustomizePage->GetGroup();

#ifdef _DEBUG
	ASSERT(nPageIndex>=0 && nPageIndex<=GetPageCount(sGroup));

	HSHBGROUP hGroupTest=NULL;
	int nIndexTest=-1;
	ASSERT(!FindPage(pCustomizePage,hGroupTest,nIndexTest));
	ASSERT(!FindPage(sTitle,sGroup,hGroupTest,nIndexTest));
#endif

	// find/create the corresponding shortcut bar group
	HSHBGROUP hGroup=m_shb.FindGroupByTitle(sGroup);
	BOOL bNewGroup=FALSE;
	if(hGroup==NULL)
	{
		hGroup=m_shb.InsertGroup(sGroup);
		bNewGroup=TRUE;
	}
	if(hGroup==NULL)
	{
		TRACE(_T("COXCustomizeManager::InsertPage: failed to create group for the specified page\n"));
		if(bNewGroup)
			m_shb.DeleteGroup(hGroup);
		return FALSE;
	}

	// associate image list with the created group
	m_shb.SetLCImageList(hGroup,&m_ilShortcutBar,LVSIL_NORMAL);

	// get image index for new page
	int nImageIndex=-1;
	if(lpszImageResource!=NULL)
	{
		CImageList imageList;
		if(!imageList.Create(lpszImageResource,32,0,clrMask))
		{
			TRACE(_T("COXCustomizeManager::InsertPage: failed to extract image for new page\n"));
			if(bNewGroup)
			{
				m_shb.DeleteGroup(hGroup);
			}
			return FALSE;
		}
		HICON hIcon=imageList.ExtractIcon(0);
		ASSERT(hIcon!=NULL);
		nImageIndex=m_ilShortcutBar.Add(hIcon);
		ASSERT(nImageIndex!=-1);
		VERIFY(::DestroyIcon(hIcon));
	}

	int nItem=m_shb.InsertLCItem(hGroup,nPageIndex,sTitle,nImageIndex,
		(LPARAM)pCustomizePage);
	if(nItem==-1)
	{
		TRACE(_T("COXCustomizeManager::InsertPage: failed to insert new item into the shortcut bar\n"));
		if(bNewGroup)
		{
			m_shb.DeleteGroup(hGroup);
		}
		return FALSE;
	}

	m_mapPages.SetAt(pCustomizePage,((PtrToLong(hGroup))<<16)+nItem);
	m_mapTooltips.SetAt(pCustomizePage,sTooltip);

	return TRUE;
}