|
|
Hi, I'm writing a MediaPlayer so I need to keep the monitor on and screen saver disabled during the life of my application. I understand that I need to handle certain windows messages SC_SCREENSAVE, SC_MONITORPOWER but I'm not sure how. So Please Advice
Thanks...
|
|
|
|
|
|
I got the following suggestion from someone
START
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SYSCOMMAND:
switch (wParam)
{
// disable screen saver and monitor power-saving mode
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
END
I goggled and tried to find various Constants used and replaced them with their values
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
//case WM_SYSCOMMAND: //REPLACED
case 0x0112:
switch (m.WParam.ToInt32())
{
// disable screen saver and monitor power-saving mode
//case SC_SCREENSAVE: //REPLACED
case 0xF140:
//case SC_MONITORPOWER: //REPLACED
case 0xF170:
return;
}
break;
//case WM_DESTROY: //REPLACED
case 0003:
PostQuitMessage(0); // Wont Compile in C#
return;
}
base.DefWndProc(ref m);
//return DefWindowProc(hwnd, message, wParam, lParam);
}
NOw the Function PostQuitMessage(0) wont compile and without my whole Control layout goes wrong
I checked the link you provided but being very new to Windows Programming & C# I dont know how to use all this.
So your thoughts...
Thanks...
|
|
|
|
|
Include the following in your code:
[DllImport("user32.dll")]
public external void PostQuitMessage(int returnVal);
Jeff
|
|
|
|
|
After Updating the code and running my observations are that my MainForm does not show anymore and the app just exits (Runs fine after removing the following bit of code).
[System.Runtime.InteropServices.DllImport("user32.dll")]<br />
public static extern void PostQuitMessage(int returnVal);<br />
<br />
protected override void WndProc(ref Message m)<br />
{<br />
switch (m.Msg)<br />
{<br />
case 0x0112:<br />
<br />
switch (m.WParam.ToInt32())<br />
{<br />
case 0xF140:<br />
case 0xF170:<br />
<br />
return;<br />
}<br />
<br />
break;<br />
<br />
case 0003:<br />
PostQuitMessage(0);<br />
return;<br />
}<br />
<br />
base.DefWndProc(ref m);<br />
}
|
|
|
|
|
Put in some breakpoints and find the path that the code is taking to exit your application. Then post the results here so we can get a better idea of what is going on. Why do you call base.DefWndProc instead of base.WndProc?
Jeff
|
|
|
|
|
Sukhjinder_K wrote: being very new to Windows Programming
Sukhjinder_K wrote: I'm writing a MediaPlayer
very new and writing a MediaPlayer
Sukhjinder_K wrote: So your thoughts...
My thought is, that does not compute.
|
|
|
|
|
I have programmed in Java a lot. So I'm just new to Windows Programming and C# and have never done Windows Message handling (or anything having HWND in it) before. I was looking for a Free Media Player which had what I needed, I couldn't find one. So I decided to build one on my own. And I chose C# to learn a new Language/Platform.
Thanks for your thoughts Mike...
|
|
|
|
|
Did you check it switching to appropriate Case block?
|
|
|
|
|
Thanks Everybody for your help. Here is the Solution
const int WM_SYSCOMMAND = 0x0112, SC_SCREENSAVE = 0xF140, SC_MONITORPOWER = 0xF170;<br />
protected override void WndProc(ref Message m)<br />
{<br />
if( m.Msg == WM_SYSCOMMAND )
{<br />
if( m.WParam.ToInt32() == SC_SCREENSAVE || m.WParam.ToInt32() == SC_MONITORPOWER )<br />
{
return;<br />
}<br />
} <br />
base.WndProc(ref m);<br />
}
|
|
|
|
|
Hi All,
I am writting a C# project in which am using Browser Control. The object of this project to read values of JavaScript's variables values on the current page ,and add those values to ListBox control. Can anybody show me how to do this. Please help if you can I need to do this ASAP for my job.
Thanks,
Asif
|
|
|
|
|
A.Asif wrote: am using Browser Control.
There are many articles on MSDN and I imagine some on CodeProject as well for using the Browser Control in C#, try starting there.
|
|
|
|
|
I did research almost erevry site including microsoft but found no luck to my perticullar problem.
So please help if you can
Thanks,
Asif
|
|
|
|
|
Add a reference to the MSHTML.dll and cast to the DOM types as explained in some document you read (you said you did them all). Then simply use the DOM to get the values.
xacc.ide
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Thanks for your help! I am trying DOM but don't seems to work for me, can you please show me or send me some sytax how to get this values. I'll really apreciate your help.
Thanks
Asif
|
|
|
|
|
Hi Guys. I have a very stupid/simple question for you. I have two forms in my project, one a logon form called from my main form. When the user enters his username on the logon form I want to move the username into a label on my mainform. Can somebody please advise me on how to do this?
Thanks in advance.
|
|
|
|
|
|
I am using backgroundworker thread in my application... i need to track each background worker and need to show the status in a datagrid ...
my application is used for database administrating ...
backups
restore
attaching
so various activities are going in different background workdes and their status need to show on a datagrid ... and each row in the datagrid should updated correctly ....
can someone write a small piece of code ....
thankzzzzzzzz
A123-B321
|
|
|
|
|
Have your background threads fire events for different states. Then your UI thread can listen to those events and respond appropriately.
You can also poll the status of the background threads by keeping track of the object reference, however, the event model is easier.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
You can use ProgressChanged event of the backgroundworker component to report progress
|
|
|
|
|
can you just write a small piece of code to update the activities into a datagridview ....
i mean, if i am click on a button control to run backup activity and it will update into a datagrid row as dbname, backup going on and when i click again on same button control and it need to appear in the grid as second row ... with dbname, backup going on ... .and when the first thread completes, the grid first row need to update with dbname, backupcompleted ... how could i do this ... please write a small piece of code ...
A123-B321
|
|
|
|
|
Hi I am writing an application which retrieves your outlook contacts.
Right now I am able pop up the contacts window of the Outlook, but I want the specific fields to be printed in my checkedlistbox
I used the following code to pop up the contacts window. Now I want to get he name+last name and the fax number to printed in my chckedlistbox. But I cant find the object under OutlookItems to print the whole contacts list. Any Help?
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();
string faxNum;
faxNum = oCt.BusinessFaxNumber.Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");
this.txtRecipientFax.Text = faxNum;
// Display the contact.
//oCt.Display(true);
|
|
|
|
|
s3rro wrote: But I cant find the object under OutlookItems to print the whole contacts list.
They hide that information in the documentation[^]
|
|
|
|
|
I read the document.
I can get the first/last contact. I tried most of them to list the whole Outlook Contacts, list none worked, thats why i asked it here.
Thanks
|
|
|
|