|
Hi everyone
I wonder if there is any embedded implementaion or helper class of Regular Expression in VC/C++? Or any third part surport?
I've heard that Regular Expression is used a lot by compliers. So can we use the complier as the embedded intepreter of Regular Expression? If we can, how?
Thank you. Waiting for your help.
|
|
|
|
|
there are libraries (i never used)
try search for regex, regexp++ etc. (see http://www.codeproject.com/string/re.asp or sourceforge.net)
t!
|
|
|
|
|
I've used the Regex classes in boost (www.boost.org) - they seem to work pretty well. There's also the Greta library from some guy @ Microsoft (go to research.microsoft.com & search for 'Greta')
Hope these help...
|
|
|
|
|
I've heard something to the effect that these two very implementations are the ones competing for a place in the C++0x library. As with all rumours one should take them with a grain of salt, but perhaps it could be something to plan for.
|
|
|
|
|
You can use Regular Expression with ATL 7. I forgot the name of the new classes
but go to MSDN, you can have more details.
One good thing about getting older, you don't lose the ages you've been!
|
|
|
|
|
Thank you all. These are really helpful.
But there is really a petty about using boost. When I've installed it, I find the RE implementaion relies on some DLL objects. That introduces the installation problem because I want to build a COM server that depends on nothing except using static linking.
Maybe I should try ATL 7, as Ernest suggested.
|
|
|
|
|
You can build the regular expression library in Boost as a static link library - Boost Regex should pick that if you're statically linking to the C run-time. To force use of the static library, put
#define BOOST_REGEX_STATIC_LINK
in your stdafx.h (or as a command-line argument to the compiler, whatever). It does work, believe me - I've been through all that (used it in a small WTL app. that I wanted to have minimal DLL dependencies...)
|
|
|
|
|
It provide DesktopColorizer.dsw demo From www.softshape.com , we can move the entire window in client , now I want to nomove the window , What can I do it ?
sai of china
|
|
|
|
|
Say I have a Bitmap resource IDB_BITMAP1
How do I draw this bitmap onto my CView ?
Regards
Nish
p.s. did some quick searches on CP. Saw some classes. I dont want any classes. Want some code pointers
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Check out my screen saver I take the CP logo from a resource and draw it on the screen. Drawing to a CView is just like drawing to any old window (only you'd use the MFC DC wrappers of course).
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.10414 AcidHelm
|
|
|
|
|
Hi Mike
I got it to work on my own with some trial/error. But I am worried about leaks
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Okay, after some fiddling I came up with this. It works, but is it okay?
CDC mdc;
mdc.CreateCompatibleDC(pDC);
CBitmap b;
b.LoadBitmap(IDB_BITMAP1);
BITMAP bmap;
b.GetBitmap(&bmap);
CSize s = CSize(bmap.bmWidth,bmap.bmHeight);
mdc.SelectObject(&b);
pDC->BitBlt(0,0,s.cx,s.cy,&mdc,0,0,SRCCOPY );
I am not deleting or releasing the CBitmap or the CDC as I assume their destructors will do it for me. is that a valid assumption?
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
When b's destructor is called, the bitmap is still selected into mdc device context. ::DeleteObject call silently fails and you have resource leak. You have to ensure that b isn't selected into any context when its C++ d'tor is executed. The tricky way is to change order of declarations of mdc and b. If mdc is second, it'll be destroyed first and your bitmap will be released.
Or - you can store CBitmap* returned from mdc.SelectObject call and re-select it after BitBlt.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Hello Tomasz, I realized that. So I did this :-
CDC mdc;
mdc.CreateCompatibleDC(pDC);
CBitmap b;
b.LoadBitmap(IDB_BITMAP1);
BITMAP bmap;
b.GetBitmap(&bmap);
CSize s = CSize(bmap.bmWidth,bmap.bmHeight);
mdc.SelectObject(&b);
pDC->BitBlt(0,0,s.cx,s.cy,&mdc,0,0,SRCCOPY );
b.DeleteObject();
I have added b.DeleteObject() and I hope that'll avoid the situation you predict
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
Sorry - this will not work. b is selected into mdc when you're calling DeleteObject; the call fails. GDI doesn't allow deletions on objects (brushes, pens, bitmaps, etc) selected into any device context.
DeleteObject call doesn't make any difference - CBitmap d'tor calls it anyway.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Thanks Tomasz. I alreday sent the prototype. But the leak is a once only leak. You see, when the app starts up there is no msp file loaded and thus no image to show. So I addeda default bitmap resource and was showing it. so it'll be a one-time leak
anyway, bnad of me to do that
Nish
ps. thanks
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
Nish - Native CPian wrote:
so it'll be a one-time leak
I'm not sure. If the code you've posted is in OnDraw, you'll have a leak each time your view is repainted.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Tomasz Sowinski wrote:
I'm not sure. If the code you've posted is in OnDraw, you'll have a leak each time your view is repainted.
Actually, it is a one-time leak. Because I check my document variables and ONLY if they are empty do I attempt to do all this stuff. That entire block of code I pasted is in an if() {} block. And I have removed "New" from the menu, toolbar and the accelerator keys.
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
Assuming that it's inside OnDraw (is it?), the leak will occur anytime WM_PAINT is processed. This can happen when you resize the window, open About box of your program, switch between applications, start screensaver, etc.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Tomasz Sowinski wrote:
Assuming that it's inside OnDraw (is it?), the leak will occur anytime WM_PAINT is processed. This can happen when you resize the window, open About box of your program, switch between applications, start screensaver, etc.
Uh Oh! That's true. But I hope that the moment they run the program, they'll open an image file. If they don't and they leave it open....I hate to think of the rest...
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
Nish - Native CPian wrote:
I am not deleting or releasing the CBitmap or the CDC as I assume their destructors will do it for me. is that a valid assumption?
No, it isn't, because the bitmap is selected in the DC, the DC cannot be destroyed. Therefore I would change your code to following:
CDC mdc;
mdc.CreateCompatibleDC(pDC);
CBitmap b;
b.LoadBitmap(IDB_BITMAP1);
BITMAP bmap;
b.GetBitmap(&bmap);
CSize s = CSize(bmap.bmWidth,bmap.bmHeight);
CBitmap* pOldBitmap = (CBitmap*)mdc.SelectObject(&b);
pDC->BitBlt(0,0,s.cx,s.cy,&mdc,0,0,SRCCOPY );
mdc.SelectObject(pOldBitmap); SelectObject returns the previous selected object of that type (in this case a bitmap), so you can use this to unselect your bitmap.
Regards
Thomas
Sonork id: 100.10453 Thömmi
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
Hi Nish. Check out this [clickety] article by Joseph Newcomer.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
isn't it okay if I do a b.DeleteObject()
That'll delete the bitmap even if it's selected in a DC, won't it?
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
|
Nope, because even if the bitmap handle is invalid, it is still selected in the DC. It would be an overkill, if Windows had to check, if any selected handle is still valid, when it deletes a DC.
Regards
Thomas
Sonork id: 100.10453 Thömmi
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|