|
Oh whow, you are my hero - it works!! Yipppieeeehh!!! You made my day, no, my month;) How for heavens sake did find that out???
Thanks and bye
Matze
|
|
|
|
|
|
Option 2:
- Change the
NONCLIENTMETRICS to a struct (NB: You'll have to remove the constructor.) - Change the declaration to:
[DllImport("User32.dll")]
public static extern bool SystemParametersInfo(int Action,
int uiParam, ref NONCLIENTMETRICS pvParam, int WinIni); - Change the call to:
NONCLIENTMETRICS ncm = new NONCLIENTMETRICS();
ncm.cbSize = Marshal.SizeOf(ncm);
bool b = SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
ncm.cbSize, ref ncm, 0);
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi Richard,
this was my very first try, before I changed NCM to a class (and before I read any documentation;)). The call succeeds, too, but NCM remains at its initial state...
Referring to leppie I would prefer this method, too, since it's much more NET like. Does this call succeed on your machine?
Thanks and bye
Matze
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) Here's the code I used, and the output on my XP Pro machine:
using System;
using System.Runtime.InteropServices;
class App
{
[StructLayout(LayoutKind.Sequential)]
public struct LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision;
public byte lfQuality;
public byte lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
public string lfFaceName;
}
[StructLayout(LayoutKind.Sequential)]
public struct NONCLIENTMETRICS
{
public int cbSize;
public int iBorderWidth;
public int iScrollWidth;
public int iScrollHeight;
public int iCaptionWidth;
public int iCaptionHeight;
public LOGFONT lfntCaptionFont;
public int iSMCaptionWidth;
public int iSMCaptionHeight;
public LOGFONT lfntSMCaptionFont;
public int iMenuWidth;
public int iMenuHeight;
public LOGFONT lfntMenuFont;
public LOGFONT lfntStatusFont;
public LOGFONT lfntMessageFont;
}
[DllImport("User32.dll")]
public static extern bool SystemParametersInfo(
int Action, int uiParam,
ref NONCLIENTMETRICS pvParam, int WinIni);
static void Main()
{
const int SPI_GETNONCLIENTMETRICS = 41;
try
{
NONCLIENTMETRICS ncm = new NONCLIENTMETRICS();
ncm.cbSize = Marshal.SizeOf(ncm);
bool b = SystemParametersInfo(
SPI_GETNONCLIENTMETRICS,
ncm.cbSize, ref ncm, 0);
if (b)
{
Console.WriteLine("Border Width: {0}",
ncm.iBorderWidth);
Console.WriteLine("Scroll Width: {0}",
ncm.iScrollWidth);
Console.WriteLine("Caption Font: {0}",
ncm.lfntCaptionFont.lfFaceName);
}
else
Console.WriteLine("Failed");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
} Output:
Border Width: 1
Scroll Width: 17
Caption Font: Trebuchet MS
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hi Richard,
sorry for answering much too late, had the dog tapdancing on my desk...
I tried your code on my two XP machines, and the strange thing is:
- it did not work on the machine with XP freshly installed
- it worked on the machine I have upgraded from W2K
?!?!? Looks like MS alive;)
If I have the time to explore this and find the reason I'll let you know waht happens here; in the meantime I use Stephane's hint, this works on both machines.
Thanks a lot again for your effort, have a nice christmas!
Bye
Matze
|
|
|
|
|
|
I have one too! MYrc on SF
I suggest you use the excellenct Thresher lib for the protocol implementation!
Hope this helps
PS: This have been done too many times.
Shock The Dark Mage wrote:
The VS.NET Debugger raise an exception saying that I can't modify an control(Crownwood.Magic.Controls.TabControl) created in another thread.
Had similar problem. You need to invoke the method that creates new tabs instead of calling it directly!
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET low popularity, please visit ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Can't help you directly - but since you are using the dotnet magic library you could always ask the author - He is a nice man I've worked with him and in the end if he says no then you will be no worse off
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Shock The Dark Mage wrote:
The VS.NET Debugger raise an exception saying that I can't modify an control(Crownwood.Magic.Controls.TabControl) created in another thread.
I had this problem in my app but I figured out how to fix it.
If you want to modify a control or add a control to a form in other thread the exception will be thrown.
My solution is to use the SendMessage function to move the execution process from one thread to the other. Use DllImport to be able to call it in your code.
SendMessage( hHandle, WM_USER + 1, 0, 0 );
hHandle is the window's handle you want to send a message to
WM_USER + 1 is the message that the main form will receive.
In the main thread you must have a form ( whose handle you passed to SendMessage ). Override the WndProc method
public virtual void WndProc( Message* m )
{
if ( m->Msg == WM_USER + 1 )
{
}
}
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
|
Thanks for yours solutions but none worked.
Here the function(in MainForm) that add a new tabpage in TabControl
<br />
public void AddTabPage(string name, TabType type)<br />
{<br />
Crownwood.Magic.Controls.TabPage addedtab = new Crownwood.Magic.Controls.TabPage(name);<br />
switch(type)<br />
{<br />
case TabType.Status:<br />
TemplateStatusWindow status = new TemplateStatusWindow(this.m_connection);<br />
addedtab.Control = status;<br />
break;<br />
case TabType.Channel:<br />
TemplateChannelForm channel = new TemplateChannelForm(name, this.m_connection);<br />
addedtab.Control = channel;<br />
break;<br />
}<br />
addedtab.Tag = type;<br />
addedtab.Name = "tab"+name;<br />
int index = 0;<br />
if(this.TabChannels.TabPages.Count == 0)<br />
{<br />
this.TabChannels.TabPages.Add(addedtab);<br />
}<br />
else<br />
{<br />
System.Windows.Forms.MessageBox.Show(System.Threading.Thread.CurrentThread.Name.ToString());<br />
index = this.TabChannels.TabPages.Count;<br />
this.TabChannels.TabPages.Insert(index, addedtab);<br />
}<br />
<br />
}<br />
Here is the function called from IRCParser in IRCConnection
<br />
public void CreateChannelTabPage(string name)<br />
{<br />
m_parent.AddTabPage(name, TabType.Channel);<br />
}<br />
And finnaly, the function that invoke all the chain in the Thread ReceiveThread
<br />
private void cmd331(string[] args)<br />
{<br />
if(args[2].IndexOf("#")>-1 || args[2].IndexOf("&")>-1)<br />
{<br />
string msg = JoinString(args, 3, args.Length);<br />
msg = msg.Replace(":", "");<br />
#if Terminal<br />
connection.Received("*** No topic set in "+args[2]+crlf);<br />
#elif MainForm<br />
connection.ReceiveTo("Status", "*** No topic set in "+args[2]+crlf, Color.Red);<br />
#endif<br />
}<br />
else<br />
{<br />
#if Terminal<br />
connection.Received("*** You have joined "+args[3]+crlf);<br />
#elif MainForm<br />
connection.CreateChannelTabPage(args[3]);<br />
#endif<br />
}<br />
}<br />
Hope this will you help you to help me ^_^
Trully, if there evil in this world, It lies within the heard of mankind
Shock The Dark Mage
shock@romhack.net
Main Project: Aeru IRC - http://www.sf.net/projects/aeruirc
|
|
|
|
|
Shock The Dark Mage wrote:
public void CreateChannelTabPage(string name)
{
m_parent.AddTabPage(name, TabType.Channel);
}
change this to:
public void CreateChannelTabPage(string name)
{
if (m_parent.InvokeRequired)
{
m_parent.Invoke(m_parent.AddTabPage, name, TabType.Channel);
}
else m_parent.AddTabPage(name, TabType.Channel);
}
Now as you can see, you will invoke the method if needed else it will be called directly.
Cheers
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET popularity better now, thank you ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Thanks leppie. Now it's work. Your code need another thing. You need to declare a delegate because Invoke method require a delegate.
In MainForm:
public delegate void AddingChannelTab();
New create CreateChannelTabPage function.
<br />
public void CreateChannelTabPage(string name)<br />
{<br />
if (m_parent.InvokeRequired) <br />
{ <br />
try<br />
{<br />
m_parent.ChannelToAdd = name;<br />
AeruIRC.MainForm.AddingChannelTab addingchannel = new AeruIRC.MainForm.AddingChannelTab(m_parent.AddTabPage2);<br />
m_parent.Invoke(addingchannel); <br />
}<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
} <br />
else <br />
m_parent.AddTabPage(name, TabType.Channel);<br />
}<br />
The only problem is invoking the delegate with parameters. But now, I call a function without parameters. But it's work
Trully, if there evil in this world, It lies within the heard of mankind
Shock The Dark Mage
shock@romhack.net
Main Project: Aeru IRC - http://www.sf.net/projects/aeruirc
|
|
|
|
|
Shock The Dark Mage wrote:
Thanks leppie. Now it's work. Your code need another thing. You need to declare a delegate because Invoke method require a delegate.
A delegate purely a pointer to a method.
Shock The Dark Mage wrote:
AeruIRC.MainForm.AddingChannelTab addingchannel = new AeruIRC.MainForm.AddingChannelTab(m_parent.AddTabPage2);
That is not correct! You will be creatign a new form every time! You should be doing a cast instead.
Cheers
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET
|
|
|
|
|
leppie wrote:
WHy WHy Why? Why are you doing it this way when all you need to do is invoke it!
Because I haven't known this method. It requires less coding and it's more legible.
Note that if you check the call stack you'll see that the Framework does the same work I described. So my method is not suitable here but it explains how the Invoke function works.
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
|
I want my menu item to be highlighted when the mouse cursor moves over it (just like in visual studio.NET's IDE). I believe this can be done by putting all the drawing code in the DrawItem() function. Then depending on which state the MenuItem is in, I draw the appropriate graphics.
I think the DrawItemState.Hotlight state is the one that deals with mouse hovers. But when I tried checking to see if my MenuItem state is Hotlight, it always returns false. The code inside that IF statement never gets executed I dont know why. Can someone please help me? Thanks, and here's the code:
private void menuItem1_DrawItem(object sender, DrawItemEventArgs e)
{
int x = e.Bounds.X, y = e.Bounds.Y, h = e.Bounds.Height, w = e.Bounds.Width;
if (e.State == DrawItemState.HotLight)
{
e.Graphics.FillRectangle(Brushes.Orange, x, y, w, h);
e.Graphics.DrawRectangle(Pens.Black, x, y, w, h);
}
e.Graphics.DrawString("Description", Font, Brushes.Black, x, y);
}
|
|
|
|
|
Why I'm getting this error for main.resx and about.resx:
Resource transformation for file 'main.resx' failed. Invalid ResX input.
Below is the about.cs code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Change_Management_System
{
///
/// Summary description for frmRequest.
///
public class frmAbout : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnClose;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public frmAbout()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmAbout));
this.btnClose = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(328, 264);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 0;
this.btnClose.Text = "OK";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// frmAbout
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(426, 304);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnClose});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmAbout";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "About..";
this.ResumeLayout(false);
}
#endregion
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
Jassim Rahma
|
|
|
|
|
Well, a ResX error seems that compiling the resx into a resources file fails. From your code I assume that you have only one item in the resx file, the icon for your dialog.
From time to time I encounter icons which do not follow the ico format. So may be this is here the case? If yes then trying another icon would help.
Hmm, did you already try the Resource"Editor" available in the samples of .Net? At least in debugging mode it will give you more hints.
Hope this helps in any way.
Bye
Matze
|
|
|
|
|
I need to create a customized form just like the one
available in Microsoft Access to allow the user to design
his own form style from a fix list of fields with only
textBoxes, date pickers and comboBoxes?
How can I do that? any one tried it?
Many Thanks,
Jassim Rahma
Jassim Rahma
|
|
|
|
|
How can I display the default Microsoft Windows about box
[attached] within my application?
Many Thanks,
Jassim Rahma
Jassim Rahma
|
|
|
|
|
how can I check if and mdb password is password protected
or not? I need to write a code to check if the the mdb
file was not password, then setup a password for it.
Jassim Rahma
|
|
|
|
|
Can any one explain how can create a DLL library [in a
design time] which will contains audio or video file, then
write a code to read and play that file [in run-time] on a
windows form?
Please note that I don't want to extract the file from the
DLL library every time user wants to play it to avoid
having a copy of the original audio/video file on the
local machine if the application was aborted.
Thanks in advance......
Jassim Rahma
|
|
|
|
|
I really think you should slowdown a bit and try focusing on one particular problem at a time
jrahma wrote:
Can any one explain how can create a DLL library [in a
design time] which will contains audio or video file
I know of no way, unless add it as a resource maybe...but you will still have to read it to memory and play it from there. Sounds dangerous!
DBHelper - SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET low popularity, please visit ![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|