|
|
|
Hi,
I have a Panasonic TDA100D PBX for our phone exchnage. It has Serial and USA connection. I have already tried the Serial and I am ble to get the calls records as it will automatically throw it to the hyper terminal once I connect. Now I want to know how can I do the same when I am connected to the PBX using USB?
Thanks,
Jassim
|
|
|
|
|
Generally in these situations the USB acts as another serial port - just tell Hyperterminal (or your code) to use that COM port.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi all. I have a Panel control that I have created like a sheet of paper that contains different child controls. There are pictureboxes, labels, and TableLayoutPanel controls. I want to print all objects on the Panel control. What I was trying to do was creating a Graphics object from the Panel control which is the Sheet:
Graphics sheetGraphics = Sheet.CreateGraphics();
The object 'Sheet' used to create the Graphics is actually the Panel control that contains child controls. I tried to create an image from the Graphics object:
Bitmap sheetBitmap = new Bitmap(Sheet.Width, Sheet.Height, sheetGraphics);
Having thought I had an image I tried to print by using a printer graphics object but none of the child controls appeared in the image, only the panel. But I'm guessing it did not work because I used a Graphics object from the Panel control to create the image. Is there a way I can create the image to include the data in the child controls as well as the Panel control, or maybe a better way of achieving the creation of the image? I would really appreciate to know if there is. Thanks in advance.
|
|
|
|
|
Try:
Bitmap bm = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(bm, new Rectangle(0,0, bm.Width, bm.Height));
bm.Save(@"D:\Temp\pan.jpg", ImageFormat.Jpeg);
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Works Griff, thanks. But another problem. The printout of the document looks like a compressed image that has been printed, some kind of blurr image. The preview also shows the same. Anyway of maintaining the look of the document without being compressed?
|
|
|
|
|
I am not sure but this[^] may help.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Still not looking good like the one on the Panel control. Can't understand why this is happening.
|
|
|
|
|
Dan_K wrote: Can't understand why this is happening.
That is simple; you are basically capturing a screen image at the screen's resolution (by default, a Bitmap object has the resolution of the screen, typically some 96 or 120 dpi), whereas most printers do print at 300 dpi, so they would upscale your bitmap by a linear factor of around 3 to get the size right, resulting in a pixelated outcome.
I haven't done this myself (explicitly printing controls inside controls that is), however I would try using a larger bitmap, setting its resolution to the printer resolution, then painting the panel into it.
|
|
|
|
|
Yeah I believe so. I thought of it earlier and as a try, I changed the resolution of the image to 300. After printing, I realised the print output had become very small so I stopped using that approach. But if the cause has got something to do with the resolution, then It means that I have to make some calculations that will give the size of the print output the same as the size of the Panel control when I change the resolution. I will try that and see. Thanks.
|
|
|
|
|
Yep, you need to upscale the bitmap size by printerDPI/screenDPI . Both are available in their respective Graphics objects; the screen DPI is also available in other classes (SystemInformation, Screen, not sure). And they come as pairs (dpiX,dpiY), I have never seen those numbers not being equal though.
|
|
|
|
|
Luc, changing the resolution keeps changing the size of the print output but it's still not looking good, just the same. Don't know if I got it wrong. This is what I did:
bmp.SetResolution(ppea.Graphics.DpiX, ppea.Graphics.DpiX);
bmp is the Bitmap object, and ppea is the PrintPageEventArgs object which has the printer settings. You've already said you have not used them before, but do you know any link to tutorials or resources that can help? I don't know what to do again.
|
|
|
|
|
I hope you did increase the bitmap size by the DPI ration, and then applied SetResolution before executing Griff's panel1.DrawToBitmap(...) . I expect it to work properly, but then printing is a complex topic.
Warning: when you get it to work, it will show what the screen shows, even when the printer page is larger. There are ways to print all the content of panning Controls (ListBox, RichTextBox, DataGridView, ...) , that involves a fair amount of P/Invoke and Windows magic.
FWIW: when I want full control of the printed output, I simply avoid all WinForms Controls, and construct my own page control using Graphics.DrawXyz into a PrintDocument. My Sokoban article holds an example.
|
|
|
|
|
As Luc says - it is printing at screen resolution. Personally, I find it pretty useless - it is normally easier to get decent quality by setting up a PrintDocument[^] object and printing the data properly yourself. It may take a little longer to start with, but it is quicker, prettier and more flexible in the long run!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thanks Griff! Is it possible to avoid creating the image from the Panel control and setting up the PrintDocument to get the same output?
|
|
|
|
|
Yes - just loop through the panel Controls in the PrintDocument.PrintPage Event[^] and position them relative to the panel size / page size. If you just draw the Text (using the Graphics.DrawString method) then you will be able to see where they are.
I find it is handy to have a PDF printer driver installed for print debugging - it is a lot quieter, cheaper and quicker than a real printer, particularly in the early stages!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Greeting Gurus,
I have been going around in circles trying to get a value from HKLM\Security\Policy\PolEdtEv and would like to ask for your help please. The key has a "Default" name and a REG_NONE type.
The Goal:
Retrieve the value (I'm pretty sure it's hex) which has a default of
00 fa 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00
If the above value is retrieved, change it to
01 fa 07 00 03 00 00 00 03 00 00 00 03 00 00 00 03 00 00 00 03 00 00 00 03 00 00 00 03 00 00 00 03 00 00 00 03 00 00 00 09 00 00 00
This effectively enables Success & Failure audits under Local Policies\Audit Policy
The Problem:
According to MSoft…"GetValue does not support reading values of type REG_NONE or REG_LINK. In both cases, the default value (Nothing) is returned instead of the actual value."
this means you can't use:
RegistryKey RegKey = Registry.LocalMachine;
RegKeyIN = RegKey.OpenSubKey("SECURITY\\Policy\\PolEdtEv");
Object Value = RegKey.GetValue("SOMEVALUE");
…so you need to use P/Invoke, and that’s where I’m stuck
The Solution:
I understand you need to use
[DllImport("advapi32.dll", EntryPoint = "RegOpenKeyEx")]
public static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey, int ulOptions, int samDesired, out string phkResult); to open the key and then
[DllImport("advapi32.dll",EntryPoint = "RegQueryValueEx")]
public static extern int RegQueryValueEx(UIntPtr hKey,string lpValueName,int lpReserved,out uint lpType,StringBuilder lpData,ref int lpcbData); to get the value.
Despite my best efforts and dozens of hours going through many forum examples I just can't get my code to work. I know the following code is a mess but having been over and over and over so many suggested methods and examples I am now at a complete loss. My code (please don't laugh)...
using Microsoft.Win32;
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
public static readonly UIntPtr HKEY_LOCAL_MACHINE = new UIntPtr(0x80000002u);
public const string lpSubKey = "SECURITY\\Policy\\PolEdtEv";
public const int KEY_READ = 0x20019;
[DllImport("advapi32.dll", EntryPoint = "RegOpenKeyEx")]
public static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey, int ulOptions, int samDesired, out string phkResult);
[DllImport("advapi32.dll",EntryPoint = "RegQueryValueEx")]
public static extern int RegQueryValueEx(UIntPtr hKey,string lpValueName,int lpReserved,out uint lpType,StringBuilder lpData,ref int lpcbData);
private static int ReadRegKey(UIntPtr HKEY_LOCAL_MACHINE, string lpSubKey, string valueName)
{
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_READ, out valueName ) == 0)
{
Console.WriteLine(valueName);
int size = 1024;
uint type;
string keyValue = null;
StringBuilder keyBuffer = new StringBuilder();
if (RegQueryValueEx(HKEY_LOCAL_MACHINE, valueName, 0, out type, keyBuffer, ref size) == 0)
keyValue = keyBuffer.ToString();
Console.WriteLine(keyValue);
return (keyValue);
}
}
}
}
The above returns "not all code paths return a value" which is the fewest errors I have got so far.
Could you help please?
|
|
|
|
|
CCodeNewbie wrote: not all code paths return a value
You need to add a return statement after the if block, for the situation where the call to RegOpenKeyEx() does not succeed.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
In RegQueryValueEx[^] lpData should be A pointer to a buffer that receives the value's data. They do mean a sufficiently large buffer, not a zero-length one, so you need to give your StringBuilder some Capacity .
|
|
|
|
|
@Luc - is this what you mean
StringBuilder keyBuffer = new StringBuilder(100);
@Richard - ok did this (following an example on pinvoke.net)
{
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_READ, out valueName ) == 0)
{
Console.WriteLine(valueName);
int size = 1024;
uint type;
string keyValue = null;
StringBuilder keyBuffer = new StringBuilder(100);
if (RegQueryValueEx(HKEY_LOCAL_MACHINE, valueName, 0, out type, keyBuffer, ref size) == 0)
keyValue = keyBuffer.ToString();
Console.WriteLine(keyValue);
return (keyValue);
}
return (null);
}
now I get "cannot convert string to int" on "return(keyValue);" &
"cannot convert null to int because it is a value type" on "return(null)";
|
|
|
|
|
Your function definition is:
private static int ReadRegKey(UIntPtr HKEY_LOCAL_MACHINE, string lpSubKey, string valueName)
You cannot return a string when you have defined the return value as int .
You are also declaring a StringBuilder of 100 characters and then telling RegQueryValueEx() that it is 1024 long. However, this will still (probably) not work as I don't think you can write directly into a StringBuilder object. You should allocate a BYTE array sufficiently large to get the key value; since your value is not a string in the first place it seems rather pointless to use string types. I suggest reviewing the MSDN documentation for the RegGetValue()[^] function, to see how to find the length of the value data before extracting it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Richard MacCutchan wrote: I don't think you can write directly into a StringBuilder object
Yes you can. When the native world needs to read a string, pass a string; when it needs to write a string, pass a capacitized StringBuilder (together with its Capacity when a length parameter is also required), and upon return apply ToString() to it.
More info could be found here[^]/
|
|
|
|
|
Thanks for the information.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Sorry Richard I don't understand what you mean. The documentation refers to using 0x00000001 for REG_NONE but where do I use that?
I have changed the code to "int keyValue = 0;" is this right? I have also changed "StringBuilder keyBuffer = new StringBuilder(1024);"
Please forgive me if I am being dense but I am in way over my head here and trying hard to understand.
|
|
|
|
|