|
I am having a hard time finding the articles. I'm still looking, but here is a couple simple code snippets. Maybe they will give you somewhere to get started.
This code will get a Full name for a user from ADS.
public static string getFullName(string sUserAndDomain)
{
string u = sUserAndDomain.Replace('\\', '/');
try
{
DirectoryEntry e = new DirectoryEntry("WinNT://" + u);
return (string)e.Properties["FullName"].Value;
}
catch (Exception)
{
return null;
}
}
But to get that you need the User & Domain name of the logged in user. Below is the code
public static string getCurrentUsernameAndDomain()
{
WindowsIdentity user = WindowsIdentity.GetCurrent();
return user.Name;
}
I normally don't like giving out code like that, and I'm sure some people frown upon it. But, it's pretty simple and maybe that will get you headed in the right direction. If I can find those articles I'll post here. Hope that gets you started!
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I would like my form not to be "prone" for such shortcuts like win+d or win+m or any other minimize action.
When all other programs are minimized I would like my form stay visible on the desktop.
How can I do it? I've tried on other forums but noone could help me :-/
//sorry for my english but I'm not native english
regards
Y.
|
|
|
|
|
There's an onWindowStateChanged event, which fires after the window has been minimized / restored / maximized. If it gets minimized you can just restore it again imediatly.
Although your window may minimize them maximize straight away, rather than just staying where it is. Im not sure, you should check it out.
Wait... did i just imagine this event... i can't seem to find it... oh well, the location changed event catches minimizing too, use that
Oh, and your english is just fine.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Thanks indeed.
I'm going to try this.
But it can be visible when form is "returning" from minimize state. But this may be the only way to solve this problem...
|
|
|
|
|
Infact, i've just remembered a much more reliable way of stopping your window from minimizing / maximizing / whatever. You can override the message in WndProc:
protected override void WndProc(ref Message m)
{
switch(m.Msg) {
case 0x112:
if(m.WParam == (IntPtr)0xF032 || m.WParam == (IntPtr)0xF020)
m.WParam = (IntPtr)0xF122;
break;
}
base.WndProc(ref m);
}
That should disable any such resizing of your form, whether it be by clicking, shortcuts, or magical powers, of course if you want to maxmimize the form, just take out the first part of the IF statement.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
That's it!
Thanks
//edit:
that code doesn't work with win+d. When I press win+m all windows are minimizing and my form is still on the desktop. But when I press win+d all windows hide. But when I click any window on the taskbar (eg. IE, mozilla or any) my form is visible again.
Any idea?
Maybe I should catch event of pressing win+d and restore my form again...?
//edit2:
Option in the taskbar context menu "Show Desktop" affects my form too. It's the same as pressing win + d :/
-- modified at 11:33 Tuesday 16th October, 2007
|
|
|
|
|
Same issue here. I'm trying to figure out how to prevent Win+D or "Show Desktop" from working on a specific form. In other words, I need a form that is unhidable.
|
|
|
|
|
Found it! This will disable minimization and "hiding" for a form by attaching it to the desktop (or progman, technically). Here's the code in C# (should be easy to adapt)
<br />
[DllImport("User32", SetLastError = true)]<br />
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);<br />
<br />
[DllImport("User32", SetLastError = true)]<br />
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);<br />
<br />
public static void AttachFormToDesktop(Form frmToAttach)<br />
{<br />
IntPtr desktopHandle = FindWindow("Progman", null);<br />
IntPtr result = SetParent(frmToAttach.Handle, desktopHandle);<br />
}<br />
One problem I've encountered so far, though, is that I can no longer set the TransparencyKey property on a form that's been attached to the desktop.
Hope this helps someone!
|
|
|
|
|
hi.
i create an application that user can save a file with .mnm extension.
now i want to when user double click on this file, my application run and show the file content.
such as a .txt file , that user double click on it, "note pad" run and show the content.
my problem is that user click on a file can not get file's path.
how can get file path ?
tanks
|
|
|
|
|
If you have set up an association with a particular file type for your application, Windows will pass the file name to it as a command line argument when a file is selected.
In the static void main(string[] args) method for your application, the file name can be referenced using args[0] .
If you need to set up the file association programmatically, there is an article here on CodeProject[^] that explains how to do it.
Paul Marfleet
|
|
|
|
|
|
Hi,
I am trying to print my Outlook contacts to a checkelistbox I am trying to get only the Fullname and the phonenumber fields. The code below pops up a message box and give s me the nubmer of the contacts I have.
try
{
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(System.Reflection.Missing.Value, System.Reflection.Missing.Value, true, true);
// Get the default Contacts folder.
Outlook.MAPIFolder oContacts = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
// Get the Items collection from the folder.
Outlook.Items oItems = (Outlook.Items)oContacts.Items;
// Get the first contact item in the Items collection.
//Outlook.ContactItem oCt = (Outlook.ContactItem)oItems.GetLast();
Outlook.MAPIFolder foldercontacts = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items searchFolder = foldercontacts.Items;
int counter = 0;
foreach (Outlook.ContactItem foundContact in searchFolder)
{
counter = counter + 1;
//foundContact.FullName.ToString();
}
MessageBox.Show("You have" + counter + "contacts" );
Any help, to print the contacts to a listBox..
Thanks
|
|
|
|
|
s3rro wrote: Any help, to print the contacts to a listBox..
Maybe I don't understand what you mean. From what I think you are trying to say, can't you just do a listBox.Items.add(youritem); ?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Hy,
I have 3 pictures in a project resource, a picturebox and a button.
I want when I press the button to change dynamic the pictures from picturebox.
Can anybody help me?
thx
|
|
|
|
|
Sure, we woyld love to help. Where are you at on the task right now? Where are you stuck at?
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
It's not a task is for my knowledge.
I want to place random image from the project resource to my picturebox.that's it
|
|
|
|
|
Create an array, and put the images from the project resource in it.
Image[] images = new Image[5]; Then create an object of type System.Random:
Random ran = new Random();
^ These two must be defined outside a method.
Then do the following in your button event handler:
images[0] = Properties.Resources.Image1;
images[1] = Properties.Resources.Image2;
images[2] = Properties.Resources.Image3;
images[3] = Properties.Resources.Image4;
images[4] = Properties.Resources.Image5;
int pic = ran.Next(5);
pictureBox1.Image = images[pic];
And that should do the trick.
Edit: Perhaps it would be better to fill up the array in the form's constructor (usually public Form1() ):
public Form1()
{
InitializeComponent();
images[0] = Properties.Resources.Image1;
images[1] = Properties.Resources.Image2;
}
Virtual1ty "Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"
|
|
|
|
|
I'm trying to find out how the config file works.
This is how my config file looks like now.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Settingstest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<Settingstest.Properties.Settings>
<setting name="SampleText" serializeAs="String">
<value>foo</value>
</setting>
</Settingstest.Properties.Settings>
</userSettings>
</configuration>
The Sampletext is connected to a textbox and the default value shows.
But how do I make if i want to write a new text and save it for the user, and next time I run the program the new value should show up in the textbox?
I've tried with ConfigurationManager to store the new value, but I only get System.NullReferenceException so I do something wrong.
-- modified at 13:11 Monday 15th October, 2007
|
|
|
|
|
|
Right click on your project and properties then goto settings. you can create a string there. It's a configuration property. These values are saved to your EXE' exe.config file. you can set to this string you created by doing a
your.projects.namespace.Properties.Settings.Default.YourSettingName = m_YourVariable;
Then to get the value of the settings you created you can do
m_YourVariable = your.projects.namespace.Properties.Settings.Default.YourSettingName;
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I am attempting to make a new RichTextBox class (called RTBE) which inherits from RichTextBox. One of the things I want to implement is selection graying, so setting the HideSelection property to false makes selections get a gray BackColor on loss of focus. Because I have to restore the original BackColor in the text, I am wondering if there is a faster way to get/set the SelectionBackColor property so I don't have to go through each character in the selection and obtain the color for that character (through the GUI) using RTB.Select(start, 1) followed by calling RTB.SelectionBackColor. Basically, I am hoping there is a Win API call that can get the backcolor of the text in a RTB without changing the selection. Anyone have some insight? Thanks,
Jeff
|
|
|
|
|
Take a look at the EM_GETCHARFORMAT and EM_SETCHARFORMAT message as well as the CHARFORMAT2 struct. They can be used with the RTB to enable some more functionality than what the built-in RTB gives you.
Nevertheless, these messages also work on the current selection.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I think what I will end up doing is overriding the OnPaint method, and only call the base.OnPaint when I am not figuring out what the current highlighting is. That way, my RTB doesn't flicker. Am I correct in assuming that the WinAPI calls are faster than those exposed by the RTB? If so, I may still use the SendMessage / PostMessage duo in place of the methods exposed on the control as you suggested. Thanks,
Jeff
|
|
|
|
|
I have a legacy DLL written in unmanaged C++ that I need to use in a C# application. I can use it ok, but testing shows we don't get the string information when we catch any exceptions it throws.
It throws a simple TCHAR string exception. example:
throw(_T("My Exception Message."))
We can catch it in C# with the System.Exception class, but the string message is lost. (The Message member is empty.) We tried using a RuntimeWrappedException but that did not catch it.
I can not change the code in the DLL. How can I catch these exceptions and get the string info they contain?
|
|
|
|
|
Not Knuth wrote: I can not change the code in the DLL.
But you can create a C++/CLI assembly that can 1) catch the native exception, 2) Create a managed exception and marshal the message into it 3) throw the managed exception.
|
|
|
|