Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Application locked Drag , +
Hi, I am playing a game that requires full screen in order to run but I also want to listen to some music and or do other things on the side. but in order to switch between windows I would have to leave the game unattended which is bad when your playing an MMO(anything can happen in less than a second)So I was thinking of making an app that allows the user to drag and drop a window into my application and lock my application's window to keep it from hiding in the background or minimize. Is this possible? if so, how can this be done?
 

operating system windows 7, programing language visual C#
Posted 8-Feb-12 18:29pm
Comments
Dave Kreskowiak at 8-Feb-12 23:41pm
   
This doesn't make sense. What do you mean EXACTLY by:
"that allows the user to drag and drop a window into my application". To what purpose??
 
"and lock my application's window to keep it from hiding in the background or minimize" Why? For what purpose??
angelllll at 9-Feb-12 0:04am
   
I thought it was clear enough, You see when your playing a MMO you cant pause the game therefore you are pretty much vulnerable if you have to tab in order to look at another window. A lot of programs don't support features that allows you to keep the window from hiding in the background, so by dragging a window for example a media player playing a song into my application's window I will be able to keep my window from minimizing or hiding, thus allowing me to control the media player while keeping track of the game.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

OK, I see what you're doing now. First, does you MMO play fullscreen?? If so, you've got a problem. DirectX will constantly be redrawing the screen, thereby completely overdrawing any window you put on top of it, making it vanish.
 
You might get away with this though. All you have to do to test this is create a blank form, set it's TopMost property to True, launch it, then play your MMO. If your window disappears, your sunk before you even get started.
  Permalink  
Comments
angelllll at 9-Feb-12 22:19pm
   
Thanks, I'm glad you finally understand. I did some diagnostics on what you said and it seems like the game allows some options that enable it to be windowed instead of full screen. So no problem there, it displays the form first when switched to those settings. Even if I don't need to make this program anymore I can tell it will be handy to know its functionality and plus it might be more convenient in other games or programs. So its a go, if your still willing to help out.
Dave Kreskowiak at 9-Feb-12 22:35pm
   
You don't need the code snippet that was posted. All you need is http://msdn.microsoft.com/en-us/library/windows/desktop/ms633541(v=vs.85).aspx
 
That will let you set the parent window of any window to a control on your form, usually a Panel. Getting the window handle of a control is easy. Every control has a Handle property that contains its own window handle. That's going to be your Parent parameter.
 
Dragging a window on top of your form is not something I've done. Should be easy enough to find with a little Google though.
angelllll at 10-Feb-12 22:42pm
   
I'm so dumb lol, I was searching for the solution online(which was not successful) and realized that instead of trying to dock a program into mines why not open the program within mines. Do you know how this could be done? I've done some research and haven't found anything yet. Thanks,
Dave Kreskowiak at 11-Feb-12 7:53am
   
You cannot launch an app inside your own. You can launch an app, wait for its window to be created, then use SetParent (the link I posted above) on it.
angelllll at 11-Feb-12 14:07pm
   
I found a way to capture windows in my program in this link http://stackoverflow.com/questions/758494/how-can-i-run-another-application-within-a-panel-of-my-c-sharp-program
 
But I noticed that I can only capture simple things like notepad and cmd but not windows media player and others(most likely because they don't support that function). The link that you sent me is kind of confusing to me and I'm not sure how to implement the code. If your link can do any type of program then could you show an example and explain it to me?
Dave Kreskowiak at 11-Feb-12 15:41pm
   
The code snippet you found is exactly how it works. It will NOT work for every window because not every window has a window handle.
angelllll at 11-Feb-12 19:36pm
   
Actually windows media player works now that I tried it again. Before I draw this to a close I have one more question, in the code from the link it responds by starting a program by calling it by its name. I made some changes so that it opens a filebrowser and you choose what to open and capture. Is there a way to fire the code by dragging a program into the application instead?
 
I thank you for your time, you help me tremendously.
Dave Kreskowiak at 11-Feb-12 20:52pm
   
Define "program". Are you talking about a shortcut to an .EXE, the .EXE itself, or the main window of the application??
 
In all three cases, yes, it is. What you do is research Drag and Drop. There's a few events to read up on. What exactly you look for in the DragEnter event will change depending on what you're dragging into the window. I haven't done a drag and drop in quite a long time, so the details are quite fuzzy.
angelllll at 11-Feb-12 22:40pm
   
got it! Once again thank you for all of your help. All that's left to do is to polish it and then find a site to publish it. Just a free program nothing big. and use it for myself when I'm playing my game. I have one more problem that I need help with but its something simple. If your up to it here is a link to another question I posted
 
http://www.codeproject.com/Questions/328900/how-to-check-if-a-file-name-and-or-path-exists-in
 

thanks,
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
1. Just input this code in your form code behind:
//Drag Forms w/out titlebar
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
//End
 
2. Input a Panel in your form as your title bar.
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
 

 
I hope this one can help.
 
Thank You.
  Permalink  
v3
Comments
angelllll at 9-Feb-12 0:13am
   
hey sayrecollado, I'm not sure if I put your code in the right place but I seem to be getting some errors, here is the full code.
 
Thanks,
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
 
}
//Drag Forms w/out titlebar
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
(error on this line) [DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd,
int Msg, int wParam, int lParam);
(error on this line) [DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
//End
 
private void Form1_Load(object sender, EventArgs e)
{

}
 

 

 
}
}
 

the error says the type or namespace could not be found.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
just a suggestion, can't you pause game when user switch to other application ? isn't it will be good for users?
 
Thanks
-Amit
  Permalink  
Comments
angelllll at 9-Feb-12 7:25am
   
lol I can tell you guys haven't played MMOs wich means massive multiplayer online. Pretty much you play the game in a server which players from all over the world can connect and play. you just can't pause the game, have you ever played world of Warcraft? That's pretty much why I want to make this app.
amitgajjar at 12-Feb-12 23:19pm
   
Hehe, i never played such games... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 9 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100