Site hosted by Angelfire.com: Build your free website today!

Windows Programming Tips 'n' Tricks

 

This is a page where I am going to put a few tips 'n' tricks to use in windows programming, one reason is cos my memory sucks so it's a useful place to collate things that I find useful, and I thought some other people might find these useful as well so here you go. For a more comprehensive guide to windows programming, buy Charles Petzold's book Programming Windows 5th edition as it is excellent.

Activate Screen Saver                                Fixed Size Window

Turn off the monitor

Tab in dialogs

Minimize To Systray

Always on top

Activate Screen Saver

    Here's a useful line of code to activate the screen saver, might come in useful some time.

SendMessage(GetActiveWindow(),WM_SYSCOMMAND,SC_SCREENSAVE,NULL);

Turn off the monitor

    Here's a nice one to turn the monitor off.

SendMessage(HWND_BROADCAST, WM_SYSCOMMAND,(WPARAM)SC_MONITORPOWER, 2) ;

Tab in dialogs

    I had a bit of trouble getting tab to work in my dialogs at first but here's how u do it (well, how I did it, there could be a better way). You have to use IsDialogMessage() in the main message loop. Here's an example of one of my loops implementing IsDialogMessage().

 

Minimize To Systray

    This is another thing that can be fun if you cant find out how to do it. Below is a link to a file that has a systray_add and a systray_rem function, I did not write this code so do not blame me if you have problems :) I have used these and it is working fine.

sex01_source.zip

To get the window to dissapear when it is minimised is shown below :

There you go. Simple.

Always on top

Here's a piece of code that you can put in a menu item case to toggle between a window item being always on top or not, obviously replace ID_FILE_ALWAYSONTOP with your menu item and replace the co-ordinates with whatever you want them to be,

Fixed Size Window

To make a window a fixed size so the user cannot change it at run time, instead of using just WS_OVERLAPPEDWINDOW in CreateWindow or CreateWindowEx for the style, use WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME.

If you have any questions feel free to email me, I can't guarantee that I will know the answer but as long as I have some time I will reply. My email address is r0ute@r0ute-software.tk