|
Thank You,That seems to be what I'm looking for.
Regards
Rick
|
|
|
|
|
This will only work for a top level window, and could give false hits ( if a lower down folder of the same name, is open, or an app has the same name as the folder ). It's as close as you can get, but it's very fragile.
I asked you this before - why do you need to do this ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
The code as written will return false positives. Multiple parent folders may have seperate child folders with the same name. Which one is really open??
The only way to detemine this would be to enumerate the Explorer windows, treating them like Internet Explorer windows and getting the URL they are showing.
|
|
|
|
|
Hi Dave!
Sorry I've completely forgotten about this , I was hurried to much for my lunch before the post.In order to avoid confusion I've just deleted my previous post.I agree that my fast method by using FindWindow wasn't sophisticated.
Here is my C++ function that solves the solution.It easy could be converted to .NET too.
<br />
BOOL IsOpenedNyWindowsExplorer(CString FolderName)<br />
{<br />
ATLENSURE(FolderName);<br />
<br />
BOOL RESULT=FALSE;<br />
IShellWindows *psw;<br />
HRESULT hr=0;<br />
<br />
hr = CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL,IID_IShellWindows,(void**)&psw);<br />
<br />
if (SUCCEEDED(hr))<br />
{<br />
long lCount=0;<br />
psw->get_Count(&lCount);<br />
for (int i = 0; i < (int)lCount; i++)<br />
{<br />
_variant_t vtIndex( (long)i);<br />
IDispatch* pDisp=NULL;<br />
hr=psw->Item(vtIndex,&pDisp);<br />
if(SUCCEEDED(hr))<br />
{<br />
IWebBrowser2* pBrowser=NULL;<br />
hr=pDisp->QueryInterface(IID_IWebBrowser2,(void**)&pBrowser);<br />
if(SUCCEEDED(hr))<br />
{<br />
BSTR Loc=SysAllocStringLen(NULL,270);<br />
hr=pBrowser->get_LocationURL(&Loc);<br />
if(SUCCEEDED(hr))<br />
{<br />
TCHAR* Dest=new TCHAR[270];<br />
DWORD Buff=0; <br />
CString str(Loc);<br />
if(AtlUnescapeUrl(str,Dest,&Buff,270))<br />
{<br />
str.ReleaseBuffer();<br />
str=Dest;<br />
<br />
str.TrimLeft(L"file:///").Replace('/','\\');<br />
if(!FolderName.CompareNoCase(str)) <br />
RESULT=TRUE;<br />
<br />
str.ReleaseBuffer();<br />
}<br />
str.ReleaseBuffer();<br />
delete[] Dest;<br />
pBrowser->Release();<br />
}<br />
SysFreeString(Loc);<br />
}<br />
pDisp->Release();<br />
}<br />
}<br />
<br />
psw->Release();<br />
}<br />
<br />
return RESULT;<br />
}<br />
|
|
|
|
|
Hi,
Am writing a function which should return a dataset to bind to a grid control. It is a linq query, Can I type cast var type variable to DataSet and return it.
Here is my funtion below.
public DataSet GetSites()
{
SiteTerDBDataContext ctx = new SiteTerDBDataContext();
ctx.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString;
var res = from sites in ctx.tblSites select sites;
return (DataSet)res;
}
Any early replies will be appreciated.
regards
Sajid
|
|
|
|
|
Sayed Sajid wrote: Any early replies will be appreciated.
You're in a hurry, but you didn't think to try this and see what happened, or check res in the debugger to see what type it is ?
I would be stunned if it came back as a dataset. I expect it would be a collection.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Mr Chris,
Thanks for your answer.
What would be the appropiate way of returning var type?
This is my intension to do actually.
public var GetSites()
{
SiteTerDBDataContext ctx = new SiteTerDBDataContext();
ctx.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString;
var res = from sites in ctx.tblSites select sites;
return res;
}
Many thanks.
Sajid
|
|
|
|
|
You cannot return var type since it's not a type like int or string.
It simply allows the compiler to infer the real type.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Sayed Sajid wrote: Can I type cast var type variable to DataSet and return it.
No.
var is just a syntactic sugar. In your case, res will be enumerable of ctx.tblSites 's type. You can't cast it directly to a DataSet .
Create a DatTable , Iterate the contents of res in a loop and fill data into DataTable . Once data table is ready, add it to a DataSet and return.
|
|
|
|
|
Hey Everyone,
I'm looking for some ideas on how to find the indexes of nested parentheses () in a string.
Basically the user is going to type a complex mathematical formula and i would like to know where all the nested ( and )'s are.
I have considered RegEx, but i had some real trouble with the nested part and i dont want to remove that functionality)
Any Ideas?
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Have a look at Expresso[^] - it is a regex creation / testing tool. One of its pre-built expressions is:
\(
(?>
[^()]+
| \( (?<number>)
| \) (?<-number>)
)*
(?(number)(?!))
\)
Which is a parentheses matcher. May be a good start for you?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thanks for the reply, this a start for sure. I could use something like this then just recursively go through the matches finding all the nested pairs.
Thanks for the reply
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Hi,
you probably want to create a parser for your expressions, not just some code about parentheses.
So you first of all need a parser that understand identifiers, literals and operators, with operator precedence (identified by a value in a limited range, say add=0, sub=0, mul=1, div=1, etc up to 9). You need a little stack to hold operands, push operands as long as operator precedence is increasing, and popping operands and executing operators when precedence is decreasing or constant (and something special for right-to-left associativity as in a^b^c).
Now there are two ways to extend to expressions with parentheses:
1. the easy and slightly more expensive one uses recursion:
- create a method that implements the simple parser, and start scanning the input;
- once you hit a left parenthesis, you know a subexpression is going to start, hence let your method
call itself to parse that subexpression
- once you hit a right parenthesis or end-of-input, return.
2. the other way basically implements one overall parser:
- scan the expression left-to-right doing all the things your parser needs to do;
- once you hit a left parenthesis, adapt the current state and increase the precedence value of all future operators causing them to get executed sooner than everything outside the parentheses.
While (1) seems simpler than (2) when everything is fine, the recursive one becomes a little more complex if you want it to deal with mistakes properly: you have to unwind the recursions when invalid expressions are being fed, and you need to figure a way to generate proper error reporting, all of which is much simpler in a single overall parser.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hey Luc,
As per usual your answer is extremely well thought out and just all around a very good answer.
However; I already have the validation and the execution of the formula figured out.
The problem is that I am trying to add some visual indication of the operator precedence using a RTF textbox and some extremely simple syntax highlighting.
I can find all the operators (even the ()) but the problem is that i would like to use a different colour for each pair of () in the formula.
Thanks again for your input.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Hi Adam,
you're welcome.
if all you need is locating parentheses and assigning some colors, I wouldn't use any Regex, because (1) I'm not really familiar with them and (2) I find them both powerful and cryptic, yielding hard-to-read code.
So I would just search for the next string.IndexOfAny('(',')') and then check:
for a '(' increment your color index and apply
for a ')' apply color, then decrement color index,
where color index is indexing an array of colors in round-robin fashion.
Personally I don't like multiple colors for the same token, so what I usually do is choose only one color for all parentheses (or brackets or whatever comes in pairs), then use a second color for such token and the matching one when the cursor is right behind one.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
unfortunately not, nice article though.
Thanks for the reply.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
hi to all
i would like to ask, is it possible that if i create a system and i want to generate the display items into excel file or txt file is it possible??
Warm Regards
Veon
|
|
|
|
|
Yes.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
LOL, i was going to answer the exact same way but i decided against it.
LOL though
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
|
Adam R Harris wrote: Well anything IS possible
No CG got to say no to the open folder detection question
Just that this question is not totally invalid.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Have 5 - some of the questions here seem to be just plain silly, and then someone comes up with an answer.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi all
how can i find specific values in the List<> class?
there is "
public T Find (Predicate <T> match)" , FindAll and findindex class functions ... but there all using the
Predicate Delegate function , the search value is fixed in the Delegated function (as seen in the example in MSDN).
is there way to search the list<> in Generic function specific values without using for each loop or any other loops?
Thanks
|
|
|
|