Writing the first ReactOS application.

Got a ReactOS tutorial to share? Drop it in here

Moderator: Moderator Team

Davy Bartoloni
Posts: 1483
Joined: Wed Jan 04, 2006 11:31 pm
Location: Cuneo
Contact:

Writing the first ReactOS application.

Post by Davy Bartoloni » Mon Dec 29, 2008 10:14 pm

hi! to everyone
this post is a simple ENG porting of : http://www.reactos.org/forum/viewtopic.php?f=15&t=6355

I'm going to explain how to build your own ReactOS application using ROSBE :)
the examples works without changes, if source code was located in c:\ReactOS-SRC and ROSBE is installed correctly.

all the examples are named : firstapp.exe, and can builded by a simple: MAKE FIRSTAPP from ROSBE CONSOLE
i edit the c-code using the standard NOTEPAD... and it can be compiled using only ReactOS ( however, I used xp. )

first, create a directory called FIRSTAPP located in C:\ReactOS-src\base\setup
i used Setup-directory because it contains WELCOME application.. that can be a good source of example code...
Image

now.. edit the setup.rbuild located in SETUP directory and ADD then new FIRSTAPP entry.
Image

open FIRSTAPP directory and create a new rbuild file named: firstapp.rbuild
copy this code on it:

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
<module name="firstapp" type="win32gui" installbase="system32" installname="firstapp.exe" unicode="yes">
	<bootstrap installbase="$(CDOUTPUT)" />
	<include base="firstapp">.</include>
	<library>kernel32</library>
	<library>gdi32</library>
	<library>user32</library>
	<file>firstapp.c</file>
</module>
Image

now.. is time to write the c-code... is a good idea to write some REM, something like that:
( GNU licence infos.. date... developer... )

Code: Select all

/*
 * ReactOS Application
 * Copyright (C) 2008-2009 :P Davy Bartoloni :P
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: firstapp.c 2008-28-12 21:17:12 $
 *
 * COPYRIGHT:   See COPYING in the top level directory
 * PROJECT:     ReactOS Simple EXAMPLE
 * FILE:        base\setup\firstapp.c
 * PROGRAMMERS: Davy Bartoloni <davy@bartoloni.org>
 */
next... write this code:

Code: Select all

#include <windows.h> // managing windows...
#include <tchar.h>   // for TEXT function ( unicode strings )

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
     //this is the first Message BOX...
     MessageBox(
		0,
		TEXT("This is my first Reactos-Application"),
		TEXT("This is a MESSAGEBOX"),
	 	MB_OK
		);

     //and this is the second... the code is the same, but on a single-line.
     MessageBox(0,TEXT("This is another MESSAGEBOX"),TEXT("Press OK..."), MB_OK);

return(0);
}

Image

the full code was:

Code: Select all

/*
 * ReactOS Application
 * Copyright (C) 2008-2009 :P Davy Bartoloni :P
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: firstapp.c 2008-28-12 21:17:12 $
 *
 * COPYRIGHT:   See COPYING in the top level directory
 * PROJECT:     ReactOS Simple COMPILER-TEST
 * FILE:        base\setup\firstapp.c
 * PROGRAMMERS: Davy Bartoloni <davy@bartoloni.org>
 */


#include <windows.h> // managing windows...
#include <tchar.h>   // for TEXT function ( unicode strings )

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
     //this is the first Message BOX...
     MessageBox(
		0,
		TEXT("This is my first Reactos-Application"),
		TEXT("This is a MESSAGEBOX"),
	 	MB_OK
		);

     //and this is the second... the code is the same, but on a single-line.
     MessageBox(0,TEXT("This is another MESSAGEBOX"),TEXT("Press OK..."), MB_OK);

return(0);
}
now... JUST go on ROSBE shell... and type: MAKE FIRSTAPP
Image

the compiled program are created on directory: C:\ReactOS-src\output-i386\base\setup\firstapp
Image
now, copy FIRSTAPP.EXE on ReactOS desktop.. and double-click it!
( in Q-EMU just MOUNT the c-drive image using ROSTE, and copy firstapp.exe on UNIT:\Documents and Settings\Administrator\Desktop )
( in win.. just doubleclick the program )
Image

now, we can introduce a simple DEBUG output...
this is the code:

Code: Select all

OutputDebugStringW(L"Example Debug-line : Started first example <firstapp.exe>\n");
place it before the first MessageBox

Code: Select all

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
     OutputDebugStringW(L"Example Debug-line : Started first example <firstapp.exe>\n");
     //this is the first Message BOX...
     MessageBox(
		0,
now.. start ROS (debug version) in QEMU and the debug-output will appear in the debug window
Image

NOW, THE SECOND EXAMPLE.. a simple WINDOW

edit the firstapp.c.. and put in it this code:

Code: Select all

/*
 * ReactOS Application
 * Copyright (C) 2008-2009 :P Davy Bartoloni :P
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: firstapp.c 2008-28-12 21:17:12 $
 *
 * COPYRIGHT:   See COPYING in the top level directory
 * PROJECT:     ReactOS Simple NOT ACTIVE WINDOW EXAMPLE
 * FILE:        base\setup\firstapp.c
 * PROGRAMMERS: Davy Bartoloni <davy@bartoloni.org>
 */

#include <windows.h>
#include <tchar.h>

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

{
	CreateWindowEx(
                    0,
                    WC_DIALOG,
                    TEXT("My First Window"), // This is the title :)
                    WS_OVERLAPPEDWINDOW | WS_VISIBLE, // Some attributes...
                    200, // orizontal starting coord
                    100, // vertical starting coord
                    400, // lenght of the window
                    300, // Height of the window
                    NULL,
                    NULL,
                    NULL,
                    NULL
                );

	//and now, for preventing end of the application... a Message Box.

        MessageBox(
                    NULL,
                    TEXT("Press OK to END application."), // main Text...
                    TEXT("I'm a Message BOX"),	// title...
                    0   // 0 is the standard "OK"
                );
	return 0;
}
now.. building it with the usual MAKE FIRSTAPP .. the result is:
Image

example number 3... ACTIVE WINDOW WITH SOME TEXTS
this is the code...

Code: Select all

/*
 * ReactOS Application
 * Copyright (C) 2008-2009 :P Davy Bartoloni :P
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: firstapp.c 2008-28-12 21:17:12 $
 *
 * COPYRIGHT:   See COPYING in the top level directory
 * PROJECT:     ReactOS Simple ACTIVE WINDOW EXAMPLE
 * FILE:        base\setup\firstapp.c
 * PROGRAMMERS: Davy Bartoloni <davy@bartoloni.org>
 */

#include <windows.h>
#include <tchar.h>

TCHAR *applicationtitle=TEXT("Simple REACTOS application");
TCHAR *firsttext=TEXT("This is an ACTIVE\r\nWINDOW...");
TCHAR *secondtext=TEXT("CALLBACK with WM_PAINT and DESTROY");

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
  switch (msg)
  {
    case WM_PAINT:   // drawing the content of window.
    {
      PAINTSTRUCT ps;
      HDC dc;
      RECT r;
      GetClientRect(hwnd,&r);
      dc=BeginPaint(hwnd,&ps);
      DrawText(dc,firsttext,-1,&r,DT_CENTER|DT_VCENTER);  // first line of text...
      DrawText(dc,secondtext,-1,&r,DT_SINGLELINE|DT_CENTER|DT_VCENTER); // second line of text...
      EndPaint(hwnd,&ps);
      break;
    }

    case WM_DESTROY:   // closing the window..
      PostQuitMessage(0);
      break;

    default:
      return DefWindowProc(hwnd, msg, wparam, lparam);
  }
  return 0;
}

// the winmain...

int WINAPI _tWinMain(HINSTANCE hInstance,
		HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
  // Window class and registerclass...

  WNDCLASS wc;
  HWND hwnd;
  MSG msg;

  wc.style=CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc=WindowProc;
  wc.cbClsExtra=0;
  wc.cbWndExtra=0;
  wc.hInstance=hInstance;
  wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
  wc.hCursor=LoadCursor(NULL,IDC_ARROW);
  wc.hbrBackground=(HBRUSH)COLOR_WINDOWFRAME;
  wc.lpszMenuName=NULL;
  wc.lpszClassName=applicationtitle;

  if (!RegisterClass(&wc))
    return 0;
    // create a window from 0,0 to 400,120
  hwnd = CreateWindow(applicationtitle,applicationtitle,
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,CW_USEDEFAULT,400,120,
    NULL,NULL,hInstance,NULL);

  if (!hwnd)
    return 0;

  ShowWindow(hwnd,nCmdShow);
  UpdateWindow(hwnd);

   // main loop...

  while (GetMessage(&msg,NULL,0,0) > 0)
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
return 0;
}
and the compiled example...
Image

now... the first graphical app...
create the RES folder on : C:\ReactOS-src\base\setup\firstapp
Image

create firstapp.rc on C:\ReactOS-src\base\setup\firstapp and put this code in it...

Code: Select all

#include "resource.h"

IDB_IMMAGINE           BITMAP DISCARDABLE     "res/immagine.bmp"
Image

edit firstapp.rbuild and add this entry: firstapp.rc
like this:

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
<module name="firstapp" type="win32gui" installbase="system32" installname="firstapp.exe" unicode="yes">
	<bootstrap installbase="$(CDOUTPUT)" />
	<include base="firstapp">.</include>
	<library>kernel32</library>
	<library>gdi32</library>
	<library>user32</library>
	<file>firstapp.c</file>
	<file>firstapp.rc</file>
</module>
Image

now.. create resource.h on C:\ReactOS-src\base\setup\firstapp
and write this line in it...

Code: Select all

#define IDB_IMMAGINE                    101
Image

ok... now download this image: http://www.wcn.it/immagine.bmp and put the bitmap on C:\ReactOS-src\base\setup\firstapp\res
(full image created by Rendergraf , THX! )
Image

now... is the c-code time...
edit firstapp.c ...

Code: Select all

/*
 * ReactOS Application
 * Copyright (C) 2008-2009 :P Davy Bartoloni :P
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* $Id: firstapp.c 2008-28-12 21:17:12 $
 *
 * COPYRIGHT:   See COPYING in the top level directory
 * PROJECT:     ReactOS Simple BITMAP IN A WINDOW
 * FILE:        base\setup\firstapp.c
 * PROGRAMMERS: Davy Bartoloni <davy@bartoloni.org>
 */

#include <windows.h>
#include "resource.h"
#include <tchar.h>

TCHAR *g_szClassName = TEXT("BITMAP IN A WINDOW");
HBITMAP immagine = NULL;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
			immagine = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_IMMAGINE));
			if(immagine == NULL)
				MessageBox(hwnd, TEXT("Error loading BITMAP."), TEXT("Warning!"), MB_OK | MB_ICONEXCLAMATION);
		break;
		case WM_CLOSE:
			DestroyWindow(hwnd);
		break;
		case WM_PAINT:
		{
			BITMAP bm;
			PAINTSTRUCT ps;

			HDC hdc = BeginPaint(hwnd, &ps);

			HDC hdcMem = CreateCompatibleDC(hdc);
			HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, immagine);

			GetObject(immagine, sizeof(bm), &bm);

			BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

			SelectObject(hdcMem, hbmOld);
			DeleteDC(hdcMem);

			EndPaint(hwnd, &ps);
		}
		break;
		case WM_DESTROY:
			DeleteObject(immagine);
			PostQuitMessage(0);
		break;
		default:
			return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}

int WINAPI _tWinMain(HINSTANCE hInstance,
		HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

{
	WNDCLASSEX wc;
	HWND hwnd;
	MSG Msg;

	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.style		 = 0;
	wc.lpfnWndProc	 = WndProc;
	wc.cbClsExtra	 = 0;
	wc.cbWndExtra	 = 0;
	wc.hInstance	 = hInstance;
	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = g_szClassName;
	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, TEXT("Error registering class."), TEXT("Warning!"),
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	hwnd = CreateWindowEx(
		WS_EX_CLIENTEDGE,
		g_szClassName,
		TEXT("ReactOS Logo"),
		WS_OVERLAPPEDWINDOW,
		100, 100, 224, 214,
		NULL, NULL, hInstance, NULL);

	if(hwnd == NULL)
	{
		MessageBox(NULL, TEXT("Error creating window."), TEXT("Warning!"),
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}
Compile it.. and...
Image

Some other examples.. on italian forum...

Thanks for your patience.. and sorry for my poor english :P

Davy

vicmarcal
Test Team
Posts: 2732
Joined: Mon Jul 07, 2008 12:35 pm

Re: Writing the first ReactOS application.

Post by vicmarcal » Tue Dec 30, 2008 2:24 am

NICE really NICE.Thanks or ur work :D
Image

Davy Bartoloni
Posts: 1483
Joined: Wed Jan 04, 2006 11:31 pm
Location: Cuneo
Contact:

Re: Writing the first ReactOS application.

Post by Davy Bartoloni » Tue Dec 30, 2008 2:56 am

:)

Elledan
Posts: 363
Joined: Sat Jan 01, 2005 3:18 pm
Location: Netherlands
Contact:

Re: Writing the first ReactOS application.

Post by Elledan » Tue Dec 30, 2008 1:20 pm

Very informative, thanks :)

Freshbru
Posts: 1
Joined: Sun Jan 04, 2009 1:36 pm

Re: Writing the first ReactOS application.

Post by Freshbru » Sun Jan 04, 2009 2:08 pm

:D A big thank you for this excellent tutorial. Much appreciate.

Happy New Year or should I say Felice Anno Nuovo :wink:

Davy Bartoloni
Posts: 1483
Joined: Wed Jan 04, 2006 11:31 pm
Location: Cuneo
Contact:

Re: Writing the first ReactOS application.

Post by Davy Bartoloni » Sun Jan 04, 2009 8:28 pm

I hope it can help some "future new developer" :)

piepieonline
Posts: 3
Joined: Mon May 19, 2008 6:50 am

Re: Writing the first ReactOS application.

Post by piepieonline » Fri Jan 09, 2009 6:41 am

Is there any way to program in other languages at the moment? Because that would be much more helpful for me...

EDIT: Corrected spelling mistakes.

led-bloon
Posts: 27
Joined: Fri Jan 09, 2009 10:08 am

Re: Writing the first ReactOS application.

Post by led-bloon » Fri Jan 09, 2009 10:38 am

First off, greetings to all. I have been monitoring this site for months
and have finally decided to join and (hopefully) contribute.

In answer to your question re: other programming languages, I have been using Rapidq for some years
(under XP) and find it brilliant. I have tried it under ReactOS and on the whole most of the components
work as expected. It could be worth a look...here:-
http://tech.groups.yahoo.com/group/rapidq/

Rapidq is a basic compiler/interpreter which produces "exe" programs with the interpreter built-in.
It is totally free to join the group and free to use plus there are hundreds, if not thousands, of programs
and example code to try.

One drawback when compiling under ReactOS is that many (100+) temporary files are created (a bug I would like
to find and fix) instead of the customary 4-5 temp files, when compiling source code. However a simple batch file
to delete these files can be used to "clean up" the folder.

Rgds
Don
AMD Athlon 2650e - Windows XP Home SP3 - VMWare Player v2

piepieonline
Posts: 3
Joined: Mon May 19, 2008 6:50 am

Re: Writing the first ReactOS application.

Post by piepieonline » Fri Jan 09, 2009 11:23 am

Yea, I was thinking vb6 or vb.net type things

GoBusto
Posts: 579
Joined: Fri Jan 25, 2008 11:13 am
Location: UK
Contact:

Re: Writing the first ReactOS application.

Post by GoBusto » Fri Jan 09, 2009 5:04 pm

piepieonline wrote:Yea, I was thinking vb6 or vb.net type things
Look at http://www.reactos.org/en/screenshots.html and you'll see this under 0.3.4: http://www.reactos.org/media/screenshot ... 34_vb5.jpg

pbreneman
Posts: 78
Joined: Wed Feb 25, 2009 5:12 am

Re: Writing the first ReactOS application.

Post by pbreneman » Tue Jan 04, 2011 7:30 pm

Here is a *very* easy way to compile and run a GUI program written with Free Pascal and the fpGUI widget set. The compiler and everything needed is in a 3.2 MB zip file and no install program is needed (just unzip).

I just tried the i386 Win32 zip on this page and it works good except the screen colors are not correct (in VMware):
http://www.turbocontrol.com/easyfpgui.htm

And the programs developed using Free Pascal and fpGUI are cross-platform!

pbreneman
Posts: 78
Joined: Wed Feb 25, 2009 5:12 am

Re: Writing the first ReactOS application.

Post by pbreneman » Fri Jan 07, 2011 9:35 pm

The fpGUI minimal Free Pascal distro I mentioned before is an easy way to see a Free Pascal GUI program work in ReactOS. But note that fpGUI just uses the GDI layer and not the normal Windows widgets. fpGUI is useful for low-resource specialized cross-platform applications but not everyone needs those.

If you use Free Pascal and Lazarus then you'll use the native widgets:
http://lazarus.freepascal.org/

If you want to see the potential of Free Pascal and Lazarus for ReactOS application development, you might consider doing what I did and install the 220MB CodeTyphon download in a virtual machine with Windows:
http://www.pilotlogic.com/
CodeTyphon takes a while to install since it compiles everything from source.

You can see what is possible on Windows (see the two links at the bottom of this page):
http://www.pilotlogic.com/codetyphon_he ... _areas.htm

I hope to try a Lazarus install in ReactOS soon. If anyone tries this please share your experience.

Haos
Test Team
Posts: 2954
Joined: Thu Mar 22, 2007 5:42 am
Contact:

Re: Writing the first ReactOS application.

Post by Haos » Fri Jan 07, 2011 10:03 pm

This is a tutorial thread, not a discussion. Please do not steal it, if you want to present something, ROS-related - then create your own thread. If you want to discuss stuff, please use appropriate board.

pbreneman
Posts: 78
Joined: Wed Feb 25, 2009 5:12 am

Re: Writing the first ReactOS application.

Post by pbreneman » Sat Jan 08, 2011 1:11 am

Sorry for inviting discussion. You are correct that it doesn't belong here. I'll continue elsewhere on the forum. I'm trying to find easy ways to introduce PC programming and using free and open-source compilers and IDEs on ROS looks attractive so the topic of introductory tutorials is of particular interest to me. Thanks to all who worked on ROS!

Qrchack
Posts: 3
Joined: Tue Apr 26, 2011 12:20 pm

Re: Writing the first ReactOS application.

Post by Qrchack » Thu Apr 28, 2011 1:11 am

I've got error when compiling the one with graphics

Image

setup/firstapp/firstapp.c

Code: Select all

    /*
    * ReactOS Application
    * Copyright (C) 2008-2009 :P Davy Bartoloni :P
    *
    * This library is free software; you can redistribute it and/or
    * modify it under the terms of the GNU Lesser General Public
    * License as published by the Free Software Foundation; either
    * version 2.1 of the License, or (at your option) any later version.
    *
    * This library is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    * Lesser General Public License for more details.
    *
    * You should have received a copy of the GNU Lesser General Public
    * License along with this library; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */

    /* $Id: firstapp.c 2008-28-12 21:17:12 $
    *
    * COPYRIGHT:   See COPYING in the top level directory
    * PROJECT:     ReactOS Simple BITMAP IN A WINDOW
    * FILE:        base\setup\firstapp.c
    * PROGRAMMERS: Davy Bartoloni <davy@bartoloni.org>
    */

    #include <windows.h>
    #include "resource.h"
    #include <tchar.h>

    TCHAR *g_szClassName = TEXT("BITMAP IN A WINDOW");
    HBITMAP immagine = NULL;

    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
       switch(msg)
       {
          case WM_CREATE:
             immagine = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_IMMAGINE));
             if(immagine == NULL)
                MessageBox(hwnd, TEXT("Error loading BITMAP."), TEXT("Warning!"), MB_OK | MB_ICONEXCLAMATION);
          break;
          case WM_CLOSE:
             DestroyWindow(hwnd);
          break;
          case WM_PAINT:
          {
             BITMAP bm;
             PAINTSTRUCT ps;

             HDC hdc = BeginPaint(hwnd, &ps);

             HDC hdcMem = CreateCompatibleDC(hdc);
             HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, immagine);

             GetObject(immagine, sizeof(bm), &bm);

             BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

             SelectObject(hdcMem, hbmOld);
             DeleteDC(hdcMem);

             EndPaint(hwnd, &ps);
          }
          break;
          case WM_DESTROY:
             DeleteObject(immagine);
             PostQuitMessage(0);
          break;
          default:
             return DefWindowProc(hwnd, msg, wParam, lParam);
       }
       return 0;
    }

    int WINAPI _tWinMain(HINSTANCE hInstance,
          HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

    {
       WNDCLASSEX wc;
       HWND hwnd;
       MSG Msg;

       wc.cbSize       = sizeof(WNDCLASSEX);
       wc.style       = 0;
       wc.lpfnWndProc    = WndProc;
       wc.cbClsExtra    = 0;
       wc.cbWndExtra    = 0;
       wc.hInstance    = hInstance;
       wc.hIcon       = LoadIcon(NULL, IDI_APPLICATION);
       wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
       wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
       wc.lpszMenuName  = NULL;
       wc.lpszClassName = g_szClassName;
       wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

       if(!RegisterClassEx(&wc))
       {
          MessageBox(NULL, TEXT("Error registering class."), TEXT("Warning!"),
             MB_ICONEXCLAMATION | MB_OK);
          return 0;
       }

       hwnd = CreateWindowEx(
          WS_EX_CLIENTEDGE,
          g_szClassName,
          TEXT("ReactOS Logo"),
          WS_OVERLAPPEDWINDOW,
          100, 100, 224, 214,
          NULL, NULL, hInstance, NULL);

       if(hwnd == NULL)
       {
          MessageBox(NULL, TEXT("Error creating window."), TEXT("Warning!"),
             MB_ICONEXCLAMATION | MB_OK);
          return 0;
       }

       ShowWindow(hwnd, nCmdShow);
       UpdateWindow(hwnd);

       while(GetMessage(&Msg, NULL, 0, 0) > 0)
       {
          TranslateMessage(&Msg);
          DispatchMessage(&Msg);
       }
       return Msg.wParam;
    }
setup/firstapp/firstapp.rbuild

Code: Select all

    <?xml version="1.0"?>
    <!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
    <module name="firstapp" type="win32gui" installbase="system32" installname="firstapp.exe" unicode="yes">
       <bootstrap installbase="$(CDOUTPUT)" />
       <include base="firstapp">.</include>
       <library>kernel32</library>
       <library>gdi32</library>
       <library>user32</library>
       <file>firstapp.c</file>
       <file>firstapp.rc</file>
    </module>
setup/firstapp/firstapp.rc

Code: Select all

    #include "resource.h"

    IDB_IMMAGINE           BITMAP DISCARDABLE     "res/immagine.bmp"
setup/firstapp/resource.h

Code: Select all

    #define IDB_IMMAGINE                    101
setup/firstapp/res/immagine.bmp EXISTS

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests