- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •InvalidateRect(hWnd,&rt,true);
- •InvalidateRect(hWnd,&rt,true);
- •InvalidateRect(hWnd,&rt,true);
- •InvalidateRect(hWnd,&rt,true);
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •If (!hWnd) return false;
- •If(!RegisterClass(&w)) return false;
- •If(!RegisterClass(&w)) return false;
- •If(!RegisterClass(&w)) return false;
- •InvalidateRect(hWnd,&rt,true);
- •If(!RegisterClass(&w)) return false;
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •InvalidateRect(hWnd,&rt,true);
- •InvalidateRect(hWnd,&rt,true);
- •InvalidateRect(hWnd,&rt,true);
- •InvalidateRect(hWnd,&rt,true);
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •InvalidateRect(hWnd,&rt,true);
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •Int winapi WinMain(hinstance hInstance, hinstance hPrevInstance, lpstr lpCmdLine, int nCmdShow)
- •If(!RegisterClass(&w)) return false;
- •If (!hWnd) return false;
- •If(!RegisterClass(&w)) return false;
#include <windows.h>
#include <stdio.h>
#include "resource.h"
#define IDD_DIALOG1 101
#define IDD_PARFUN 101
#define IDC_EXmin 1000
#define IDC_EXmax 1001
#define IDC_BUTTON1 1002
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);
LRESULT CALLBACK ParFun(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
double Xmin, Xmax;
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)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rt;
switch(msg)
{
case WM_CREATE:
Xmin=1,Xmax=100;
break;
case WM_LBUTTONDOWN:
DialogBox(NULL, (LPCTSTR)IDD_PARFUN, hWnd, (DLGPROC)ParFun);
GetClientRect(hWnd, &rt);
InvalidateRect(hWnd,&rt,TRUE);
break;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK ParFun(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
char minim[100],maxim[100];
switch (message)
{
case WM_INITDIALOG:
sprintf(minim,"%.2f",Xmin);
sprintf(maxim,"%.2f",Xmax);
SetDlgItemText(hDlg,IDC_EXmin,minim);
SetDlgItemText(hDlg,IDC_EXmax,maxim);
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
GetDlgItemText(hDlg,IDC_EXmin,minim,sizeof(minim));
GetDlgItemText(hDlg,IDC_EXmax,maxim,sizeof(maxim));
Xmin=atof(minim);
Xmax=atof(maxim);
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
}
return FALSE;
}
dialog
Сохранение или открытие файлов
Поля структуры OPENFILENAME:
lStructSize – размер структуры;
hWndOwner – дескриптор родительского окна;
lpstrFilter – фильтр;
nFilterIndex – номер активного фильтра;
lpstrFile – имя файла с путем;
nMaxFile – размер поля lpstrFile;
lpstrFileTitle – имя файла без пути;
nMaxFileTitle – размер поля lpstrFileTitle;
lpstrInitialDir – каталог по умолчанию;
lpstrDefExt – расширение по умолчанию;
Flags – флаги:
OFN_OVERWRITEPROMPT
OFN_ALLOWMULTISELECT
OFN_HIDEREADONLY
#include <windows.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;
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);
HRGN hRgn;
hRgn=CreateEllipticRgn(100,100,400,400);
SetWindowRgn(hWnd,hRgn,TRUE);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return int(msg.wParam);
}
LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return LONG(DefWindowProc(hWnd, msg, wParam, lParam));
}
return 0;
} // создает круглое окно (белое)
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define ID_BUTTON1 1001
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);
int WINAPI WinMain…
LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND rButton[10];
int i;
char bname[40];
switch(msg)
{
case WM_COMMAND:
if (LOWORD(wParam)>=ID_BUTTON1 && LOWORD(wParam)<=ID_BUTTON1+4)
{
sprintf(bname,"Нажата %d кнопка",LOWORD(wParam)-ID_BUTTON1);
SetWindowText(hWnd, bname);
}
if (LOWORD(wParam)>=ID_BUTTON1+5)
{
for(i=5; i<10; i++)
{
sprintf(bname,"%d button",i);
SetWindowText(rButton[i], bname);
}
sprintf(bname,"Нажата %d кнопка",LOWORD(wParam)-ID_BUTTON1);
SetWindowText(rButton[LOWORD(wParam)-ID_BUTTON1], bname);
}
break;
case WM_CREATE:
for(i=0; i<10; i++)
{
sprintf(bname,"%d button",i);
if (i==0 || i==5) rButton[i]=CreateWindow("button",bname,WS_TABSTOP|WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON|BS_FLAT|BS_PUSHLIKE|WS_GROUP, 10, 10+i*25, 145, 25, hWnd, (HMENU)(ID_BUTTON1+i),NULL,NULL);
else rButton[i]=CreateWindow("button",bname,WS_TABSTOP|WS_CHILD|WS_VISIBLE|BS_AUTORADIOBUTTON|BS_FLAT|BS_PUSHLIKE, 10, 10+i*25, 145, 25, hWnd, (HMENU)(ID_BUTTON1+i),NULL,NULL);
}
SendMessage(rButton[0], BM_SETCHECK,1,0);
SetWindowText(hWnd, "Нажата 0 кнопка");
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define ID_LIST 1001
#define ID_BUTTON 1002
#define ID_COMBO 1003
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);
int WINAPI WinMain…
LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND List1, Button1, Combo1;
static int en;
char item[150];
int nItem;
switch(msg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_LIST:
if (HIWORD(wParam)==LBN_DBLCLK)
{
nItem=SendMessage(List1,LB_GETCURSEL,0,(LPARAM)item);
if (nItem!=LB_ERR)
{
SendMessage(List1,LB_GETTEXT,nItem,(LPARAM)item);
SetWindowText(hWnd,item);
}
}
break;
case ID_BUTTON:
EnableWindow(List1, ++en%2);
sprintf(item,"%d record",en);
if (SendMessage(List1,LB_FINDSTRINGEXACT,0,(LPARAM)item)==LB_ERR)
SendMessage(List1,LB_ADDSTRING,0,(LPARAM)item);
break;
case ID_COMBO:
if (HIWORD(wParam)==CBN_EDITCHANGE)
{
GetWindowText(Combo1,item,sizeof(item));
SetWindowText(hWnd,item);
}
if (HIWORD(wParam)==CBN_KILLFOCUS)
{
GetWindowText(Combo1,item,sizeof(item));
if (SendMessage(Combo1,CB_FINDSTRINGEXACT,0,(LPARAM)item)==CB_ERR)
{
SendMessage(Combo1,CB_ADDSTRING,0,(LPARAM)item);
SetWindowText(Combo1,"");
}
}
break;
}
break;
case WM_CREATE:
Button1=CreateWindow("button","Добавить", WS_CHILD|WS_VISIBLE,10,270,100,30,hWnd,(HMENU)ID_BUTTON,NULL,NULL);
List1=CreateWindow("listbox",NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_HSCROLL|LBS_STANDARD|LBS_NOINTEGRALHEIGHT, 10,40,100,220,hWnd,(HMENU)ID_LIST,NULL,NULL);
SendMessage(List1,LB_SETHORIZONTALEXTENT,200,0);
SendMessage(List1,LB_ADDSTRING,0,(LPARAM)"1 record");
SendMessage(List1,LB_ADDSTRING,0,(LPARAM)"5 record");
SendMessage(List1,LB_ADDSTRING,0,(LPARAM)"3 record");
SendMessage(List1,LB_SETCURSEL,1,0);
en=1;
Combo1=CreateWindow("combobox",NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP|CBS_AUTOHSCROLL|CBS_DROPDOWN|CBS_SORT, 10,320,100,200,hWnd,(HMENU)ID_COMBO,NULL,NULL);
SendMessage(Combo1,CB_SETEXTENDEDUI,1,0);
SendMessage(Combo1,CB_ADDSTRING,0,(LPARAM)"1 record");
SendMessage(Combo1,CB_ADDSTRING,0,(LPARAM)"5 record");
SendMessage(Combo1,CB_ADDSTRING,0,(LPARAM)"3 record");
SendMessage(Combo1,CB_SETCURSEL,1,0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
#include <windows.h>
#include "resource.h"
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);
int WINAPI
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);