[ mostart @ 19.10.2006. 15:06 ] @
trebao bih neke upute kako da ovu aplikaciju iz C# prebacim u win32 API!
radi se o jednostavnom proogramu za crtanje. ima jedan prozor i 5 dugmadi kojima mjenjam boje.


using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;



namespace crta
{
//
//kratak opis za obrazac form
//

public class Form1 : System.Windows.Forms.Form
{

Bitmap bitmap = null;
Bitmap curBitmap = null;
Graphics curGraphics;
SolidBrush curBrush, black, red, blue, grin, grej, jelov;
Size fullSize;

int x, y;
bool write;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;


private System.ComponentModel.Container components = null;

public Form1()
{
//
// Neophodno za podršku Windows Forms Designera
//
InitializeComponent();

SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);

}

///
/// Oslobodite korištene resurse.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(584, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Obriši sve";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.Black;
this.button2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button2.Location = new System.Drawing.Point(0, 0);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 23);
this.button2.TabIndex = 2;
this.button2.Text = "Crna";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.BackColor = System.Drawing.Color.Red;
this.button3.Location = new System.Drawing.Point(64, 0);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 23);
this.button3.TabIndex = 3;
this.button3.Text = "Crvena";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.BackColor = System.Drawing.Color.Blue;
this.button4.Location = new System.Drawing.Point(128, 0);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(64, 23);
this.button4.TabIndex = 4;
this.button4.Text = "Plava";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.BackColor = System.Drawing.Color.Green;
this.button5.Location = new System.Drawing.Point(192, 0);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(64, 23);
this.button5.TabIndex = 5;
this.button5.Text = "Zelena";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.BackColor = System.Drawing.Color.Yellow;
this.button6.Location = new System.Drawing.Point(256, 0);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(64, 23);
this.button6.TabIndex = 6;
this.button6.Text = "Žuta";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(320, 0);
this.button7.Name = "button7";
this.button7.TabIndex = 7;
this.button7.Text = "Gumica";
this.button7.Click += new System.EventHandler(this.button7_Click);
this.button7.Paint += new System.Windows.Forms.PaintEventHandler(this.onPaint);
this.button7.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouseDown);
//
// button8
//
this.button8.Location = new System.Drawing.Point(456, 0);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(96, 23);
this.button8.TabIndex = 8;
this.button8.Text = "Bože Sacuvaj";
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.LightGray;
this.ClientSize = new System.Drawing.Size(648, 266);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Cursor = System.Windows.Forms.Cursors.Hand;
this.HelpButton = true;
this.Name = "Form1";
this.Text = "CRTA!";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouseDown);
this.Load += new System.EventHandler(this.Form1_Load);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.mouseUp);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.onPaint);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.mouseMove);
this.ResumeLayout(false);

}
#endregion

///
/// Glavna ulazna tocka za aplikaciju.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

string m_strFileName = "";
public void RefreshFormBackground()
{
// Clone the form and use it as a background image
curBitmap = bitmap.Clone(new Rectangle(0, 0, this.Width, this.Height),
bitmap.PixelFormat);
this.BackgroundImage = curBitmap;

}

private void Form1_Closed(object sender, System.EventArgs e)
{


curBrush.Dispose();
curGraphics.Dispose();

}

private void Form1_Load(object sender, System.EventArgs e)
{
// Get form size
fullSize = SystemInformation.PrimaryMonitorMaximizedWindowSize;
// Create a bitmap
bitmap = new Bitmap(fullSize.Width, fullSize.Height);
// Give the bitmap to a graphics object
curGraphics = Graphics.FromImage(bitmap);
// Use the background color of the form
curGraphics.Clear(this.BackColor);



black = new SolidBrush(Color.Black);
red = new SolidBrush(Color.Red);
blue = new SolidBrush(Color.Blue);
jelov = new SolidBrush(Color.Yellow);
grin = new SolidBrush(Color.Green);
grej = new SolidBrush(Color.LightGray);
curBrush = grej;
write = false;
}


private void button1_Click(object sender, System.EventArgs e)
{
curGraphics.Clear(this.BackColor);
RefreshFormBackground();
}

private void mouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// At every mouse mouse, get the current x and y position
// Capture the background
x = e.X;
y = e.Y;
RefreshFormBackground();
}

private void mouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
write = false;
}

private void mouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
x = e.X;
y = e.Y;
write = true;
}


private void onPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// When mouse is down, fill an ellipse at the current x and y position
if (write)
{
curGraphics.FillEllipse(curBrush, x, y, 5, 5);
}
}

private void button2_Click(object sender, System.EventArgs e)
{
curBrush = black;
}

private void button3_Click(object sender, System.EventArgs e)
{
curBrush = red;
}

private void button4_Click(object sender, System.EventArgs e)
{
curBrush = blue;
}

private void button5_Click(object sender, System.EventArgs e)
{
curBrush = grin;
}

private void button6_Click(object sender, System.EventArgs e)
{
curBrush = jelov;
}

private void button7_Click(object sender, System.EventArgs e)
{
curBrush = grej;
}

private void button8_Click(object sender, System.EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
saveFileDialog1.Title = "Save an Image File";
saveFileDialog1.ShowDialog();
// If the file name is not an empty string open it for saving.
if(saveFileDialog1.FileName != "")
{
// Saves the Image via a FileStream created by the OpenFile method.
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
// Saves the Image in the appropriate ImageFormat based upon the
// File type selected in the dialog box.
// NOTE that the FilterIndex property is one-based.
switch(saveFileDialog1.FilterIndex)
{
case 1 :
this.button2.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;

case 2 :
this.button2.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;

case 3 :
this.button2.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Gif);
break;
}

fs.Close();
}
}
}
}






[Ovu poruku je menjao mostart dana 23.10.2006. u 16:11 GMT+1]

[Ovu poruku je menjao mostart dana 23.10.2006. u 16:12 GMT+1]
[ passwdpasswd @ 19.10.2006. 15:27 ] @
Ne kuzim u cem je problem......?

Kako mislis preko Win32Apija?.. ako mislis da znaci samo apije pozivas bez bilo koje C# fje onda prosto uradi RegisterClassEx, CreateWindowEx, ShowWindow i UpdateWindow!

Za kreiranje dugmadi isto koristi CreateWindow sa "BUTTON" style-om.. mozes da ih pravis kao ownerdraw pa ih onda sam crtas, ili jednostavno napravis Rectangle() pa sa CreateRectRgn napravis kao regiju i onda dalje s njom radis... za rad sa fajlovima imas OpenFile, WriteFile, ReadFile, OpenFileMapping, CreateFile, FileExists etc.

Za crtanje i mjenjanje boja imas GDI fje [Rectangle, Poly, SelectObject, GetStockBrush, DeleteObject....]

Za dialoge imas GetOpenFileName, GetSaveFileName etc.

Evo ti jedan primjer iz delphia [isti racku i u BCB-u] gdje sam s apijima napravio listview, znaci bez koristenja LISTVIEW klase.. od nule :)

Code:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CommCtrl, CommDlg, ExtCtrls;




type
  TForm2 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    GroupBox2: TGroupBox;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Shape1: TShape;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    procedure Button4Click(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);

    procedure LButtonDown(var Msg:TMessage); message WM_LBUTTONDOWN;
  private
    { Private declarations }
  public
    { Public declarations }
    _hdc:HDC;
    pocetna:integer;
    _hbrush:HBRUSH;
    form2_paint:boolean;
    form2_paint_color:COLORREF;
    form2_item:boolean;
    form2_item_color:COLORREF;
    red:array [1..18,1..3] of string;
  end;



var
  Form2: TForm2;

implementation

{$R *.dfm}

var brojac:integer;





procedure UbaciRed(br:integer;s1,s2,s3:string;posebna:boolean;boja:COLORREF);
begin
Form2.red[br,1]:=s1;
Form2.red[br,2]:=s2;
Form2.red[br,3]:=s3;
 Form2._hdc:=GetDC(Form2.Handle);
 if posebna then SetBkColor(Form2._hdc,boja) else
  if Form2.form2_item then
  SetBkColor(Form2._hdc,RGB(GetRValue(Form2.form2_item_color),GetGValue(Form2.form2_item_color),GetBValue(Form2.form2_item_color)))
  else SetBkColor(Form2._hdc,RGB($d4,$ec,$fb));
 SetTextColor(Form2._hdc,RGB(0,0,1));
 TextOut(Form2._hdc,11,16+(br*20),PChar(Form2.red[br,1]),length(Form2.red[br,1]));
 TextOut(Form2._hdc,121,16+(br*20),PChar(Form2.red[br,2]),length(Form2.red[br,2]));
 TextOut(Form2._hdc,241,16+(br*20),PChar(Form2.red[br,3]),length(Form2.red[br,3]));
 ReleaseDC(Form2.Handle,Form2._hdc);
end;







procedure TForm2.LButtonDown(var Msg:TMessage);
var x,y:integer;
    broj_reda:integer;
    r:TRect;
begin
x:=Msg.LParamLo;
y:=Msg.LParamHi-35;
broj_reda:=(y div 20)+1;

 if (x>10) and (x<360) and (Msg.LParamHi>35) and (Msg.LParamHi<410) 
    and (red[broj_reda,1]<>'') and (red[broj_reda,2]<>'') and (red[broj_reda,3]<>'') then
  begin
  Form2._hdc:=GetDC(Form2.Handle);
  Form2._hbrush:=CreateSolidBrush(RGB(255,0,0));
  SelectObject(Form2._hdc,Form2._hbrush);
  r.Left:=10;
  r.Right:=360;
  r.Bottom:=35+(broj_reda*20);
  r.Top:=r.Bottom-20;
  FillRect(Form2._hdc,r,Form2._hbrush);

  //pravljenje 3 kolone
  MoveToEx(_hdc,120,10,NIL);
  LineTo(_hdc,120,410);
  MoveToEx(_hdc,240,10,NIL);
  LineTo(_hdc,240,410);

  //izcrtavanje linija
  for y:=1 to 18 do
  begin
   MoveToEx(_hdc,10,35+(y*20),NIL);
   LineTo(_hdc,360,35+(y*20));
  end;

  UbaciRed(broj_reda,red[broj_reda,1],red[broj_reda,2],red[broj_reda,3],true,RGB(255,0,0));
  DeleteObject(Form2._hdc);
  ReleaseDC(Form2.Handle,Form2._hdc);

end;

end;





procedure TForm2.Button1Click(Sender: TObject);
begin
 if brojac=18 then ShowMessage('Ne stane vise :P') else
 begin
 inc(brojac);
 UbaciRed(brojac,Edit1.Text,Edit2.Text,Edit3.Text,false,RGB(0,0,0));
 end;
end;

procedure TForm2.FormCreate(Sender: TObject);
var z:integer;
begin
form2_paint:=false;
form2_item:=false;
brojac:=0;
 for z:=1 to 18 do
  begin
  red[z][1]:='';
  red[z][2]:='';
  red[z][3]:='';
  end;

end;
procedure TForm2.FormPaint(Sender: TObject);
var y:integer;
begin
Form2._hdc:=GetDC(Form2.Handle);
RoundRect(Form2._hdc,10,10,360,410,10,10);

//podjeljivanje texta za kolone od prvog itema
MoveToEx(Form2._hdc,10,35,NIL);
LineTo(Form2._hdc,360,35);


//bojamo prostor za imena kolona
if form2_paint then begin
   SetBkColor(Form2._hdc,form2_paint_color);
   Form2._hbrush:=CreateSolidBrush(RGB(GetRValue(form2_paint_color),GetGValue(form2_paint_color),GetBValue(form2_paint_color)));
   end else begin
   SetBkColor(Form2._hdc,RGB($7c,$9b,$cf));
   Form2._hbrush:=CreateSolidBrush(RGB($7c,$9b,$cf));
   end;
SelectObject(Form2._hdc,Form2._hbrush);
FloodFill(Form2._hdc,15,20,RGB(0,0,0));
DeleteObject(Form2._hbrush);

//bojamo prostor za iteme
if form2_item then
 begin
 Form2._hbrush:=CreateSolidBrush(RGB(GetRValue(form2_item_color),GetGValue(form2_item_color),GetBValue(form2_item_color)));
 end else Form2._hbrush:=CreateSolidBrush(RGB($d4,$ec,$fb));
SelectObject(Form2._hdc,Form2._hbrush);
FloodFill(Form2._hdc,20,40,RGB(0,0,0));
DeleteObject(Form2._hbrush);


TextOut(Form2._hdc,20,15,'Filename',length('Filename'));
TextOut(Form2._hdc,130,15,'File attributes',length('File attributes'));
TextOut(Form2._hdc,260,15,'Date/Time',length('Date/Time'));

//pravljenje 3 kolone
MoveToEx(Form2._hdc,120,10,NIL);
LineTo(Form2._hdc,120,410);
MoveToEx(Form2._hdc,240,10,NIL);
LineTo(Form2._hdc,240,410);

Form2.pocetna:=35;
 for y:=1 to 18 do
  begin
   MoveToEx(Form2._hdc,10,Form2.pocetna+(y*20),NIL);
   LineTo(Form2._hdc,360,Form2.pocetna+(y*20));
  end;


if Form2.red[1,1]<>'' then
for y:=1 to 18 do UbaciRed(y,Form2.red[y,1],Form2.red[y,2],Form2.red[y,3],false,RGB(0,0,0));


ReleaseDC(Form2.Handle,Form2._hdc);
end;

procedure TForm2.Button2Click(Sender: TObject);
var z:integer;
begin
 for z:=1 to 18 do
   begin
    red[z,1]:='';
    red[z,2]:='';
    red[z,3]:='';
   end;
 brojac:=0;
 Form2.Paint;
end;

procedure TForm2.Button3Click(Sender: TObject);
var kolor:array [1..16] of COLORREF;
    cc:TCHOOSECOLOR;
begin
form2_paint_color:=RGB(0,0,0);

cc.lStructSize:=sizeof(TCHOOSECOLOR);
cc.hWndOwner:=Form2.Handle;
cc.hInstance:=0;
cc.lpCustColors:=@kolor;
cc.rgbResult:=form2_paint_color;
cc.Flags:=CC_RGBINIT or CC_FULLOPEN;
cc.lCustData:=0;
cc.lpfnHook:=Nil;
cc.lpTemplateName:=0;
ChooseColor(cc);

form2_paint_color:=cc.rgbResult;
if RGB(0,0,0)=form2_paint_color then form2_paint:=false else form2_paint:=true;
Form2.Paint;
end;

procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var broj_r:integer;
    broj_stupaca:integer;
begin

Label5.Caption:=IntToStr(X);
Label6.Caption:=IntToStr(Y);

//za kolone
if (X>10) and (X<120) then broj_stupaca:=1;
if (X>120) and (X<240) then broj_stupaca:=2;
if (X>240) and (X<360) then broj_stupaca:=3;


Y:=Y-35;
broj_r:=(Y div 20)+1;

if (X>10) and (X<360) and (Y>1) and (Y+35<410) then
begin
Label7.Caption:=IntToStr(broj_r);
Label8.Caption:=IntToStr(broj_stupaca);
end else begin
         Label7.Caption:=IntToStr(0);
         Label8.Caption:=IntToStr(0);
         end;
end;

procedure TForm2.Button4Click(Sender: TObject);
var kolor:array [1..16] of COLORREF;
    cc:TCHOOSECOLOR;
begin
form2_item_color:=RGB(0,0,0);

cc.lStructSize:=sizeof(TCHOOSECOLOR);
cc.hWndOwner:=Form2.Handle;
cc.hInstance:=0;
cc.rgbResult:=RGB($80,$80,$80);
cc.lpCustColors:=@kolor;
cc.rgbResult:=form2_item_color;
cc.Flags:=CC_RGBINIT or CC_FULLOPEN;
cc.lCustData:=0;
cc.lpfnHook:=Nil;
cc.lpTemplateName:=0;
ChooseColor(cc);

form2_item_color:=cc.rgbResult;
if RGB(0,0,0)=form2_item_color then form2_item:=false else form2_item:=true;

Form2.Paint;
end;

end.


Znaci to je delphi VCL forma i na njoj sa apijima iscrtan listview, u attachu imas .exe cisto da vidis kako bi to izgledalo sa bojama [rekao si da trebas mjenjat boje buttonima]!

Probaj, ako zapnes javi... mada javi sto prije jer me od danas navece nema nadalje.. :/

z
[ mostart @ 19.10.2006. 16:21 ] @
evo kako to izgleda kompajlirano iz c#


[Ovu poruku je menjao mostart dana 23.10.2006. u 16:13 GMT+1]
[ passwdpasswd @ 19.10.2006. 16:55 ] @
Cek...aj ovako:

-ovaj program crta.exe je to sto trebas napravit preko cistog win32 apija?
-dali treba bit C++ ili C# style?


Ako je crta.exe ono sto trebas da napravis preko apija i ako ti odgovara C++ [i to u Dev-C++, jer nemam trenutno drugi] onda ti nakucam to za 10 min! :)

Trebao bi ti taj kod radit onda i u borlandovim alatima i u ms studio..


Javi dal ti to odgovara ;)

z
[ mostart @ 19.10.2006. 17:08 ] @
naravno da mi odgovara! to je to!
dakle treba biti c++ style
to bi bilo super.
puno ti zahvaljujem!
[ passwdpasswd @ 19.10.2006. 17:26 ] @
Evo sad cu pocet kucat.. samo mi reci sta ti onaj button Boze sacuvaj treba radit... neki error mi izbacuje kad ga kliknem??
I oces da jos sta dodam u program.. ovo je jako prosto.. mozda neki mainmenu pa About.. il recimo da mozes birat dal da crta bude tockasta, puna linija itd..??

poz
[ mostart @ 19.10.2006. 17:45 ] @
ma dobro je onako prosto...
a što se tiče dugmeta, ne mora radit. nije bitno toliko
što jednostavnije to bolje. :)
može se dodati samo about.
[ passwdpasswd @ 19.10.2006. 20:45 ] @
Omg.. jbte :D

Zaboravio ja na tebe :D

Drugar me nesto zvao.. otiso van, doso sad doma i skoro u krevet kad se sjetim ovoga, evo nabrzaka.. nije bog zna sta al radi:

Code:

#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";
HWND _hwnd;
char txt[5][10]={"Crna","Crvena","Plava","Zelena","Zuta"};
HBRUSH hBrush[4];


int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_HREDRAW | CS_VREDRAW;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    _hwnd = CreateWindowEx (
           WS_EX_OVERLAPPEDWINDOW,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           500,                 /* The programs width */
           370,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */

    ShowWindow (_hwnd, SW_SHOWNORMAL);
    UpdateWindow(_hwnd);

  HDC hdc;
  HBRUSH hBrush[4];
  HBRUSH hBr;
  int _x;
            hdc=GetDC(_hwnd);
            hBrush[0]=CreateSolidBrush(RGB(0,0,0)); //crna
            hBrush[1]=CreateSolidBrush(RGB(0xFF,0,0)); //crvena
            hBrush[2]=CreateSolidBrush(RGB(0,0,0xFF)); //plava
            hBrush[3]=CreateSolidBrush(RGB(0x32,0xCD,0x32)); //zelena
            hBrush[4]=CreateSolidBrush(RGB(0xFF,0xFF,0)); //zuta
            
                for (_x=0;_x<=4;_x++)  
                 {
                   SelectObject(hdc, hBrush[_x]);
                   Rectangle(hdc,(_x*70),0,(_x+1)*70,20);
                   SetTextColor(hdc, RGB(0,0,0));
                      if (_x==0) {SetTextColor(hdc, RGB(0xFF,0xFF,0xFF));
                                 SetBkColor(hdc, RGB(0,0,0));};
                      if (_x==1)  SetBkColor(hdc, RGB(0xFF,0,0));
                      if (_x==2)  SetBkColor(hdc, RGB(0,0,0xFF));
                      if (_x==3)  SetBkColor(hdc, RGB(0x32,0xCD,0x32));
                      if (_x==4)  SetBkColor(hdc, RGB(0xFF,0xFF,0));
                        
                  TextOut(hdc,(_x*70)+5,1,txt[_x],strlen(txt[_x]));
                  DeleteObject(hBrush);
                }
                 hBr=CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
                 SelectObject(hdc,hBr);
                 Rectangle(hdc,0,30,500,370);
                 DeleteObject(hBr);
                 ReleaseDC(_hwnd,hdc);
    

    

            hBrush[0]=CreateSolidBrush(RGB(0,0,0)); //crna
            hBrush[1]=CreateSolidBrush(RGB(0xFF,0,0)); //crvena
            hBrush[2]=CreateSolidBrush(RGB(0,0,0xFF)); //plava
            hBrush[3]=CreateSolidBrush(RGB(0x32,0xCD,0x32)); //zelena
            hBrush[4]=CreateSolidBrush(RGB(0xFF,0xFF,0)); //zuta
            
    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ int x,y;
  HPEN hPen=CreatePen(PS_DOT,10,RGB(0,0,0));;
  HDC hdc;
  POINT p;
  static BOOL crna=false, crvena=false, plava=false, zelena=false, zuta=false;
  int tipka;
    
    switch (message)                  /* handle the messages */
    {


       case WM_LBUTTONDOWN:
            GetCursorPos(&p);
            ScreenToClient(_hwnd,&p);
            
            if (p.y<=20 && p.x<=350)
             {
              tipka=p.x/70;
              if (tipka==0) {crna=true;
                             crvena=false;
                             plava=false;
                             zelena=false;
                             zuta=false;
                              hPen=CreatePen(PS_DOT,10,RGB(0,0,0));};
              if (tipka==1) {crna=false;
                             crvena=true;
                             plava=false;
                             zelena=false;
                             zuta=false;
                             hPen=CreatePen(PS_DOT,10,RGB(0xFF,0,0));};
              if (tipka==2) {plava=false;
                             crvena=false;
                             plava=true;
                             zelena=false;
                             zuta=false;
                             hPen=CreatePen(PS_DOT,10,RGB(0,0,0xFF));};
              if (tipka==3) {plava=false;
                             crvena=false;
                             plava=false;
                             zelena=true;
                             zuta=false;
                             hPen=CreatePen(PS_DOT,10,RGB(0x32,0xCD,0x32));};
              if (tipka==4) {crna=false;
                             crvena=false;
                             plava=false;
                             zelena=false;
                             zuta=true;
                             hPen=CreatePen(PS_DOT,10,RGB(0xFF,0xFF,0));};
             }
               
            if (p.y>32)
            {
             
            hdc=GetDC(_hwnd);
             x=LOWORD(lParam);
             y=HIWORD(lParam);
              if (wParam==MK_LBUTTON)
               {               
               if (crna==true) hPen=CreatePen(PS_DOT,10,RGB(0,0,0));
               if (crvena==true) hPen=CreatePen(PS_DOT,10,RGB(0xFF,0,0));
               if (plava==true) hPen=CreatePen(PS_DOT,10,RGB(0,0,0xFF));
               if (zelena==true) hPen=CreatePen(PS_DOT,10,RGB(0x32,0xCD,0x32));
               if (zuta==true) hPen=CreatePen(PS_DOT,10,RGB(0xFF,0xFF,0));
               SelectObject(hdc, hPen);
               MoveToEx(hdc,x,y,0);
               LineTo(hdc,x,y);
               DeleteObject(hPen);
               }
               ReleaseDC(_hwnd,hdc); 
               } 
             break;
        case WM_MOUSEMOVE:
            GetCursorPos(&p);
            ScreenToClient(_hwnd,&p);

            
            if (p.y>32)
            {
             hdc=GetDC(_hwnd);
             x=LOWORD(lParam);
             y=HIWORD(lParam);
              if (wParam==MK_LBUTTON)
               {
               if (crna==true) hPen=CreatePen(PS_DOT,10,RGB(0,0,0));
               if (crvena==true) hPen=CreatePen(PS_DOT,10,RGB(0xFF,0,0));
               if (plava==true) hPen=CreatePen(PS_DOT,10,RGB(0,0,0xFF));
               if (zelena==true) hPen=CreatePen(PS_DOT,10,RGB(0x32,0xCD,0x32));
               if (zuta==true) hPen=CreatePen(PS_DOT,10,RGB(0xFF,0xFF,0));
               SelectObject(hdc, hPen);
               MoveToEx(hdc,x,y,0);
               LineTo(hdc,x,y);
               DeleteObject(hPen);
               }
               ReleaseDC(_hwnd,hdc); 
              }
             break;   
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}




U attachu imas .exe

z
[ mostart @ 20.10.2006. 00:23 ] @
ludilo!
program je drama, bolje nije moglo! ovo je savršeno!
zahvalan sam ti do neba!
šta god trebalo, možeš tražit, a ja ako mognemto ispunit, uradit ću u što kraćem roku!
nemam riječi da dovoljno zahvalim!
hvala!
[ passwdpasswd @ 21.10.2006. 20:40 ] @
Evo mene napokon :)

Ovaj... ma to nije nista, to je najgore sto se moglo napravit.. :/

Ne znam kolko cu imat sta vremena tu ic po ES-u, ako sta budes trebao .. bilo sta samo mi posalji mail na [email protected], ako budem u prilici uvijek cu ti pomoc!!

z
[ passwdpasswd @ 22.10.2006. 19:05 ] @
Hehe, bas mi je drago!!

Sta studiras?
[ icobh @ 22.10.2006. 20:18 ] @
Eh kad bi se na mom faxu tako polagali ispiti, gdje bi inžinjerima i magistrima bio kraj...
[ android~paranoid @ 22.10.2006. 21:09 ] @
Lep programcic. passwd, gde mogu da skinem slicne kodove (za vc++). Ili ako imas neku svoju kolekciju da posaljes :)
[ stargazer @ 23.10.2006. 08:25 ] @
Lep kod samo malo sumnjiv.

Deklaracija ( globalna i lokalna ) :
HBRUSH hBrush[4];
a u WinMain :
hBrush[4]=CreateSolidBrush(RGB(0xFF,0xFF,0)); //zuta
Ovo je Access Violation koliko znam.

Nigde nema DeleteObject za te HBRUSH objekte, a ovo :
DeleteObject(hBrush);
ne znam šta briše.

U proceduri prozora se za svaku poruku izvršava ovo, ne znam zašto :
HPEN hPen=CreatePen(PS_DOT,10,RGB(0,0,0)); // 2. linija
a nigde nema DeleteObject za nju. Tu malo curi memorija?

PS: Možda sam zakeralo....