Итак, у меня есть этот проект, где я должен сделать логическую схему. Единственное, что мне нужно научиться делать, - это линия, которая может соединиться с boxe. Думайте об этом, как о дереве в С ++, у меня есть пузыри, и все, что мне нужно сделать, это соединить их линией (я думаю, как двойной щелчок по первому пузырю, затем удерживать нажатие, пока не доберусь до другого пузыря). ). Это код, который у меня есть до сих пор (больше похож на тестовый код)
#include <stdio.h>
#include <winuser.h>
#include <iostream>
#define File_Menu_NEW 1
#define File_Menu_OPEN 2
#define File_Menu_EXIT 3
#define Change_Title 4
#define Open_file 5
#define Save_file 6
LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);
void AddMenus(HWND);
void AddControls(HWND);
HMENU hMenu;
HWND hEdit;
HWND hDestroy;
int x=100,y=100,h=200,l=20,ok;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int ncmdshow)
{
WNDCLASSW wc = {0};
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hInstance = hInst;
wc.lpszClassName = L"myWindowClass";
wc.lpfnWndProc = WindowProcedure;
HCURSOR SetCursor(HCURSOR hCursor);
DRAGDROP_S_USEDEFAULTCURSORS;
if(!RegisterClassW(&wc))
return -1;
CreateWindowW(L"myWindowClass",L"Transformator Logic",WS_OVERLAPPEDWINDOW | WS_VISIBLE,100,100,500,500,
NULL,NULL,NULL,NULL);
MSG msg={0};
while(GetMessage(&msg,NULL,NULL,NULL) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
void display_file(char* path)
{
FILE *file;
file = fopen(path,"rb");
fseek(file,0,SEEK_END);
int _size = ftell(file);
rewind(file);
char *data = new char[_size+1];
fread(data,_size,1,file);
data[_size] = '\0';
SetWindowText(hEdit,data);
fclose(file);
}
void open_file(HWND hWnd)
{
OPENFILENAME ofn;
char file_name[100];
ZeroMemory(&ofn,sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = file_name;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 100;
ofn.lpstrFilter = "All files\0*.*\0Source Files\0*.CPP\0Text Files\0*.TXT\0";
ofn.nFilterIndex = 1;
GetOpenFileName(&ofn);
display_file(ofn.lpstrFile);
}
void write_file(char *path)
{
FILE *file;
file = fopen(path,"w");
int _size = GetWindowTextLength(hEdit);
char *data = new char[_size+1];
GetWindowText(hEdit,data,_size+1);
fwrite(data,_size+1,1,file);
fclose(file);
}
void save_file(HWND hWnd)
{
OPENFILENAME ofn;
char file_name[100];
ZeroMemory(&ofn,sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = file_name;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 100;
ofn.lpstrFilter = "All files\0*.*\0Source Files\0*.CPP\0Text Files\0*.TXT\0";
ofn.nFilterIndex = 1;
GetSaveFileName(&ofn);
write_file(ofn.lpstrFile);
}
LRESULT CALLBACK WindowProcedure(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp)
{
switch(msg)
{
case WM_LBUTTONDBLCLK:
{
int xm = LOWORD(lp);
int ym = HIWORD(lp);
}
case WM_LBUTTONDOWN:
{
int iPosX = LOWORD(lp);
int iPosY = HIWORD(lp);
if(x<=iPosX&&x+l>=iPosX&&y<=iPosY&&y+h>=iPosY)
{
DestroyWindow(hDestroy);
ok=1;
}
break;
}
case WM_LBUTTONUP:
{
int iPosx = LOWORD(lp);
int iPosy = HIWORD(lp);
x=iPosx;
y=iPosy;
if(ok==1)
{
hDestroy=CreateWindowW(L"Static",L"Drag and drop test",WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,x,y,h,l,hWnd,
NULL,NULL,NULL);
ok=0;
}
break;
}
case WM_COMMAND:
switch(wp)
{
case Open_file:
open_file(hWnd);
break;
case Save_file:
save_file(hWnd);
break;
case File_Menu_EXIT:
DestroyWindow(hWnd);
break;
case File_Menu_NEW:
MessageBeep(MB_ICONINFORMATION);
break;
case Change_Title:
wchar_t text[100];
GetWindowTextW(hEdit,text,100);
SetWindowTextW(hWnd,text);
break;
}
break;
case WM_CREATE:
AddMenus(hWnd);
AddControls(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hWnd,msg,wp,lp);
}
}
void AddMenus(HWND hWnd)
{
hMenu = CreateMenu();
HMENU hFileMenu = CreateMenu();
HMENU hSchemePrestabilite = CreateMenu();
HMENU hSubMenu = CreateMenu();
AppendMenu(hMenu,MF_POPUP,(UINT_PTR)hFileMenu,"File");
AppendMenu(hFileMenu,MF_STRING,File_Menu_NEW,"New");
AppendMenu(hFileMenu,MF_POPUP,(UINT_PTR)hSubMenu,"Open SubMenu");
AppendMenu(hSubMenu,MF_STRING,NULL,"SubMenu Item");
//AppendMenu(hSubMenu,MF_STRING,Change_Title,"Change Title");
AppendMenu(hFileMenu,MF_SEPARATOR,NULL,NULL);
AppendMenu(hFileMenu,MF_STRING,File_Menu_EXIT,"Exit");
AppendMenu(hMenu,MF_STRING,Open_file,"Open File");
AppendMenu(hMenu,MF_STRING,Save_file,"Save File");
SetMenu(hWnd,hMenu);
}
void AddControls(HWND hWnd)
{
hDestroy =CreateWindowW(L"Static",L"Drag and drop test",WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,x,y,h,l,hWnd,
NULL,NULL,NULL);
CreateWindowW(L"Static",L"Line",WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,100,200,200,20,hWnd,
NULL,NULL,NULL);
//hEdit = CreateWindowW(L"Edit",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,100,100,300,300,hWnd,
//(HMENU)Open_file,NULL,NULL);
// CreateWindowW(L"Button",L"Change Title",WS_VISIBLE | WS_CHILD,100,254,200,20,hWnd,
// (HMENU)Change_Title,NULL,NULL);
}