|
Hi peoples. I have a quick question reguarding API usuage....im trying to create collision detection by grapping just the color of the pixel on the outer edge of my object. This works okay for me using the API call GetPixel
the problem lies in that i have to get the pointer to the GetPixel call for this i have been using GetDesktopWindow() another api call that returns the Handle for the graphics on the entire desktop. Now this worked.. the problem is that its the hole desktop i.e everything drawn on it....if im trying to get the color in ONLY my program and someone opens a window above mine the GetPixel will grap the pixel from the open window not my program. What im looking for is a way for the API to only look at my program. Is there a easy / way to do this ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
You should be able to call CreateGraphics on your top level form, then use the GetHdc /ReleaseHdc methods on the Graphics object to retreive the HDC which you can use with GetPixel .
The only thing I'm unsure of is if the HDC returned is clipped around the child controls.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
Thanks for your help james. It turns out that it is clipped around the controls. and i need it for only the controls. I tryed passing the Handle to just the control i want (Ctrl.CreateGraphics().GetHdc) but i get a out of memory exception. But when i call the api call with another api call in it (GetDesktopWindow()-returns pointer to desktop) it works fine. Any ideas ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
Hi,
I am creating a MDI based allpications, and trying to handle the events for Enter and Leave in the MDi child, but when I create a new child, its Enter event handler is called 2 and Leave One in (Enter, Leave then enter) fashion. Why so ? I need to do some action in them, which is called twice? Is there an alternative to it. I do not have any compenets on the child also and using .net 2002.
Thanx
mayank Goyal
Mayank Goyal
|
|
|
|
|
I'm new to c# and programming altogether, so can you help me figure out the best way to do this?
i have a "Tools > Options" dialog box where a user can put in the db settings to connect to a database (IP, username, password, etc). once a user submits these settings, i want the whole application to reference these settings for the database connection.
i have about 5 forms on this small app that connect to a db, so i don't want to statically assign these settings per form.
can i (or should I) use a struct and define the users settings as constants? if so, how can i call the struct from each form?
Thanks for your help.
|
|
|
|
|
.gonad wrote:
i have a "Tools > Options" dialog box
You have or want?
.gonad wrote:
i want the whole application to reference these settings for the database connection.
Add a name/value to your config file. Then you can just get the value via dynamic properties.
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
Hi.
actually, I already have a dialog box where the user will have to enter the db connection properties. basically, i wrote this because i use this app at home AND at the office, but my network settings are different, so this "tools > options" dialog box will be helpful for me to make the these changes easily.
I just don't know how to make those changes permanent throughout the execution of the app and how to call those settings from each of the forms.
Thanks for you help.
|
|
|
|
|
The best way to make the settings global to your application is by having a class that is visible to the whole app. Something like:
<br />
public class MySettings<br />
{<br />
public static string MyDbConnectionString;<br />
public static string SomeOtherSettings;<br />
}<br />
Notice the keyword static infront. This means that you do not need an instance of the class to reference those members. You would access them like:
MySettings.MyDbConnectionString = ...
So you just load your settings from a file at the start of your app, and then just set them again from the options dialog.
Hope this helps and gives you a start,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thank you for your help. that's exactly what i needed to know, and it works like i expected.
|
|
|
|
|
Glad that I could be of help
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
|
leppie wrote:
Its generally better to place things like your own SQL/Access connectiong string in the machine.config file.
I would advise against this for a couple reasons:
- Your app will break if you move to a new version of the framework, but forget to update the machine.config for that version of the framework. Or worse, another application does the same thing, but storing a different connection string.
- You are taking something that should be local, and making it global. You wouldn't want your connection strings entered into another application so you should keep them local to the apps that need it.
Instead you should store the read-only setting in the app.config file. If you expect to make more applications using the same connection string then you would be better off creating your own settings class and storing that in the user's application directory, or the common application directory if the settings should apply to everyone.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
James T. Johnson wrote:
You are taking something that should be local, and making it global. You wouldn't want your connection strings entered into another application so you should keep them local to the apps that need it.
I realise that! I was thinking more in a development enviroment, rather than production. Obviously on deployment, an app.config file is created to carry the setting. That makes sense doesnt it?
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
You have probably noticed that if the text attributes are set to bold, larger size etc. on most of the controls the text itself is displaced to the left (usually). I'm talking here about the standard .NET controls (button, etc)
Can something be done? Are custom controls the only solution to this problem?
Also buttons with an image and text do not look very good.
|
|
|
|
|
|
Looking for C# game developers, I've already got the engine started, I just want more people to work on this with, it's coming pretty far and I want to collaberate with others that have some experience with these matters, anyways, all the information is at http://xed.kicks-ass.net/ypconquest[^]. Thanks
|
|
|
|
|
I am writing a method in C# and I need to execute applications from it. I have used ShellExecute in C++ before. So I thought that I would be able to make a managed extension. For the method, it was suppose to take in a string, the name of the application to execute. I got an error message when I used String, string, CString. I don't know what to use as the type. So I tried something different in C#, I used
Process myProcess = new Process();
myProcess.StartInfo.FileName = "Notepad";
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
myProcess.Start();
but that did not show the notepad application (I didn't try any other application program yet). The process is running in the background, I check with task manager. The problem is that I don't know how to write managed code and I don't know how to use C#. I am new to both.
Thanks for any help
|
|
|
|
|
I used the exact same code that you did (I copied and pasted just to be sure), and it worked.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
This is how I have done it in the past :
<br />
FileInfo launchfi = new FileInfo("myprogram.exe");<br />
if (launchfi.Exists)<br />
{<br />
Process mainapplication = new Process();<br />
mainapplication.StartInfo.FileName = launchfi.FullName;<br />
mainapplication.StartInfo.WorkingDirectory = launchfi.Directory.FullName;<br />
mainapplication.StartInfo.UseShellExecute = false;<br />
<br />
try<br />
{<br />
mainapplication.Start();<br />
}<br />
catch<br />
{<br />
MessageBox.Show("Unable to start application.");<br />
}<br />
}<br />
|
|
|
|
|
hi,
I'm a beginner of C#,
recently, I have to handle a project which need a dash line object.
I know I need to make my own control, however, I can't find any solution and idea at all.
actually, the application is composed by a panel, and a picture box. The picturebox is placed inside panel, and the image will show inside pictureBox (fixed). Then I need to make 2 dash line that are able to "drag" left/right like a splitter in order to let user measure the length of picture.
Does any experts made an example like this?
or do you know where has this type of example?
I'm quite urgent to do this. Please help and guide me on right way..
Thank you very very much !!
|
|
|
|
|
|
Hi, Leppie,
Thank you very much for your reply. You did a great job, however, it's a little bit hard for me. I'm sorry, I'm stupid...
I don't need to do such powerful as your's, I just need a control that is movable dash line. I would like to move the line over picture. I know it's bascially as same as your's. But could you explain it more to me, or teach me how to make this control.
Thank you very very much
|
|
|
|
|
Hi all. I apologize to the mods if this is against the rules..I'm not sure where to find the rules anymore.
Just announcing my new website meant to be a code developer type of website like this one, only on a much smaller (mostly personal) scale. Please feel free to stop by and discuss things.
KingTermite.Net
KingTermite
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
Hi.
I'm writing a new app in C# where i'm using an old C++ app written in Power++. in my C# app i'm writing files whisch will be read by the C++ app. the C++ app is started from my C# app using the "proces" class in the .NET framework.
Before the C++ app will read the files it has to recieve a user event (WM_USER Event) from my C# app. My question is this:
How do i genereate a event in my C# app with the appropriate data that will be seen by the c++ app?
for the record: i Usually code C#. I do not code C++. i can read it but not well.
I have access to the sourcecode of both app's but I am not interestest in changeing the C++ app.
I have pasted a small part of the c++ app where i think the "eventlistener" is created.
------------------
WBool Form_POSManager::Form_POSManager_User(
WObject * source,
WUserEventData * event )
{
FindPOSFiler(event->data);
return FALSE;
}
----------------
I have abserlotely no idea how i am going to generate or send the event from C#.
Can anyone help me out?
//finger
|
|
|
|
|
i found the solution:
http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=119342&Page=1#119937
|
|
|
|