segunda-feira, 22 de novembro de 2010

Determining If A Monitor Is Off

Determining If A Monitor Is Off: "AnswerDetermining If A Monitor Is Off

*
Wednesday, July 18, 2007 5:03 PMstack Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote
I've found code that will turn a monitor on and off:

Code Snippet

#include

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Eliminate user's interaction for 500 ms
Sleep(500);

// Turn off monitor
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);

// Turn on monitor
// SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1);

// Low power monitor
// SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 1);

return 0;
}

Now I am looking for code that will tell me if a monitor is on or off. Anyone have any examples?
o ReplyReply
o QuoteQuote


Answers

*
Thursday, July 19, 2007 8:10 AMBruno van Dooren Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

I don't know. Try asking in the appropriate platform SDK nntp newsgroup

http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx



Even if you can query the monitor state, this won't tell you if the monitor itself is powered on.

At home I still use a 19' iyama crt. Windows doesn't know when I press the monitor power button.

Btw: have you tried google or www.codeproject.com ?
o ReplyReply
o QuoteQuote


All Replies

*
Thursday, July 19, 2007 8:10 AMBruno van Dooren Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

I don't know. Try asking in the appropriate platform SDK nntp newsgroup

http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx



Even if you can query the monitor state, this won't tell you if the monitor itself is powered on.

At home I still use a 19' iyama crt. Windows doesn't know when I press the monitor power button.

Btw: have you tried google or www.codeproject.com ?
o ReplyReply
o QuoteQuote

– Enviado usando a Barra de Ferramentas Google"

How to detect if monitor was on or off with C#

How to detect if monitor was on or off with C#: "AnswerHow to detect if monitor was on or off with C#

*
Monday, June 01, 2009 8:48 AMRiteru Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote
I'm trying to write a software to detect the status of monitor (or perhap HD LCD television screen) in order to create a report about the availability of the output screen.

- I've tried to use WMI (Win32_DesktopMonitor ) to check availability but it alway return 3 which mean On, no matter my computer LCD screen is On or Off;

Anyone have any idea on detecting the monitor status?

PS. The LCD screen i'm using connected to my PC via DVI port, I'm not sure yet which port will be used in the real run (DVI, Serial , etc) so I'm trying to find a solution that can support all this port.
o ReplyReply
o QuoteQuote


Answers

*
Tuesday, June 02, 2009 12:32 PMJagadeesan Kandasamy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

I hope this might be helpful...

Try to use with GetDesktopWindow(), The below code is just to switch on / off the moniter, from this you can try to the status as well.

[DllImport(

'user32.dll')]

static



extern IntPtr SendMessage(IntPtr hWnd, uint Msg,



IntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll', SetLastError = true)]

static



extern bool PostMessage(IntPtr hWnd, uint Msg,



IntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll')]

static



extern bool PostThreadMessage(uint idThread, uint Msg,



UIntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll', SetLastError=true, CharSet=CharSet.Auto)]

static



extern bool SendMessageCallback(IntPtr hWnd, uint Msg,



UIntPtr wParam, IntPtr lParam,

SendMessageDelegate lpCallBack,

UIntPtr dwData);

//Or

[DllImport(

'user32.dll', SetLastError=true, CharSet=CharSet.Auto)]

static



extern bool SendNotifyMessage(IntPtr hWnd, uint Msg,



UIntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll')]

private



static extern IntPtr GetDesktopWindow();

//Or

[DllImport(

'user32.dll', SetLastError = true)]

static



extern IntPtr FindWindow(string lpClassName, string lpWindowName);

//Or

[DllImport(

'user32.dll', SetLastError = true)]

static



extern IntPtr FindWindowEx(IntPtr hwndParent,



IntPtr hwndChildAfter, string lpszClass, string lpszWindow);





const



int SC_MONITORPOWER = 0xF170;

const



int WM_SYSCOMMAND = 0x0112;

const



int MONITORON = -1;

const



int MONITOROFF = 2;

const



int MONITORSTANBY = 1;

int



HWND_BROADCAST = 0xffff; //the message is sent to all top-level windows in the system

int



HWND_TOPMOST = -1;

int



HWND_TOP = 0; //

int



HWND_BOTTOM = 1; //limited use

int



HWND_NOTOPMOST = -2; //

Form frm =

new Form();

Frm.Handle();

SendMessage(ValidHWND, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOROFF );

SendMessage(ValidHWND, WM_SYSCOMMAND, SC_MONITORPOWER, MONITORON);
Regards, Jagadeesan
o Marked As Answer byBin-ze ZhaoMicrosoft, ModeratorFriday, June 05, 2009 2:04 AM
o
o ReplyReply
o QuoteQuote


All Replies

*
Tuesday, June 02, 2009 12:32 PMJagadeesan Kandasamy Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
Answer
Sign In to Vote
0
Sign In to Vote

I hope this might be helpful...

Try to use with GetDesktopWindow(), The below code is just to switch on / off the moniter, from this you can try to the status as well.

[DllImport(

'user32.dll')]

static



extern IntPtr SendMessage(IntPtr hWnd, uint Msg,



IntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll', SetLastError = true)]

static



extern bool PostMessage(IntPtr hWnd, uint Msg,



IntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll')]

static



extern bool PostThreadMessage(uint idThread, uint Msg,



UIntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll', SetLastError=true, CharSet=CharSet.Auto)]

static



extern bool SendMessageCallback(IntPtr hWnd, uint Msg,



UIntPtr wParam, IntPtr lParam,

SendMessageDelegate lpCallBack,

UIntPtr dwData);

//Or

[DllImport(

'user32.dll', SetLastError=true, CharSet=CharSet.Auto)]

static



extern bool SendNotifyMessage(IntPtr hWnd, uint Msg,



UIntPtr wParam, IntPtr lParam);

//Or

[DllImport(

'user32.dll')]

private



static extern IntPtr GetDesktopWindow();

//Or

[DllImport(

'user32.dll', SetLastError = true)]

static



extern IntPtr FindWindow(string lpClassName, string lpWindowName);

//Or

[DllImport(

'user32.dll', SetLastError = true)]

static



extern IntPtr FindWindowEx(IntPtr hwndParent,



IntPtr hwndChildAfter, string lpszClass, string lpszWindow);





const



int SC_MONITORPOWER = 0xF170;

const



int WM_SYSCOMMAND = 0x0112;

const



int MONITORON = -1;

const



int MONITOROFF = 2;

const



int MONITORSTANBY = 1;

int



HWND_BROADCAST = 0xffff; //the message is sent to all top-level windows in the system

int



HWND_TOPMOST = -1;

int



HWND_TOP = 0; //

int



HWND_BOTTOM = 1; //limited use

int



HWND_NOTOPMOST = -2; //

Form frm =

new Form();

Frm.Handle();

SendMessage(ValidHWND, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOROFF );

SendMessage(ValidHWND, WM_SYSCOMMAND, SC_MONITORPOWER, MONITORON);
Regards, Jagadeesan
o Marked As Answer byBin-ze ZhaoMicrosoft, ModeratorFriday, June 05, 2009 2:04 AM
o

– Enviado usando a Barra de Ferramentas Google"

SC_MONITORPOWER in Windows 7?

SC_MONITORPOWER in Windows 7?: "SC_MONITORPOWER in Windows 7?

*
Wednesday, January 13, 2010 1:46 PMRodTech Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote
Hi, I have developed a program which turns off the monitor by sending message :

SendMessage(-1, WM_SYSCOMMAND, SC_MONITORPOWER, 2)

The problem is that is not working in Windows 7. Does anybody know if WM_SYSCOMMAND and SC_MONITORPOWER are still supported in Win7?
In case is not, what are the replacemente for this actions? thanks in advance
Rod
o ReplyReply
o QuoteQuote


All Replies

*
Sunday, February 28, 2010 6:31 PMRaymond Rogers Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote
I'm seeing the same problem with my application. Have you found a solution for this yet?
o ReplyReply
o QuoteQuote

*
Friday, June 11, 2010 5:30 PMRomashka_Sky Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals

Sign In to Vote
0
Sign In to Vote
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
o ReplyReply
o QuoteQuote

– Enviado usando a Barra de Ferramentas Google"

Visual Basic :: Turn Monitor Off Or Place It On Standby...

Visual Basic :: Turn Monitor Off Or Place It On Standby...: "Turn Monitor Off Or Place It On Standby...

I have found this code splattered all over VBF, or code similar, which I have modified...

VB Code:
Option Explicit Private Declare Function SendMessage Lib 'user32' Alias 'SendMessageA' (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long Private Const WM_SYSCOMMAND = &H112Private Const SC_MONITORPOWER = &HF170 Private Sub cmdTurnOFF_Click() Debug.Print SendMessage(Form1.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, 2&)End Sub Private Sub cmdStandby_Click() Debug.Print SendMessage(Form1.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, 1&)End Sub Private Sub cmdTurnON_Click() Debug.Print SendMessage(Form1.hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, -1&)End Sub

But it doesn't work...I alwasy get a 0 returned from the SendMessage and the monitor does absolutely nowt

Anyone got any ideas?

Woka

– Enviado usando a Barra de Ferramentas Google"

quinta-feira, 4 de novembro de 2010

16 bit in Windows 7 with XP mode

16 bit in Windows 7 with XP mode


Assuming you can run the program on Windows XP, you might be able to run it. If you meet the hardware requirements you can go ahead and try it out. See the following link for the requirements and other information about Windows XP mode:
http://www.microsoft.com/windows/virtual-pc/get-started.aspx

sexta-feira, 29 de outubro de 2010

Ubuntu Bloke: HOWTO: VirtualBox 3.2 "headless" on Lucid Lynx

Ubuntu Bloke: HOWTO: VirtualBox 3.2 "headless" on Lucid Lynx: "HOWTO: VirtualBox 3.2 'headless' on

HOWTO: VirtualBox 3.2 "headless" on Lucid Lynx

As of karmic koala, Vbox 3.x is provided via the standard Ubuntu repositories. Unfortunately, this is the OSE version and it does not appear to work headless.

So, we have to download the "free as in beer" version from the Oracle website, which is currently here

At the time of writing the current build for Lucid is virtualbox-3.2_3.2.4-62467~Ubuntu~lucid_i386.deb

Before we can install the deb, we will also need to install some dependencies.
sudo apt-get install libcurl3 dkms libqt4-network libqtgui4 libxslt1.1 libasound2 \
libdirectfb-1.2-0 libgl1-mesa-dri libgl1-mesa-glx libqt4-opengl libsdl1.2debian \
libsdl1.2debian-alsa libsysfs2 libts-0.0-0 libxcursor1 linux-headers-`uname -r` \
libxdamage1 libxfixes3 libxmu6 libxxf86vm1 tsconf

Now we can install the virtualbox deb that we downloaded earlier.
sudo dpkg -i virtualbox-3.2_3.2.4-62467~Ubuntu~lucid_i386.deb

Next, add your user account to the vboxusers group
sudo adduser brettg vboxusers

Virtualbox machines that you create will by default go in your home directory
/home/brettg/.VirtualBox/

Ensure vboxusers have appropriate permissions to the kernel, create the file;
sudo vi /etc/udev/rules.d/40-permissions.rules

/etc/udev/rules.d/40-permissions.rules
KERNEL=="vboxdrv", GROUP="vboxusers", MODE="0660"

That's it, Virtualbox should be installed and ready to go.
Now we can move on to creating a virtual machine
Create a machine named "io"
VBoxManage createvm -name io --ostype Ubuntu -register

Configure it with a nic bridged to eth0, 256Mb RAM, enable acpi and set to boot from DVD
VBoxManage modifyvm io --memory 256 --pae on --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0

Create a virtual IDE controller
VBoxManage storagectl io --name IDE0 --add ide

Create a virtual HDD
VBoxManage createvdi -filename ~/.VirtualBox/Machines/io/sda.vdi -size 48000 -register

Attach the virtual HDD
VBoxManage storageattach io --storagectl IDE0 --port 0 --device 0 --type hdd --medium ~/.VirtualBox/Machines/io/sda.vdi

Create and attach a virtual DVD drive to the controller and insert the DVD image
VBoxManage storageattach io --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium /store/archive/ISO/ubuntu-10.04-server-i386.iso

The default vrdp port for machines is 3389, however, if you intend to run more than one guest then each one will need to listen on a different port. I use the 3xxx range with the xxx being the last octet of the machines IP address. For example, 192.168.0.1 would be 3001.
VBoxManage modifyvm io --vrdpport 3001

And thats it, your machine has been created. Time to start it up and give it a test drive!

Using the virtual machine

Start the machine
nohup VBoxHeadless -startvm io &

On a GUI workstation, establish a remote desktop connection to the machine. In my case, the host server is called "jupiter" so I type;
rdesktop -a 8 jupiter:3001

After you have installed the OS, you need to tell the machine to boot from the hdd.
VBoxManage modifyvm io --boot1 disk

You can also deregister the dvd image if you don't intend to use it again.
VBoxManage unregisterimage dvd /store/archive/ISO/ubuntu-10.04-server-i386.iso


Here are some other useful commands;
VBoxManage showvminfo io
VBoxManage list hdds
VBoxManage list runningvms
VBoxManage controlvm io poweroff
VBoxManage unregistervm io --delete
VBoxManage controlvm io savestate
VBoxManage closemedium disk UUID
VBoxManage modifyhd UUID --type immutable

[ubuntu] Virtualbox: Save Windows XP guest screen resolution - Ubuntu Forums

[ubuntu] Virtualbox: Save Windows XP guest screen resolution - Ubuntu Forums: "Virtualbox: Save
Virtualbox: Save Windows XP guest screen resolution

I've got VirtualBox 1.6.2 installed on a Ubuntu 8.04 host. Running Windows XP SP3 in VM. I prefer to use a screen resolution of 1440x900x32 for my guest and can easily set this using:

VBoxManage controlvm [xpGuestName] setvideomodehint 1440 900 32

HOWEVER, I have to do this every time, as the default resolution of 1024x768 is how it starts at bootup. Is there any way to save the 1440x900 screen resolution properties so that my VBox WinXP guest will start that way every time?

sábado, 23 de outubro de 2010

How to install Windows 2000/XP/2003 guests with SATA support (View topic) • virtualbox.org

How to install Windows 2000/XP/2003 guests with SATA support (View topic) • virtualbox.org:

How to install Windows 2000/XP/2003 guests with SATA support

How to install Windows 2000/XP/2003 guests with SATA support

Postby chungy » 14. Sep 2008, 10:00

I'll show how to install Windows 2000, XP, or 2003 on a SATA disk without much hassle. Additionally, when you use this with Windows 2000, you avoid the Win2k IDE driver bug which can cause installation failures as described in the VirtualBox manual section 11.2.2; you will not need to provide any delayed writing in order to install it on a fast computer.

You need:
1. Sun xVM VirtualBox version 1.6.0 or higher (this process has only been tested on 2.2.0, however)
2. Windows 2000, XP, or 2003 installation CD-ROM; any release/edition should do, although this process has only been tested on the latest service packs
3a. If you need Windows XP or 2003: Download the drivers from Intel
3b. If you need Windows 2000: There are no official drivers, however you may use unofficial drivers as described in an MSFN forum post. WARNING, of course, that using these drivers comes with a certain amount of risk; scan with virus checkers and back up important data inside the VM periodically, I cannot guarantee the safety of these drivers.

For Windows 2000, you need to create a floppy disk (real or image) from the unofficial files you downloaded; all the files should be placed in the root directory of the disk.
(Under Windows, I am unfortunately not well-versed enough to understand how to create floppy images using native tools, however the GNU/Linux instructions should work under Cygwin as well)
To create an appropriate image under GNU/Linux hosts, you will need the unzip and mtools software packages installed (check your local package manager):
Code: Select all Expand viewCollapse view
$ unzip AHCI_v7.0.0.1020_for_ICH8.zip
$ dd if=/dev/zero of="Win2000 SATA.img" bs=1k count=1440
$ mformat -i "Win2000 SATA.img" -f 1440 ::
$ mcopy -i "Win2000 SATA.img" "AHCI v7.0.0.1020 for ICH8"/* ::

(note the position of the quotes on the last command, the asterisk cannot be placed inside quotes!)

For Windows XP/2003, you need to extract the f6flpy32.zip Zip file. Inside it is an EXE; all it does is write an image to a real floppy; if you're already using Windows and want to make a real floppy disk, go ahead and use it, otherwise just use an UnZip utility to extract the image (named F32.IMA).

Just create a virtual machine now for Windows, and change the virtual hard disk so it uses SATA instead of the default IDE. Mount the floppy in VBox (either real or the disk image, the latter is faster), and make sure that the floppy drive is not set as one of the boot devices (or press F12 when you start the VM and boot the CD-ROM manually).

Press F6 when Windows Setup prompts you if you want to load additional drivers. It doesn't seem to take effect immediately, but just wait a few seconds. Once that is done, this screen will come up:
Image

Press S, and select "Intel(R) 82801HEM/HBM SATA AHCI Controller (Mobile ICH8M-E/M)" as the driver to load:
Image

After that's done, just press Enter to continue installing Windows as normal. Be sure to remove the floppy disk after the text mode portion of the installation is completed, or you may encounter boot issues (the floppy is not bootable itself of course).

Windows 2000 in the graphical portion of the setup might warn about unsigned drivers being loaded, this is normal as the drivers in use are not official ones from Intel.
chungy
Volunteer
Posts: 132
Joined: 26. Jan 2008, 10:27

Postby Sasquatch » 14. Sep 2008, 15:44

Thanks, I will sticky it. This is for 2000, XP and 2003 Guest systems, as Vista and above already has the ICH8 driver. Older Windows Guests will not be able to use SATA in this way. They might be able to see and read/write it, but that is currently unknown.

Usually, I advise people to use nLite to integrate it, but this is also an option and saves the trouble of extracting the iso/copy the cd to the hard drive. Great Howto.
As it's a howto, I will also lock it so it won't be cluttered with questions and all, that is for a separate topic.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions + Xorg config
Howto: Use Shared Folders
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

PMs asking for help will be ignored. Create a topic instead.
Sasquatch
Site Moderator
Posts: 13701
Joined: 17. Mar 2008, 13:41
Location: Netherlands
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Windows XP, Linux

Re: How to install Windows 2000/XP/2003 guests with SATA support

Postby Technologov » 6. Oct 2010, 20:04

The original link to Intel SATA driver no longer works.

Any updated link ?
Technologov
Site Moderator
Posts: 1782
Joined: 10. May 2007, 16:59
Location: Israel

Re: How to install Windows 2000/XP/2003 guests with SATA support

Postby Sasquatch » 6. Oct 2010, 20:47

Attached the .zip of the driver, version 7.8 which works with the VB SATA controller because the link no longer works.
Attachments
Intel Storage Manager 7.8 Floppy.zip
Intel Matrox Storage driver floppy files
(205.99 KiB) Downloaded 113 times
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions + Xorg config
Howto: Use Shared Folders
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

PMs asking for help will be ignored. Create a topic instead.
Sasquatch
Site Moderator
Posts: 13701
Joined: 17. Mar 2008, 13:41
Location: Netherlands
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Windows XP, Linux

Re: How to install Windows 2000/XP/2003 guests with SATA support

Postby fixedwheel » 6. Oct 2010, 20:49

Technologov wrote:The original link to Intel SATA driver no longer works.

Any updated link ?

5 results: there are F6 drivers for 32 and 64bit as well as the full blown ones =>
http://downloadcenter.intel.com/SearchR ... amilyId=40

quarta-feira, 20 de outubro de 2010

How to disable user list in log-in screen? - Ubuntu Forums

How to disable user list in log-in screen? - Ubuntu Forums: "Re: How to disable user list in log-in screen?
I had some luck executing the following in a terminal:
Code:

sudo gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
--type bool --set /apps/gdm/simple-greeter/disable_user_list true

– Enviado usando a Barra de Ferramentas Google"

quarta-feira, 9 de junho de 2010

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009

List: gnome.devel

Date: Prev Next Index Thread: Prev Next Index

В Чтв, 05/01/2006 в 11:28 -0500, Hans Deragon пишет:
> Greetings.
>
>
> Under Gnome 2.10, using glade-2, I created a simple window with
> GtkHBox. The GtkHBox as 3 sections, the first a small image, the second
> a label and the tird a small button.
>
> The GtkLabel is the widget that should take all the rest of available
> space. When clicking on it, I see that it seams to be taking it, as the
> border shown with glade-2 confirms it. Yet, the text I have entered,
> multi-line and very long, seams to wrap much before the right border of
> the widget. I tried all sort of stuff, but could not have the text go
> as far as the right border. There seams to be an imaginary boundary in
> the middle of the label where the text wraps.
>
> I noticed that if I increase the width of the widget in pixels, in
> the Properties/Common/width entry, I can sorta fix this. But that means
> I have to enter a specific width. I do not want this. I want for the
> label to expand and wrap as the user changes the size of the window.
>
> This must be a common problem. Probably there is an easy solution I
> simply am not to figure out.
>
>
> Best regards,
> Hans Deragon
> --

Hello Hans

You are correct, it's just an internal hard-coded behaviour of the
GtkLabel with wrapped text. If you just need to have simple label, it
may have sense to implement your own label-like widget.

Otherwise, you should look at gtk_label_ensure_layout function in gtk
sources (there is if (label->wrap) statement). It uses quite hackish
algorithm to determine label's width from layout width, screen width and
so on. Of course, it can be improved. Probably you can suggest something
better. In that case you should search bugzilla for similar bugs,
probably create a bug in bugzilla against gtk and mail a patch to gtk-
devel list.

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009 - gnome.devel

Re: How to get a GtkLabel to fill all the available space. - msg#00009

List: gnome.devel

Date: Prev Next Index Thread: Prev Next Index

В Чтв, 05/01/2006 в 11:28 -0500, Hans Deragon пишет:
> Greetings.
>
>
> Under Gnome 2.10, using glade-2, I created a simple window with
> GtkHBox. The GtkHBox as 3 sections, the first a small image, the second
> a label and the tird a small button.
>
> The GtkLabel is the widget that should take all the rest of available
> space. When clicking on it, I see that it seams to be taking it, as the
> border shown with glade-2 confirms it. Yet, the text I have entered,
> multi-line and very long, seams to wrap much before the right border of
> the widget. I tried all sort of stuff, but could not have the text go
> as far as the right border. There seams to be an imaginary boundary in
> the middle of the label where the text wraps.
>
> I noticed that if I increase the width of the widget in pixels, in
> the Properties/Common/width entry, I can sorta fix this. But that means
> I have to enter a specific width. I do not want this. I want for the
> label to expand and wrap as the user changes the size of the window.
>
> This must be a common problem. Probably there is an easy solution I
> simply am not to figure out.
>
>
> Best regards,
> Hans Deragon
> --

Hello Hans

You are correct, it's just an internal hard-coded behaviour of the
GtkLabel with wrapped text. If you just need to have simple label, it
may have sense to implement your own label-like widget.

Otherwise, you should look at gtk_label_ensure_layout function in gtk
sources (there is if (label->wrap) statement). It uses quite hackish
algorithm to determine label's width from layout width, screen width and
so on. Of course, it can be improved. Probably you can suggest something
better. In that case you should search bugzilla for similar bugs,
probably create a bug in bugzilla against gtk and mail a patch to gtk-
devel list.

quarta-feira, 2 de junho de 2010

GtkSharp: Widget Colours - Mono

GtkSharp: Widget Colours - Mono

GtkSharp: Widget Colours


Colouring Widgets and Windows

Colouring widgets and windows (which is itself a widget) alluded me for ages due to my basic knowledge of gtk.

Thanks to a tiny example (http://lists.ximian.com/pipermail/gtk-sharp-list/2004-September/004820.html) I found by John Bailo on the gtk# mailing list (http://lists.ximian.com/pipermail/gtk-sharp-list/) it turns out to not be such a tricky thing after all. I’ve recreated it here.

The following code sets up a gtk.window, a DrawingArea widget on top, colours the window and the drawing area both red, then draws a diagonal line across the page.

using System;
using Gtk;

class ColourExample
{
Window win;
DrawingArea da;

static void Main (){
Application.Init ();
new ColourExample ();
Application.Run ();
}

ColourExample(){
win = new Window ("Colour Example");
win.SetDefaultSize (400, 300);
win.DeleteEvent += OnWinDelete;

da = new DrawingArea();
da.ExposeEvent += OnExposed;

Gdk.Color col = new Gdk.Color();
Gdk.Color.Parse("red", ref col);
win.ModifyBg(StateType.Normal, col);
da.ModifyBg(StateType.Normal, col);

win.Add (da);
win.ShowAll ();
}

void OnExposed (object o, ExposeEventArgs args) {
da.GdkWindow.DrawLine(da.Style.BaseGC(StateType.Normal), 0, 0, 400, 300);
}


void OnWinDelete (object o, DeleteEventArgs args){
Application.Quit ();
}
}

The code declares a global Window widget, and a global DrawingArea widget. Then a Gdk.Color object is created. We need to create a Color object so that this can be passed to the .ModifyBg() method of whatever widget is to be coloured. At first, just a blank Gtk.Color object is created.

We still need to tell the object what colour to be. This is done using the Gtk.Color.Parse method. The first parameter is a colour to try and translate. In this example “red” is passed and the method can easily work out what red is. The second parameter is which Gtk.Color object to send the colour to. Of course, this is ‘col’. So in short, declare a Gtk.Color object called ‘col’ and inform it to be a particular colour using Gtk.Color.Parse();

Both widgets are going to be coloured red. I have done this is for two reasons.

One: rarely, does a gtk# application contain just a Window widget and nothing else alone, so we need to put something practical in there and a drawingarea will do fine.

Two: although you really only need to change the background colour in the drawingarea widget to achieve the desired effect, I have elected to colour the window widget as well so that you don’t get an annoying white/grey flick the moment before the drawingarea object appears on the window when the .Show() method is called.

Finally, I used the expose event of the drawingarea widget to draw a simple line to just give the program some real world practicality.

TextReader and TextWriter In C# | C# Help – C# Tutorials Resources

TextReader and TextWriter In C# | C# Help – C# Tutorials Resources


TextReader and TextWriter In C#


INTRODUCTION:

This article covers the information of how toread or write (Unicode) character based data through TextReader andTextWriter. The TextReader and TextWriter are base classes. TheStreamReader and StringReader derives from the abstract typeTextReader. Similarly the StreamWriter and StringWriter derives fromthe abstract type TextWriter.

STREAMWRITERS & STREAMREADERS:

As I mentioned earlier StreamWriter typederives from a base class named TextWriter. This class defines membersthat allow derived types to write textual data to a given characterstream.

Let us see some of the main members of the abstract class TextWriter.

1.close() — Closes the Writer and frees any associated resources.
2.Write() — Writes a line to the text stream, with out a newline.
3.WriteLine() — Writes a line to the text stream, with a newline.
4.Flush() — Clears all buffers.

WRITING – TEXT FILE:

Let us see the Writing to a Text File with a example.

Before we move into writing to a text file wehave to know about "FileInfo" class. What is FileInfo? In the frameworkof .NET , the system.IO namespace is the region of the base classlibraries devoted to file-based input and output services.File Info isone of the core type of System.IO Namespace.The function of the FileInfo is to encapsulate a number of detailsregarding existing files on your hard drive (size,fileattributes,creating time,etc.)as well as aid in the creation anddestruction of new files. Let us move to example.

In this example in the Writetextfile class Icreate a file named "Arungg.txt" using the FileInfo class. Aftercreating the text file using the CreateText() method, I get aStreamWriter and write some textual data to the newly created textfile. We can also add numeric data into the text file.

public class Writetextfile

{
public static int Main(sting[] args)
{
FileInfo t = new FileInfo("Arungg.txt");
StreamWriter Tex =f.CreateText();
Tex.WriteLine("Arungg has launced another article");
Tex.WriteLine("csharpheaven is the new url for c-sharpcorner");
Tex.Write(Tex.NewLine);
Tex.close;
Console.WriteLine(" The Text file named Arungg is created ");
}
}

If you open the text file the data is entered there.

READING – TEXT FILE:

Now let us see how to read a text file using the StreamReader type.

Let us see some of the main members of the abstract class TextReader.

1.Read() — Reads data from an input stream.
2.ReadLine() — Reads a line of characters from the current stream and returns the data as a string.
3.ReadToEnd() — Reads all characters to the end of the TextReader and returns them as one string.

public class Readtextfile
{
public static int Main(string[] args)
{
StreamReader re = File.OpenText("Arungg.txt");
string input = null;
while ((input = re.ReadLine()) != null)
{
Console.WriteLine(input);
}
re.close;
return 0;
}
}

In the above class Readtextfile I open the text file Arungg.txt and read the contents using the ReadLine() method.In both StreamReader and StreamWriter are concerned with moving text data to and from a specified file.

STRINGWRITERS & STRINGREADERS:

Using the StringReaders and StringWriters cantreat textual information as a stream of in-memory characters. In thiswe can insert or remove string between a block of textual data.Let us see a program in which I add and delete some string between ablock of text.Running the above program we get the textual data in the console.

The output:

Data:
Friendship is not a two way road.
It is a one way road travelled by two people.

Press any key to continue

Now I show you how to insert and delete some string between textual data.

using System.Text;

public class stringwrite
{
public static int Main(string[] args)
{
StringWriter wr = new StringWriter();
wr.WriteLine("Friendship is not a two way road.");
wr.WriteLine("It is a one way road travelled by two people.");
wr.Write(Writer.NewLine);
wr.close();

StringBuilder bu = wr.GetStringBUilder();
string entiredata = bu.ToString();
Console.WriteLine("The data:{\n0}",entiredata);
// TO ADD SOME STRING.

bu.Insert(45,"together-hand in hand");
entiredata = bu.ToString();
Console.WriteLine("The modified data:\n{0}",entiredata);

// TO REMOVE SOME STRING.

bu.Remove(45."together-hand in hand".Length);
entiredata = bu.ToString
Console.WriteLine("The original data:\n{0}",entiredata);
return 0;
}
}

In the above program I write some characterdata to a StringWriter type and modify the data by inserting some itemto buffer at position 45.After inserting I also show how to remove someparticular string from the data.

The Output:

The Data:
Friendship is not a two way road.
It is a one way road travelled by two people.

The modified data:
Friendship is not a two way road.
It is a one way road travelled by two people together-hand in hand.

The original data:
Friendship is not a two way road.
It is a one way road travelled by two people.

Now Let us see how to use StringReader to read a block of character data rather than a entire file.

StringReader re = new StringReader(wr.ToString());

string input = null;
while(( input = re.ReadLine()) != null)
{
Console.Write\line(input);
}
re.close();

Like the above way by using StringReader we can read data from a file.

CONCLUSION:

I hope after reading this article , the userhas gained some information about how to create,write and read in atext file using TextReader and TextWriter in C# and also somethingabout Friendship!.

Related Articles :

sexta-feira, 28 de maio de 2010

connecting to openoffice.org base from a form via macro [GkSpk]

connecting to openoffice.org base from a form via macro [GkSpk]

Base is the database package that comes with openoffice.org 2.x. It seems quite OK as a desktop database package. But, I’ve found that resources for macro editing in basic for base are quite scarce. This is quite a problem since the editor it comes with doesn’t have intellisense/autocomplete. The uno documentation is way too big to be of any real use as a reference document. So I thought I’ll just write a beginners tutorial for connecting to the base database that is currently open from a form using openoffice.org basic macro.
The syntax itself is quite similar to VBA, so it should appear familiar to excel and access macro coders.

Example Scenario

In the example below, we will simply get a reference to our database, execute a simple select query, and retrieve the results.

For this example, we need a database table called MY_TABLE which will need an integer column and a varchar column in that order. We also need a form with a button to invoke the method we will write.

The macro code

We will create a macro to handle the button click from the form above. It will contain a function which requires an event object as its parameter as shown below:

Sub DoSomething(evt as Object)
// code goes here
End Sub

To run our queries we need a reference to our current database. This can be obtained from the form object, which can be obtained through the event parameter passed to our function.

Dim frm As object
frm = evt.Source.Model.Parent

This form object will also come in handy, if you have text boxes etc. you wish to populate with your sql results.

Now that we have a function which gets our form object, we can get on with a few examples.

Making a sql query:

First we create an object to store the results.

dim rows
rows = createUnoService("com.sun.star.sdb.RowSet")

We then get the connection for the database:

rows.ActiveConnection = frm.ActiveConnection

and, set the command type, create a sql statement, and execute it:

rows.CommandType = com.sun.star.sdb.CommandType.COMMAND
rows.Command = "select * from MY_TABLE"
rows.execute()

This puts all the rows from MY_TABLE into our rows object, and we can go through them using the following:

dim col1, col2

while rows.next()
col1 = rows.getInt(1)
col2 = rows.getString(2)
wend

The while loop goes through the records, which you can use to get your data.

This has been a basic intro into running custom queries from a form. Hopefully this will help you get started with your macros.

Posted in Programming

Assigning Macros to OpenOffice Events: How to Assign an OpenOffice.org Basic Macro to an Event

Assigning Macros to OpenOffice Events: How to Assign an OpenOffice.org Basic Macro to an Event


Adding an OpenOffice.org macro is a very useful way of extending the functionality of a Calc spreadsheet or a Writer document. For example, a user may wish to time stamp a spreadsheet every time that it's opened - a task that can easily be achieved by adding a macro which the user manually runs whenever they open the spreadsheet. Of course, there are some drawbacks to this:

  • the user must remember to run the macro
  • the user must know how to run the macro
  • the user must want to run the macro.

A much better solution for everyone is to get OpenOffice to do all of the hard work itself - and for that macros can be assigned to events.

OpenOffice.org's Built-in Events

OpenOffice has a number of built-in events that can be used to trigger any macro; these events are:

  • activate document
  • close application
  • close document
  • create document
  • deactivate document
  • document has been save as
  • document has been saved
  • document is closing
  • 'Modified' status was changed
  • open document
  • print document
  • save document
  • save document as
  • start application

So if, for example, the user wants the macro to run whenever they open the document then the trigger event should be 'open document'.

Having decided which is to be the trigger event then next step is to create a macro for that event.

Number format no mysql - Fórum do Clube do Hardware

Number format no mysql - Fórum do Clube do Hardware
Pode usar assim:

REPLACE( REPLACE( REPLACE( FORMAT( value, 2), '.', '|'), ',', '.'), '|', ',')

Alguem sabe uma forma mais direta?
Vitor.anacleto está offline Responder com Quote

terça-feira, 25 de maio de 2010

HOWTO: Install FreeNX - Ubuntu Forums

What is FreeNX

FreeNX is a system that allows you to access your desktop from another machine over the Internet. You can use this to login graphically to your desktop from a remote location. One example of its use would be to have a FreeNX server set up on your home computer, and graphically logging in to the home computer from your work computer, using a FreeNX client.

It's Open Source, secure (SSH based), fast and versatile!

Note: Running FreeNX as server on Ubuntu with the free "NX Client for Windows" from NoMachine on a Windows workstation is working fine.

Terminology

The Server is the computer you want to connect to. This is the computer where the FreeNX server will need to be installed. The name of the Ubuntu package providing the server is "freenx". For the example used here, the home computer is the server.

The Client is the computer from which you want to be able to access the Server. The name of the Ubuntu package providing the client is "nxclient". For the example used here, the work computer is the client.

Installation

Before installing FreeNX server make sure you have SSH set up and is working. You can find the SSH Howto here: https://help.ubuntu.com/community/SSHHowto

We will be installing the FreeNX server on the Server machine, i.e., the machine that you want to access remotely. In the stated example, this is your computer that is at home.

FreeNX is not included in Ubuntu, so we'll add it from the FreeNX Team PPA.

For the paranoid: there is an added security risk involved in using the default keys. If you keep the default keys then everybody will be able to connect to your SSH server as the NX user which is added to your system during the installation. This opens an additional (and unnecessary) opportunity to attack your computer. You could avoid it by using custom SSH keys, as explained later.

Installing the FreeNX server on Ubuntu Lucid (10.04)

Ubuntu Lucid now uses Neatx, the Open Source NX server from Google.

Installation is simple enough, and similar to the Ubuntu Karmic method.

  1. Open your terminal

    Applications->Accessories->Terminal

    and type in this command

    sudo add-apt-repository ppa:freenx-team
  2. Then Update Apt

    sudo apt-get update
  3. At this point, the repository is added and apt is updated, then install the neatx-server package (using Aptitude to install extra needed packages).

    sudo apt-get install neatx-server

Installing the FreeNX server on Ubuntu Karmic (9.10)

Karmic introduces the add-apt-repository command that simplifies most of the work of adding a third party repository.

  1. Open your terminal

    Applications->Accessories->Terminal

    and type in this command

    sudo add-apt-repository ppa:freenx-team
    • NOTE: If you do not have add-apt-repository installed add the following

        sudo apt-get install python-software-properties
  2. Then Update Apt

    sudo apt-get update
  3. At this point, the repository is added and apt is updated, then install the freenx package (using Aptitude to install extra needed packages).

    sudo aptitude install freenx
  4. Now use nxsetup to install necessary files and create the special user "nx"

    sudo /usr/lib/nx/nxsetup --install 

Installing the FreeNX server on older Ubuntu Versions

This Instructions are for older Ubuntu versions. FreeNX is not included in Ubuntu, so we'll add it from the FreeNX Team PPA.

Add this repository using the Third-Party Sources Tab in Software Sources. When it asks, Reload the information about available software. Now you can see and install the freenx package in Synaptic Package Manager.

You must edit the configuration files and install by hand:

  1. Open your apt sources list

    gksudo gedit /etc/apt/sources.list

    and append the two lines for the repository

    deb http://ppa.launchpad.net/freenx-team/ppa/ubuntu VERSION main
    deb-src http://ppa.launchpad.net/freenx-team/ppa/ubuntu VERSION main

    where VERSION can be: dapper, hardy, intrepid or jaunty. More information can be found at FreeNX Team PPA.

  2. Save and then close.

    To add the public key of FreeNX PPA run:

    sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2a8e3034d018a4ce
  3. Then Update Apt

    sudo apt-get update
  4. After you add the repository, then install the freenx package (using Aptitude to install extra needed packages).

    sudo aptitude install freenx
  5. Now use nxsetup to install necessary files and create the special user "nx"

    sudo /usr/lib/nx/nxsetup --install 

Installing the NX Client

The official NX client is not in the Ubuntu repositories.

You should be able to access your Ubuntu box from any Windows or Linux box using the free client from NoMachine's website. You can also embed your NX Server in a webpage by installing the Nomachine Web Companion and the Apache webserver.

Now you can execute the installed client using the following command:

/usr/NX/bin/nxclient &

Or by looking it up in the menu

This will start the NX client in a GUI, and step you through getting connected to the FreeNX server, and you will be on your way! [Note: If you are behind a firewall you may need to enable SSL encryption under the Advanced configuration tab - JeremySchroeder]

Installing QTNX (Opensource client)

sudo apt-get install qtnx

Miscellany

NX Server Free Edition

NX Server Free Edition provided by NoMachine is not related to FreeNX. NXSFE has a limit of 2 sessions per server. FreeNX doesn't have this limit.

FreeNX on PowerPC

There are no precompiled binaries of FreeNX on this platform (Launchpad PPA doesn't provide support), so FreeNX have to be compiled from source. Sources can be found at the FreeNX Team PPA.

These steps will build FreeNX from source (you need to add the deb-src repository):

  1. Create a directory to hold the FreeNX source, and cd into it.

    mkdir freenxSource; cd freenxSource
  2. Build the freenx packages and install related packages.

    sudo apt-get build-dep nx freenx
    apt-get -b source nx freenx
    This will download the source tarballs and build the freenx packages (*.deb) in the current directory.
  3. Install the FreeNX packages.

    sudo dpkg -i *.deb
  4. If dpkg complains about missing packages, let apt fix it

    sudo apt-get -f install
    sudo dpkg -i *.deb

How to start/stop FreeNX

The FreeNX server is not a service but uses ssh. The following command will stop the FreeNX program from accepting connections.

sudo /etc/init.d/freenx-server stop

(Replace stop by start for starting it again)

Configuring SSH port

By default, nxserver uses port 22 for communicating over SSH. On some machines or networks, port 22 may be blocked; some Internet providers block port 22, for instance. Port 22 is also a common target of people trying to crack into a network. To make the SSH server listen on port 8888, you can do the following:

Edit the file /etc/ssh/sshd_config

gksudo gedit /etc/ssh/sshd_config

Find

Port 22

and change it to

Port 8888

You then need to restart SSHD. Try

/etc/init.d/ssh restart

FreeNX should detect the SSHD port, but otherwise: Edit the file /etc/nxserver/node.conf

gksudo gedit /etc/nxserver/node.conf

Find

# The port number where local 'sshd' is listening.
#SSHD_PORT=22

and change it to:

# The port number where local 'sshd' is listening.
SSHD_PORT=8888

That is, change the port number to the one that sshd is listening to, and uncomment the line.

Using custom SSH keys

After installation, FreeNX will use a set of default ssh keys for authentication. This is a security risk, especially on any internet-facing machines, and the default keys should be replaced with your own custom keys.

To change the default keys to your own custom keys - on the machine hosting the freenx-server, run the command:

sudo dpkg-reconfigure freenx-server

This will launch a dialogue that will guide you through the generation of custom keys. On the first page hit 'OK' and on the second page select 'Create new custom keys'

a key file called client.id_dsa.key will be created in: /var/lib/nxserver/home/custom_keys/

Now, we need to transfer the key to the client machine so that it can be imported in the FreeNX client application. First copy the key to your home directory on the server machine:

sudo cp /var/lib/nxserver/home/custom_keys/client.id_dsa.key ~/

Next, copy client.id_dsa.key to your client machine. Ideally you should copy the file securely, for example by running the following command from the client computer:

scp user@freenx-server:~/client.id_dsa.key ~/

which will securely copy the client.id_dsa.key file from the freenx-server computer to your home directory on the client.

If your client is a Windows machine, just copy the key with your preferred method.

In the nx client software you can now import this key.

After you have tested that authentication is working using your custom keys you should then remove the client.id_dsa.key file from your home directories on both the server and client machines.

Troubleshooting

  • Problem: Everything is installed as described above, but I still get errors at installing nxsetup --install

  • Solution: Check that this line exists in /etc/ssh/sshd_config "AllowUsers nx" and this line also exists and is set to authorized_keys2 "AuthorizedKeysFile %h/.ssh/authorized_keys2", if commented, just uncomment them. after that run this command in a terminal sudo /etc/init.d/ssh restart .This issue is due custom SSH server configuration.

  • Problem: At the client, the !M logo window appears, but after a few seconds that window just closes, even without showing any error message.

  • Solution: In the server, access your home directory and run this command, sudo rm .Xauthority* followed by touch .Xauthority and finally chmod 600 .Xauthority . This issue is due custom VNC configuration.

  • Problem: What can I do if I get the error 'Could not yet establish the connection to the remote proxy' ?

  • Solution: This commonly happens when the Advanced tab configuration option "Disable encryption of all traffic" has been selected, but the appropriate firewall ports have not been opened. Open the necessary firewall ports, or uncheck the option to re-enable encryption over SSH. NoMachine knowledge base article

  • Problem: NX Client connects and displays the desktop but the screen does not refresh.

  • Solution: Set Disable Direct Draw for screen rendering in the client's advanced configuration tab.

References

You can also have a look at the article about installing the NX packages provided by NoMachine company

Desktop integration wanted

For those who want to have freenx supported in krfb, krdc, log into bugs.kde.org, and add a comment and vote for the following bugs (wishlist) :

  • 187310 : nxserver support in krfb

  • 149482 :nx support in krdc (client), it seems that work is already in progress, and there only a few problems left.

The same should be done on gnome side, for vino and vinagre.

NXLaunch is another solution and could possibly be integrated in other Remote Desktop clients.