Archive for September 2011

Creating Window Basics

Getting to know Windows – Part 7
Volume – Windows User Interface

Introduction
This is part 7 of my series, Getting to know Windows. I assume you have read all the previous tutorials before this one. You should be reading the tutorials in the order given. In this part of the series we look at creating window basics.

Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.

Creating a Window
An application typically creates the main window as its first window before it can go on to create other windows. You create a window using the CreateWindowEx function. Before creating a window, you have to register the class of the window first, and then provide a window procedure for the class; then you can create the window.

A class has the characteristics of a window. Some of these characteristics can be given when creating the window in the CreateWindowEx function. If you do not give the characteristic in the CreateWindowEx function, make sure you give it in the class description (see details later), unless the characteristic is optional.

The CreateWindowEx Function
There is a predefined function called CreateWindowEx, which is used to create a window. Two other functions are normally used with the CreateWindowEx function. The functions are ShowWindow and UpdateWindow. Example code of the use of these functions is:

HINSTANCE hinst;
HWND hwndMain;
 
hwndMain = CreateWindowEx(0, “MainWClass”, “Main Window”, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, (HWND) NULL, (HMENU) NULL, hinst, NULL);                 
 
if (!hwndMain)
    return FALSE;
 
ShowWindow(hwndMain, SW_SHOWDEFAULT);
UpdateWindow(hwndMain);

The first thing in the code is the declaration of an identifier that will hold the instance handle of the class. Next you have the declaration of the identifier that will hold the handle of the window created. The CreateWindowEx function returns the handle of the window it has created. This will be held by hwndMain.

The CreateWindowEx function has many arguments. The second argument is the name of the class; it is a string in double quotes. The third argument is the name of the window, which will be displayed in the title bar of the window. It is a string in double quotes and it can have spaces. One of the arguments is the identifier for the class instance handle.

There is an if-statement. This if-statement checks if the window was successfully created. If it was not successfully created, the if-statement returns FALSE to the calling environment (operating system). The condition, (!hwndMain) will result in False if the window was not created (successfully). Note the NOT (!) inside the condition.

When the window is created by the CreateWindowEx function it is not displayed. The ShowWindow predefined function displays the window. It first argument is the handle of the window. We shall talk about its second argument later. As the window is just displayed, it does not have a color. The UpdateWindow predefined function paints the window’s client area. Its argument is the window handle. The uses of the last two functions do not look logical; but that is how things are with Windows.

Destroying a Window
Closing a window does not destroy the window. Destroying a window means the window has to save its system data and then free the memory that the window was using and free any resources that were allocated to the window, so that other applications can use the resources (and memory). We shall see more about this, as we go along.
 
The Windows API Volumes
Those of us who write (publish) for the Internet, write for money. We get our earnings through the advertisements you see on our web pages like this one. So please, do click the advertisements on my pages to know what my partners are advertising. In that way they pay me on your behalf, for advertising their products. If you do not click the advertisements of the Internet articles, they will not pay us. I know you are getting the stuff free, but do click the advertisements to enable us continue to write. Thanks.

We can stop here. We continue in the next part of the series.

Chrys

To arrive at any of the parts of this series, just type the corresponding title below in the Search Box of this page and click Search (use menu if available):

Getting to know Windows
What is a Microsoft Window?
Basics of Window Classes
Window Procedure Basics
Message Basics for Window Class Procedure
Basics of Message Handling in Windows
Creating Window Basics
Basic Coding of Window Class Procedure
Your first Window

Written by Chrys

Computer Repair: Why Is Your Computer Running Slower Than Normal

If you have a computer you are not unfamiliar to computer repairs. It is inevitable that your computer will eventually run slow or not at all especially if you are a novice to technology which lets admit most of us are. One of the biggest reasons clients bring their computers in is that they are slower than when they first purchased them. They always want to know who or what is to blame for this. No one wants to hear it but the problem your computer may be running slower than when you purchase it is…YOU!
Maintenance is the key in making sure your computer keeps running at peak performance. Just like your car needs regular oil changes and filter changes your computer needs tune ups to clean up the registry of old programs not in use, updates on spyware and adjustment of settings to insure peak performance. Of course there could be more reasons for the slow down. It is best to take the computer in to a local computer repair firm, as you would your car to a mechanic; to have it thoroughly looked at.
Other reasons that your computer may be having issues running slower than normal could be that your computer has contracted a virus. Trojans, spyware and malware may be the cause of the issue with your computer running slowly. Spyware creates an issue where outsiders have gotten into your computer without you knowing it and start sending out personal data to entities that will take advantage of your system and cause it to run slowly. Even if you have up to date virus protection you can still become infected it just lessens the likelihood. Computer repair in the form of a virus scan and removal are needed and can be done at your local computer repair store. It is also recommended that a tune up be performed on your PC at this time to regain the speed and efficiency of your computer.
You can also inspect your computer and delete files and programs that have been added that are unnecessary. The more files and programs you keep stored on the hard drive of your computer the slower it will run. I recommend having a separate flash drive to store big files such as pictures, word and excel documents. The space adds up quickly. Also, delete any unnecessary short cuts on your desk top they could be causing your computer to run at a snail’s pace.
It is important if you have tried all of the similar solutions to look at the computer’s hard drive. Run a disk defragmenter which will help optimize how data is stored and then Scandisk to help ensure nothing is actually corrupt within the drive.

Another issue that is common is that the processor overheats. This is common. You must first ensure that the cooling system on the computer, the fan is running. If it does not have to be cut and subjected to the fans to be replaced. If the fan is looking to ensure that dust is not causing a problem or that the cabinet is stored in the computer is not blocking the airflow. I found this happens when I’m in bed with the laptop and forget about the heat problem. If I put the team in the blankets of air flow is blocked and the team will have problems.
Memory, hard disk space and conflict in the hardware / software are problems that could also be responsible for the slowness of your computer. If you have a computer repair check the above and there are still problems will most likely recommend that you reload the operating system. Basically, this will be to clean your computer clean and reload the operating system. Make sure your data is backed up before doing this. In addition, this requires the installation of programs running on your computer. This is basically a last resort, but it will make your computer and the first time I brought home.

Written by requered