Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Win32 Tutorial Part 2d- Creating Window

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Freiza
Grandmaster Cheater
Reputation: 22

Joined: 28 Jun 2010
Posts: 662

PostPosted: Thu Feb 23, 2012 3:55 am    Post subject: Win32 Tutorial Part 2d- Creating Window Reply with quote

Step 4) -->

Code:
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch(uMsg)
   {
   
   case WM_DESTROY: PostQuitMessage(0);return 0;
      break;
   default: return DefWindowProc(hwnd,uMsg,wParam,lParam);
   }
   return 0;
}


Now its time to handle messages and add functionality to our window.
But little theory first.
After retrieving message through GetMessage function. the message is send via DispatchMessage function to WindowProc.
In WindowProc function we receive top 4 arguments of message structure.

Here uMsg will contain the message number.

for example: if left mouse button is pressed in our window then WM_LBUTTONDOWN message is generated.

WM_LBUTTONDOWN is just a plain number. And it is defined as

#define WM_LBUTTONDOWN 0x0201

there are many other messages some important message are:

WM_DESTROY - Sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.
WM_CLOSE - Sent as a signal that a window or an application should terminate. WM_CLOSE indicates a request to close a window, such as by clicking on the close button.
WM_LBUTTONDBLCLK - when mouse left mouse button is double clicked.
WM_RBUTTONDOWN -When right mouse button is clicked.
WM_RBUTTONUP - When right mouse button is released
etc...

You can check more message constants in msdn.

Since there are hundreds of message that can happen to our little program. But we are interested in dealing only one of them "WM_DESTROY"

Therefore, We have used switch statement. As we know the message number is stored in uMsg. Now we will compare it with WM_DESTROY since we only want
to handle this message

switch(uMsg)
{
case WM_DESTROY: PostQuitMessage(0);
break;
}

Q1) What is PostQuitMessage ?
Q2) Since we are dealing with only one message what will happen to other messages?

Ans1) If you remember we had put GetMessage function inside a while loop. And while loop will iterate till GetMessage function returns false.
GetMessage returns false when we call PostQuitMessage() function.
PostQuitMessage() sends WM_QUIT message to GetMessage function forcing it to return false. hence while loop terminates. and our program ends
Hence PostQuitMessage() is just a function whenever called it sends WM_QUIT message to GetMessage function forcing it to return false to while loop.
WM_QUIT message is a constant when received by GetMessage function it will return false.

Ans2) Since we cannot tackle each and every messages created by our window. Our operating system comes into the scene.
The messages which are not interesting to us. We just pass them back to operating system. And operating system take care of that messages for us.
for ex:- We have not tackled minimize messages. So if somehow we pass minimize message to operating system. It will perform default operations. Here It will minimize the window.

Q)so how do we do this?
Ans) we simply return DefWindowProc(hwnd,uMsg,wParam,lParam) with the same parameters that we got from DispatchMessage. It is a default window procedure to handle all the unhandled messages.

Code:
switch(uMsg)
   {
      case WM_DESTROY: PostQuitMessage(0);
         break;
                default:
                             return DefWindowProc(hwnd,uMsg,wParam,lParam);  // this function handles all the ignored messages.

   }


note:
Translate function just translates virtual-key messages into character messages

I think Part 2 is finished.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites