- •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;
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
По нажатию ЛКМ – окно диалога «сохранить как», а по ПКМ – окно диалога изменения шрифта.
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.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);
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;
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);