- •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;
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
Динамическое создание 10 кнопок, по нажатию на первые 5 – меняется заголовок окна, по нажатию на остальные – меняется название самой кнопки.
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define ID_BUTTON1 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|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 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;
}
Пример 7
Динамическое создание скролла, по его перемещению – в заголовке окна выдается расстояние
#include <windows.h>
#include <stdio.h>
#include <string.h>
#define ID_SCROLL 1001
LONG MyWinP(HWND, UINT,WPARAM,LPARAM);