is it possible to make a dll that draws on your screen? Like you know how in visual studio you can make a form? Well how can I make a certain dll draw a form like that? Possible or no? thanks in advanced
[QUOTE=c-unit;22410412]is it possible to make a dll that draws on your screen? Like you know how in visual studio you can make a form? Well how can I make a certain dll draw a form like that? Possible or no? thanks in advanced[/QUOTE]
Of course you can. You just need something else to call a method to do so.
For example, you can still import Windows.Forms just fine.
Can I make the form in visual studio and incorporate that? Or do I need to do it all within the dll
[QUOTE=c-unit;22410664]Can I make the form in visual studio and incorporate that? Or do I need to do it all within the dll[/QUOTE]
Sure, if you want to copy paste it in.
Why not just ADD A NEW FORM in the dll project, and use the designer there (As I assume that's what you mean).
or if you mean just drawing random things in a random window(or maybe even not in a window) then you can use one of the drawing APIs, I know of DirectDraw, Direct2D and GDI. At least that is for unmanaged C++ code, stuff may be a bit different for managed code/C# code. Oh and for drawing random stuff you might have to learn some windows API but that is pretty simple(in theory).
[QUOTE=barchar;22415440]or if you mean just drawing random things in a random window(or maybe even not in a window) then you can use one of the drawing APIs, I know of DirectDraw, Direct2D and GDI. At least that is for unmanaged C++ code, stuff may be a bit different for managed code/C# code. Oh and for drawing random stuff you might have to learn some windows API but that is pretty simple(in theory).[/QUOTE]
Well, actually if he's drawing to the desktop at large it's quite easy. You can simply used the Graphics class with the desktop's intptr.
Here's some example code that 'blacks out' the user's screen.
[cpp] static void Blackout()
{
IntPtr hdc = GetDCEx(GetDesktopWindow(), IntPtr.Zero, 1027);
Graphics g1 = Graphics.FromHdc(hdc);
while (true)
{
g1.Clear(Color.Black);
}
}
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgn, uint flags);[/cpp]
From the MSDN documentation it looks like you might be able to do that for any window as there is a method to create a graphics object from an Hwnd. It would appear that the Graphics class is part of GDI+. Lets see if I cant cook up some code to actually do this.
[CODE]
string friendlyName = AppDomain.CurrentDomain.FriendlyName;
Process[] pro = Process.GetProcessesByName(friendlyName.Substring(0,friendlyName.LastIndexOf('.')));
IntPtr hwndHandle = pro[0].mainWindowHandle;
[/CODE]
and there you have a pointer to the window handle, you should be able to plug that into the graphics object constructor and do what you want to.
[QUOTE=ShaRose;22417807]Well, actually if he's drawing to the desktop at large it's quite easy. You can simply used the Graphics class with the desktop's intptr.
Here's some example code that 'blacks out' the user's screen.
[cpp] static void Blackout()
{
IntPtr hdc = GetDCEx(GetDesktopWindow(), IntPtr.Zero, 1027);
Graphics g1 = Graphics.FromHdc(hdc);
while (true)
{
g1.Clear(Color.Black);
}
}
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgn, uint flags);[/cpp][/QUOTE]
ok so that makes sense, I can go create the form in visual C++ or Visual Studio (obviously) then copy and paste the code in, then 'call'(I don't know how to word it) it to pop-up
Yes, it's call.
If you are just adding a form, right click the project, add, new windows form.
That's it. The code I gave you blanks your screen.
[QUOTE=ShaRose;22431683]Yes, it's call.
If you are just adding a form, right click the project, add, new windows form.
That's it. The code I gave you blanks your screen.[/QUOTE]
I think I'll save that code somewhere, could be useful or a good reference, anyways thank you for your help
[editline]10:06PM[/editline]
Oh and one more question, what commands can I use to "bind" keys, so if I push F1 it opens up the menu, F2 closes things like that?
[QUOTE=c-unit;22432269]I think I'll save that code somewhere, could be useful or a good reference, anyways thank you for your help
[editline]10:06PM[/editline]
Oh and one more question, what commands can I use to "bind" keys, so if I push F1 it opens up the menu, F2 closes things like that?[/QUOTE]
[code] public Form1()
{
InitializeComponent();
this.KeyPreview = true; // Needed to register keypress hooks with this form.
this.KeyUp += new KeyEventHandler(Form1_KeyUp);
}
void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.F1)
{
MessageBox.Show("This is your help window!!!");
e.Handled = true;
}
}[/code]
For windows forms. You could also do an events based system, but meh. That kind of code will probably be fine for you.
Note that if you are using more than one, use a switch / case.
[QUOTE=c-unit;22432269]I think I'll save that code somewhere, could be useful or a good reference, anyways thank you for your help
[editline]10:06PM[/editline]
Oh and one more question, what commands can I use to "bind" keys, so if I push F1 it opens up the menu, F2 closes things like that?[/QUOTE]You could use [URL="http://msdn.microsoft.com/en-us/library/ms646293%28VS.85%29.aspx"]GetAsyncKeyState()[/URL] to check the keys.
[QUOTE=-SC-Lakitu;22433143]Use [url=http://msdn.microsoft.com/en-us/library/ms646293%28VS.85%29.aspx]GetAsyncKeyState[/url] to check the keys.[/QUOTE]
That's for global hooks, I think he means in application.
[editline]02:39AM[/editline]
And if he WANTS that, you should have linked [url]http://www.pinvoke.net/default.aspx/user32/GetAsyncKeyState.html[/url]
Sorry, you need to Log In to post a reply to this thread.