Getting to know Windows – Part 6
Volume – Windows User Interface
Introduction
This is partial 6 of my series, Getting to know Windows. we pretence we have review all the prior tutorials prior to this one. You should be celebration of the mass the tutorials in the sequence given. In this partial of the array we demeanour during basis of summary doing in windows.
Note: If we cannot see the formula or if we consider anything is blank (broken link, picture absent), usually hit me during forchatrans@yahoo.com. That is, hit me for the smallest complaint we have about what we have been reading.
Some Data Types as good as Predefined Functions
In this territory we demeanour during the little interpretation sorts as good as the little predefined functions offering by the User Interface (Windows API) to hoop messages. We have been articulate about the messages which have been sent to the window category procedure. A summary has to be private from the reserve as good as finished with (sent) to the procedure. There have been sure interpretation sorts as good as functions compared with this.
The DOOL Type
The BOOL interpretation sort is for the Boolean value. A Boolean worth is presumably the value, TRUE or FALSE. TRUE can additionally be the array as good as FALSE can additionally be the number.
The MSG struct
A summary has 4 tools (parameters). The MSG is the struct similar to the C++ struct. It is used to reason the complement message. Its members are:
{
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
}
We shall not operate the final dual members for many of the tutorials. The initial 4 members have been the opposite summary tools we have been articulate about. You have the windows handle, the summary identifier (message) as good as the dual parameters for the summary interpretation (or interpretation location).
The GetMessage Function
The GetMessage duty retrieves the summary from the reserve as good as places it in an MSG structure, which we should have declared. When the summary is retrieved, it is private from the reserve as good as it is no longer in the queue. The GetMessage duty would routinely lapse the nonzero number. However, if the summary it retrieves is WM_QUIT, which equates to Quit the Application, the duty will lapse zero. Any summary identifier similar to WM_QUIT is essentially an integer value. In alternative words, an integer has been reserved to it.
The elementary antecedent of the GetMessage duty is:
BOOL WINAPI GetMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax);
lpMsg is the residence to the MSG structure. hWnd is the hoop of the window whose messages have been to be retrieved from the queue. If hWnd is NULL the funtion retrieves summary which is for any window. wMsgFilterMin as good as wMsgFilterMax have been any an interger value. For elementary programming, set these dual values to zero.
The lapse worth is the BOOL. The accurate lapse sort is BOOL WINAPI; do not be endangered most about which for now. The duty routinely gain the nonzero number. If the duty retrieves the WM_QUIT message, the lapse worth is zero. If there is an error, the returned worth is – 1. Note which 0 of the parameters of the GetMessage duty essentially handles the message. The duty gets the summary form the reserve as good as places it in the MSG struct; the summary does not pass by the function.
The TranslateMessage Function
The TranslateMessage duty deals with set of keys impression inputs. Each time the user presses the key, the doing complement generates virtual-key messages (WM_KEYDOWN as good as WM_KEYUP). As the user is dire the key, the WM_KEYDOWN summary is generated as good as goes in to the queue. When the user releases the key, the WM_KEYUP summary is generated as good as goes in to the queue. Remember, these messages have been essentially integers.
A virtual-key summary contains the virtual-key formula which identifies which pass was pressed, though not the impression value. To acquire the value, we have to operate the TranslateMessage function. The made easy antecedent of the TranslateMessage duty is:
BOOL WINAPI TranslateMessage(const MSG *lpMsg);
It has usually the single argument, which is the residence of the MSG struct, which should be carrying the summary which the GetMessage duty got from the queue. Its lapse worth is the BOOL (a number). If the summary is translated, the lapse worth is nonzero. If the summary is not translated the lapse worth is zero.
If the TranslateMessage duty translates the message, it posts (sends) the translated summary to the queue.
Note: The lapse worth of the duty is not the impression value. The TranslateMessage duty translates (converts) the virtual-key summary in to the impression summary (WM_CHAR) as good as places it behind in to the focus summary queue. The impression summary will afterwards have to be private from the reserve prior to being sent (dispatched) to the window category procedure. The summary placed behind in to the reserve has the impression worth (code).
The DispatchMessage Function
The DispatchMessage duty sends the summary review from the MSG struct to the window category procedure. This duty knows what window the summary will movement on, by the window hoop in the summary in the MSG struct. If the window hoop parameter in the MSG struct is NULL, the DispatchMessage duty does 0 (does not send any message) so distant as windows have been concerned.
Handling Events in Windows
Any submit movement (keyboard or mouse) in Windows is an event. When the user clicks an item, he sees the reply automatically. From the technical indicate of view, there is 0 like, automatically, in the doing of events. You, the focus developer has to write the WHILE Loop to do that.
When an eventuality occurs the analogous summary is sent to the complement summary reserve as good as it stays there. If it is not private as good as sent to the window category procession the user will see no response. You have to write the whilst double back which will be iterating continuously, stealing the messages from the reserve as good as promulgation to their particular windows (procedures). It is the window category procession which provides the response. Since the whilst double back is doing of course really discerning as good as continuously, the user sees the really discerning reply to his event. So to the user, the reply is automatic.
WHILE Loop Code for Events
The whilst double back functions with an MSG interpretation type. The following is exemplary code:
MSG msg;
BOOL bRet;
HWND hwnd;
while( (bRet = GetMessage( &msg, hwnd, 0, 0 )) != 0)
{
if (bRet == -1)
{
// hoop the blunder as good as presumably exit the application
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
In the code, initial we have the identifier (msg) for an MSG struct declared. Next we have an identifier (bRet) for the BOOL sort declared. You afterwards have an additional identifier (hwnd) for the window hoop of interest, declared, with the HWND type. We shall see some-more about window handles later. Then we have the whilst loop.
If the worth of the hwnd parameter in the GetMessage duty is NULL, afterwards the GetMessage duty will mislay the subsequent summary in the queue. If the hwnd parameter is not NULL, afterwards the duty will mislay the subsequent window summary from the queue.
The condition in the whilst double back is:
(bRet = GetMessage(&msg, hwnd, 0, 0 )) != 0
Look during the condition really well. It removes the subsequent window summary from the reserve as good as places it in the msg struct. The lapse worth of the GetMessage duty is the BOOL (and not the message) is reserved to the identifier, bRet. If the worth of bRet is zero, it equates to the summary is WM_QUIT, which equates to the focus should give up as good as the whilst double back should stop. If bRet is not 0 is means, the GetMessage duty succeeded to mislay the summary from the reserve or an blunder occurred in the try to mislay the message. That is because we have “!= 0″ during the finish of the whilst condition. If the worth of bRet is -1, it equates to an blunder occurred in the summary dismissal attempt. However, the whilst double back iteration will still execute, given it is “!=-0″ as good as not “!= -1″ which determines the execution of the whilst double back block.
If the whilst double back retard is to execute, it equates to presumably the summary dismissal as good as fixation in to the msg struct was successful or an blunder occurred. In the whilst double back block, there is an if-construct. The if-block of the erect handles the blunder if bRet were -1. The else-block of the erect has the TranslateMessage, as good as the DispatchMessage functions. Each of these functions uses the summary in the msg struct.
The Window Class Procedure
One procession can offer some-more than the single window, though the windows have to be of the same class. If the procession is portion the single window, it equates to which window is alone in the class.
A window procession should not omit the message. If it does not routine the message, it contingency send the summary to the DefWindowProc procession for default processing. In sequence to do this, the window procession calls the default DefWindowProc procedure, which performs the default movement as good as gain the summary result. DefWindowProc is the predefined duty which would give the default estimate to what the window category procession does not do.
The Windows API Volumes
Those of us who write (publish) for the Internet, write for money. We get the gain by the advertisements we see upon the web pages similar to this one. So please, do click the advertisements upon my pages to know what my partners have been advertising. In which approach they compensate me upon your behalf, for promotion their products. If we do not click the advertisements of the Internet articles, they will not compensate us. we know we have been removing the things free, though do click the advertisements to capacitate us go on to write. Thanks.
We have seen most in this partial of the series. Let us take the mangle here as good as go on in the subsequent part.
Chrys
To arrive during any of the tools of this series, usually sort the analogous pretension next in the Search Box of this page as good as click Search (use menu if available):
Getting to know Windows
What is the 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 initial Window
Can we paint a wall as well as operate a screw driver? Are we desirous to have a beautiful room that will artistically feed a senses of your child?
One of a alternative uses of roof lights is to bedeck a room. They can assistance take a room up a stage in a grand ladder of intemperate lifestyle. They can be a cherry during a tip of a pie. To do this however they contingency be great picked out as well as competence additionally need a vast cheque. In a finish however they can only do a pretence of transforming a room in to something superb. It can spin it in to a room which we can be unapproachable of.