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.
Printable View
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.
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?
I havn't really thought about that, well, what would you like to see new in a text editor?
anybody?
i think u need DirectX for better graphics :)
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
sorry if my post was to long
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
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.Quote:
Neatpad.c invalid conversion from `void*' to ` HINSTANCE__*'
i.e.
Code:HINST hInst = (HINST*)someFunction();
neatpad huh? I remember when I was in your shoes. Holy Christ. You've got a long way to go, my friend.
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.