Freiza Grandmaster Cheater Reputation: 22
Joined: 28 Jun 2010 Posts: 662
|
Posted: Thu Feb 23, 2012 12:42 am Post subject: Win32 Tutorial Part 1 - MessageBox |
|
|
Code: | #ifndef UNICODE
#define UNICODE
#endif
#include<windows.h>
int WINAPI wWinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, PWSTR szCmdLine, int nCmdShow)
{
MessageBox(NULL,L"Body Message",L"Title Here",MB_OK);
return 0;
} |
windows.h is a header that contains other important Header file. And is important if you want to create windows application.
WINAPI is a calling convention that specifies how the arguments are received by the function. Here the arguments are received right to left.
And it also specifies that the calling function is responsible for cleaning stack. (If you didn't understood a bit, do not worry as it is not important now. just remember to write it.)
wWinMain is an Entry function name similar to main() function in C.
hinstance is a handle(variable) to program running instance. It is a unique number assigned by operating system.
hprevinstance is always null. It is not used in Win32 systems.
szCmdLine is pointer to command line string.
nCmdShow is a parameter that controls how the window should be displayed on screen (i.e. maximized, minimized). We will discuss it later.
MessageBox is a function that shows a minimal dialog box.
First parameter is handle to owner of this MessageBox. In our program there is no owner of this MessageBox. More about owner window later. Since there are no owner of this window the first parameter is passed NULL.
Second Parameter is the message to be displayed.
Third Parameter is caption or title message of the MessageBox.
Fourth Message is a defined constant that represents OK button .
Important Typedefs:
typedef HANDLE HINSTANCE; //HANDLE is void*
typedef WCHAR *PWSTR; // WCHAR is wchar_t
Note:
wchar_t is UNICODE equivalent to char datatype.
Ex:-
char a = ‘m’;
wchar_t a = L’a’; //L is used to denote that ‘a’ is Unicode character and not an ASCII character.
WCHAR A =L’a’; // same as wchar_t
char a[100]=”hello world”; // ASCII String
wchar_t a[100] =L”hello world”; // Unicode string
WCHAR a[100] == L”hello world”; // WCHAR is just typedef of wchar_t
strlen(a); //returns the length of ASCII string;
wcslen(a); // returns the lenght of Unicode string;
Rule:
For string functions
strcmp --> wcscmp (ASCII --> Unicode)
strcpy --> wcscpy (ASCII --> Unicode)
strcat -->wcscat (ASCII --> Unicode)
....
....
etc.
<string.h> --> <wchar.h> (ASCII --> Unicode)
|
|