Создание меню из трех пунктов, в первых двух – по 2 подпункта, по нажатию ПКМ – контекстное меню из тех же двух подпунктов.



Мы поможем в написании ваших работ!


Мы поможем в написании ваших работ!



Мы поможем в написании ваших работ!


ЗНАЕТЕ ЛИ ВЫ?

Создание меню из трех пунктов, в первых двух – по 2 подпункта, по нажатию ПКМ – контекстное меню из тех же двух подпунктов.



L4.cpp

#include <windows.h>

#include <stdio.h>

#include <math.h>

 

#define MAX_LOADSTRING 100

HINSTANCE hInst;

wchar_t szTitle[MAX_LOADSTRING];

wchar_t szWindowClass[MAX_LOADSTRING];

wchar_t ClassNameMain[] = L"MainWindow";

 

BOOL MyRegisterClass(WNDPROC, LPCTSTR, UINT);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

PAINTSTRUCT ps;

HDC hdc;

 

typedef void ( __cdecl *_DrawFunc ) ( HWND hWnd, HDC hdc, double xMin, double xMax );

_DrawFunc DrawFunc;

HINSTANCE dllInstance;

 

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)

{

HWND hWnd;

MSG msg;

hInst = hInstance;

if (!MyRegisterClass((WNDPROC)WndProc, ClassNameMain, COLOR_WINDOW)) return false;

hWnd=CreateWindow(ClassNameMain, L"Лр4", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

if (!hWnd) return false;

while (GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

 

return int(msg.wParam);

}

 

BOOL MyRegisterClass…

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

int wmId, wmEvent;

PAINTSTRUCT ps;

HDC hdc;

wchar_t szHello[MAX_LOADSTRING];

 

switch (message)

{

case WM_NCCREATE:

{

dllInstance = ::LoadLibrary ( L"dll.dll" );

if ( dllInstance == NULL )

{

::MessageBox ( 0, L"В процессе загрузки динамической библиотеки произошла ошибка.", L"Ошибка", MB_OK );

return 0;

}

 

DrawFunc = ( _DrawFunc ) ::GetProcAddress ( dllInstance, "Draw" );

if ( DrawFunc == NULL )

{

::MessageBox ( 0, L"В процессе загрузки динамической библиотеки произошла ошибка.", L"Ошибка", MB_OK );

return 0;

}

 

return 1;

}

 

case WM_PAINT:

 

hdc = BeginPaint(hWnd, &ps);

DrawFunc ( hWnd, hdc, 0.1, 10 );

::EndPaint ( hWnd, &ps );

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

 

default:

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

}

return 0;

}

 

***** void Draw ( HWND hWnd, HDC hdc, double xMin, double xMax )

{

Xmin = xMin;

Xmax = xMax;

FillArray();

 

#include <windows.h>

#include <stdio.h>

#define ID_EDIT 1001

#define ID_BUTTON 1002

 

LONG WinProc(HWND, UINT, WPARAM, LPARAM);

HINSTANCE hInstance;

char szTitle[]="Однострочный редактор";

int zna=1;

// WINMAIN

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR pCmdLine,

int nCmdShow){

char ProgName[]="Labrab";

 

HWND hWnd;

MSG msg;

//РЕГИСТРАЦИЯ ОКОННОГО КЛАССА

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)WinProc;

w.hCursor=LoadCursor(NULL, IDC_ARROW);

w.hIcon=LoadIcon(NULL, IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);

w.style=CS_HREDRAW | CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

if(!RegisterClass(&w)) return false;

//

 

hWnd=CreateWindow(

ProgName, //имя класса

szTitle, //имя окна (заголовок)

WS_OVERLAPPEDWINDOW, //стиль окна

100, //x-координата окна

100, //y-координата окна

GetSystemMetrics(SM_CXSCREEN)/2, //ширина окна

GetSystemMetrics(SM_CYSCREEN)/2, //высота окна

NULL, // дескриптор родительского или окна владельца

NULL, // дескриптор меню или идентификатор дочернего окна

hInstance, // дескриптор экземпляра приложения

NULL // указатель на данные создания окна

);

//CreateWindow("STATIC","Подготовка ко второму модулю",WS_CHILD|WS_VISIBLE|SS_LEFT,10,1,220,20,hWnd,NULL,hInstance,NULL);

 

ShowWindow(hWnd, nCmdShow);

while(GetMessage(&msg, NULL, 0, 0)) //цикл обработки сообщений

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

//

 

//ОКОННАЯ ПРОЦЕДУРА

LONG WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){

//POINT LeftCorner;

RECT rect;

//int x,y,x1,y1;

//POINT pt;

//чтобы преобразовать чар в бу НАДО СПРИНТФ

 

static HWND hEdit, hButton, hStatic;

char chBuff[80]=" ";

 

switch(msg){

case WM_CREATE:

{

hStatic=CreateWindow("static","Введите строку и нажмите кнопку ОК",WS_CHILD|WS_VISIBLE|SS_CENTER,30,10,300,20,hWnd,(HMENU)0,hInstance,NULL);

hEdit=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_LEFT,30,40,300,30,hWnd,(HMENU)ID_EDIT,hInstance,NULL);

hButton=CreateWindow("button","OK",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,130,85,100,30,hWnd,(HMENU)ID_BUTTON,hInstance,NULL);

SetFocus(hEdit);

return 0;

}

case WM_COMMAND:

{

switch(LOWORD(wParam))

{

case ID_EDIT:

{

if((HIWORD(wParam))==EN_ERRSPACE)

{

MessageBox(hWnd,"Мало памяти",szTitle,MB_OK);

}

return 0;

}

case ID_BUTTON:

{

SendMessage(hEdit,EM_GETLINE,0,(LPARAM)chBuff);

//MessageBox(hWnd,chBuff,"Нежданчик",MB_OK);

SetWindowText(hEdit,"\0");

SetFocus(hEdit);

sscanf(chBuff,"%d", &zna);

//GetClientRect(hWnd, &rect);

InvalidateRect(hWnd,NULL,TRUE);

 

//sprintf(chBuff,"%d", &zna);

//MessageBox(hWnd,chBuff,"Нежданчик",MB_OK);

return 0;

 

}

}

return 0;

}

case WM_PAINT:

{

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hWnd,&ps);

MoveToEx(hdc,30,150,NULL),

LineTo(hdc,2*zna+130,150);

 

//sprintf(chBuff,"%d", zna);

//MessageBox(hWnd,chBuff,"Нежданчик",MB_OK);

UpdateWindow(hWnd);

//ValidateRect(hWnd,NULL);

EndPaint(hWnd,&ps);

 

 

return 0;

}

case WM_DESTROY:

PostQuitMessage(0);

break;

 

case WM_LBUTTONDOWN:

 

break;

 

default:

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

break;

 

}

return 0;

}

 

 

 

ЧЕК БАТТОН В СТАТУС БАР =)

 

 

#include <windows.h>

#include <stdio.h>

#include <commctrl.h>

#pragma comment(lib,"comctl32.lib")

 

#define ID_BUTTON1 1001

#define ID_CHECK1 1001

#define ID_CHECK2 1002

#define ID_CHECK3 1003

#define ID_CHECK4 1004

#define ID_CHECK5 1005

#define ID_STATBAR 2001

 

HINSTANCE hInst;

 

LONG WinProc(HWND,UINT,WPARAM,LPARAM);

 

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd)

{char ProgName[]="My Window";

char Title[]="Window";

HWND hWnd;

MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)WinProc;

w.hCursor=LoadCursor(NULL,IDC_ARROW);

w.hIcon=LoadIcon(NULL,IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+7);

w.style=CS_HREDRAW|CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

hInst=hInstance;

if(!RegisterClass(&w)) return false;

hWnd=CreateWindow(ProgName, Title, WS_OVERLAPPEDWINDOW,

200,0,1010,740,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);

while(GetMessage(&msg,NULL,0,0))

{TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

 

LONG WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

 

static HWND r1,r2,r3,r4;

static HWND rButton[10];

static HWND hStatus;

char bname[40],buf[40];

int i;

static int che=-1;

 

switch(msg)

{case WM_CREATE:

hStatus=CreateStatusWindow(WS_CHILD|WS_VISIBLE,(LPCSTR)"Вывод",hWnd,ID_STATBAR);

for(i=0;i<5;i++)

{

if (i==0) sprintf(bname,"1");

if (i==1) sprintf(bname,"2");

if (i==2) sprintf(bname,"3");

if (i==3) sprintf(bname,"4");

if (i==4) sprintf(bname,"5");

rButton[i]=CreateWindow("button",bname,WS_TABSTOP|WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON|BS_FLAT,500,140+i*20,35,25,hWnd,(HMENU)(ID_BUTTON1+i),NULL,NULL);

}

break;

 

case WM_COMMAND:

switch(LOWORD(wParam))

{

case ID_CHECK1:

{ che=1;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK2:

{ che=2;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK3:

{ che=3;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK4:

{ che=4;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK5:

{ che=5;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

}

break;

 

case WM_SIZE:

MoveWindow(hStatus,0,0,0,0,TRUE);

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;

}

 

 

 

РИСОВАНИЕ ОТРЕЗКА

 

 

#include <windows.h>

 

#define ID_EDIT1 1001

#define ID_EDIT2 1002

#define ID_EDIT3 1003

#define ID_EDIT4 1004

#define ID_BUTTON 2001

 

HINSTANCE hInst;

LONG MyWinP(HWND,UINT,WPARAM,LPARAM);

 

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd)

{char ProgName[]="My Window";

char Title[]="Window";

HWND hWnd;

MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)MyWinP;

w.hCursor=LoadCursor(NULL,IDC_ARROW);

w.hIcon=LoadIcon(NULL,IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+7);

w.style=CS_HREDRAW|CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

hInst=hInstance;

if(!RegisterClass(&w)) return false;

hWnd=CreateWindow(ProgName, Title, WS_OVERLAPPEDWINDOW,

200,30,800,540,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);

while(GetMessage(&msg,NULL,0,0))

{TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

 

LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

static HDC hdc;

static PAINTSTRUCT ps;

static RECT rt;

static HWND edit1,edit2,edit3,edit4,btn;

static char buf[100],old_edit[100];

static int n_x,n_y,k_x,k_y;

 

switch(msg)

{case WM_CREATE:

CreateWindow("static","Координаты начала отрезка:",WS_CHILD|WS_VISIBLE|SS_CENTER,150,30,230,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","x:",WS_CHILD|WS_VISIBLE|SS_CENTER,220,55,30,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","y:",WS_CHILD|WS_VISIBLE|SS_CENTER,320,55,30,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","Координаты конца отрезка:",WS_CHILD|WS_VISIBLE|SS_CENTER,390,30,230,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","x:",WS_CHILD|WS_VISIBLE|SS_CENTER,420,55,30,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","y:",WS_CHILD|WS_VISIBLE|SS_CENTER,520,55,30,20,hWnd,NULL,NULL,NULL);

edit1=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,200,80,70,20,hWnd,(HMENU)ID_EDIT1,NULL,NULL);

edit2=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,300,80,70,20,hWnd,(HMENU)ID_EDIT2,NULL,NULL);

edit3=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,400,80,70,20,hWnd,(HMENU)ID_EDIT3,NULL,NULL);

edit4=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,500,80,70,20,hWnd,(HMENU)ID_EDIT4,NULL,NULL);

btn=CreateWindow("button","Enter",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,340,130,100,30,hWnd,HMENU(ID_BUTTON),NULL,NULL);

break;

 

case WM_COMMAND:

switch(LOWORD(wParam))

{case ID_BUTTON:

GetWindowText(edit1,buf,sizeof(buf));

n_x=atof(buf);

GetWindowText(edit2,buf,sizeof(buf));

n_y=atof(buf);

GetWindowText(edit3,buf,sizeof(buf));

k_x=atof(buf);

GetWindowText(edit4,buf,sizeof(buf));

k_y=atof(buf);

GetClientRect(hWnd,&rt);

InvalidateRect(hWnd,&rt,TRUE);

break;

 

}

break;

 

case WM_PAINT:

 

hdc=BeginPaint(hWnd,&ps);

MoveToEx(hdc,n_x,n_y,NULL);

LineTo(hdc,k_x,k_y);

EndPaint(hWnd,&ps);

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;

}

 

 

 

ИЗ СПИСКА В ТЕКСТОВОЕ ПОЛЕ

 

#include <windows.h>

#include <stdio.h>

 

#define ID_LIST 1001

#define ID_EDIT 2001

#define ID_BUTTON 3001

 

HINSTANCE hInst;

LONG MyWinP(HWND,UINT,WPARAM,LPARAM);

 

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd)

{char ProgName[]="My Window";

char Title[]="Window";

HWND hWnd;

MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)MyWinP;

w.hCursor=LoadCursor(NULL,IDC_ARROW);

w.hIcon=LoadIcon(NULL,IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+7);

w.style=CS_HREDRAW|CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

hInst=hInstance;

if(!RegisterClass(&w)) return false;

hWnd=CreateWindow(ProgName, Title, WS_OVERLAPPEDWINDOW,

200,30,800,540,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);

while(GetMessage(&msg,NULL,0,0))

{TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

 

LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

static HDC hdc;

static PAINTSTRUCT ps;

static RECT rt;

static HWND list,edit,btn;

static char l[100];

static int tmp;

 

switch(msg)

{case WM_CREATE:

list=CreateWindow("listbox",NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,300,80,130,130,hWnd,(HMENU)ID_LIST,NULL,NULL);

SendMessage(list,LB_ADDSTRING,0,(LPARAM)"Choise 1");

SendMessage(list,LB_ADDSTRING,0,(LPARAM)"Choise 2");

SendMessage(list,LB_ADDSTRING,0,(LPARAM)"Choise 3");

edit=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,470,120,170,20,hWnd,(HMENU)ID_EDIT,NULL,NULL);

btn=CreateWindow("button","Enter",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,400,230,100,30,hWnd,HMENU(ID_BUTTON),NULL,NULL);

break;

 

case WM_COMMAND:

switch(LOWORD(wParam))

{

case ID_LIST:

tmp=(int)SendMessage(list,LB_GETCURSEL,0,0);

if(tmp==0) sprintf(l, "Choise 1");

if(tmp==1) sprintf(l, "Choise 2");

if(tmp==2) sprintf(l, "Choise 3");

break;

case ID_BUTTON:

SetWindowText(edit,l);

break;

 

}

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;

}

 

 

Пример 1

Пример 2

Пример 3

Пример 4

Пример 5

Создание скролбара

#include <windows.h>

#include <stdio.h>

#include <string.h>

#define ID_SCROLL 1001

LONG MyWinP(HWND, UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

char ProgName[]="My Window";

char Title[]="Заголовок окна";

HWND hWnd; MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)MyWinP;

w.hCursor=LoadCursor(NULL, IDC_ARROW);

w.hIcon=LoadIcon(NULL,IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);

w.style=CS_HREDRAW | CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

if(!RegisterClass(&w)) return false;

hWnd=CreateWindow(ProgName,Title, WS_OVERLAPPEDWINDOW,0,0,

CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

if (!hWnd) return false;

ShowWindow(hWnd, nCmdShow);

while(GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

static HWND Scroll1;

switch(msg)

{

case WM_CREATE:

Scroll1=CreateWindow("scrollbar",NULL, SBS_SIZEBOX|WS_CHILD|WS_VISIBLE,10,10,16,16,hWnd,(HMENU)0,NULL,NULL);

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}return 0;}

Пример 6

Пример 7

Пример 8

Создание тулбара


#include <windows.h>

#include <commctrl.h>

#define ID_TOOLBAR 100

#define ID_FILEOPEN 40001

#define ID_FILESAVE 40002

#define ID_FILENEW 40003

LONG MyWinP(HWND, UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

char ProgName[]="My Window";

char Title[]="Заголовок окна";

HWND hWnd; MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)MyWinP;

w.hCursor=LoadCursor(NULL, IDC_ARROW);

w.hIcon=LoadIcon(NULL, IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);

w.style=CS_HREDRAW | CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

if(!RegisterClass(&w)) return false;


hWnd=CreateWindow(ProgName,Title, WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,0,0,

CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

if (!hWnd) return false;

ShowWindow(hWnd, nCmdShow);

while(GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{ static TBBUTTON but[5];

static HWND hToolBar;

switch(msg)

{ case WM_CREATE:

but[0].fsStyle=TBSTYLE_SEP;

but[1].iBitmap=STD_FILENEW;

but[1].idCommand=ID_FILENEW;

but[1].fsState=TBSTATE_ENABLED;

but[1].fsStyle=TBSTYLE_GROUP;

but[2].fsStyle=TBSTYLE_SEP;

but[3].iBitmap=STD_FILEOPEN;

but[3].idCommand=ID_FILEOPEN;

but[3].fsState=TBSTATE_ENABLED;

but[3].fsStyle=TBSTYLE_GROUP;

but[4].iBitmap=STD_FILESAVE;

but[4].idCommand=ID_FILESAVE;

but[4].fsState=TBSTATE_ENABLED;

but[4].fsStyle=TBSTYLE_GROUP;

hToolBar=CreateToolbarEx(hWnd,WS_CHILD|WS_VISIBLE|WS_DLGFRAME,ID_TOOLBAR,0,HINST_COMMCTRL,IDB_STD_LARGE_COLOR,but,5,0,0,0,0,sizeof(TBBUTTON));

break;

case WM_SIZE:

MoveWindow(hToolBar,0,0,0,0,TRUE);

break;

case WM_COMMAND:

switch(LOWORD(wParam))

{

case ID_FILEOPEN:

MessageBox(hWnd,"Открыть файл","",MB_OK);

break;

case ID_FILESAVE:

MessageBox(hWnd,"Сохранить файл","",MB_OK);

break;

case ID_FILENEW:

MessageBox(hWnd,"Новый файл","",MB_OK);

break;

} break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;}

Пример 9

L4.cpp

#include <windows.h>

#include <stdio.h>

#include <math.h>

 

#define MAX_LOADSTRING 100

HINSTANCE hInst;

wchar_t szTitle[MAX_LOADSTRING];

wchar_t szWindowClass[MAX_LOADSTRING];

wchar_t ClassNameMain[] = L"MainWindow";

 

BOOL MyRegisterClass(WNDPROC, LPCTSTR, UINT);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

PAINTSTRUCT ps;

HDC hdc;

 

typedef void ( __cdecl *_DrawFunc ) ( HWND hWnd, HDC hdc, double xMin, double xMax );

_DrawFunc DrawFunc;

HINSTANCE dllInstance;

 

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)

{

HWND hWnd;

MSG msg;

hInst = hInstance;

if (!MyRegisterClass((WNDPROC)WndProc, ClassNameMain, COLOR_WINDOW)) return false;

hWnd=CreateWindow(ClassNameMain, L"Лр4", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

if (!hWnd) return false;

while (GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

 

return int(msg.wParam);

}

 

BOOL MyRegisterClass…

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

int wmId, wmEvent;

PAINTSTRUCT ps;

HDC hdc;

wchar_t szHello[MAX_LOADSTRING];

 

switch (message)

{

case WM_NCCREATE:

{

dllInstance = ::LoadLibrary ( L"dll.dll" );

if ( dllInstance == NULL )

{

::MessageBox ( 0, L"В процессе загрузки динамической библиотеки произошла ошибка.", L"Ошибка", MB_OK );

return 0;

}

 

DrawFunc = ( _DrawFunc ) ::GetProcAddress ( dllInstance, "Draw" );

if ( DrawFunc == NULL )

{

::MessageBox ( 0, L"В процессе загрузки динамической библиотеки произошла ошибка.", L"Ошибка", MB_OK );

return 0;

}

 

return 1;

}

 

case WM_PAINT:

 

hdc = BeginPaint(hWnd, &ps);

DrawFunc ( hWnd, hdc, 0.1, 10 );

::EndPaint ( hWnd, &ps );

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

 

default:

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

}

return 0;

}

 

***** void Draw ( HWND hWnd, HDC hdc, double xMin, double xMax )

{

Xmin = xMin;

Xmax = xMax;

FillArray();

 

#include <windows.h>

#include <stdio.h>

#define ID_EDIT 1001

#define ID_BUTTON 1002

 

LONG WinProc(HWND, UINT, WPARAM, LPARAM);

HINSTANCE hInstance;

char szTitle[]="Однострочный редактор";

int zna=1;

// WINMAIN

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR pCmdLine,

int nCmdShow){

char ProgName[]="Labrab";

 

HWND hWnd;

MSG msg;

//РЕГИСТРАЦИЯ ОКОННОГО КЛАССА

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)WinProc;

w.hCursor=LoadCursor(NULL, IDC_ARROW);

w.hIcon=LoadIcon(NULL, IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);

w.style=CS_HREDRAW | CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

if(!RegisterClass(&w)) return false;

//

 

hWnd=CreateWindow(

ProgName, //имя класса

szTitle, //имя окна (заголовок)

WS_OVERLAPPEDWINDOW, //стиль окна

100, //x-координата окна

100, //y-координата окна

GetSystemMetrics(SM_CXSCREEN)/2, //ширина окна

GetSystemMetrics(SM_CYSCREEN)/2, //высота окна

NULL, // дескриптор родительского или окна владельца

NULL, // дескриптор меню или идентификатор дочернего окна

hInstance, // дескриптор экземпляра приложения

NULL // указатель на данные создания окна

);

//CreateWindow("STATIC","Подготовка ко второму модулю",WS_CHILD|WS_VISIBLE|SS_LEFT,10,1,220,20,hWnd,NULL,hInstance,NULL);

 

ShowWindow(hWnd, nCmdShow);

while(GetMessage(&msg, NULL, 0, 0)) //цикл обработки сообщений

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

//

 

//ОКОННАЯ ПРОЦЕДУРА

LONG WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){

//POINT LeftCorner;

RECT rect;

//int x,y,x1,y1;

//POINT pt;

//чтобы преобразовать чар в бу НАДО СПРИНТФ

 

static HWND hEdit, hButton, hStatic;

char chBuff[80]=" ";

 

switch(msg){

case WM_CREATE:

{

hStatic=CreateWindow("static","Введите строку и нажмите кнопку ОК",WS_CHILD|WS_VISIBLE|SS_CENTER,30,10,300,20,hWnd,(HMENU)0,hInstance,NULL);

hEdit=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_LEFT,30,40,300,30,hWnd,(HMENU)ID_EDIT,hInstance,NULL);

hButton=CreateWindow("button","OK",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,130,85,100,30,hWnd,(HMENU)ID_BUTTON,hInstance,NULL);

SetFocus(hEdit);

return 0;

}

case WM_COMMAND:

{

switch(LOWORD(wParam))

{

case ID_EDIT:

{

if((HIWORD(wParam))==EN_ERRSPACE)

{

MessageBox(hWnd,"Мало памяти",szTitle,MB_OK);

}

return 0;

}

case ID_BUTTON:

{

SendMessage(hEdit,EM_GETLINE,0,(LPARAM)chBuff);

//MessageBox(hWnd,chBuff,"Нежданчик",MB_OK);

SetWindowText(hEdit,"\0");

SetFocus(hEdit);

sscanf(chBuff,"%d", &zna);

//GetClientRect(hWnd, &rect);

InvalidateRect(hWnd,NULL,TRUE);

 

//sprintf(chBuff,"%d", &zna);

//MessageBox(hWnd,chBuff,"Нежданчик",MB_OK);

return 0;

 

}

}

return 0;

}

case WM_PAINT:

{

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hWnd,&ps);

MoveToEx(hdc,30,150,NULL),

LineTo(hdc,2*zna+130,150);

 

//sprintf(chBuff,"%d", zna);

//MessageBox(hWnd,chBuff,"Нежданчик",MB_OK);

UpdateWindow(hWnd);

//ValidateRect(hWnd,NULL);

EndPaint(hWnd,&ps);

 

 

return 0;

}

case WM_DESTROY:

PostQuitMessage(0);

break;

 

case WM_LBUTTONDOWN:

 

break;

 

default:

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

break;

 

}

return 0;

}

 

 

 

ЧЕК БАТТОН В СТАТУС БАР =)

 

 

#include <windows.h>

#include <stdio.h>

#include <commctrl.h>

#pragma comment(lib,"comctl32.lib")

 

#define ID_BUTTON1 1001

#define ID_CHECK1 1001

#define ID_CHECK2 1002

#define ID_CHECK3 1003

#define ID_CHECK4 1004

#define ID_CHECK5 1005

#define ID_STATBAR 2001

 

HINSTANCE hInst;

 

LONG WinProc(HWND,UINT,WPARAM,LPARAM);

 

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd)

{char ProgName[]="My Window";

char Title[]="Window";

HWND hWnd;

MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)WinProc;

w.hCursor=LoadCursor(NULL,IDC_ARROW);

w.hIcon=LoadIcon(NULL,IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+7);

w.style=CS_HREDRAW|CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

hInst=hInstance;

if(!RegisterClass(&w)) return false;

hWnd=CreateWindow(ProgName, Title, WS_OVERLAPPEDWINDOW,

200,0,1010,740,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);

while(GetMessage(&msg,NULL,0,0))

{TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

 

LONG WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

 

static HWND r1,r2,r3,r4;

static HWND rButton[10];

static HWND hStatus;

char bname[40],buf[40];

int i;

static int che=-1;

 

switch(msg)

{case WM_CREATE:

hStatus=CreateStatusWindow(WS_CHILD|WS_VISIBLE,(LPCSTR)"Вывод",hWnd,ID_STATBAR);

for(i=0;i<5;i++)

{

if (i==0) sprintf(bname,"1");

if (i==1) sprintf(bname,"2");

if (i==2) sprintf(bname,"3");

if (i==3) sprintf(bname,"4");

if (i==4) sprintf(bname,"5");

rButton[i]=CreateWindow("button",bname,WS_TABSTOP|WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON|BS_FLAT,500,140+i*20,35,25,hWnd,(HMENU)(ID_BUTTON1+i),NULL,NULL);

}

break;

 

case WM_COMMAND:

switch(LOWORD(wParam))

{

case ID_CHECK1:

{ che=1;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK2:

{ che=2;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK3:

{ che=3;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK4:

{ che=4;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

case ID_CHECK5:

{ che=5;

sprintf(buf,"%d",che);

SetWindowText(hStatus,buf);

}

break;

}

break;

 

case WM_SIZE:

MoveWindow(hStatus,0,0,0,0,TRUE);

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;

}

 

 

 

РИСОВАНИЕ ОТРЕЗКА

 

 

#include <windows.h>

 

#define ID_EDIT1 1001

#define ID_EDIT2 1002

#define ID_EDIT3 1003

#define ID_EDIT4 1004

#define ID_BUTTON 2001

 

HINSTANCE hInst;

LONG MyWinP(HWND,UINT,WPARAM,LPARAM);

 

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd)

{char ProgName[]="My Window";

char Title[]="Window";

HWND hWnd;

MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)MyWinP;

w.hCursor=LoadCursor(NULL,IDC_ARROW);

w.hIcon=LoadIcon(NULL,IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+7);

w.style=CS_HREDRAW|CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

hInst=hInstance;

if(!RegisterClass(&w)) return false;

hWnd=CreateWindow(ProgName, Title, WS_OVERLAPPEDWINDOW,

200,30,800,540,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);

while(GetMessage(&msg,NULL,0,0))

{TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

 

LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

static HDC hdc;

static PAINTSTRUCT ps;

static RECT rt;

static HWND edit1,edit2,edit3,edit4,btn;

static char buf[100],old_edit[100];

static int n_x,n_y,k_x,k_y;

 

switch(msg)

{case WM_CREATE:

CreateWindow("static","Координаты начала отрезка:",WS_CHILD|WS_VISIBLE|SS_CENTER,150,30,230,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","x:",WS_CHILD|WS_VISIBLE|SS_CENTER,220,55,30,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","y:",WS_CHILD|WS_VISIBLE|SS_CENTER,320,55,30,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","Координаты конца отрезка:",WS_CHILD|WS_VISIBLE|SS_CENTER,390,30,230,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","x:",WS_CHILD|WS_VISIBLE|SS_CENTER,420,55,30,20,hWnd,NULL,NULL,NULL);

CreateWindow("static","y:",WS_CHILD|WS_VISIBLE|SS_CENTER,520,55,30,20,hWnd,NULL,NULL,NULL);

edit1=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,200,80,70,20,hWnd,(HMENU)ID_EDIT1,NULL,NULL);

edit2=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,300,80,70,20,hWnd,(HMENU)ID_EDIT2,NULL,NULL);

edit3=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,400,80,70,20,hWnd,(HMENU)ID_EDIT3,NULL,NULL);

edit4=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,500,80,70,20,hWnd,(HMENU)ID_EDIT4,NULL,NULL);

btn=CreateWindow("button","Enter",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,340,130,100,30,hWnd,HMENU(ID_BUTTON),NULL,NULL);

break;

 

case WM_COMMAND:

switch(LOWORD(wParam))

{case ID_BUTTON:

GetWindowText(edit1,buf,sizeof(buf));

n_x=atof(buf);

GetWindowText(edit2,buf,sizeof(buf));

n_y=atof(buf);

GetWindowText(edit3,buf,sizeof(buf));

k_x=atof(buf);

GetWindowText(edit4,buf,sizeof(buf));

k_y=atof(buf);

GetClientRect(hWnd,&rt);

InvalidateRect(hWnd,&rt,TRUE);

break;

 

}

break;

 

case WM_PAINT:

 

hdc=BeginPaint(hWnd,&ps);

MoveToEx(hdc,n_x,n_y,NULL);

LineTo(hdc,k_x,k_y);

EndPaint(hWnd,&ps);

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;

}

 

 

 

ИЗ СПИСКА В ТЕКСТОВОЕ ПОЛЕ

 

#include <windows.h>

#include <stdio.h>

 

#define ID_LIST 1001

#define ID_EDIT 2001

#define ID_BUTTON 3001

 

HINSTANCE hInst;

LONG MyWinP(HWND,UINT,WPARAM,LPARAM);

 

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nShowCmd)

{char ProgName[]="My Window";

char Title[]="Window";

HWND hWnd;

MSG msg;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)MyWinP;

w.hCursor=LoadCursor(NULL,IDC_ARROW);

w.hIcon=LoadIcon(NULL,IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+7);

w.style=CS_HREDRAW|CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

hInst=hInstance;

if(!RegisterClass(&w)) return false;

hWnd=CreateWindow(ProgName, Title, WS_OVERLAPPEDWINDOW,

200,30,800,540,NULL,NULL,hInstance,NULL);

ShowWindow(hWnd,nShowCmd);

while(GetMessage(&msg,NULL,0,0))

{TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

 

LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

static HDC hdc;

static PAINTSTRUCT ps;

static RECT rt;

static HWND list,edit,btn;

static char l[100];

static int tmp;

 

switch(msg)

{case WM_CREATE:

list=CreateWindow("listbox",NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,300,80,130,130,hWnd,(HMENU)ID_LIST,NULL,NULL);

SendMessage(list,LB_ADDSTRING,0,(LPARAM)"Choise 1");

SendMessage(list,LB_ADDSTRING,0,(LPARAM)"Choise 2");

SendMessage(list,LB_ADDSTRING,0,(LPARAM)"Choise 3");

edit=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_CENTER|ES_LOWERCASE,470,120,170,20,hWnd,(HMENU)ID_EDIT,NULL,NULL);

btn=CreateWindow("button","Enter",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,400,230,100,30,hWnd,HMENU(ID_BUTTON),NULL,NULL);

break;

 

case WM_COMMAND:

switch(LOWORD(wParam))

{

case ID_LIST:

tmp=(int)SendMessage(list,LB_GETCURSEL,0,0);

if(tmp==0) sprintf(l, "Choise 1");

if(tmp==1) sprintf(l, "Choise 2");

if(tmp==2) sprintf(l, "Choise 3");

break;

case ID_BUTTON:

SetWindowText(edit,l);

break;

 

}

break;

 

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;

}

 

 

Пример 1

Создание меню из трех пунктов, в первых двух – по 2 подпункта, по нажатию ПКМ – контекстное меню из тех же двух подпунктов.

#include <windows.h>

#include "resource.h"

LONG MyWinP(HWND, UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

char ProgName[]="My Window";

char Title[]="Заголовок окна";

HWND hWnd; MSG msg;

HMENU menu;

WNDCLASS w;

w.lpszClassName=ProgName;

w.hInstance=hInstance;

w.lpfnWndProc=(WNDPROC)MyWinP;

w.hCursor=LoadCursor(NULL, IDC_ARROW);

w.hIcon=LoadIcon(NULL, IDI_APPLICATION);

w.lpszMenuName=NULL;

w.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);

w.style=CS_HREDRAW | CS_VREDRAW;

w.cbClsExtra=0;

w.cbWndExtra=0;

if(!RegisterClass(&w)) return false;

menu=LoadMenu(NULL,(LPCTSTR)IDR_MENU1);

hWnd=CreateWindow(ProgName,Title, WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,0,0,

CW_USEDEFAULT, CW_USEDEFAULT, NULL, menu, hInstance, NULL);

if (!hWnd) return false;

ShowWindow(hWnd, nCmdShow);

while(GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

PAINTSTRUCT ps;

HDC hdc;

HBRUSH brush;

static COLORREF clf;

HMENU popupmenu;

int x,y;

RECT rt;

static HMENU systemmenu;

switch(msg)

{

case WM_COMMAND:

switch (LOWORD(wParam))

{

case ID_RED:

clf=RGB(255,0,0);

GetClientRect(hWnd, &rt);

InvalidateRect(hWnd,&rt,TRUE);

break;

case ID_GREEN:

clf=RGB(0,255,0);

GetClientRect(hWnd, &rt);

InvalidateRect(hWnd,&rt,TRUE);

break;

case ID_BLUE:

clf=RGB(0,0,255);

GetClientRect(hWnd, &rt);

InvalidateRect(hWnd,&rt,TRUE);

break;

}

break;

case WM_CREATE:

clf=RGB(255,0,0);

systemmenu=GetSystemMenu(hWnd,FALSE);

AppendMenu(systemmenu,MF_SEPARATOR,0,0);

AppendMenu(systemmenu,0,5000,"Зеленый");

AppendMenu(systemmenu,MF_SEPARATOR,0,0);

AppendMenu(systemmenu,0,5001,"Сообщение1");

break;

case WM_CONTEXTMENU:

popupmenu=GetSubMenu(GetMenu(hWnd),0);

x=LOWORD(lParam);

y=HIWORD(lParam);

TrackPopupMenu(popupmenu,TPM_CENTERALIGN|TPM_LEFTBUTTON|TPM_VCENTERALIGN,x,y,0,hWnd,NULL);

break;

case WM_SYSCOMMAND:

if (LOWORD(wParam)==5000)

{

clf=RGB(0,255,0);

GetClientRect(hWnd, &rt);

InvalidateRect(hWnd,&rt,TRUE);

break;

}

if (LOWORD(wParam)==5001)

{

MessageBox(hWnd,"Сообщение 1",NULL,MB_OK);

break;

}

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

break;

 


case WM_PAINT:

hdc=BeginPaint(hWnd,&ps);

brush=CreateSolidBrush(clf);

SelectObject(hdc, brush);

GetClientRect(hWnd, &rt);

Rectangle(hdc,rt.left,rt.top,rt.right,rt.bottom);

 

EndPaint(hWnd,&ps);

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

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

}

return 0;

}

 


Пример 2



Последнее изменение этой страницы: 2016-07-14; просмотров: 79; Нарушение авторского права страницы; Мы поможем в написании вашей работы!

infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 54.165.57.161 (0.007 с.)