- •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;
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");
DeleteMenu(systemmenu,0,MF_BYPOSITION);
break;
case WM_CONTEXTMENU:
popupmenu=GetSubMenu(GetMenu(hWnd),0);
x=LOWORD(lParam);
y=HIWORD(lParam);
TrackPopupMenu(popupmenu,TPM_RIGHTALIGN|TPM_RIGHTBUTTON|TPM_TOPALIGN,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;
}
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define ID_SCROLL 1001
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);
int WINAPI …
LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND Scroll1;
static int nPage, nCurPos, nPosMin, nPosMax;
char pos[5];
switch(msg)
{
case WM_CREATE:
Scroll1=CreateWindow("scrollbar",NULL, SBS_HORZ|SBS_BOTTOMALIGN|WS_CHILD|WS_VISIBLE,10,10,160,16,hWnd,(HMENU)0,NULL,NULL);
nPage=10;
nPosMin=1;
nPosMax=150;
nCurPos=30;
SetScrollRange(Scroll1, SB_CTL, nPosMin, nPosMax, TRUE);
SetScrollPos(Scroll1, SB_CTL, nCurPos, TRUE);
sprintf(pos,"%d",nCurPos);
SetWindowText(hWnd, pos);
break;
case WM_HSCROLL:
switch (LOWORD(wParam))
{
case SB_LEFT:
nCurPos=nPosMin;
break;
case SB_LINELEFT:
nCurPos--;
break;
case SB_PAGELEFT:
nCurPos-=nPage;
break;
case SB_RIGHT:
nCurPos=nPosMax;
break;
case SB_LINERIGHT:
nCurPos++;
break;
case SB_PAGERIGHT:
nCurPos+=nPage;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
nCurPos=HIWORD(wParam);
break;
}
if (nCurPos>=nPosMax)
{
nCurPos=nPosMax;
EnableScrollBar(Scroll1, SB_CTL, ESB_DISABLE_RIGHT);
}
if (nCurPos<=nPosMin)
{
nCurPos=nPosMin;
EnableScrollBar(Scroll1, SB_CTL, ESB_DISABLE_LEFT);
}
SetScrollPos(Scroll1, SB_CTL, nCurPos, TRUE);
sprintf(pos,"%d",nCurPos);
SetWindowText(hWnd, pos);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
scrollbar
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);
…
LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
static CHOOSECOLOR ccol;
static COLORREF clf;
static COLORREF clfusers[16];
RECT rt;
HBRUSH brush;
HFONT font;
HANDLE hOldBrush, hOldFont;
static CHOOSEFONT cfont;
static COLORREF colfont;
static LOGFONT lf;
static OPENFILENAME ofn;
static char filename[256];
FILE *f;
switch(msg)
{
case WM_CREATE:
ccol.lStructSize=sizeof(CHOOSECOLOR);
ccol.Flags=CC_RGBINIT;
ccol.lpCustColors=clfusers;
clf=RGB(192,217,192);
colfont=RGB(0,255,0);
lf.lfHeight=20;
lf.lfWidth=20;
lf.lfEscapement=0;
lf.lfOrientation=0;
lf.lfItalic=1;
lf.lfUnderline=1;
lf.lfStrikeOut=0;
lf.lfWeight=FW_BOLD;
lf.lfCharSet=RUSSIAN_CHARSET;
strcpy(lf.lfFaceName,"Arial");
cfont.lStructSize=sizeof(CHOOSEFONT);
cfont.Flags=CF_SCREENFONTS|CF_EFFECTS|CF_INITTOLOGFONTSTRUCT;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = filename;
ofn.nMaxFile = sizeof(filename);
ofn.lpstrFilter = "Data files (*.dat)\0*.dat\0Text files (*.txt)\0*.txt\0Data and Text files (*.dat;*.txt)\0*.dat;*.txt\0All files (*.*)\0*.*\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrDefExt="dat";
break;
case WM_LBUTTONDOWN:
ofn.Flags=OFN_OVERWRITEPROMPT;
if (GetSaveFileName(&ofn))
{
f=fopen(ofn.lpstrFile,"w");
fprintf(f,"%x %x %x %x \n%s",lf.lfWidth, lf.lfHeight, lf.lfWeight, colfont, lf.lfFaceName);
fclose(f);
}
break;
case WM_RBUTTONDOWN:
cfont.lpLogFont=&lf;
cfont.rgbColors=colfont;
if (ChooseFont(&cfont))
{
lf=*cfont.lpLogFont;
colfont=cfont.rgbColors;
GetClientRect(hWnd,&rt);
InvalidateRect(hWnd,NULL,TRUE);
}
break;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rt);
brush=CreateSolidBrush(clf);
hOldBrush=SelectObject(hdc,brush);
font=CreateFontIndirect(&lf);
hOldFont=SelectObject(hdc,font);
SetTextColor(hdc,colfont);
Rectangle(hdc,rt.left,rt.top,rt.right,rt.bottom);
TextOut(hdc,20,20,lf.lfFaceName,strlen(lf.lfFaceName));
SelectObject(hdc, hOldBrush);
DeleteObject(brush);
SelectObject(hdc, hOldFont);
DeleteObject(hOldFont);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
standard dialog
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "resource.h"
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);
LRESULT CALLBACK DialProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LONG MyWinP(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
DialogBox(NULL, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)DialProc);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK DialProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND Static1, Edit1;
char str[100];
RECT rt;
POINT pt;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_INITDIALOG:
Static1=CreateWindow("static","Статический текст",WS_CHILD|WS_VISIBLE|WS_BORDER|SS_CENTER, 10,10,140,20,hDlg,NULL,NULL,NULL);
break;
case WM_PAINT:
hdc=BeginPaint(Static1,&ps);
SetTextColor(hdc, RGB(255,0,0));
GetWindowText(Static1,str,sizeof(str));
TextOut(hdc,0,0,str,strlen(str));
EndPaint(Static1,&ps);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
GetWindowRect(Static1,&rt);
rt.left+=10;
rt.right+=10;
pt.x=rt.left;
pt.y=rt.top;
ScreenToClient(hDlg,&pt);
MoveWindow(Static1,pt.x,pt.y,rt.right-rt.left,rt.bottom-rt.top,TRUE);
break;
}
if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
break;
}
break;
}
return FALSE;
}
static, edit
#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);
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|TBSTYLE_TOOLTIPS,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_NOTIFY:
LPTOOLTIPTEXT TTStr;
TTStr=(LPTOOLTIPTEXT)lParam;
if (TTStr->hdr.code!=TTN_NEEDTEXT) break;
switch (TTStr->hdr.idFrom)
{
case ID_FILEOPEN:
TTStr->lpszText="Открыть файл";
break;
case ID_FILENEW:
TTStr->lpszText="Новый файл";
break;
case ID_FILESAVE:
TTStr->lpszText="Сохранить файл";
}
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;
}
toolbar
#include <windows.h>
#define ID_FIRST 40001
#define ID_SECOND 40002
#define ID_THIRD 40003
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);