Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

C complete tutorial part 2-The first window

2pi

Newbie Spellweaver
Joined
Oct 30, 2009
Messages
40
Reaction score
2
Nowdays almost all programs are controled by GUI(Graphical User Interface),with windows,buttons,labels,etc...
You had seen what c programs ALWAYS need a main function(int main())where the program has started,but in windows programs that function's called WinMain(obvious),the functions in a windows program're of two types:The functions that you program(more or less like the functions of console programs)and functions of the windows operating system.
All windows functions're on DLL (dynamic-linked libraries),the group of DLL it's called API(Application Programming Interface).This DLLs are:kernel32.dll, user32.dll and gdi32.dll.

Now let's go:

The first Windows GUI Program
Create the new project in |Project/Create|,give to him a name,and change the directory,in "options" click in "single user",until here all like the first tutorial ok:cool:
1.In "type of project"click in "Windows Application".
2.Click in create and when show "Do you want to use the wizard to generate the application skeleton?" click "yes"
3.In the dialog box,"Application characteristics"in the "Type of apllication" click in "Dialog based" and after "ok".
4.Now click in "ok"
5.In the window "Compiler settings", click in [Next]. In the window "Linker settings", click [Next]. In the window "Debugger settings",click [Finish].
Tcharam!All cool,the code's ready for compile now prees f9 and after ctrl+f5 and see it:
http://www.numaboa.com/images/stories/info_tuto/tutoC/testedlg.png
The code generated by LCC
Don't be afraid!After you will learn all functions of that code,but now look him:
Code:
/*@@ Wedit generated application. Written Sat Jan 23 13:12:48 2010
 @@header: c:\lcc\projects\testres.h
 @@resources: c:\lcc\projects\test.rc
 Do not edit outside the indicated areas */
/*<---------------------------------------------------------------------->*/
/*<---------------------------------------------------------------------->*/
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <string.h>
#include "testres.h"
/* --- The following code comes from C:\lcc\lib\wizard\dlgbased.tpl. */
/*<---------------------------------------------------------------------->*/

/*
Template for a dialog based application. The main procedure for this
template is the DialogFunc below. Modify it to suit your needs.
*/
/* prototype for the dialog box function. */
static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
/*
Win main just registers a class of the same type that the dialog class, and
then calls DialogBox. Then it exits. The return value is the return value of
the dialog procedure.
*/

int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASS wc;
	INITCOMMONCONTROLSEX cc;

	memset(&wc,0,sizeof(wc));
	wc.lpfnWndProc = DefDlgProc;
	wc.cbWndExtra = DLGWINDOWEXTRA;
	wc.hInstance = hinst;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
	wc.lpszClassName = "test";
	RegisterClass(&wc);
	memset(&cc,0,sizeof(cc));
	cc.dwSize = sizeof(cc);
	cc.dwICC = 0xffffffff;
	InitCommonControlsEx(&cc);

	return DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINDIALOG), NULL, (DLGPROC) DialogFunc);

}

/*
You should add your initialization code here. This function will be called
when the dialog box receives the WM_INITDIALOG message.
*/
static int InitializeApp(HWND hDlg,WPARAM wParam, LPARAM lParam)
{
	return 1;
}

/*
This is the main function for the dialog. It handles all messages. Do what your
application needs to do here.
*/
static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	/* This message means the dialog is started but not yet visible.
	   Do All initializations here 
        */
	case WM_INITDIALOG:
		InitializeApp(hwndDlg,wParam,lParam);
		return TRUE;
	/* By default, IDOK means close this dialog returning 1, IDCANCEL means
           close this dialog returning zero
        */
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
			case IDOK:
				EndDialog(hwndDlg,1);
				return 1;
			case IDCANCEL:
				EndDialog(hwndDlg,0);
				return 1;
		}
		break;
        /* By default, WM_CLOSE is equivalent to CANCEL */
	case WM_CLOSE:
		EndDialog(hwndDlg,0);
		return TRUE;
	
	}
	return FALSE;
}
That code have 3 functions WinMain,InitializaApp,DialogFunc.The InitializaApp don't make anything just return 1,it's just used if you want make something before the window initialization,next tutorial we will to learn the functions WinMain and DialogFunc.

2pi Considerations:
Oh!The Windows API code it's so fantastic!He's hard,he's big,he's stupid,so do you wanna learn the c commands with windows programs or console programs?Ok i think what console is more easy to learn so,the next tutorial will be...
Basic C commands!
Are you ready to the black screen?

2pi
 
Back
Top