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 2a- 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 1:17 am    Post subject: Win32 Tutorial Part 2a- Creating Window Reply with quote

Creating Window

In order to create window we must follow these steps. (To create Pre-defined window the steps are somewhat different. We will look at it later.)

Step 1) Define what type of window we need to create.
Step 2) Register our definition to Operating System.
Step 3) Now, Create Window based on our definition.
Step 4) Add functionality to our window.

One Look of how our complete code will look when we complete part 2 tutorial:-
Code:
#ifndef UNICODE
#define UNICODE
#endif

#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
   // Register the window class.
   const wchar_t CLASS_NAME[]  = L"myClassname";

   WNDCLASS wc = { };

   
   wc.lpfnWndProc=WindowProc;
   wc.hInstance=hInstance;
   wc.lpszClassName=CLASS_NAME;
   
   if(!RegisterClass(&wc))
   {
      MessageBox(NULL,L"Cannot register window",L"Title Bar",MB_OK);
      return 0;
   }

   
   HWND hwnd = CreateWindow(CLASS_NAME,L"My Title Window",WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,500,500,NULL,NULL,hInstance,NULL);

   if (hwnd == NULL)
   {
      MessageBox(NULL,L"CreateWindow Failed",L"Create Window problem",0);
      return 0;
   }

   

   MSG msg = { };
   while (GetMessage(&msg, NULL, 0, 0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }

   return 0;
}

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;
}


Step 1)--->

WNDCLASS wc={}; /*We will use WNDCLASS structure to define our window. WNDCLASS structure have several members. We will only use those that are relative to this tutorial. And rest we have set to NULL*/

wc.hInstance = hInstance; // Here we pass the handle program instance.

wc.lpfnWndProc = WindowProc /*lpfnWndProc is a function pointer. windowproc is our function that will add functionality to our window.*/

wc.lpszClassName = L"myClassname"; // Unique string that names our WNDClASS structure

For example:-

Operating system will take value from wc structure and will create something like this in memory:

struct WNDCLASS myClassname{
HINSTANCE hInstance = hinstance;
lpfnWndProc = windowproc;
style = NULL; // since we have set it to null
hIcon = NULL; // since we have set it to null
};
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