Friday, July 31, 2009

Where can i find free source code in c++ for a simple text editor?

please suggest me some address where i could find source code in c++ for a simple text editor ... i need to submit it for my project .. please help me

Where can i find free source code in c++ for a simple text editor?
just dial 040-39999999 and u will get the info from them.
Reply:I wrote a "simple" text editor some years ago... and, believe me, it was not that simple if you want to use only c++ and not the help of other components... I guess it will be done for windows, won't it (mine was for DOS). If you're going to use it in windows, I can give you this code:


(it's a really simple text editor, only contextual menu is available).





#include "windows.h"


#define x 10


#define y 10


#define CLASS_NAME "Win32AppDemo"





//////////////////////////////////////...


HWND This=0;


void SetWndRect(HWND c,int wx,int wy,int px,int py)


{


MoveWindow(c,px,py,wx,wy,1);


}


HWND CreateCtrl(char*clase,int subcl,HINSTANCE inst,HWND owner)


{ return CreateWindowEx(


WS_EX_TRANSPARENT,


clase,"",subcl|WS_CHILD|


WS_VISIBLE,


0,0,0,0,owner,NULL,inst,NULL);


}


RECT getRect(HWND c)


{


RECT r;


GetWindowRect(c,%26amp;r);


r.left-=3;r.right-=3;


r.top-=22;r.bottom-=22;


return r;


}


int ToRGB(int r,int g,int b)


{return RGB(r,g,b);}





//////////////////////////////////////...





RECT FRect={0,0,0,0};


int colorAct=ToRGB(128,128,128);


HWND wcombo=0;


HWND wtext=0;


HWND wprobar=0;





void MsgError(char* s )


{


MessageBox(This,s, CLASS_NAME, MB_APPLMODAL|MB_ICONERROR);


}








void OnPaint(HDC g, HWND w)


{


RECT r1;


GetClientRect(w,%26amp;r1);


r1.left += x ;r1.top +=y ;


r1.right -=x; r1.bottom -= y;


HBRUSH b1=


CreateSolidBrush(


ToRGB(0,0,255)


);


HBRUSH b2=


CreateSolidBrush(colorAct);


FrameRect(g,%26amp;r1,b1);


FillRect(g,%26amp;FRect,b2);


DeleteObject(b1);


DeleteObject(b2);


}





void OnCommand(HWND hwnd)


{


//Handle here commands:


}





void CreateForm(HINSTANCE hThisInstance, HWND This)


{


HWND tTarget=CreateCtrl("EDIT",


WS_BORDER |ES_MULTILINE|


WS_HSCROLL|


WS_VSCROLL,


hThisInstance,This);


SetClassLong (tTarget, GCL_HBRBACKGROUND, (long) GetStockObject(WHITE_BRUSH));


SetWindowText(tTarget,""),


SetParent(tTarget,This);


SetWndRect(


tTarget, 340,140,20,20


);


wtext=tTarget;





SetClassLong (This,


GCL_HBRBACKGROUND, (long)


GetStockObject(LTGRAY_BRUSH));


SetWindowText(This,"Text Editor");


SetWindowLong(This, GWL_STYLE, WS_CAPTION|WS_SYSMENU);


SendMessage(This,WM_SETICON, ICON_BIG,


(LPARAM)


LoadIcon(0,IDI_EXCLAMATION)


);


MoveWindow(This,0,0, 380,200,0);


ShowWindow(This,SW_SHOW);


}








//////////////////////////////////////...


LRESULT CALLBACK WinProc(HWND hwnd, UINT msg,WPARAM wP, LPARAM lP)


{


HDC dc=0;





switch (msg)


{


case WM_COMMAND:


{


OnCommand((HWND)lP);


break;


}


case WM_PAINT:


{


DefWindowProc(hwnd, msg, wP, lP);


dc=GetDC(hwnd);


OnPaint(dc,hwnd);


ReleaseDC(hwnd,dc);


break;


}


case WM_DESTROY:


{


PostQuitMessage(0);


break;


}


default: return DefWindowProc(hwnd, msg, wP, lP);


}


return 0;


}





int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)


{


WNDCLASS wincl; MSG messages;


wincl.hInstance = hThisInstance;


wincl.lpszClassName = CLASS_NAME;


wincl.lpfnWndProc = WinProc;


wincl.style = CS_DBLCLKS;


wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);


wincl.hCursor = LoadCursor(NULL, IDC_ARROW);


wincl.lpszMenuName = NULL;


wincl.cbClsExtra = 0;


wincl.cbWndExtra = 0;


wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);





if(!RegisterClass(%26amp;wincl)) return 0;





This=CreateWindow(


CLASS_NAME, // Classname


CLASS_NAME, // Title Text


WS_DLGFRAME |DS_MODALFRAME|DS_CENTER|


DS_3DLOOK|


WS_MINIMIZEBOX | WS_MAXIMIZEBOX |


WS_POPUP | WS_CAPTION | WS_SYSMENU,


CW_USEDEFAULT, // Windows decides the position


CW_USEDEFAULT, // where the window ends up on the screen


10, // The programs width


10 , // and height in pixels


HWND_DESKTOP, // The window is a child-window to desktop


NULL, // No menu


hThisInstance, // Program Instance handler


NULL // No Window Creation data


);





CreateForm(hThisInstance,


This);





while(GetMessage(%26amp;messages, NULL, 0, 0))


{


TranslateMessage(%26amp;messages);


DispatchMessage(%26amp;messages);


}


return messages.wParam;


}
Reply:dont knw about cpp, here's a link to a code in vc++ - should give you an idea


http://www.codeproject.com/useritems/tex...





hope this helps

cosmos

No comments:

Post a Comment