|
Option Explicit
Public Const GW_HWNDNEXT = 2Private Const WM_CLOSE As Long = &H10
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hwnd As Long, lpdwprocessid As Long) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
' Return PID
ProcIDFromWnd = idProc
End Function
Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long
' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)
' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If
' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
Sub Test()
Dim hInst As Long ' Instance handle from Shell function.
Dim hWndApp As Long ' Window handle from GetWinHandle.
' Shell to an app
hInst = Shell("winword.exe")
' Begin search for handle
hWndApp = GetWinHandle(hInst)
If hWndApp <> 0 Then
'Sleep for two seconds, then close it
Sleep 2000
Call PostMessage(hWndApp, WM_CLOSE, 0&, 0& )
End If
End Sub
Live Life King Size
Alomgir Miah
|
|
|
|
|
Hi,
I am trying to insert table in the DataSet in compact frame work.
praveen.N
|
|
|
|
|
This is a C# 2005 Problem:
I have an MDIForm and 5 child forms in my project. what i have to do is, during MDI Form's "MdiChildActivate" event I have to set some value to private a variable in my active child form. But when i write a statement like this : this.ActiveMdiChild.childVariableMode="0";
I get an error-"No defination For childVariableMode found in activemdichild". In vb.net i can do this by:
dim a as object
a=me.ActiveMdiChild
a.childVariableMode="0"
But i C# if i do same as VB.NET i get the same error, please solve my problem.I am in very hurry, my whole project is depended on this.
Thanks in Advance.
Sheel
Sheel Gohe
|
|
|
|
|
I am using MySqlConnector for .NET (version 1.0.4), I am using the following code for dataAdapter's update command:
this.codeListAdapter = new MySqlDataAdapter(
"SELECT * FROM CodeList", this.myConnection);
MySqlCommand codeListUpdateCmd = new MySqlCommand(
"UPDATE CodeList SET ProviderID=?ProviderID WHERE DestCode='?DestCode'", myConnection);
codeListUpdateCmd.Parameters.Add("?DestCode", MySqlDbType.VarChar, 10, "DestCode");
codeListUpdateCmd.Parameters.Add("?ProviderID", MySqlDbType.Int16,
0, "ProviderID");
codeListAdapter.UpdateCommand = codeListUpdateCmd;
codeList = new DataTable("CodeList");
this.codeListAdapter.Fill(codeList);
and then I am using the following code, (after changing some rows of 'codeList' ofcourse):
codeListAdapter.Update(codeList);
codeList.AcceptChanges();
but it throws the Exception mentioned above, what might be the problem?
The structure of the 'CodeList' table is like this:
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| DestCode | varchar(10) | | PRI | | |
| Destination | varchar(50) | YES | | NULL | |
| ProviderID | int(11) | | MUL | 0 | |
+-------------+-------------+------+-----+---------+-------+
Thanks in advance...
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
hi all,
I need to change the Color of Tittle Bar in a Windows Form..How can I do it?
thanks in advance..
|
|
|
|
|
hi all,
I need to Color Tool Bar and need to add Blue water mark for buttons when mouse on the Tool Bar Buttons?.
How do I suceed this?.
thanks in advance.
|
|
|
|
|
Hello everybody!
I want to print a document out with A4 paper size programmatically. But I don't know how to define the precise paper size in C#. And also, if I don't use the form's location, how can I locate a particular position of the paper? Could anybody help me with this please!
Thanks in advance
Asura
|
|
|
|
|
This is what I gathered from MSDN in a few minutes:
Choose one of the page sizes from PrinterSettings.PaperSizes collection and put it in the PageSettings.PaperSize property.
---
b { font-weight: normal; }
|
|
|
|
|
Ming Luo wrote:
I want to print a document out with A4 paper size programmatically.
The prefered method is to allow the user to select the paper size since their needs may change after the application is released. To do this, implement a PageSetupDialog. If A4 is the default paper size for the printer, it will already be set in the dialog. If it is not the default size, I believe you could create a PaperSize object, set it to a PaperKind of A4 in PageSettings before printing (or showing the PageSetupDialog). Check the MSDN documentation on PageSettings[^] and PaperKind Enumeration[^].
To implement PageSetupDialog, you can use this code snip from the MSDN article[^] on PageSetupDialog Class in a print button handler. (Note this code assumes a ListBox named ListBox1 that will display the settings (used to indicate how to get the values after the user clicks OK in the dialog) and a PageSetupDialog named PageSetupDialog1.
PageSetupDialog1.PageSettings = <br />
new System.Drawing.Printing.PageSettings();<br />
<br />
PageSetupDialog1.PrinterSettings = <br />
new System.Drawing.Printing.PrinterSettings();<br />
<br />
PageSetupDialog1.ShowNetwork = false;<br />
<br />
DialogResult result = PageSetupDialog1.ShowDialog();<br />
<br />
if ( result == DialogResult.OK)<br />
{<br />
object[] results = new object[]{ <br />
PageSetupDialog1.PageSettings.Margins, <br />
PageSetupDialog1.PageSettings.PaperSize, <br />
PageSetupDialog1.PageSettings.Landscape, <br />
PageSetupDialog1.PrinterSettings.PrinterName, <br />
PageSetupDialog1.PrinterSettings.PrintRange};<br />
ListBox1.Items.AddRange(results);<br />
}
If this doesn't work for you or give you enough clues, post back and let us know.
Marshall
If you continue to do the same things you always did, don't be surprised if you get the same results you always got.
|
|
|
|
|
Thanks for your code. But I think what I need is to define the paper size programmatically before the page dialog. Because there is a form need to be filled. For example, if give me a check, I need to fill in the address and customer name information in it, so I need to define the precise position of the address row and customer row in the check, then I put the check into the printer, it will print it. Just like the teller does. Actually it's not a check, what I am doing is a invoice which is A4 size. So another problem is that how can I define the location of the field I need to fill in my program??? Any idea please ?
Thanks very much
Asura
|
|
|
|
|
Ming Luo wrote:
how can I define the location of the field
There are many options. Try this CP article on DaReport PrintDocument[^] to see one approach at positioning objects (including text) on a printed document such as a check. It is not the most straight-forward approach but it is clever and extensible.
Marshall
If you continue to do the same things you always did, don't be surprised if you get the same results you always got.
|
|
|
|
|
Check Out This Code:
PageSetupDialog psd= new PageSetupDialog();
psd.PageSettings.PaperSize = psd.PrinterSettings.PaperSizes[ 4 ]; // 4 denotes the paper index you pass different index and check the Paper size. On my printer paper sizes A4 exits on 4 index.
Try this then tell me.
Muhammad Waqas Butt
waqasb4all@yahoo.com:
Muhamad Waqas Butt
waqasb4all@yahoo.com
|
|
|
|
|
Hello gurus,
I'd like to know how to detect which child has been activated in an MDI?
The MdiChildActivate does not show me which child window has been activated, or maybe there is a cast to do somewhere in the code handler...
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
Although I must admit that I didn't work with MDI much, I'd expect the sender parameter to be the MdiChild that's being activated.
Did you check this?
Regards,
mav
|
|
|
|
|
you're right, I'm not familiar with MDIs...
I mainly do dialogs :P
Thanks
fred.
There is no spoon.
|
|
|
|
|
I'm writing a function as below:
public string returnString()
{
try
{
//open connections
return var1;
}
catch (Exception ex)
{
//write to trace
}
finally
{
//close connections
}
}
I'm getting an error that says the function will not return a value in some execution.
Where should I return the value? After finally?
|
|
|
|
|
If your try fails, it will jump to the catch block. There is no return statement in the catch block therefore, once the error is handled it does not know what to return out of the method.
You either need an additional return in the catch block or you need to return something after the finally block.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
For example, if I am retrieving data from a DB and returning the dataset. An exception occurs and no data is retrieved.
In this case, should I still return the dataset in the catch block\after finally?
My initial thought was that I wouldn't return anything if an exception occurs.
|
|
|
|
|
|
I see!
Thanks very much Colin!
Regards,
Os
|
|
|
|
|
Hi
Can the backcolor of a specific row in datagrid be set. I want to compare the values in an arraylist against the values in the datagrid and if a match is found I want to change the backcolor of that row so that the user can easily see the matches.
On that point can the backcolor of all the rows in the datagrid be reset to White in one property or do I need to loop through the datagrid and set each row's backcolor to White.
Thanks
Kobus
|
|
|
|
|
public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush
foreBrush, bool alignToRight)
{
// the idea is to conditionally set the foreBrush and/or backbrush
// depending upon some crireria on the cell value
// Here, we color anything that begins with a letter higher than 'F'
try{
object o = this.GetColumnValueAtRow(source, rowNum);
if( o!= null)
{
char c = ((string)o)[0];
if( c > 'F')
{
// could be as simple as
// backBrush = new SolidBrush(Color.Pink);
// or something fancier...
backBrush = new LinearGradientBrush(bounds,
Color.FromArgb(255, 200, 200),
Color.FromArgb(128, 20, 20),
LinearGradientMode.BackwardDiagonal);
foreBrush = new SolidBrush(Color.White);
}
}
}
catch(Exception ex){ /* empty catch */ }
finally{
// make sure the base class gets called to do the drawing with
// the possibly changed brushes
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
}
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
Hello every body
i need ur help.
plz any body sendme the code in c# tha connect the webcam and then extract frames and save it into my local drive,
i realy thankful to that person.
waiting
best regards
abdullah
abd
|
|
|
|
|
search for webcam in the search bar of cp & u,ll find many things
The C Lover ..
|
|
|
|
|
How can I find out witch color in a Gif image that is transparent?
I'm creating small icons of images in an ASP page, and I'm writing the images to the output stream.
First I'm resizing the image, witch data I get from a memory stream (this data is an transparent image, and in this code example I use PNG to try to get transparency):
<br />
public Bitmap _bitmap = null;<br />
private void getGraphicsFromImageNotStretched(MemoryStream ms, int hight, int width)<br />
{ <br />
Image image = Image.FromStream(ms, true); <br />
<br />
double orgHight = (double)image.Height;<br />
double orgWidth = (double)image.Width;<br />
if((orgHight * hight) > (orgWidth * width))<br />
{<br />
double ratio = (orgWidth * width) / (orgHight * hight);<br />
_bitmap = new Bitmap(image, (int)((double)width * ratio), hight);<br />
_bitmap.Palette = image.Palette; <br />
_bitmap.MakeTransparent();<br />
}<br />
else<br />
{<br />
double ratio = (orgHight * hight) / (orgWidth * width);<br />
_bitmap = new Bitmap(image, width, (int)((double)hight * ratio));<br />
_bitmap.Palette = image.Palette;<br />
_bitmap.MakeTransparent();<br />
} <br />
<br />
image.Dispose(); <br />
}<br />
Then I write the data to the output stream:
<br />
public static byte[] GenerateImageBytes(Bitmap theBitmap)<br />
{<br />
byte[] bytes = null; <br />
<br />
System.IO.MemoryStream ms = new System.IO.MemoryStream();<br />
theBitmap.Save(ms, ImageFormat.Png);<br />
bytes = ms.ToArray();<br />
ms.Close(); <br />
<br />
return bytes;<br />
}<br />
This result in an image that is not treansparent
If anyone has a code-snip or an example to get this working, I'll be happy as a dove.
Thanks
Thomas
|
|
|
|
|