![]() |
Chirurgia spinală minim invazivă
Chirurgia spinală minim invazivă oferă pacienților oportunitatea unui tratament eficient, permițându-le o recuperare ultra rapidă și nu în ultimul rând minimizând leziunile induse chirurgical. Echipa noastră utilizează un spectru larg de tehnici minim invazive, din care enumerăm câteva: endoscopia cu variantele ei (transnazală, transtoracică, transmusculară, etc), microscopul operator, abordurile trans tubulare și nu în ultimul rând infiltrațiile la toate nivelurile coloanei vertebrale. www.neurohope.ro |
Cum declar doua clase in care se pot apela membrii celeilalte
Last Updated: Mar 29 2023 08:47, Started by
mariusg7
, Mar 25 2023 22:44
·
2

#1
Posted 25 March 2023 - 22:44

Cum declar doua clase in care se pot apela membrii celeilalte?
Deci am incercat in headere App.h #ifndef _APP_H_ #define _APP_H_ class API; class APP { public: APP() { g.winw=600; g.winh=500; } ~APP() {} void Test(); API *pAPI; }; #endifin APIwin.h #ifndef _APIWIN_H_ #define _APIWIN_H_ #include <windows.h> #include "App.h" class API { HFONT hfont; public: API(APP &rAPP_): rAPP(rAPP_) { test=69; } static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); HRESULT Create(HINSTANCE hInstance); bool Close(); int test; private: HWND hWndMain, hWndChild; HINSTANCE mHInstance; APP &rAPP; }; #endifin surse App.cpp #include "App.h" #include "APIwin.h" void APP::Test() { char out[255]; sprintf(out, "APP::Test() %d", pAPI->test); }inAPIwin.cpp #include "APIwin.h" HRESULT API::Create(HINSTANCE hInstance) { HWND hWnd; WNDCLASSEX wCs; static const char* wndClassName = "WndClass"; wCs.cbSize = sizeof wCs; wCs.style = CS_HREDRAW | CS_VREDRAW; wCs.lpfnWndProc = WindowProc; wCs.cbClsExtra = 0; wCs.cbWndExtra = 0; wCs.hInstance = hInstance; wCs.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(ID_MYICON)); wCs.hCursor = LoadCursor(NULL, IDC_ARROW); wCs.hbrBackground = NULL; wCs.lpszMenuName = NULL; wCs.lpszClassName = wndClassName; wCs.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(ID_MYICON)); if (RegisterClassEx(&wCs)) { hWnd = CreateWindowEx( WS_EX_CLIENTEDGE | WS_EX_ACCEPTFILES, // extended window style wndClassName, // registered class name TEXT("netMonitorPlugins"), // and window title WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, CW_USEDEFAULT, rAPP.g.winw, rAPP.g.winh, NULL, NULL, hInstance, // handle to application instance this // if need to take pointer ); SetWindowLongPtr(hWnd, GWLP_USERDATA, (LPARAM)this); } if(hWnd==NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return E_FAIL; } if (rAPP.g.winstate==3) ShowWindow(hWnd, SW_MAXIMIZE); else ShowWindow(hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); mHInstance=hInstance; hfont = CreateFont(15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial"); SendMessage(hWnd, WM_SETFONT, (WPARAM)hfont, TRUE); ChangeWindowMessageFilter (WM_DROPFILES, MSGFLT_ADD); ChangeWindowMessageFilter (WM_COPYDATA, MSGFLT_ADD); ChangeWindowMessageFilter (0x0049, MSGFLT_ADD); return S_OK; } LRESULT CALLBACK API::WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_CREATE) { LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam; SetWindowLongPtr(hWnd, GWLP_USERDATA, (LPARAM) (lpcs->lpCreateParams)); } API* pAPI = (API*) GetWindowLongPtr(hWnd, GWLP_USERDATA); switch(msg) { case WM_CREATE: { pAPI->hWndMain=hWnd; return 0; } case WM_CLOSE: pAPI->Close(); break; case WM_DESTROY: KillTimer(hWnd, 0); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; } bool API::Close() { char className[50]; GetClassName(hWndMain, className, sizeof(className)); DestroyWindow(hWndMain); UnregisterClass(className, mHInstance); return true; }si in final Main.cpp #include <windows.h> #include "APIwin.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int nAppResult = -1; APP oAPP; API oAPI(oAPP); oAPP.Test(); if (SUCCEEDED(oAPI.Create(hInstance))) { MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { if (msg.message == WM_KEYDOWN) { } TranslateMessage(&msg); DispatchMessage(&msg); } nAppResult = msg.wParam; } return nAppResult; } Se deschide fereastra dar este o problema cu API *pAPI; probabil e vorba de o alta instanta pentru ca test=69; nu este egal cu cel din APP::Test() |
#2
Posted 26 March 2023 - 22:37

Intre timp am gasit ce lipsea:
API(APP &rAPP): oAPP(rAPP) { oAPP.pAPI = this; Pentru ca pAPI sa fie pointer catre instanta din Main.cpp. O alta intrebare: se poate face acelasi lucru fara pointerul pAPI? Deci in loc de pointer sa folosesc tot referinta API &rAPI; ? |
#3
Posted 27 March 2023 - 19:49

Nu-mi dau seama de ce ai si APP si API. Poti si doar cu una.
|
#4
Posted 28 March 2023 - 23:26

Se vede ca nu ai facut aplicatii mai complexe, in niciun caz crossover. Dupa ce faci, o sa intelegi de ce.
|
#5
Posted 29 March 2023 - 08:47

Crossover ce ?
Vrei ca o aplicatie sa spioneze ce face alta aplicatie ? Visual Studio 6 avea Spy++ cu tot cu codul sursa. Edited by MarianG, 29 March 2023 - 08:48. |
Anunturi
▶ 0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users