Text editor

This is a discussion on Text editor within the Windows Programming forums, part of the Platform Specific Boards category; Hi all I was tempted to create a windows application, and i thought it better be something good, so i ...

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    Text editor

    Hi all
    I was tempted to create a windows application, and i thought it better be something good, so i decided on a text editor, i need programmers who are good in general C/C++, just reply on this thread if you're interested.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,755
    What will be new and interesting about this one which isn't implemented in any of the 100's of text editors which already exist?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    I havn't really thought about that, well, what would you like to see new in a text editor?

  4. #4
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    anybody?

  5. #5
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    i think u need DirectX for better graphics
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  6. #6
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    well, i have a few files already:
    This is just a skeleton of the editor

    Code:
    //Neatpad.c
    
    #include <windows.h>
    #include <tchar.h>
    #include <commctrl.h>
    #include "..\TextView\TextView.h"
    #include "resource.h"
    
    #define APP_TITLE   _T("Neatpad")
    #define WEBSITE_STR _T("www.catch22.net")
    
    TCHAR		szAppName[] = APP_TITLE;
    HWND		hwndMain;
    HWND		hwndTextView;
    
    TCHAR szFileName[MAX_PATH];
    TCHAR szFileTitle[MAX_PATH];
    
    #pragma comment(linker, "/OPT:NOWIN98")
    
    BOOL ShowOpenFileDlg(HWND hwnd, PSTR pstrFileName, PSTR pstrTitleName)
    {
    	TCHAR *szFilter = _T("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0");
    	
    	OPENFILENAME ofn	= { sizeof(ofn) };
    
    	ofn.hwndOwner		= hwnd;
    	ofn.hInstance		= GetModuleHandle(0);
    	ofn.lpstrFilter		= szFilter;
    	ofn.lpstrFile		= pstrFileName;
    	ofn.lpstrFileTitle	= pstrTitleName;
    	
    	ofn.nFilterIndex	= 1;
    	ofn.nMaxFile		= _MAX_PATH;
    	ofn.nMaxFileTitle	= _MAX_FNAME + _MAX_EXT; 
    
    	// flags to control appearance of open-file dialog
    	ofn.Flags			=	OFN_EXPLORER			| 
    							OFN_ENABLESIZING		|
    							OFN_ALLOWMULTISELECT	| 
    							OFN_FILEMUSTEXIST;
    
    	return GetOpenFileName(&ofn);
    }
    
    void ShowAboutDlg(HWND hwndParent)
    {
    	MessageBox( hwndParent, 
    				APP_TITLE _T("\r\n\r\n")  WEBSITE_STR, 
    				APP_TITLE, 
    				MB_OK | MB_ICONINFORMATION
    				);
    }
    
    void SetWindowFileName(HWND hwnd, TCHAR *szFileName)
    {
    	TCHAR ach[MAX_PATH + sizeof(szAppName) + 4];
    
    	wsprintf(ach, _T("%s - %s"), szFileName, szAppName);
    	SetWindowText(hwnd, ach);
    }
    
    //
    //	Main window procedure
    //
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	static int width, height;
    
    	switch(msg)
    	{
    	case WM_CREATE:
    		hwndTextView = CreateTextView(hwnd);
    
    		// automatically create new document when we start
    		PostMessage(hwnd, WM_COMMAND, IDM_FILE_NEW, 0);
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case IDM_FILE_NEW:
    			SetWindowFileName(hwnd, _T("Untitled"));
    			return 0;
    
    		case IDM_FILE_OPEN:
    
    			// get a filename to open
    			if(ShowOpenFileDlg(hwnd, szFileName, szFileTitle))
    			{
    				SetWindowFileName(hwnd, szFileTitle);
    			}
    
    			return 0;
    
    		case IDM_HELP_ABOUT:
    			ShowAboutDlg(hwnd);
    			return 0;
    		}
    		return 0;
    
    	case WM_CLOSE:
    		DestroyWindow(hwnd);
    		return 0;
    
    	case WM_SIZE:
    		width  = (short)LOWORD(lParam);
    		height = (short)HIWORD(lParam);
    
    		MoveWindow(hwndTextView, 0, 0, width, height, TRUE);
    		return 0;
    
    	}
    	return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
    //
    //	Register main window class
    //
    void InitMainWnd()
    {
    	WNDCLASSEX wcx;
    	HANDLE hInst = GetModuleHandle(0);
    
    	// Window class for the main application parent window
    	wcx.cbSize			= sizeof(wcx);
    	wcx.style			= 0;
    	wcx.lpfnWndProc		= WndProc;
    	wcx.cbClsExtra		= 0;
    	wcx.cbWndExtra		= 0;
    	wcx.hInstance		= hInst;
    	wcx.hCursor			= LoadCursor (NULL, IDC_ARROW);
    	wcx.hbrBackground	= (HBRUSH)0;
    	wcx.lpszMenuName	= MAKEINTRESOURCE(IDR_MENU1);
    	wcx.lpszClassName	= szAppName;
    	wcx.hIcon			= LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 32, 32, LR_CREATEDIBSECTION);
    	wcx.hIconSm			= LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, LR_CREATEDIBSECTION);
    
    	RegisterClassEx(&wcx);
    }
    
    //
    //	Create a top-level window
    //
    HWND CreateMainWnd()
    {
    	return CreateWindowEx(0,
    				szAppName,				// window class name
    				szAppName,				// window caption
    				WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
    				CW_USEDEFAULT,			// initial x position
    				CW_USEDEFAULT,			// initial y position
    				560,					// initial x size
    				320,					// initial y size
    				NULL,					// parent window handle
    				NULL,					// use window class menu
    				GetModuleHandle(0),		// program instance handle
    				NULL);					// creation parameters
    }
    
    //
    //	Entry-point for text-editor application
    //
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int iShowCmd)
    {
    	MSG			msg;
    	HACCEL		hAccel;
    
    	// initialize window classes
    	InitMainWnd();
    	InitTextView();
    
    	// create the main window!
    	hwndMain = CreateMainWnd();
    
    	ShowWindow(hwndMain, iShowCmd);
    
    	// load keyboard accelerator table
    	hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCELERATOR1));
    
    	// message-loop
    	while(GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		if(!TranslateAccelerator(hwndMain, hAccel, &msg))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    
    	return 0;
    }
    Code:
    //resource.h
    
    #define IDR_MENU1                       101
    #define IDI_ICON1                       102
    #define IDR_ACCELERATOR1                103
    #define IDM_FILE_NEW                    40001
    #define IDM_FILE_OPEN                   40002
    #define IDM_FILE_EXIT                   40003
    #define IDM_HELP_ABOUT                  40004
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        104
    #define _APS_NEXT_COMMAND_VALUE         40005
    #define _APS_NEXT_CONTROL_VALUE         1000
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    Code:
    //resource.rc
    
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"
    
    /////////////////////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS
    
    /////////////////////////////////////////////////////////////////////////////
    // English (U.K.) resources
    
    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
    #pragma code_page(1252)
    #endif //_WIN32
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //
    
    IDR_MENU1 MENU DISCARDABLE 
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&New\tCtrl+N",                IDM_FILE_NEW
            MENUITEM "&Open...\tCtrl+O",            IDM_FILE_OPEN
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       IDM_FILE_EXIT
        END
        POPUP "&Help"
        BEGIN
            MENUITEM "&About",                      IDM_HELP_ABOUT
        END
    END
    
    
    #ifdef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "resource.h\0"
    END
    
    2 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "#include ""afxres.h""\r\n"
        "\0"
    END
    
    3 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "\r\n"
        "\0"
    END
    
    #endif    // APSTUDIO_INVOKED
    
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Icon
    //
    
    // Icon with lowest ID value placed first to ensure application icon
    // remains consistent on all systems.
    IDI_ICON1               ICON    DISCARDABLE     "icon1.ico"
    
    /////////////////////////////////////////////////////////////////////////////
    //
    // Accelerator
    //
    
    IDR_ACCELERATOR1 ACCELERATORS DISCARDABLE 
    BEGIN
        "N",            IDM_FILE_NEW,           VIRTKEY, CONTROL, NOINVERT
        "O",            IDM_FILE_OPEN,          VIRTKEY, CONTROL, NOINVERT
    END
    
    #endif    // English (U.K.) resources
    /////////////////////////////////////////////////////////////////////////////
    
    
    
    #ifndef APSTUDIO_INVOKED
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //
    
    
    /////////////////////////////////////////////////////////////////////////////
    #endif    // not APSTUDIO_INVOKED
    Code:
    //textview.cpp
    
    #include <windows.h>
    #include <tchar.h>
    #include "TextView.h"
    #include "TextViewInternal.h"
    
    //
    //	Painting procedure for TextView objects
    //
    LRESULT WINAPI TextView::OnPaint()
    {
    	HDC			hdc;
    	PAINTSTRUCT ps;
    	RECT		rect;
    	char		*text = _T("Hello World!");
    
    	HANDLE		hOldFont;
    	HFONT		hFont;
    
    	hdc = BeginPaint(m_hWnd, &ps);
    
    	hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
    	hOldFont = SelectObject(hdc, hFont);
    
    	GetClientRect(m_hWnd, &rect);
    
    	ExtTextOut(hdc, 10, 10, ETO_OPAQUE, &rect, text, lstrlen(text), 0);
    
    	SelectObject(hdc, hOldFont);
    
    	EndPaint(m_hWnd, &ps);
    
    	return 0;
    }
    
    //
    //	Win32 TextView window procedure.
    //
    LRESULT WINAPI TextViewWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	TextView *ptv = (TextView *)GetWindowLong(hwnd, 0);
    
    	switch(msg)
    	{
    	// First message received by any window - make a new TextView object
    	// and store pointer to it in our extra-window-bytes
    	case WM_NCCREATE:
    
    		if((ptv = new TextView(hwnd)) == 0)
    			return FALSE;
    
    		SetWindowLong(hwnd, 0, (LONG)ptv);
    		return TRUE;
    
    	// Last message received by any window - delete the TextView object
    	case WM_NCDESTROY:
    
    		delete ptv;
    		return 0;
    
    	// Draw contents of TextView whenever window needs updating
    	case WM_PAINT:
    		return ptv->OnPaint();
    
    	default:
    		break;
    	}
    
    	return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
    //
    //	Register the TextView window class
    //
    BOOL InitTextView()
    {
    	WNDCLASSEX	wcx;
    
    	//Window class for the main application parent window
    	wcx.cbSize			= sizeof(wcx);
    	wcx.style			= 0;
    	wcx.lpfnWndProc		= TextViewWndProc;
    	wcx.cbClsExtra		= 0;
    	wcx.cbWndExtra		= sizeof(TextView *);
    	wcx.hInstance		= GetModuleHandle(0);
    	wcx.hIcon			= 0;
    	wcx.hCursor			= LoadCursor (NULL, IDC_IBEAM);
    	wcx.hbrBackground	= (HBRUSH)0;		//NO FLICKERING FOR US!!
    	wcx.lpszMenuName	= 0;
    	wcx.lpszClassName	= TEXTVIEW_CLASS;	
    	wcx.hIconSm			= 0;
    
    	return RegisterClassEx(&wcx) ? TRUE : FALSE;
    }
    
    //
    //	Create a TextView control!
    //
    HWND CreateTextView(HWND hwndParent)
    {
    	return CreateWindowEx(WS_EX_CLIENTEDGE, 
    		TEXTVIEW_CLASS, _T(""), 
    		WS_VSCROLL |WS_HSCROLL | WS_CHILD | WS_VISIBLE,
    		0, 0, 0, 0, 
    		hwndParent, 
    		0, 
    		GetModuleHandle(0), 
    		0);
    }
    Code:
    //textview.h
    
    #ifndef TEXTVIEW_INCLUDED
    #define TEXTVIEW_INCLUDED
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    //
    //	TextView API declared here
    //
    BOOL InitTextView();
    HWND CreateTextView(HWND hwndParent);
    
    //
    //	TextView Window Messages defined here
    //
    
    //
    //	TextView Macros defined here
    //
    #define TEXTVIEW_CLASS _T("TextView32")
    #define TXM_BASE         (WM_USER)
    #define TXM_OPENFILE     (TXM_BASE + 0)
    
    #define TextView_OpenFile(hwndTV, szFile) \
                      SendMessage((hwndTV), TXM_OPENFILE, 0, (LPARAM)(szFile))
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif
    Code:
    //textviewinternal.h
    
    #ifndef TEXTVIEW_INTERNAL_INCLUDED
    #define TEXTVIEW_INTERNAL_INCLUDED
    
    class TextView
    {
    public:
    
    	TextView(HWND hwnd) : m_hWnd(hwnd) {}
    	HWND	m_hWnd;
    	int x;
    
    	LRESULT WINAPI OnPaint();
    };
    
    #endif
    Last edited by beene; 10-17-2006 at 02:18 PM.

  7. #7
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    sorry if my post was to long

  8. #8
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    i get a few errors when i compile, can anyone help me?

    Code:
    `OFN_ENABLESIZING' undeclared (first  use this function)
    Code:
    Neatpad.c invalid conversion from `void*' to ` HINSTANCE__*'
    Code:
    Neatpad.c invalid conversion from `void*' to ` HICON__*'
    Code:
    Neatpad.c invalid conversion from `void*' to ` HINSTANCE__*'
    Code:
    Neatpad.c invalid conversion from `void*' to ` HICON__*'
    Code:
    Neatpad.c [Warning] no newline at end of file

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    74
    Neatpad.c invalid conversion from `void*' to ` HINSTANCE__*'
    I'm not sure off the top of my head, but perhaps some function is returning a void* and you need to type cast it before you assign it to something?!?!? Maybe..? I'm not sure.

    i.e.

    Code:
    HINST hInst = (HINST*)someFunction();

  10. #10
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    neatpad huh? I remember when I was in your shoes. Holy Christ. You've got a long way to go, my friend.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  11. #11
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    If you want to work on a project like this... check out www.emeraldeditor.com they are in need of programers who have the time to help out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 06:26 PM
  2. text editor
    By akki in forum C Programming
    Replies: 5
    Last Post: 07-11-2009, 03:05 PM
  3. C++ For Text Editor?
    By bmroyer in forum C++ Programming
    Replies: 12
    Last Post: 04-05-2005, 03:17 AM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. help about text editor
    By nag in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2003, 12:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21