|
Joaquín M López Muñoz wrote:
Please see this thread where Paolo Messina struggles his way to the solution
Wow! Do you actually book mark all interesting threads?
Nish
[Signature temporarily down]
|
|
|
|
|
Whenever I found such a gadget and use it in one of my programs, I add a little comment with the place I extracted it from for later reference. It is easier to remember where I used such and such trick rather than the URL itself.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
o.k. so say i have data like:
DataString = "2432382ab" or "238233923829cd" or "23882323rq"
and I want to extract the two rightmost elements (say the letters above) in VB I would do:
theLeft = right(DataString,2)
in C++ ?
string theLeft
theLeft = DataString.substr(-2,2);
someone told me i could do this, but I can't get it to work . . .
thanks if you can help!
tim
---------------------------------------
Tim Booher
|
|
|
|
|
CString s="hello world";
CString s2=s.Right(2);
Nish
[Signature temporarily down]
|
|
|
|
|
If you're using std::string s the way to go is DataString.substr(DataString.size()-2) .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
yeah -- that is exactly what i needed . . . thanks . .. tim
---------------------------------------
Tim Booher
|
|
|
|
|
Some time ago I wrote the code for own control delived from CWnd. The class is using the code for drawing color edge (for redrawing standart windows client edge). This code is correct but it blink. :
void CWnd::OnNCPaint(){
CWnd::OnNCPaint(); // this line I have only for drawing scrollbars because i dont know how to draw it myself. If you call this function, Windows will draw standart client edge and the control (nonclient area) blink !!
CWindowDC dc(this);
CRect rect;
GetWindowRect(&rect);
dc.Draw3dRect(0,0,rect.Width(),rect.Height(),RGB(255,0,0),RGB(0,0,255));
}
I showed in MSDN but i dont find anything
if you call this :
CScrollBar * scrollbar = GetScrollBarCtrl(SB_VERT);
scrollbar->Invalidate();
it will be assert because scrollbar is not valid window (ASSERT(::IsWindow(m_hWnd)))
Thanks very much !!!!!!!
Wiizi
|
|
|
|
|
I haven't worked out this idea, but maybe it is of some help. In your preliminary solution, instead of calling CWnd::OnNCPaint issue a call to the default window proc like this:
DefWindowProc(WM_NCPAINT,(WPARAM)hRgn,0); hRgn is a region that indicates the clipping area for doing nc painting. Maybe you can create a rectangular region that excludes the border to avoid the flickering.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Good morning everyone. Here's today question.
I have an SDI with the view spilt into 3 columns using CSplitterWnd. I'm trying to set the width of the 1st and 3rd columns to specific widths. Is there a way to explicitly set the width of the 3rd column to a fixed width? I've tried to set width of the 3rd column using
m_wndSplit.SetColumnInfo(2, 3RD_COL_WIDTH, 3RD_COL_WIDTH)
but it just sets the width to whatever is leftover from columns 1 and 2.
Do I have to just get the desired widths of 1 and 3 and set 2 to the remainding width? If so, could someone send me a snippit on the best way to do this. I'm still getting used to proper windows size management.
Thanks in advance.
Marcus
Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope
-- Daniel Burnham
|
|
|
|
|
I have a Word document.I want to input this document to a
database.Generally,i will create a table in a database,then input a
column ,then input next column. In order to save my time,now i want to
input the whole Word document by a program.
please tell me some English information about this.Or tell me web
sites.Thank you!
huang chun shen
|
|
|
|
|
I reply you once,did you see that?
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Some time ago I wrote the code for own control delived from CWnd. The class is using the code for drawing color edge (for redrawing standart windows client edge). This code is correct but it blink. :
void CWnd::OnNCPaint(){
CWnd::OnNCPaint(); // this line I have only for drawing scrollbars because i dont know how to draw it myself. If you call this function, Windows will draw standart client edge and the control (nonclient area) blink !!
CWindowDC dc(this);
CRect rect;
GetWindowRect(&rect);
dc.Draw3dRect(0,0,rect.Width(),rect.Height(),RGB(255,0,0),RGB(0,0,255));
}
I showed in MSDN but i dont find anything
if you call this :
CScrollBar * scrollbar = GetScrollBarCtrl(SB_VERT);
scrollbar->Invalidate();
it will be assert because scrollbar is not valid window (ASSERT(::IsWindow(m_hWnd)))
Thanks very much !!!!!!!
Wiizi
|
|
|
|
|
|
I used the rand() function the other day.
From the MSDN it says:
The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand.
1. Seed the generator with srand()
2. Generate a random number with rand()
3. Divide the generated number by RAND_MAX.
4. Multiply the result 9 and add 1
This will give you a number between 1 and 10
I think this is right.
Marcus
Make no little plans; they have no magic to stir your blood to action. Make big plans, aim high in work and hope
-- Daniel Burnham
|
|
|
|
|
Well, as you already know, rand returns a randoum bumber between 0 and RAND_MAX . Usually it is more useful to have a random double uniformly distributed between 0 and 1, by evaluating (double)rand()/RAND_MAX . From here to a random integer number between 1 and 10 it is just simple arithmetic. Caveat: take into account the small (but actual) probability that (double)rand()/RAND_MAX yields exactly 1.0. In these cases the standard trick is to rerun the numer generation.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I find the % operator the easiest way to generate random numbers < RAND_MAX.
rand()%10 gives a number between 0 and 9, I need only add 1 to get a range of 1-10, or add 11 if I want a range of 11-20, etc.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
ok,...
so my code will look like:
rand()%10+1;
and how do i call that number up to see what it is? like:
if (the,rand,num == 1)
{
cout << "hello";
}
what is < RAND_MAX supposed to do?
RAND_MAX = 11;
rand()%10+1;
is that right, it doensnt feel right...
Thanks
~SilverShalkin
Questions are things that teach us well.
|
|
|
|
|
if (rand()%10)==1)
will do fine if you just want a 1 in 10 chance.
RAND_MAX is set in a #define, that is why it is all caps. It is the maximum value that rand() will return. If you don't use it in your calculations, i.e.
rand() * 10 / RAND_MAX
then it has no effect on the calculation at hand - it's not a magic constant, it's just a variable that the SDK sets to equal the top value that rand() can return.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Ok guys... I´m not much experienced with CSocket class... so here goes my question:
I´m creating a Windows NT service that open up a socket in a specific port and keep listening that port until someone connects to it. I´ve created a CListeningSock class, derived from CSocket, that has an override to the OnAccept virtual function. I created the socket, set it up to listening state and tried to activate my client software. The client socket was able to connect but the server socket didn´t received the OnAccept message (the virtual function was not called). I´ve created a Log function so that when the Services receives the OnAccept, an entry in the log file is created. The fact is that this entry was never written to the log file. The strangest thing is that if I use the same CListeningSock class in a "Dialog Based" project, instead of my nt service, the got damn class works and received the OnAccept ! Has anyone ever passed throught this ? Does CSocket needs a window to work !?!?
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
|
|
|
|
|
Mauricio,
First of all I think it's not a good idea to use MFC in an NT service. I didnt think so till two days ago, when in a newsgroup discussion I had with Joseph Newcomer, he told me, why I should avoid using MFC in services.
Second I think OnAccept requires a valid HWND. I am not at all sure about this. *I might be absolutely wrong*.
Thanks
Nish
[Signature temporarily down]
|
|
|
|
|
Nish [BusterBoy] wrote:
First of all I think it's not a good idea to use MFC in an NT service
Why ? I´ve used MFC in other services I´ve developed and they´re working for years by now... without any problems. Do you have the link to the newsgrp ?
Nish [BusterBoy] wrote:
Second I think OnAccept requires a valid HWND
That´s what I thought... I think I´ll start it over (using you socket articles as reference )
Nish [BusterBoy] wrote:
[Signature temporarily down]
Missing inspiration for poetry Nish !?
P.S.: By the way Nish... do you want a beta version of RaceX ? You said that you want to be the first one to try it out.
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
|
|
|
|
|
Mauricio Ritter wrote:
Why ? I´ve used MFC in other services I´ve developed and they´re working for years by now... without any problems. Do you have the link to the newsgrp ?
Here are some snips :-
As you can see he discourages even STL.
I think he knows enough of what he is talking about, to take this seriously...
You can't. Don't even waste time trying. Services should not use MFC, even for simple
structures like CString. Services should be written in C. Usage of C++, including but not
limited to MFC, is often fatal to services (you can't control the storage allocation, and
a service is expected to run for months; even slight storage fragmentation is fatal).
joe
Gosh Joe
This is bad news for me.
I was planning to convert a proxy server [http/smtp/pop3] into individual
services [each protocol proxy as a separate service]
And the original used only C and API.
This time I thought I'd use some MFC, primarily so that I could enjoy the
luxuries of CString.
(((
Nish
In fact, the use of CString is one of the serious horrors that will impact reliability. A
service needs to have very precise storage management, and C++ (and worse still, MFC)
mitigate strongly against this. I used to write operating system services, many years ago,
and storage fragmentation was the single greatest problem we had. For example, I replaced
one system with an allocator that only allocated blocks that were multiples of 256 bytes,
and the change in service reliability was amazing. While the release version of CString
uses heavy quantization (64, 128, 256 and 512 byte strings, plus "bigger"), that is three
more quanta than are acceptable, and the "bigger" does not allocate in multiples of the
quantum. The result will eventually be a memory footprint that consumes all available swap
space. Note that using STL has the same problems. I've often said that code space is a
concept so completely irrelevant that it is not worth wasting time on. Data space, on the
other hand, can kill you. The real art in writing reliable system services is in managing
the data space *very* carefully.
joe
Nish
[Signature temporarily down]
|
|
|
|
|
Well, if your service uses string data extensively, you'll be doing memory allocations anyway. I don't belive you should abandon the idea of using C++ for services just because somebody says that it's a bad idea.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Tomasz Sowinski wrote:
don't belive you should abandon the idea of using C++ for services just because somebody says that it's a bad idea
Well it was said by a renowned Win32 Guru.
But I am really in a confused state now
Nish
[Signature temporarily down]
|
|
|
|
|
Nish [BusterBoy] wrote:
Well it was said by a renowned Win32 Guru
Was he a member of NT team at MS, or something like that?
C++ has a features to make your software more -- and not less -- reliable. Just think about programming a complex piece without RAII idiom.
To make your confusion worse, check .NET framework - they have managed classes for creating services.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|