Ejemplo n.º 1
0
void MainWndSize(MAINWND *mainWnd, int width, int height)
{
    int statusheight;
    static int tabheight = 0;
    int toolheight;
    HDWP hdwp;
    RECT rect;
    RECT rcClient;

    HWND hwndHV = GetActiveHexView(mainWnd->hwndMain);

    hdwp = BeginDeferWindowPos(0);

    GetWindowRect(mainWnd->hwndStatusBar, &rect);
    statusheight = rect.bottom-rect.top;

    // dock out where docking windows are allowed
    SetRect(&rcClient, 0, 0, width, height-statusheight);
    //TRACEA("1: %d %d %d %d\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);

    // Position the specified dock windows. rect will be modified to contain the
    // "inner" client rectangle, where we can position an MDI client,
    // view window, whatever
//	DockWnd_Position(hwnd, hdwp, &g_DockBar[0], 3, &rcClient);

    DockWnd_DeferPanelPos(hdwp, mainWnd->hwndMain, &rcClient);

    //TRACEA("2: %d %d %d %d\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);

    if(rcClient.top > 0)//DockWnd_IsOpen(hwnd, DWID_TOOLBAR))
        rcClient.top += 1;

    // make a resize bar
    //rcClient.top += 2;

    height  = rcClient.bottom-rcClient.top;
    width = rcClient.right-rcClient.left;

    //TRACEA("3: %d %d %d %d\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);

    if(TabCtrl_GetItemCount(mainWnd->hwndTabView) > 1)
    {
        tabheight = 32;
    }
    else
    {
        TCHAR  szText[20];
        TCITEM tci = { TCIF_TEXT|TCIF_PARAM, 0, 0, szText, 20 };

        TabCtrl_GetItem(mainWnd->hwndTabView, 0, &tci);
        if(lstrcmp(szText, TEXT("(Untitled)")) == 0)
            tabheight = 0;//max(tabheight, 0);
        else
            tabheight =max(tabheight, 0);
    }
    //mainWnd->hwndTabView ? 32 : 0;

    //TRACEA("4: %d %d %d %d\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);


    toolheight = 43;

    //DeferWindowPos(hdwp, g_hwndToolbar, hwnd, 0, 0, width, toolheight, SWP_NOACTIVATE|SWP_NOZORDER);
    //DeferWindowPos(hdwp, g_hwndDock[0], hwnd, 0, 0, width, toolheight, SWP_NOACTIVATE|SWP_NOZORDER);

//		// resize editbox to fit in main window
    //TRACEA("%d %d %d %d\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
    DeferWindowPos(hdwp, hwndHV, mainWnd->hwndMain, rcClient.left, rcClient.top, width, height-tabheight,SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW);

    DeferWindowPos(hdwp, mainWnd->hwndTabView,  mainWnd->hwndMain, rcClient.left, rcClient.top+height-tabheight, width, tabheight, SWP_NOACTIVATE|SWP_NOZORDER);

    GetClientRect(mainWnd->hwndMain, &rect);
    DeferWindowPos(hdwp, mainWnd->hwndStatusBar, mainWnd->hwndMain, 0, rect.bottom-statusheight, rect.right, statusheight,SWP_NOACTIVATE|SWP_NOZORDER);

    EndDeferWindowPos(hdwp);

    SetStatusBarParts(mainWnd->hwndStatusBar);
}
Ejemplo n.º 2
0
//
//	Main Window message handler
//
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    NMHDR *hdr;
    POINT pt;
    RECT  rect;
    HMENU hMenu;
    HWND hwndHV = GetActiveHexView(hwnd);//g_hwndHexView;
    int i;
    TCITEM tci;

    MAINWND *mainWnd = (MAINWND *)GetWindowLongPtr(hwnd, 0);

    switch(msg)
    {
    case WM_NCCREATE:

        if((mainWnd = malloc(sizeof(MAINWND))) == 0)
            return FALSE;

        SetWindowLongPtr(hwnd, 0, (LONG_PTR)mainWnd);
        ZeroMemory(mainWnd, sizeof(MAINWND));
        return TRUE;

    case WM_NCDESTROY:
        free(mainWnd);
        return 0;

    case WM_CREATE:

        g_hwndMain = hwnd;

        SetWindowIcon(hwnd, IDI_APP);

        // create a child-window EDIT control
        //g_hwndHexView	= CreateHexViewCtrl(hwnd);
        g_hwndTabView	= CreateWindow(WC_TABVIEW, TEXT(""), WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd, 0, g_hInstance, 0);
        g_hwndStatusBar = CreateStatusBar(hwnd);

        SendMessage(g_hwndTabView, TCM_SETITEMSIZE, 0, MAKELPARAM(150, 0));

        SetStatusBarParts(g_hwndStatusBar);

        hwndHV = g_hwndHexView;

        mainWnd->hwndMain		= hwnd;
        mainWnd->hwndStatusBar	= g_hwndStatusBar;
        mainWnd->hwndTabView	= g_hwndTabView;

        CreateToolTip(g_hwndHexView);

//		g_hwndDock[0] = CreateDockWnd(&dock, hwnd, TEXT("Toolbar"));



        //g_hwndToolbar   = InitToolbar(hwnd);
        //g_hwndSearchBar = CreateSearchBar(hwnd);
        //g_hwndTypeView  = CreateTypeView(hwnd);


        SetFocus(hwndHV);


        // tell windows that we can handle drag+drop'd files
        DragAcceptFiles(hwnd, TRUE);

        UpdateRecentMenu(GetSubMenu(GetMenu(hwnd), 0));

        SetTimer(hwnd, 0xdeadbeef, 1000, 0);

        return TRUE;

    case WM_TIMER:
        if(wParam == 0xdeadbeef)
        {
            KillTimer(hwnd, wParam);
            //FirstTimeOptions(hwnd);
        }
        return 0;

    case WM_DROPFILES:

        // get the screen coordinates of the drop-location
        if(DragQueryPoint((HDROP)wParam, &pt))
            ClientToScreen(hwnd, &pt);

        GetWindowRect(hwndHV, &rect);

        // drop anywhere *except* the hexview, as that does D&D itself
        if(!PtInRect(&rect, pt))
        {
            HandleDropFiles(hwnd, (HDROP)wParam);
        }

        //CreateToolTip(mainWnd->hwndTabView);
        return 0;

    case WM_ENABLE:
        EnableWindow(g_hwndSearch, (BOOL)wParam);
        EnableWindow(g_hwndGoto, (BOOL)wParam);
        return 0;

    case WM_CONTEXTMENU:
        if((HWND)wParam == DockWnd_GetWindow(hwnd, DWID_TYPEVIEW))
        {
            HMENU hMenu = GetSubMenu(LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_TYPECONTEXT)), 0);
            UINT  u;

            MenuCheckMark(hMenu, IDM_TYPEVIEW_HEX, g_fDisplayHex);
            MenuCheckMark(hMenu, IDM_TYPEVIEW_BIGENDIAN, g_fDisplayBigEndian);
            u = TrackPopupMenu(hMenu, TPM_RETURNCMD, (short)LOWORD(lParam), (short)HIWORD(lParam), 0, hwnd, 0);

            SendMessage(DockWnd_GetContents(hwnd, DWID_TYPEVIEW), WM_COMMAND, u, 0);
        }

        break;

    case WM_COMMAND:
        return HexEdit_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);

    case WM_NOTIFY:
        hdr = (NMHDR *)lParam;
        if(hdr->hwndFrom == hwndHV)
            return HexViewNotifyHandler(mainWnd, hwnd, hdr);
        else
            return HexEdit_OnNotify(mainWnd, hwnd, (UINT)wParam, (NMHDR *)lParam);

    case WM_CLOSE:

        tci.mask = TCIF_PARAM;

        for(i = 0; (hwndHV = EnumHexView(hwnd, i)) != NULL; )
        {
            UINT uAnswer = HexFileCloseNotify(hwnd, hwndHV);

            if(uAnswer == IDCANCEL)
            {
                return 0;
            }
            else if(uAnswer == IDNO)
            {
                SaveHighlights(hwndHV);
                TabCtrl_DeleteItem(mainWnd->hwndTabView, i);
            }
            else
            {
                i++;
            }
        }

        // save settings *before* we destroy anything!
        DockWnd_SaveSettings(hwnd);

        // shut program down
        DestroyWindow(hwnd);
        return 0;

    case WM_DESTROY:
        DestroyWindow(hwndHV);

        //
        PostQuitMessage(0);
        return 0;

    case WM_SETFOCUS:
        SetFocus(hwndHV);
        return 0;

    case WM_SIZE:

        MainWndSize(mainWnd, LOWORD(lParam), HIWORD(lParam));
        UpdateStatusbar(mainWnd->hwndStatusBar);

        return 0;

    case WM_INITMENUPOPUP:
        hMenu = (HMENU)wParam;//GetMenu(hwnd);

        MenuCheckMark(hMenu, IDM_VIEW_TOOLBAR, DockWnd_IsOpen(hwnd, DWID_TOOLBAR));
        MenuCheckMark(hMenu, IDM_TOOLS_TYPEVIEW, DockWnd_IsOpen(hwnd, DWID_TYPEVIEW));
        MenuCheckMark(hMenu, IDM_TOOLS_SEARCHBAR, DockWnd_IsOpen(hwnd, DWID_SEARCHBAR));

        CheckMenuRadioItem(hMenu, IDM_VIEW_HEX, IDM_VIEW_BIN,
                           IDM_VIEW_HEX + (HexView_GetStyle(hwndHV) & HVS_FORMAT_MASK),
                           MF_BYCOMMAND);

        {   int look[32] = { 0, 0, 1, 0, 2 };
            CheckMenuRadioItem(hMenu, IDM_GROUP_BYTE, IDM_GROUP_DWORD,
                               IDM_GROUP_BYTE + look[HexView_GetGrouping(hwndHV)],
                               MF_BYCOMMAND);
        }

        {
            size_w selsize;
            UINT   edmode  = HexView_GetEditMode(hwndHV);
            BOOL   cftext  = IsClipboardFormatAvailable(CF_TEXT);
            BOOL   canundo = HexView_CanUndo(hwndHV);
            BOOL   canredo = HexView_CanRedo(hwndHV);

            HexView_GetSelSize(hwndHV, &selsize);

            //hMenu = GetSubMenu(GetMenu(hwnd), 1);

            EnableMenuCmdItem(hMenu, IDM_EDIT_UNDO,  canundo);
            EnableMenuCmdItem(hMenu, IDM_EDIT_REDO,  canredo);
            EnableMenuCmdItem(hMenu, IDM_EDIT_CUT,  selsize > 0 && edmode == HVMODE_INSERT);
            EnableMenuCmdItem(hMenu, IDM_EDIT_COPY, selsize > 0);
            EnableMenuCmdItem(hMenu, IDM_EDIT_COPYAS, selsize > 0);
            EnableMenuCmdItem(hMenu, IDM_EDIT_PASTE, cftext && edmode != HVMODE_READONLY  );
            EnableMenuCmdItem(hMenu, IDM_EDIT_PASTESPECIAL, edmode != HVMODE_READONLY  );
            EnableMenuCmdItem(hMenu, IDM_EDIT_DELETE, selsize > 0 && edmode != HVMODE_READONLY );

            EnableMenuCmdItem(hMenu, IDM_EDIT_REVERSE, selsize > 0 && edmode != HVMODE_READONLY );
            EnableMenuCmdItem(hMenu, IDM_TOOLS_TRANSFORM, selsize > 0 && edmode != HVMODE_READONLY );

            EnableMenuCmdItem(hMenu, IDM_FILE_REVERT, canundo || canredo);
        }

        return 0;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}
Ejemplo n.º 3
0
//
//	Main window procedure
//
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	int width, height, heightsb;
	HIMAGELIST hImgList;
	RECT rect;
	HDWP hdwp;
	NMHDR *nmhdr;
	TCHAR msgstr[MAX_PATH+200];

	switch(msg)
	{
	case WM_CREATE:
		g_hwndTextView  = CreateTextView(hwnd);
		g_hwndStatusbar = CreateStatusBar(hwnd);

		TextView_SetContextMenu(g_hwndTextView, GetSubMenu(LoadMenu(GetModuleHandle(0),
			MAKEINTRESOURCE(IDR_MENU2)), 0));

		// load the image list
		hImgList = ImageList_LoadImage(
			GetModuleHandle(0), 
			MAKEINTRESOURCE(IDB_BITMAP1), 
			16, 0, 
			RGB(255,0,255),
			IMAGE_BITMAP,
			LR_LOADTRANSPARENT|LR_CREATEDIBSECTION
			);
		
		TextView_SetImageList(g_hwndTextView, hImgList);

		// highlight specific lines with image-index "1"
		//TextView_SetLineImage(g_hwndTextView, 16, 1);
		//TextView_SetLineImage(g_hwndTextView, 5,  1);
		//TextView_SetLineImage(g_hwndTextView, 36, 1);
		//TextView_SetLineImage(g_hwndTextView, 11, 1);

		// tell windows that we can handle drag+drop'd files
		DragAcceptFiles(hwnd, TRUE);
		return 0;

	case WM_DROPFILES:
		HandleDropFiles(hwnd, (HDROP)wParam);
		return 0;

	case WM_DESTROY:
		SaveFileData(g_szFileName, hwnd);
		PostQuitMessage(0);
		DeleteObject(g_hFont);
		return 0;

	//case WM_NCCALCSIZE:
	//	return NcCalcSize(hwnd, wParam, lParam);

	case WM_INITMENU:
		CheckMenuCommand((HMENU)wParam, IDM_VIEW_LINENUMBERS,	g_fLineNumbers);
		CheckMenuCommand((HMENU)wParam, IDM_VIEW_LONGLINES,		g_fLongLines);
		CheckMenuCommand((HMENU)wParam, IDM_VIEW_SAVEEXIT,		g_fSaveOnExit);
		CheckMenuCommand((HMENU)wParam, IDM_VIEW_STATUSBAR,		g_fShowStatusbar);
		//CheckMenuCommand((HMENU)wParam, IDM_VIEW_SEARCHBAR,		g_hwndSearchBar ? TRUE : FALSE);

		EnableMenuCommand((HMENU)wParam, IDM_EDIT_UNDO,		TextView_CanUndo(g_hwndTextView));
		EnableMenuCommand((HMENU)wParam, IDM_EDIT_REDO,		TextView_CanRedo(g_hwndTextView));
		EnableMenuCommand((HMENU)wParam, IDM_EDIT_PASTE,	IsClipboardFormatAvailable(CF_TEXT));
		EnableMenuCommand((HMENU)wParam, IDM_EDIT_COPY,		TextView_GetSelSize(g_hwndTextView));
		EnableMenuCommand((HMENU)wParam, IDM_EDIT_CUT,		TextView_GetSelSize(g_hwndTextView));
		EnableMenuCommand((HMENU)wParam, IDM_EDIT_DELETE,	TextView_GetSelSize(g_hwndTextView));

		return 0;

	//case WM_USER:
	//	wsprintf(msgstr, _T("%s\n\nThis file has been modified outside of Neatpad.")
	//					 _T("Do you wish to reload it?"), g_szFileName);
	//	MessageBox(hwnd, msgstr, _T("Neatpad"), MB_ICONQUESTION|MB_YESNO);
	//
	//	return 0;

	case WM_ENABLE:

		// keep the modeless find/replace dialog in the same enabled state as the main window
		EnableWindow(g_hwndSearchDlg, (BOOL)wParam);
		return 0;

	case WM_MENUSELECT:
		StatusBarMenuSelect(hwnd, g_hwndStatusbar, wParam, lParam);
		return 0;

	case WM_NOTIFY:
		nmhdr = (NMHDR *)lParam;
		
		if(nmhdr->hwndFrom == g_hwndTextView)
			return TextViewNotifyHandler(hwnd, nmhdr);
		else
			return NotifyHandler(hwnd, nmhdr);

	case WM_COMMAND:
		return CommandHandler(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);

	case WM_SETFOCUS:
		SetFocus(g_hwndTextView);
		return 0;

	case WM_CLOSE:
		
		// does the file need saving?
		if(TextView_CanUndo(g_hwndTextView))
		{
			UINT r;
			wsprintf(msgstr, _T("Do you want to save changes to\r\n%s?"), g_szFileName);
			r = MessageBox(hwnd, msgstr, APP_TITLE, MB_YESNOCANCEL | MB_ICONQUESTION);

			if(r == IDCANCEL)
				return 0;
		}

		DestroyWindow(hwnd);
		return 0;

	case WM_SIZE:

		// resize the TextView and StatusBar to fit within the main window's client area
		width  = (short)LOWORD(lParam);
		height = (short)HIWORD(lParam);
		
		GetWindowRect(g_hwndStatusbar, &rect);
		heightsb = rect.bottom-rect.top;

		hdwp = BeginDeferWindowPos(3);
		
		if(g_fShowStatusbar)
		{
			DeferWindowPos(hdwp, g_hwndStatusbar, 0, 0, height - heightsb, width, heightsb, SWP_SHOWWINDOW);
		//	MoveWindow(g_hwndStatusbar, 0, height - heightsb, width, heightsb, TRUE);
			height -= heightsb;
		}

		DeferWindowPos(hdwp, g_hwndTextView, 0,  0, 0, width, height, SWP_SHOWWINDOW);
		//MoveWindow(g_hwndTextView, 0, 0, width, height, TRUE);

		EndDeferWindowPos(hdwp);

		SetStatusBarParts(g_hwndStatusbar);

		return 0;

	}
	return DefWindowProc(hwnd, msg, wParam, lParam);
}