|
hi,
using the MFC, I just want to have a window in which u can chat, so with an edit control at the bottom and also a view to display a text.
and then my real problem will be to display a text on this window, I thing that I will have to use the OnPaint(), but I don't really know how to deal with that stuff.
thx for ur help.
--
Kas'pac'll be back.
|
|
|
|
|
Hello.
You can use the CFormView Class .The FormView have a look like Dialog.You can place a RichEdit control on the top of form view and place a Edit control on the bottom of form view.
Good luck!
|
|
|
|
|
Hi,
thanks for ur idea TLiu, I'll try that, but I still wonder how to do to display a text on the RichEdit control.
thx very much.
--
Kaspac'll be back.
|
|
|
|
|
You can reference to MSDN about CRichEidt.I remenber that there is a sample in MSDN about wordpad.Using CRichEdit in the sample.;)
|
|
|
|
|
ummmmm i hate to rain on ur parade man (as the man said) but theres just a little more to a chat program than an edit window and a few buttons
"traffic lights are for people who can't make their own decisions" biz stuff about me
|
|
|
|
|
I'm working on a MDI in which I use CScrollView for the document view. I want to use the mouse wheel strictly for a special zoom function but, if I click on the scroll bar, the mouse wheel activates both my zoom event and the natural scrolling of the window.
How do I prevent the mouse wheel from scrolling the view?
|
|
|
|
|
You just need to add a handler for WM_MOUSEWHEEL. Unless you handle it explicitly, it is translated
into WM_VSCROLLs. Just type WM_MOUSEWHEEL into MSDN help index, and there are plenty of pages which
can help you.
Good luck,
Iain.
|
|
|
|
|
Yes but I've already added a handler for WM_MOUSEWHEEL. My CScrollView now correctly zooms my view in an out with the mouse wheel but, if I click on the scroll bars, using the mouse wheel still scrolls the window as well as zooming it. It only seems to happen when a scroll bar was the last interface item clicked.
|
|
|
|
|
If you've got a
BOOL CMyView::OnMouseWheel(UINT fFlags, short zDelta, CPoint point)
{
...
}
function in your class, and a
ON_WM_MOUSEWHEEL()
in the message map, then the CScrollView::OnMouseWheel should never be called.
Unless you are calling it from your function?
I would also check the return value from the function. There are only two, so
try both. I reckon FALSE would be correct, but I can't check at the moment.
Iain.
|
|
|
|
|
Ah! That was the problem. I did prevent CScrollView::OnMouseWheel from being called but I was returning FALSE from the OnMouseWheel event. When I changed the return value to TRUE, it prevented wheel-based scrolling.
Thanks for the help!
|
|
|
|
|
Hello,
I want to create a random password generator. I would like to generate 56 chars of garbage like “₧○▲╫º╪§a2/1&*(#C23j;lc)(8sdalk+]ds<32ds?9s%ncKLJw@#*)54^”
Anyone know of any way to do this?
Rob
|
|
|
|
|
You could try using a loop and rand() to generate the ASCII codes for the characters, thats the only thing that comes to mind just now. And then swap the ASCII character into the string. Not looked in MSDN to see if thats possible and can't remember if it is.
|
|
|
|
|
char buf[ 56+1 ] ;
for ( size_t i=0 ; i < sizeof(buf)-1 ; ++i )
buf[i] = 32 + (rand() % (127-32)) ;
buf[i] = '\0' ;
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Perfect
Thanks
|
|
|
|
|
Great stuff Taka,
it was way beyond my hungover brain just now to think of the code so thanks for clearing it up for me
|
|
|
|
|
Getting the range right and avoiding off-by-one errors is such a drag, even when you're sober
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
I've been working on a small utility that needs to read/write Linux style configuration files. I have just started templating the class responsible for holding the file's content and I've run into a small problem. The following is a listing of the template declaration for the class.
template<
class Element,
class Traits = std::char_traits<Element>,
class Allocator = std::allocator<Element>,
class Container = std::map<std::basic_string<Element, Traits, Allocator>,
std::basic_string<Element, Traits, Allocator> >
>
class basic_configuration {
};
My hope was to allow for the container used for storing the key/value pairs (key=value) to be changeable via a template parameter. Unfortunately, the above code will not compile... it crashes the compiler (VC 6.0, SP5).
Any suggestions on how I might go about fixing this?
cheers,
-B
|
|
|
|
|
Here is how, for anyone who's interested.
template<
class Element,
class Traits = std::char_traits<Element>,
class Allocator = std::allocator<Element>
>
struct MyContainer {
typedef std::basic_string<Element, Traits, Allocator> string_type;
typedef std::map<string_type, string_type> type;
};
template<
class Element,
class Traits = std::char_traits<Element>,
class Allocator = std::allocator<Element>,
class Container = MyContainer::type
>
class basic_configuration {
};
cheers,
-B
|
|
|
|
|
I have an old HP LaserJet 4 printer, which is a wonderfully reliable old piece of iron they will
probably bury with me. Under DOS I knew how to write code to put it in manual feed mode so I
could print envelopes fed into the manual feed bin. Now I am trying to figure out how to do so
using Microsoft VC++ under Windows (98, ME, 2000, and XP). I have written a short test procedure
(see TestPrint below), which does print the desired text but does not switch to the manual feed
bin as it I intended. The test procedure calls a function (HaveCapability) to test whether manual
feed is available and the fuction correctly determines that it is.
I would greatly appreciate any help you can give me in solving this problem.
//*********************************************************************************
void TestPrint()
{
// Instantiate a CPrintDialog.
CPrintDialog *printDlg = new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);
printDlg->GetDefaults();
//Set up to see if printer has a manual feed mode (pDevMode->dmDefaultSource == DMBIN_MANUAL)
LPDEVMODE pDevMode = NULL;
WORD nOldDefaultSource;
BOOL bHaveCapability = HaveCapability(printDlg->GetDeviceName(), printDlg->GetPortName(), DMBIN_MANUAL);
//If printer has a manual feed mode, select it
if (bHaveCapability == TRUE)
{
pDevMode = printDlg->GetDevMode();
nOldDefaultSource = pDevMode->dmDefaultSource;
pDevMode->dmDefaultSource = DMBIN_MANUAL;
}
// Obtain handle to the device context.
HDC hdcPrn = printDlg->GetPrinterDC();
if (hdcPrn == NULL)
{
delete printDlg;
return;
}
CDC* pDC = new CDC;
pDC->Attach(hdcPrn); // attach handle to a printer DC
pDC->StartDoc("Test print job");// begin a new print job
//Set the font
int nPointSizeX10 = 140;
CFont fntCurrent;
fntCurrent.CreatePointFont(nPointSizeX10, "Times New Roman", pDC);
CFont* pOldFont = pDC->SelectObject(&fntCurrent);
//Get the line height
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int nLineHeight = tm.tmHeight + tm.tmInternalLeading;
//Specify where to print on page
int nLineX = 10;
int nLineY = 10;
pDC->StartPage(); // begin a new page
//Create and print the test text
CString csTestText;
for (int i = 0; i < 4; i++)
{
csTestText.Format("Line %i", i + 1);
pDC->TextOut(nLineX, nLineY, csTestText);
nLineY += nLineHeight;
}
pDC->EndPage(); // end a page
pDC->SelectObject(pOldFont);//Restore font
pDC->EndDoc(); // end a print job
//Restore original paper source
if (bHaveCapability == TRUE)
{
pDevMode->dmDefaultSource = nOldDefaultSource;
}
pDC->Detach(); // detach the printer DC
delete pDC;
delete printDlg;
}
//***********************************************************************************
/* Notes on HaveCapability
HaveCapability calls DeviceCapabilities to determine whether specified capability is available.
The following is from the MSDN library regarding use of DeviceCapabilities.
DWORD DeviceCapabilities(
LPCTSTR pDevice, // printer name
LPCTSTR pPort, // port name
DC_BINS, // device capability
LPTSTR pOutput, // output buffer
CONST DEVMODE *pDevMode); // device data buffer
Retrieves a list of available paper bins. The pOutput buffer receives an array of WORD values
that indicate the available paper sources for the printer. The return value indicates the number
of entries in the array. For a list of the possible array values, see the description of the
dmDefaultSource member of the DEVMODE structure. If pOutput is NULL, the return value indicates
the required number of entries in the array.
Possible WORD values
DMBIN_ONLYONE
DMBIN_LOWER
DMBIN_MIDDLE
DMBIN_MANUAL
DMBIN_ENVELOPE
DMBIN_ENVMANUAL
DMBIN_AUTO
DMBIN_TRACTOR
DMBIN_SMALLFMT
DMBIN_LARGEFMT
DMBIN_LARGECAPACITY
DMBIN_CASSETTE
DMBIN_FORMSOURCE
*/
BOOL HaveCapability(CString csDeviceName, CString csPortName, WORD nCapabilityToTest)
{
WORD pOutput[64];//Should be big enough
DWORD nNumEntries = DeviceCapabilities(
csDeviceName,
csPortName,
DC_BINS,
(char*)pOutput,
NULL);
if (nNumEntries != -1)
{
for (DWORD i = 0; i < nNumEntries; i++)
{
if (pOutput[i] == nCapabilityToTest)
return TRUE;
}
}
return FALSE;
}
|
|
|
|
|
I am trying to convert a CString to char so I can run it through inet_addr I think I have done this before but cannot remember how. Thanks if anyone can help.
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
Matt Newman wrote:
convert a CString to char
I think you actually want a const char*. Anyway, you should be able to just pass the CString object right in because it has a default LPCTSTR operator.
|
|
|
|
|
Matt Gullett wrote:
I think you actually want a const char*.
I double checked and that is the one I want. However when I try to compile
CString strDest = _T("192.168.0.6");
...
dwForwardDest = inet_addr(strDest);
I get this compile error:
error C2664: 'inet_addr' : cannot convert parameter 1 from 'CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
CString strDest = _T("192.168.0.6");
char buff[512];
_tcscopy(buff,strDest);
dwForwardDest = inet_addr(buff);
Thats what I'd do, and I've used it on a couple of oldie winsock programs so it seems to work for me.
|
|
|
|
|
I tried this but I got an error
error C2664: 'wcscpy' : cannot convert parameter 1 from 'char [512]' to 'wchar_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
- Matt Newman / Windows XP Activist
"Well, the guy that's giving you a hard time is a f***in moron, and you can tell him thats straight from another Linux user." - John Simmons on Linux Users Just do the American thing and shoot him... - Jim Crafton on Linux Users Wh3n my l33t skillz 1mpr0v3, I w1ll h4ck M$, 4nd th3n wh0 w1ll b3 l4ugh1ng ? N0t Bill. H4 h4 h4 h4 h4 h4 h4. - Christian Graus
|
|
|
|
|
Is this a UNICODE build? Are you building under VC7?
I am not 100% sure, but on VC7 you may need to do (LPCTSTR)strSomeString to get what you want.
If this is a UNICODE build, you will need to convert the contents of the CString from UNICODE WCHAR to char. Take a look at the wctomb function.
|
|
|
|