
- •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;
}
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;