.


:




:

































 

 

 

 


-




  1. Properties.
  2. , (Pop-up).
  3. .
  4. -, , &.

-

  1. Properties.
  2. , (Pop-up), , .
  3. ID
  4. .
  5. -, , &.

 

  1. .
  2. Properties.
  3. Pop-up.
  4. (Separator)

 

, .

 

, :

  • ,
  • ,
  • .

(, , ). . , (Dark- , Medium - , Light - ), , ( , ). , .

File, .

 

1. drawShape , . , .

, .

 

 

#define W 200 //

#define H 140 //

enum ShapeSize {MIN, MAX }; // MIN = 0, MAX = 1

struct SHAPE_DATA {

int id_shape; // ,

//

BOOL fRed; //

BOOL fGreen; //

BOOL fBlue; //

int id_bright; //

};

// drawShape :

// hWnd -

// hdc -

// shapeData -

// shapeSize -

// bShow - ( )

void drawShape (HWND hWnd, HDC hdc, SHAPE_DATA shapeData,

ShapeSize shapeSize, BOOL bShow)

{

if (bShow)

{

int intensity[3] = {100, 170, 255 };

int brightness = intensity [shapeData.id_bright - ID_DARK ];

// , hBrush

HBRUSH hBrush = CreateSolidBrush (RGB(

shapeData.fRed? brightness: 0,

shapeData.fGreen? brightness: 0,

shapeData.fBlue? brightness: 0)

);

// hBrush ,

// holdBrush

HBRUSH holdBrush = (HBRUSH) SelectObject(hdc,hBrush);

RECT rect; // rect RECT, RECT

// ,

// ,

GetClientRect(hWnd, &rect); //

// rect

// (x0, y0) - ()

int x0=rect.right /2, x1, x2;

int y0=rect.bottom /2, y1, y2;

//

if (shapeSize == MIN)

{ x1 = x0 - W/2; y1 = y0 - H/2;

x2 = x0 + W/2; y2 = y0 + H/2;

}

else

{

x1 = y1 = 0;

x2 = rect.right; y2 = rect.bottom;

}

// pt[4] POINT

POINT pt[4];

pt[0].x = (x1+x2) / 2; pt[0].y = y1;

pt[1].x = x2; pt[1].y = (y1+y2) / 2;

pt[2].x = (x1+x2) / 2; pt[2].y = y2;

pt[3].x = x1; pt[3].y = (y1+y2) / 2;

switch (shapeData.id_shape)

{

case ID_RECTANGLE:

Rectangle(hdc, x1,y1,x2,y2);

break;

case ID_RHOMB:

Polygon(hdc, pt,4);

break;

case ID_ELLIPSE:

Ellipse(hdc, x1,y1,x2,y2);

break;

}

// , , -

DeleteObject(SelectObject(hdc,holdBrush));

} // if (bShow)

}

2. Win32 Project _ 1.

 

 

. .

 

 

Resource.h , #define. , , , , .

, , _ 1.rc . Resource.h , .

, . . ( !)

Resource.h _ 1.rc

 

3. _ 1.rc . Menu, IDC_MY ( ), .

 

. ( ), ( ). :

  • ;
  • - ( ) (Caption).

 

, . . .

 

 

. , .

(0- )

& - 0 ( )
& -  
& -  
&! IDM_RESIZE  
& - 4 ( )

 

, -, True False   , . Resource.h , , !!!!

 

! , , , .

 

 

, ,

 

 

(1- )

& IDM_OPEN
& IDM_CLOSE
& IDM_SAVE
- SEPARATOR -
& IDM_EXIT ( )
     

 

(1- )

& IDM_SHOW_SHAPE
& IDM_HIDE_SHAPE

 

 

(1- )

-
-

 

. 1 . , -, False True   , Resource.h , , !!!!

 

(1- )

IDM_ABOUT

 

 

 

 

(2- )

ID_RECTANGLE
ID_RHOMB
ID_ELLIPSE

(2- )

ID_RED
ID_GREEN
ID_BLUE
- SEPARATOR -
ID_DARK
ID_MEDIUM
ID_LIGHT

 

Resource.h _ 1.rc .

 

. , .

 

4. _ 1.h W H,

enum ShapeSize, SHAPE_DATA.

 

#define W 200 //

#define H 140 //

 

enum ShapeSize { MIN, MAX }; // MIN = 0, MAX = 1

struct SHAPE_DATA {

int id_shape; // ,

//

BOOL fRed; //

BOOL fGreen; //

BOOL fBlue; //

int id_bright; //

};

 

drawShape.cpp,

drawShape.

#include "stdafx.h"

#include ".h"

 

5. _ 1.cpp. drawShape _ 1. cpp

WndProc, , WM_CREATE, WM_COMMAND WM_PAINT, . case WM_COMMAND, .

 

 

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,

LPARAM lParam)

{

int wmId, wmEvent;

PAINTSTRUCT ps;

HDC hdc;

// ,

// , drawShape.

//

// drawShape

 

static ShapeSize shapeSize = MIN;

static BOOL bShow = TRUE;

static SHAPE_DATA shapeData = { ID_RECTANGLE, TRUE, FALSE, FALSE, ID_DARK};

static HMENU hMenu = GetMenu(hWnd); //

// GetMenu

// static.

// , static, ,

// . . , , ,

// . ,

// , ,

// . ,

// .

 

switch (message)

{

 

 

case WM_COMMAND:

wmId = LOWORD(wParam);

wmEvent = HIWORD(wParam);

 

switch (wmId)

{

case IDM_OPEN:

// MessageBox

//

MessageBox (hWnd, TEXT(" ' ' "),

TEXT(" '' "), MB_OK);

break;

case IDM_CLOSE:

MessageBox(hWnd, TEXT(" ' ' "),

TEXT(" ' '"), MB_OK);

break;

case IDM_SAVE:

MessageBox(hWnd, TEXT(" ' ' "),

TEXT(" "), MB_OK);

break;

case IDM_SHOW_SHAPE:

bShow = TRUE;

break;

case IDM_HIDE_SHAPE:

bShow = FALSE;

break;

case ID_RECTANGLE:

shapeData.id_shape = ID_RECTANGLE;

break;

case ID_RHOMB:

shapeData.id_shape = ID_RHOMB;

break;

case ID_ELLIPSE:

shapeData.id_shape = ID_ELLIPSE; break;

case ID_RED:

shapeData.fRed= TRUE;

shapeData.fGreen =FALSE;

shapeData.fBlue=FALSE;

break;

case ID_GREEN:

shapeData.fRed=FALSE;

shapeData.fGreen =TRUE;

shapeData.fBlue=FALSE;

break;

case ID_BLUE:

shapeData.fRed=FALSE;

shapeData.fGreen = FALSE;

shapeData.fBlue=TRUE;

break;

case ID_DARK:

shapeData.id_bright = ID_DARK;

break;

case ID_MEDIUM:

shapeData.id_bright = ID_MEDIUM;

break;

case ID_LIGHT:

shapeData.id_bright = ID_LIGHT;

break;

case IDM_RESIZE:

// !!!!!!!!

break;

case IDM_ABOUT:

DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);

break;

case IDM_EXIT:

DestroyWindow(hWnd);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

// InvalidateRect , ,

// drawShape

// InvalidateRect, WM_PAINT, // hWnd

InvalidateRect(hWnd,NULL,TRUE);

break;

case WM_PAINT:

hdc = BeginPaint(hWnd, &ps);

// TODO: Add any drawing code here...





:


: 2016-11-18; !; : 454 |


:

:

80% - .
==> ...

1509 - | 1350 -


© 2015-2024 lektsii.org - -

: 0.114 .