|
Here is the code ...
#define WIN32_LEAN_AND_MEAN
#include < windows.h >
#include < stdlib.h >
#include < richedit.h >
#include < commctrl.h >
HWND _rich;
HMODULE _hRich;
char className[14];
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
_rich = CreateWindowEx(WS_EX_CLIENTEDGE,
className,
"Sample Text",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_BORDER | WS_VSCROLL,
10, 10,
200, 200,
hWnd,
0,
GetModuleHandle(0),
0);
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox(
NULL,
(LPCTSTR)lpMsgBuf,
"Error",
MB_OK | MB_ICONINFORMATION
);
LocalFree( lpMsgBuf );
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
HWND _hWnd;
ZeroMemory(className, 14);
InitCommonControls();
_hRich = LoadLibrary("RICHED20.DLL");
if (!_hRich)
{
_hRich = LoadLibrary("RICHED32.DLL");
if (!_hRich)
{
MessageBox(0, "Richedit control not loaded!", "Error", MB_ICONERROR);
exit(0);
}
else
{
strcpy(className, "RichEdit");
}
}
else
{
strcpy(className, "RICHEDIT_CLASS");
}
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.hCursor = 0;
wc.hIcon = 0;
wc.hIconSm = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.lpszClassName = "MainWindowClass";
wc.lpszMenuName = 0;
wc.style = 0;
if (!RegisterClassEx(&wc))
{
MessageBox(0, "Error", "", MB_ICONERROR);
exit(0);
}
_hWnd = CreateWindowEx(WS_EX_WINDOWEDGE,
"MainWindowClass",
"",
WS_OVERLAPPEDWINDOW,
0, 0,
300, 300,
0, 0,
hInstance, 0);
ShowWindow(_hWnd, SW_SHOW);
UpdateWindow(_hWnd);
MSG msg;
while (GetMessage(&msg, 0, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
-Tareq
|
|
|
|
|
This code won't work. You'll get an error message saying that you're using an unknown class. You need to change
strcpy(className, "RICHEDIT_CLASS");
to
strcpy(className, RICHEDIT_CLASS);
I tried this and it worked fine.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
thankx a lot man ... i knew it was a silly mistake!!!
-Tareq
|
|
|
|
|
Did you init richedit control??
if you use MFC, please try to call AfxInitRichedit() in App::InitInstance().
maybe that's the point.
|
|
|
|
|
No MFC. Just Win32.
-Tareq
|
|
|
|
|
try to use "InitCommonControlsEx();" in your InitInstance() function.
|
|
|
|
|
nope its the same.
-Tareq
|
|
|
|
|
try
::LoadLibrary("Riched20.dll");
For win95 the rich edit control lib is "Riched32.dll",
for win98 win2k&winxp, the lib is "Riched20.dll"
|
|
|
|
|
tried that also ... i'm sure its some silly mistake. it cant be that complicated.
HINSTANCE hLib;
hLib = LoadLibrary("Riched20.dll");
if (!hLib)
{
hLib = LoadLibrary("Riched32.dll");
if (!hLib)
{
MessageBox(0, "Richedit control failed to initialize!", "Editor", MB_ICONERROR);
exit(0);
}
else
strcpy(_className, "RichEdit");
}
else
{
strcpy(_className, "RICHEDIT_CLASS");
}
-Tareq
|
|
|
|
|
Hi,
I'm looking for an easy way to test my embedded C code.
I have figured out how to get my C code complied into MFC VC6.0, now I would like to take the native C "printf" (for debugging) and display it in a MFC list or text box. I don't care which one
I'm only after debug output and being able to push MFC buttons.
Please help me with a simple way to do this. I'm not an expert C++ programer.
|
|
|
|
|
use console output option;
#include <windows.h>
void NewLine(void);
void ScrollScreenBuffer(HANDLE, INT);
HANDLE hStdout, hStdin;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
void main(void)
{
LPSTR lpszPrompt1 = "Type something and press Enter:\n";
LPSTR lpszPrompt2 = "Type any key: ";
CHAR chBuffer[256];
DWORD cRead, cWritten, fdwMode, fdwOldMode;
WORD wOldColorAttrs;
// Get handles to STDIN and STDOUT.
hStdin = GetStdHandle(STD_INPUT_HANDLE);
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdin == INVALID_HANDLE_VALUE ||
hStdout == INVALID_HANDLE_VALUE)
{
MyErrorExit("GetStdHandle");
}
// Save the current text colors.
if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
MyErrorExit("GetConsoleScreenBufferInfo");
wOldColorAttrs = csbiInfo.wAttributes;
// Set the text attr. to draw red text on black background.
if (! SetConsoleTextAttribute(hStdout, FOREGROUND_RED))
MyErrorExit("SetConsoleTextAttribute");
// Write to STDOUT and read from STDIN by using the default
// modes. Input is echoed automatically, and ReadFile
// does not return until a carriage return is typed.
//
// The default input modes are line, processed, and echo.
// The default output modes are processed and wrap at EOL.
while (1)
{
if (! WriteFile(
hStdout, // output handle
lpszPrompt1, // prompt string
lstrlen(lpszPrompt1), // string length
&cWritten, // bytes written
NULL) ) // not overlapped
break;
if (! ReadFile(
hStdin, // input handle
chBuffer, // buffer to read into
255, // size of buffer
&cRead, // actual bytes read
NULL) ) // not overlapped
break;
if (chBuffer[0] == 'q') break;
}
// Turn off the line input mode, and echo the input mode.
if (! GetConsoleMode(hStdin, &fdwOldMode))
MyErrorExit("GetConsoleMode");
fdwMode = fdwOldMode &
~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
if (! SetConsoleMode(hStdin, fdwMode))
MyErrorExit("SetConsoleMode");
// Prompt for input.
if (! WriteFile(
hStdout, // output handle
lpszPrompt2, // prompt string
lstrlen(lpszPrompt2), // string length
&cWritten, // bytes written
NULL) ) // not overlapped
MyErrorExit("WriteFile");
// Without line and echo input modes, ReadFile returns
// when any input is available. Carriage returns must
// be handled, and WriteFile is used to echo input.
while (1)
{
if (! ReadFile(hStdin, chBuffer, 1, &cRead, NULL))
break;
if (chBuffer[0] == '\r')
NewLine();
else if (! WriteFile(hStdout, chBuffer, cRead,
&cWritten, NULL)) break;
if (chBuffer[0] == 'q') break;
}
// Restore the original console mode.
if (! SetConsoleMode(hStdin, fdwOldMode))
MyErrorExit("SetConsoleMode");
// Restore the original text colors.
if (! SetConsoleTextAttribute(hStdout, wOldColorAttrs))
MyErrorExit("SetConsoleTextAttribute");
}
// The NewLine function handles carriage returns when the processed
// input mode is disabled. It gets the current cursor position
// and resets it to the first cell of the next row.
void NewLine(void)
{
if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
MyErrorExit("GetConsoleScreenBufferInfo");
csbiInfo.dwCursorPosition.X = 0;
// If it is the last line in the screen buffer, scroll
// the buffer up.
if ((csbiInfo.dwSize.Y-1) == csbiInfo.dwCursorPosition.Y)
{
ScrollScreenBuffer(hStdout, 1);
}
// Otherwise, advance the cursor to the next line.
else csbiInfo.dwCursorPosition.Y += 1;
if (! SetConsoleCursorPosition(hStdout,
csbiInfo.dwCursorPosition))
{
MyErrorExit("SetConsoleCursorPosition");
}
}
|
|
|
|
|
stupid question here?
where would I start to get an editbox receiving strings one line at a time to display the last line. example
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7
right now line 6 and 7 are out of view in the editbox, but I want the editbox to show 6 and 7, and hide 1 and 2. In other words just auto display the last messages sent to the editbox.
thanks, JoeSox
dev in VC++ 6.0
|
|
|
|
|
Did you try out CEdit::LineScroll(...)?
from msdn:
void LineScroll(int nLines, int nChars = 0);<br />
<br />
Parameters:<br />
nLines <br />
Specifies the number of lines to scroll vertically. <br />
nChars<br />
<br />
Specifies the number of character positions to scroll horizontally. This value is ignored if the edit control has either the ES_RIGHT or ES_CENTER style.
Weiye, Chen
When pursuing your dreams, don't forget to enjoy your life...
|
|
|
|
|
thanks, I've decided to use this.
Later, JoeSox www.humanaiproject.org
"Dream as if you'll live forever; live as if you'll die tomorrow."
- James Dean(ISTP)
|
|
|
|
|
just use WM_VSCROLL like this:
::SendMessage(WM_VSCROLL,hWnd,SB_BOTTOM,0);
the hWnd is the handle of edit box;
good luck!
|
|
|
|
|
thanks
Later, JoeSox www.humanaiproject.org
"Dream as if you'll live forever; live as if you'll die tomorrow."
- James Dean(ISTP)
|
|
|
|
|
Recently I meet a problem, that is:
How can a ropertySheet instance be added to a CPropertySheet as a CPropertyPage?
Who can tell me this promblem and its realization?
|
|
|
|
|
|
Yeah, that is the point!
It is so perfect!
Thank you very much!
LeonOrient
|
|
|
|
|
for program to ras monitoring
end term create is 15.06.2003
more info: balu2@o2.pl
|
|
|
|
|
Hi,
Did any one know how to get a message in Visual C++ when a smart card was inserted or removed ?
Thanks Very much
|
|
|
|
|
I don't know the answer but asking the questions 3 times in two days isn't going to help you get an answer.
Why don't you just read all of the messages posted on this board for the last two weeks? I do that all the time and I seem to recall someone asking a question about how to detect new hardware inserted and registering your application for notification from the operating system.
As a last resort, do a search. Though, I know that can be hard getting the right keywords.
|
|
|
|
|
How to view in messagebox
sample file: http://dziennik.naczasie.pl/testfile.txt
if I try messagebox return only """
|
|
|
|
|
Load file contents to the string (CString or simply char* ), then display it. Consider scrollable edit box or some decent UI instead of a MessageBox , unless the file is always small and formatted in a way that MessageBox can handle.
Regards,
BB
|
|
|
|
|
hello,
I just recently got visual studio given to me. I am very interested in programming and I would be very appreciative if someone could point me in the right direction. I know nothing about C++ or any other computer language for that matter. Please help me.
My AIM screen name(s) are: Orch1d 7, FiveInchesOfFury
Thank you
|
|
|
|
|