|
SetCheck in UI handler.
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
I need to access network resources that are available to the logged-in user from within a service. I would like to be able to do this without prompting the user for their username/password. It looks like I can use the ImpersonateLoggedOnUser API function to do this, but I need a handle to an access token for the logged-in user. If the service and the user are on the same box, I believe I can get the token via OpenProcessToken .
Here's the tricky part. Suppose the user is logged in on machine A, and the service is running on machine B. Is there a way to pass an access token for the user to the service, that will give the service access to the user's network resources?
Software Zen: delete this;
|
|
|
|
|
If you need to do this for only one user, then you can simply run the windows service under this user's account by reconfiguring it. Use Administrative tools on Windows 2000 or Control Panel on windows NT 4.0, select Services to find the service you want to configure.
If multiple users have to use the service, then the above does not work.
My articles and software tools
|
|
|
|
|
Hi,
I would like to know how to add a delay of say 1sec in my
MDI program !!!
Ehsan Behboudi
|
|
|
|
|
Sleep() - but then people may think you program is buggy or broken.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
BuggyMax
|
|
|
|
|
maybe you want to use SetTimer
SetTimer(TIMER_ID, time);
Then just set up a message handler to check for TIMER_ID and do what you want in that message i think there are a few samples somewhere on this site :P
|
|
|
|
|
1. Sleep, but it prevents the program from responding to any other event during the Sleep interval.
2. CreateEvent to create a dummy event,
and then WaitForSingleObject
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
void Delay(DWORD dwMsecs, BOOL bBlocking)
{
DWORD dwStrtmsecs, dwCurmsecs;
dwStrtmsecs = dwCurmsecs = ::GetTickCount();
do
{
if (!bBlocking)
{
MSG msg;
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
dwCurmsecs = ::GetTickCount();
if (dwCurmsecs < dwStrtmsecs)
dwStrtmsecs = dwCurmsecs;
} while ((dwCurmsecs < (dwMsecs + dwStrtmsecs)));
}
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
im assuming this is for startup reasons?
what i do is after initialising all i need to simply send urself a message that "starts" the main app running
hope i got the right angle here
"there is no spoon" biz stuff about me
|
|
|
|
|
With CFrameWnd I can simply insert status bar by CStatusBar x(this) in OnCreate. But with CWnd it doesn't work. What else do I have to do? What is the difference between CWnd and CFrameWnd in this way?
|
|
|
|
|
CFrameWnd is the "frame" part of a window. CWnd is an MFC base class for all MFC window objects.
Kuphryn
|
|
|
|
|
I have a FILETIME struct that I want to perform arithmetic on (subtract a week from it). To do this, I need to convert it to a 64-bit integer, do the arithmetic, then convert back to a FILETIME. I've seen examples that do this with the ULARGE_INTEGER union. Something like this:
<br />
FILETIME ft;<br />
<br />
ULARGE_INTEGER uli;<br />
uli.LowPart = ft.dwLowDateTime;<br />
uli.HighPart = ft.dwHighDateTime;<br />
<br />
uli.QuadPart -= ...<br />
<br />
ft.dwLowDateTime = uli.LowPart;<br />
ft.dwHighDateTime = uli.HighPart;<br />
where the QuadPart is overlayed in memory with the LowPart/HighPart (since it's a union).
But is this legal... to set one union member and then read a different union member? Yes, I've tried it and it does work, but is it truly correct according to the language?
|
|
|
|
|
<br />
typedef union _ULARGE_INTEGER <br />
{ <br />
struct <br />
{<br />
DWORD LowPart; <br />
DWORD HighPart; <br />
};<br />
ULONGLONG QuadPart;<br />
} ULARGE_INTEGER; <br />
You should not have any problems since QuadPart is 64 bits, whereas LowPart and HighPart are 32 bits. LowPart holds the first 32 bits and HighPart represents the other 32 bits.
I hope this is correct since I never use unions and it has been 10 years since I have studied c++.
|
|
|
|
|
Yes, I realize the layout of the union. My question is sort of a tricky one that someone who is very familiar with the C or C++ language may know. Each language has specifications for what is and is not defined behavior. If something is not defined behavior, that means it may actually work sometimes or all the time, but it is still incorrectly coded. I seem to remember that it is illegal to assign to one union member and then read from a different union member. But I'm not sure, hence the question....
|
|
|
|
|
That's the whole purpose of a union - to be able to access a member by more than one name.
union u
{
DWORD dwValue;
struct s
{
WORD wValue1;
WORD wValue2;
};
};
Now I can assign a value to u.dwValue and read it as two WORD s by accessing s.wValue1 and s.wValue2 .
It looks odd but it definitely has its uses.
|
|
|
|
|
just use an overloded operatoer FILETIME operator-(FILETIME &ft, FILETIME &ft1);
|
|
|
|
|
Hi,
I'm not sure whether this is a fairly straightforward question or a lot to ask, but here goes...
I am creating a small file packing program. For selecting the files to pack, I am using a list box control with three button controls, "Browse", "Select All" and "Delete". Fairly straightforwardly, the combination of these controls lets the user browse for and select files to add to the list box, and to select and delete those items he or she wishes to get rid of etc. Everything is working great... Except that I have just realised that for this particular app the user is going to need to have the option to sort the items in the box by file type as well as by name. So I guess that means that I have to use a list _view_ control instead of a list box control, so that I can use multiple columns with headings and sort by them...
However, I have fallen at the first hurdle, as I am having problems finding concise information about how to set this up (I am relatively new to coding). My main problem is probably that I'm using _NO_ MFC, and all the tutorials/examples I can find seem to use MFC. Also there is a vast amount of info and a _long_ list of message descriptions on MSDN, but I can't seem to find any straight WinAPI examples that show the basics of setting up and populating a multi-column list view.
Could someone please point me towards a _NON_ MFC, standard C WinAPI tutorial/thread with info/any information at all on using list view controls to display a list of items with multiple columns? What I'm really aiming for is a simplified version of the sort of file list you get in WinZip or Windows Explorer (I just need to show file name, file type and path).
Many thanks to anyone who can tell me where to begin,
KB
|
|
|
|
|
Read this
You can also download ListView sample here
|
|
|
|
|
I've just started to read the Visul C++ .NET Bible hoping to learn how to master MFC. I really like book - but I'm having some problems early on.
I'm trying to create this Dialog App as explained in the text. It's about DDX and I need to wire up an edit box with a DDX value variable. So, I do the following (as explained in the text):
1. Click on the edit box in the dialog desinger.
2. Right click.
3. Choose Add Variabel from the context menu.
4. Deselect the "Control Variable" checkbox so I get a DDX value variable instead of an DDX Control variable.
5. Enter my desired type (CString) and name (m_strMessage).
6. Click Finish.
Then in a button handler I write this(again as explained in the text):
<br />
void CHelloDialogDlg::OnBnClickedOk()<br />
{ <br />
UpdateData(TRUE);<br />
AfxMessageBox(m_strMessage);<br />
}<br />
What's suppossed to happen is this: I click an OK button and the dialog apps takes what's in the edit control and show it in a message box.
It doesn't work. Very puzzeling.
So, I downloaded the source code form the books homepage (the authors ditto was down apparently so I went to the publisher's site) and looked through that.
As expected there were discrepancies. Specifically his code had this:
<br />
void CHelloDialogDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
CDialog::DoDataExchange(pDX);<br />
DDX_Text(pDX, IDC_EDIT1, m_strMessage);<br />
}<br />
Whereas mine had only this:
<br />
void CHelloDialogDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
CDialog::DoDataExchange(pDX);<br />
}<br />
Seeing this I thought I might have done a mistake when wiring up the edit box to a DDX value variable. So I tried to add yet another variable (following the same procedure as above).
Alas, same result. Somehow the edit box doesn't get wired up to my variable. I've now read the same section in the book over and over and over again; I do just as explained.
So I'm thinkign maybe something's wrong with my VS? (I'm using Visual Studio .NET 2002).
Anyway, this is getting rather long. Any ideas? Did I do something idiotic?
(BTW I really do like the book althoug I'm only 20 pages into it. I've read approx. 100 pages in a book on a similar subject: "Progamming Microsoft Visual C++ .NET" from Microsoft Press but I didn't like it so I went out and bought this one instead. Much better....very much indeed ;P)
Help
|
|
|
|
|
I think I've just found the error. Apparently it's an error in the book. And a big one as well. I'm not supposed to deselect the "Control Variable" checkbox, instead I need to change the Category combo box from Control to Value....hmmm....
Am I right?
|
|
|
|
|
First off, thank you for purchasing my book. Second, your problem can be chalked up to the joys of writing a book while working on a beta product As a result when the UI changed in Visual Studio, that particular demo became incorrect. Here's how to solve the problem.
Instead of checking or unchecking the "Control variable" check box, you need to select the appropriate entry in the Category combo box. Long story, short. Microsoft using ambiguous terms to represent two different things. Checking the "Control variable" checkbox is how you tell Visual Studio that you're either creating a simple member variable for a class (non-DDX) or you're creating a DDX variable that will be associated with a control on the dialog.
The Category combo box is where you state whether you're creating a value DDX member variable or a control DDX member variable. In your case, you need to keep the "Control variable" checked and select Value from the Category combo box. You'll then see a default type of CString. Simply type in your variable name and ignore the bit in the book about having to manually add a DDX_Text entry.
Sorry for the confusion.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Don't worry about it. It's straightened out now. Thanks for clearing up the why's and how's
So that's why that error sneaked in there - because of a beta product. Well, that's hardly your fault then.
Anyway I'm still reading, and so far I'm getting my money's worth. It's really good - so there you go.
Well I'll return to the wonders of Documents and Views in MFC now. Take care.
|
|
|
|
|
You're very welcome. Now that I've finished my "Extending MFC Applications with the .NET Framework" book, I'll be putting up a book support site this weekend that will contain things like an errata and discussion board. If you'd like I'll email you once it's live (aiming for Monday).
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
I would very much like that; yes please. I'm also the happy owner of Inside C# 2nd Ed, i.e. such a site could come in handy
Thanks again...
|
|
|
|