|
It did not remove the topmost flag as the application is still set to topmost. I would like it to go from a topmost application back to a standard z ordered application as it is before the topmost flag is set.
I was testing it with a test button for simplification is all, as soon as I get a working example I will then incorporate it into an else block
|
|
|
|
|
The problem is that your X, Y, cx and cy values are all zero, and when you switch to NoTopMost, you have omitted the flags to keep the size and position. Edit your code and replace the definition of NOTOPMOST_FLAGS with the following.
private const UInt32 NOTOPMOST_FLAGS = TOPMOST_FLAGS | SWP_SHOWWINDOW;
Had you explained exactly what happened when you ran your code we could have helped earlier.
|
|
|
|
|
Thank you.
Strangely enough when I have the above code in a separate button it removes the topmost flag correctly, but when I have it at the end of the send.keys function it does not remove the topmost flag? Any ideas on what could be causing that?
modified 5-Jan-18 22:58pm.
|
|
|
|
|
turbosupramk3 wrote: what could be causing that? Not without seeing the actual code.
|
|
|
|
|
Sure thing, the first block is my Pininvoke code, then the standard function and then the test button.
The standard function code will put the form to topmost, but will not remove the topmost flag. The test button will remove the topmost flag after the standard function places the topmost flag.
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
private static readonly IntPtr HWND_TOP = new IntPtr(0);
private const UInt32 SWP_NOSIZE = 0x0001;
private const UInt32 SWP_NOMOVE = 0x0002;
private const UInt32 SWP_NOZORDER = 0x0004;
private const UInt32 SWP_NOREDRAW = 0x0008;
private const UInt32 SWP_NOACTIVATE = 0x0010;
private const UInt32 SWP_DRAWFRAME = 0x0020;
private const UInt32 SWP_FRAMECHANGED = 0x0020;
private const UInt32 SWP_SHOWWINDOW = 0x0040;
private const UInt32 SWP_HIDEWINDOW = 0x0080;
private const UInt32 SWP_NOCOPYBITS = 0x0100;
private const UInt32 SWP_NOOWNERZORDER = 0x0200;
private const UInt32 SWP_NOREPOSITION = 0x0200;
private const UInt32 SWP_NOSENDCHANGING = 0x0400;
private const UInt32 SWP_DEFERERASE = 0x2000;
private const UInt32 SWP_ASYNCWINDOWPOS = 0x4000;
private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
private const UInt32 NOTOPMOST_FLAGS = TOPMOST_FLAGS | SWP_SHOWWINDOW;
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
private void btnType_Click(object sender, EventArgs e)
{
try
{
if (tbxTagList.Text == "")
{
MessageBox.Show("Please enter in at least 1 tag");
return;
}
int x = Convert.ToInt32(tbxXCoordinates.Text);
int y = Convert.ToInt32(tbxYCoordinates.Text);
SimulateMouseClick(x, y);
foreach (char character in tbxTagList.Text)
{
if ((character != '\n') && (character != '\r'))
{
SendKeys.Send(character.ToString());
}
if (character == '\n')
{
SendKeys.Send("{Enter}");
Thread.Sleep(3);
}
Thread.Sleep(3);
}
tbxXCoordinates.Text = "";
tbxYCoordinates.Text = "";
SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, NOTOPMOST_FLAGS);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " | " + ex.Source + " | " + ex.InnerException + " | " + ex.StackTrace);
}
}
private void btnTest_Click(object sender, EventArgs e)
{
SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, NOTOPMOST_FLAGS);
}
|
|
|
|
|
I cannot see anything wrong with that code, and the documentation does not give any further ideas.
|
|
|
|
|
Ok, thank you for trying!
|
|
|
|
|
I don't know why, but the addition of the thread sleep as pictured below fixed it?
tbxXCoordinates.Text = "";
tbxYCoordinates.Text = "";
Thread.Sleep(250);
SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, NOTOPMOST_FLAGS);
|
|
|
|
|
|
hello. is it possible to use the design pattern of MVC in my desktop application created with in WPF ?if possible give an exemple ?
|
|
|
|
|
Sure, but not exactly like you see in an ASP.NET MVC app.
The version used in WPF is far more powerful and flexible. The pattern is called "Model View ViewModel[^]".
System.ItDidntWorkException: Something didn't work as expected.
-- said no compiler, ever.
C# - How to debug code[ ^].
Seriously, go read this article.
Dave Kreskowiak
|
|
|
|
|
that is to say with WPF instead search MVC we replace that with MVVM?
|
|
|
|
|
Yes
System.ItDidntWorkException: Something didn't work as expected.
-- said no compiler, ever.
C# - How to debug code[ ^].
Seriously, go read this article.
Dave Kreskowiak
|
|
|
|
|
hi all
I have created in windows application and also one windows service using c#. this windows application has the database connection and do some functions etc which i want to daily repeat. so i have created the windows service. when i debug windows service in debug mode everything works fine. but after installation of windows service it is created the processes of that windows application. but that windows application is not initiating..
My Service code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.IO;
using System.Xml;
namespace OTMService
{
public partial class OTMService : ServiceBase
{
private Timer timer1 = null;
string tt1, tt2, tt3, tt4, tt5, tt6, thetime, time, tmp1, tmp0ch, basetmp, tmpAMPM;
int spp = 0, stime = 0;
public OTMService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
timer1 = new Timer();
this.timer1.Interval = 60000;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
timer1.Enabled = true;
Library.WriteErrorLog("Test window service started--Just Khan");
}
private void timer1_Tick(object sender, ElapsedEventArgs e)
{
mymainProg();
}
protected override void OnStop()
{
timer1.Enabled = false;
Library.WriteErrorLog("Test window service stopped--Just Khan-Service got stopped");
}
public void mymainProg()
{
string dirpath = AppDomain.CurrentDomain.BaseDirectory;
try
{
XmlDocument xmlDoc1 = new XmlDocument();
xmlDoc1.Load(dirpath+"OTMAppSetting.xml");
thetime = xmlDoc1.SelectSingleNode("Data/ServTime").InnerText;
tmp1 = thetime.Substring(3, 2);
tmp0ch = thetime.Substring(3, 1);
basetmp = thetime.Substring(0, 3);
tmpAMPM = thetime.Substring(6, 2);
spp = Convert.ToInt32(tmp1);
stime = checktime(spp);
if(tmp0ch=="0")
{
tt1 = basetmp + "0"+ stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt2 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt3 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt4 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt5 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt6 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
}
else
{
tt1 = basetmp + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt2 = basetmp + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt3 = basetmp + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt4 = basetmp + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt5 = basetmp + stime.ToString() + " " + tmpAMPM;
stime = stime + 1;
tt6 = basetmp + stime.ToString() + " " + tmpAMPM;
}
}
catch (Exception g)
{
Library.WriteErrorLog("Xml loading error for time: Error" + g.ToString());
}
DateTime dt = DateTime.Now;
time = dt.ToString("hh:mm tt");
if (time == tt1 || time == tt2 ||
time == tt3 || time == tt4 ||
time == tt5 || time == tt6)
{
try
{
Library.WriteErrorLog("Inside time and under try and catch Before Using");
foreach (var process in Process.GetProcessesByName("OTMBackendServiceExe"))
{
process.Kill();
}
using (Process pp = Process.Start(dirpath + "OTM_Plan_BackExe\\OTMBackendServiceExe.exe"))
{
int id = pp.Id;
Process tempProc = Process.GetProcessById(id);
Library.WriteErrorLog("Process completed all");
}
}
catch (Exception ex)
{
Library.WriteErrorLog("Main Exe cannot be started: " + ex.ToString());
}
}
}
private int checktime(int ss)
{
int theret = 0;
switch (ss)
{
case 54:
theret = ss - 2;
break;
case 55:
theret = ss - 3;
break;
case 56:
theret = ss - 4;
break;
case 57:
theret = ss - 5;
break;
case 58:
theret = ss - 6;
break;
case 59:
theret = ss - 6;
break;
default:
theret = ss;
break;
}
return theret;
}
}
}
and the windows application starting code:
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;
using System.Configuration;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using Oracle.DataAccess.Client;
using Excel = Microsoft.Office.Interop.Excel;
using System.Net.Mail;
namespace OTMBackendServiceExe
{
public partial class Form1 : Form
{
string oraCstr, qrystr, qrystr1, OraCon, malstatus;
bool chk1 = false, chk2 = false;
int lcount = 0, chkkedd=0;
string empname, email_id, sup_email, cc_maillst, fcc_maillst, skilltype, product, skilltrack, current_level, target_level, tomail_sub;
string mailfor, otmmailbody, mail_sent_date, mail_sent_status, mailerr_msg;
string repformpath, repoutputpath, repfilename;
StringBuilder mlmsg = new StringBuilder();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
WriteToFile("Testing: App Started");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("OTMAppSetting.xml");
oraCstr = "";
oraCstr = xmlDoc.SelectSingleNode("Data/DBstr").InnerText;
frommail = xmlDoc.SelectSingleNode("Data/frommmail").InnerText;
cc_maillst = xmlDoc.SelectSingleNode("Data/ccmaillst").InnerText;
WriteToFile("Started @:"+DateTime.Now.ToString());
nightqry();
allresettings();
skillupgrademail();
WriteToFile("Ended @:" + DateTime.Now.ToString());
Application.Exit();
}
in task manager it shows the process of that backend exe.
Need help. this backend exe is not getting executed when i run through service. if i run directly without any problem it runs.
Khan
|
|
|
|
|
Services can't start UI EXE apps directly: they are running on Session 0 and cannot create or display a UI at all.
I haven't tried it myself, but this may help: Subverting Vista UAC in Both 32 and 64 bit Architectures[^] - will it work in Win10? Dunno ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Then do i have to create the console application instead of windows application to launch through service.
Khan
|
|
|
|
|
No. A Console app is also a UI app - not a GUI, but a UI. Services cannot interact with the desktop, or initiate any interaction - because they can be running before a user has logged in, so there is no user to interact with!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
the app which is running at the backend through service doesn't have any user interaction. It just connect to database and run some procedures, get some rows from database and send mails to the participants.
Please suggest how to do that.
Khan
|
|
|
|
|
Make it a service as well...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You mean instead of creating another external exe whole code has to be written in service itself.
what i understood correct?
Khan
|
|
|
|
|
I have written all code of backend.exe file into service and it is working fine now. thanks a lot
Khan
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The comments about the UI in the other sub-thread, as far as I can tell, have no relevance to the code posted.
Presumably your log messages are showing up. Your code appears to be correctly handling potential exceptions HOWEVER you should log the stack trace also.
Finally, as to your problem...
Far as I can tell you do not seem to be actually starting the timer.
If true then what will happen is that your OnStart method will exit, which means no threads will be running in the service. Windows knows that threads are running and will not mark it as running unless one thread is running.
|
|
|
|
|
Any idea how to include thread in this service and backend.exe application
Khan
|
|
|
|
|
There are several ways. Your code is already mostly there except you are not starting the timer.
|
|
|
|
|