EDN Admin
Well-known member
Hello everybody,
I have a problem that has made me desperate! I think it is really an easy one but I really do not know why it doesnt work!
The problem is, I want to add the functionality to a DLL project to open a window and show there some information.... But I can not open the window!
Here is the code:
<br/>
#include "stdafx.h"<br/>
#include "faErgoPluginTypes.h"<br/>
#include "ErgoAPSTypes.h"<br/>
#include <iostream><br/>
#include <Windows.h><br/>
#include <string.h><br/>
#include <tchar.h><br/>
using namespace std;<br/>
HINSTANCE hInstance;<br/>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<br/>
{<br/>
<span style="white-spacere PAINTSTRUCT ps;<br/>
<span style="white-spacere HDC hdc;<br/>
<span style="white-spacere TCHAR greeting[] = _T("Hello, World!");<br/>
<span style="white-spacere switch (message)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere case WM_PAINT:<br/>
<span style="white-spacere hdc = BeginPaint(hWnd, &ps);<br/>
<span style="white-spacere TextOut(hdc, 5, 5, greeting, _tcslen(greeting));<br/>
<span style="white-spacere EndPaint(hWnd, &ps);<br/>
<span style="white-spacere break;<br/>
<span style="white-spacere case WM_DESTROY:<br/>
<span style="white-spacere PostQuitMessage(0);<br/>
<span style="white-spacere break;<br/>
<span style="white-spacere default:<br/>
<span style="white-spacere return DefWindowProc(hWnd, message, wParam, lParam);<br/>
<span style="white-spacere break;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere return 0;<br/>
}<br/>
<br/>
void Sim::OnSimStart(TplgHandle Sende)<br/>
{<span style="white-spacere
<span style="white-spacere <span style="white-spacere // Here I define a window resource
<span style="white-spacere HINSTANCE hInst;<br/>
<span style="white-spacere static TCHAR szWindowClass[] = _T("win32app");<br/>
<span style="white-spacere static TCHAR szTitle[] = _T("Win32 Guided Tour Application");<br/>
<span style="white-spacere WNDCLASSEX wcex;<br/>
<span style="white-spacere wcex.cbSize = sizeof(WNDCLASSEX);<br/>
<span style="white-spacere wcex.style = CS_HREDRAW | CS_VREDRAW;<br/>
<span style="white-spacere wcex.lpfnWndProc = WndProc;<br/>
<span style="white-spacere wcex.cbClsExtra = 0;<br/>
<span style="white-spacere wcex.cbClsExtra = 0;<br/>
<span style="white-spacere wcex.hInstance = hInstance;<br/>
<span style="white-spacere wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));<br/>
<span style="white-spacere wcex.hCursor = LoadCursor(NULL, IDC_ARROW);<br/>
<span style="white-spacere wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);<br/>
<span style="white-spacere wcex.lpszMenuName = NULL;<br/>
<span style="white-spacere wcex.lpszClassName = szWindowClass;<br/>
<span style="white-spacere wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));<br/>
<span style="white-spacere if (!RegisterClassEx(&wcex))<br/>
<span style="white-spacere {<br/>
<span style="white-spacere MessageBox(NULL,<br/>
<span style="white-spacere _T("Call to RegisterClassEx failed!"),<br/>
<span style="white-spacere _T("Win32 Guided Tour"),<br/>
<span style="white-spacere NULL);<br/>
<span style="white-spacere //return 1;<br/>
<span style="white-spacere <br/>
<span style="white-spacere }<br/>
<span style="white-spacere hInst = hInstance;<br/>
<span style="white-spacere HWND hWnd = CreateWindow(<br/>
<span style="white-spacere szWindowClass,<br/>
<span style="white-spacere szTitle,<br/>
<span style="white-spacere WS_OVERLAPPEDWINDOW,<br/>
<span style="white-spacere CW_USEDEFAULT, CW_USEDEFAULT,<br/>
<span style="white-spacere 500, 100,<br/>
<span style="white-spacere NULL,<br/>
<span style="white-spacere NULL,<br/>
<span style="white-spacere hInstance,<br/>
<span style="white-spacere NULL<br/>
<span style="white-spacere );<br/>
<br/>
<br/>
<span style="white-spacere if(!hWnd)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere MessageBox(NULL,<br/>
<span style="white-spacere _T("Call to CreateWindow failed!"),<br/>
<span style="white-spacere _T("Win32 Guided Tour"),<br/>
<span style="white-spacere NULL);<br/>
<span style="white-spacere //return 1;<br/>
<span style="white-spacere <br/>
<span style="white-spacere }<br/>
<span style="white-spacere ShowWindow(hWnd, nCmdShow);<br/>
<span style="white-spacere UpdateWindow(hWnd);<br/>
<span style="white-spacere MSG msg;<br/>
<span style="white-spacere while(GetMessage(&msg, NULL, 0, 0))<br/>
<span style="white-spacere {<br/>
<span style="white-spacere TranslateMessage(&msg);<br/>
<span style="white-spacere DispatchMessage(&msg);<br/>
<span style="white-spacere }<br/>
<span style="white-spacere //return(int) msg.wParam;<br/>
}<br/>
<br/>
<br/>
void Sim::OnSimCycleComplete(TplgHandle Sender, TplgObjectID DeviceID, double ElapsedTime, bool IsLastDevice, bool IsHiddenRun)<br/>
{<span style="white-spacere <br/>
<span style="white-spacere //......<br/>
}<br/>
<br/>
<br/>
void Sim::OnSimTargetReached(TplgObjectID DeviceID, TplgObjectID ReachedTargetID, TplgObjectID NextTargetID, TSimTargetReachedEventKind Kind)<br/>
{<br/>
<span style="white-spacere //.....<br/>
}<br/>
<br/>
<br/>
long Sim::OnErgoStep(TplgHandle Sender, PplgErgoNodeData ErgoNodeData)<br/>
{<br/>
<br/>
<br/>
<span style="white-spacere if (Device_GetActiveDeviceID() != ErgoNodeData->ActorDeviceID)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere return erUndefined;<br/>
<span style="white-spacere }<br/>
<br/>
<span style="white-spacere if (ErgoNodeData->SimTime < 0) <br/>
<span style="white-spacere {<span style="white-spacere <br/>
<span style="white-spacere return erUndefined;<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere StepCounter++;<br/>
<span style="white-spacere if(StepCounter % 100 == 0)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere <br/>
<span style="white-spacere //......<br/>
<span style="white-spacere if (StepCounter % 20 == 0)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere char DebugText1[1024];<br/>
<span style="white-spacere char DebugText2[1024];<br/>
<span style="white-spacere //char DebugText3[1024];<br/>
<span style="white-spacere //char DebugText4[1024];<br/>
<span style="white-spacere sprintf(DebugText1, "NTH X: %.2f Y: %.2f Z: %.2f",NTH[3][0],NTH[3][1],NTH[3][2]);<br/>
<span style="white-spacere Log_Message(DebugText1);<br/>
<span style="white-spacere <br/>
<span style="white-spacere sprintf(DebugText2, "CTH Winkel X: %.2f Y: %.2f Z: %.2f",CTH[2][0],CTH[2][1],CTH[2][2]);<br/>
<span style="white-spacere Log_Message(DebugText2);<br/>
<span style="white-spacere //sprintf(DebugText3, "LTS X: %.2f Y: %.2f Z: %.2f",LTS[3][0],LeftHandToLeftShoulder[3][1],LTS[3][2]);<br/>
<span style="white-spacere //Log_Message(DebugText3);<br/>
<span style="white-spacere //sprintf(DebugText4, "RTS X: %.2f Y: %.2f Z: %.2f",RTS[3][0],RTS[3][1],RightHandToRightShoulder[3][2]);<br/>
<span style="white-spacere //Log_Message(DebugText4);<br/>
<br/>
<span style="white-spacere }<span style="white-spacere <br/>
}<span style="white-spacere <br/>
}<br/>
<br/>
<br/>
long Sim::UpdateActorCount()<br/>
{<br/>
<span style="white-spacere long DeviceCount;<br/>
<span style="white-spacere long Count = 0;<br/>
<span style="white-spacere Tpfc_Device_GetDataOut DeviceData;<br/>
<span style="white-spacere TplgObjectID DeviceID;<br/>
<br/>
<br/>
<span style="white-spacere //....
<span style="white-spacere return Count;<br/>
}
Thank you very much for any help in advance!
View the full article
I have a problem that has made me desperate! I think it is really an easy one but I really do not know why it doesnt work!
The problem is, I want to add the functionality to a DLL project to open a window and show there some information.... But I can not open the window!
Here is the code:
<br/>
#include "stdafx.h"<br/>
#include "faErgoPluginTypes.h"<br/>
#include "ErgoAPSTypes.h"<br/>
#include <iostream><br/>
#include <Windows.h><br/>
#include <string.h><br/>
#include <tchar.h><br/>
using namespace std;<br/>
HINSTANCE hInstance;<br/>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<br/>
{<br/>
<span style="white-spacere PAINTSTRUCT ps;<br/>
<span style="white-spacere HDC hdc;<br/>
<span style="white-spacere TCHAR greeting[] = _T("Hello, World!");<br/>
<span style="white-spacere switch (message)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere case WM_PAINT:<br/>
<span style="white-spacere hdc = BeginPaint(hWnd, &ps);<br/>
<span style="white-spacere TextOut(hdc, 5, 5, greeting, _tcslen(greeting));<br/>
<span style="white-spacere EndPaint(hWnd, &ps);<br/>
<span style="white-spacere break;<br/>
<span style="white-spacere case WM_DESTROY:<br/>
<span style="white-spacere PostQuitMessage(0);<br/>
<span style="white-spacere break;<br/>
<span style="white-spacere default:<br/>
<span style="white-spacere return DefWindowProc(hWnd, message, wParam, lParam);<br/>
<span style="white-spacere break;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere return 0;<br/>
}<br/>
<br/>
void Sim::OnSimStart(TplgHandle Sende)<br/>
{<span style="white-spacere
<span style="white-spacere <span style="white-spacere // Here I define a window resource
<span style="white-spacere HINSTANCE hInst;<br/>
<span style="white-spacere static TCHAR szWindowClass[] = _T("win32app");<br/>
<span style="white-spacere static TCHAR szTitle[] = _T("Win32 Guided Tour Application");<br/>
<span style="white-spacere WNDCLASSEX wcex;<br/>
<span style="white-spacere wcex.cbSize = sizeof(WNDCLASSEX);<br/>
<span style="white-spacere wcex.style = CS_HREDRAW | CS_VREDRAW;<br/>
<span style="white-spacere wcex.lpfnWndProc = WndProc;<br/>
<span style="white-spacere wcex.cbClsExtra = 0;<br/>
<span style="white-spacere wcex.cbClsExtra = 0;<br/>
<span style="white-spacere wcex.hInstance = hInstance;<br/>
<span style="white-spacere wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));<br/>
<span style="white-spacere wcex.hCursor = LoadCursor(NULL, IDC_ARROW);<br/>
<span style="white-spacere wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);<br/>
<span style="white-spacere wcex.lpszMenuName = NULL;<br/>
<span style="white-spacere wcex.lpszClassName = szWindowClass;<br/>
<span style="white-spacere wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));<br/>
<span style="white-spacere if (!RegisterClassEx(&wcex))<br/>
<span style="white-spacere {<br/>
<span style="white-spacere MessageBox(NULL,<br/>
<span style="white-spacere _T("Call to RegisterClassEx failed!"),<br/>
<span style="white-spacere _T("Win32 Guided Tour"),<br/>
<span style="white-spacere NULL);<br/>
<span style="white-spacere //return 1;<br/>
<span style="white-spacere <br/>
<span style="white-spacere }<br/>
<span style="white-spacere hInst = hInstance;<br/>
<span style="white-spacere HWND hWnd = CreateWindow(<br/>
<span style="white-spacere szWindowClass,<br/>
<span style="white-spacere szTitle,<br/>
<span style="white-spacere WS_OVERLAPPEDWINDOW,<br/>
<span style="white-spacere CW_USEDEFAULT, CW_USEDEFAULT,<br/>
<span style="white-spacere 500, 100,<br/>
<span style="white-spacere NULL,<br/>
<span style="white-spacere NULL,<br/>
<span style="white-spacere hInstance,<br/>
<span style="white-spacere NULL<br/>
<span style="white-spacere );<br/>
<br/>
<br/>
<span style="white-spacere if(!hWnd)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere MessageBox(NULL,<br/>
<span style="white-spacere _T("Call to CreateWindow failed!"),<br/>
<span style="white-spacere _T("Win32 Guided Tour"),<br/>
<span style="white-spacere NULL);<br/>
<span style="white-spacere //return 1;<br/>
<span style="white-spacere <br/>
<span style="white-spacere }<br/>
<span style="white-spacere ShowWindow(hWnd, nCmdShow);<br/>
<span style="white-spacere UpdateWindow(hWnd);<br/>
<span style="white-spacere MSG msg;<br/>
<span style="white-spacere while(GetMessage(&msg, NULL, 0, 0))<br/>
<span style="white-spacere {<br/>
<span style="white-spacere TranslateMessage(&msg);<br/>
<span style="white-spacere DispatchMessage(&msg);<br/>
<span style="white-spacere }<br/>
<span style="white-spacere //return(int) msg.wParam;<br/>
}<br/>
<br/>
<br/>
void Sim::OnSimCycleComplete(TplgHandle Sender, TplgObjectID DeviceID, double ElapsedTime, bool IsLastDevice, bool IsHiddenRun)<br/>
{<span style="white-spacere <br/>
<span style="white-spacere //......<br/>
}<br/>
<br/>
<br/>
void Sim::OnSimTargetReached(TplgObjectID DeviceID, TplgObjectID ReachedTargetID, TplgObjectID NextTargetID, TSimTargetReachedEventKind Kind)<br/>
{<br/>
<span style="white-spacere //.....<br/>
}<br/>
<br/>
<br/>
long Sim::OnErgoStep(TplgHandle Sender, PplgErgoNodeData ErgoNodeData)<br/>
{<br/>
<br/>
<br/>
<span style="white-spacere if (Device_GetActiveDeviceID() != ErgoNodeData->ActorDeviceID)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere return erUndefined;<br/>
<span style="white-spacere }<br/>
<br/>
<span style="white-spacere if (ErgoNodeData->SimTime < 0) <br/>
<span style="white-spacere {<span style="white-spacere <br/>
<span style="white-spacere return erUndefined;<br/>
<span style="white-spacere }<br/>
<br/>
<br/>
<span style="white-spacere StepCounter++;<br/>
<span style="white-spacere if(StepCounter % 100 == 0)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere <br/>
<span style="white-spacere //......<br/>
<span style="white-spacere if (StepCounter % 20 == 0)<br/>
<span style="white-spacere {<br/>
<span style="white-spacere char DebugText1[1024];<br/>
<span style="white-spacere char DebugText2[1024];<br/>
<span style="white-spacere //char DebugText3[1024];<br/>
<span style="white-spacere //char DebugText4[1024];<br/>
<span style="white-spacere sprintf(DebugText1, "NTH X: %.2f Y: %.2f Z: %.2f",NTH[3][0],NTH[3][1],NTH[3][2]);<br/>
<span style="white-spacere Log_Message(DebugText1);<br/>
<span style="white-spacere <br/>
<span style="white-spacere sprintf(DebugText2, "CTH Winkel X: %.2f Y: %.2f Z: %.2f",CTH[2][0],CTH[2][1],CTH[2][2]);<br/>
<span style="white-spacere Log_Message(DebugText2);<br/>
<span style="white-spacere //sprintf(DebugText3, "LTS X: %.2f Y: %.2f Z: %.2f",LTS[3][0],LeftHandToLeftShoulder[3][1],LTS[3][2]);<br/>
<span style="white-spacere //Log_Message(DebugText3);<br/>
<span style="white-spacere //sprintf(DebugText4, "RTS X: %.2f Y: %.2f Z: %.2f",RTS[3][0],RTS[3][1],RightHandToRightShoulder[3][2]);<br/>
<span style="white-spacere //Log_Message(DebugText4);<br/>
<br/>
<span style="white-spacere }<span style="white-spacere <br/>
}<span style="white-spacere <br/>
}<br/>
<br/>
<br/>
long Sim::UpdateActorCount()<br/>
{<br/>
<span style="white-spacere long DeviceCount;<br/>
<span style="white-spacere long Count = 0;<br/>
<span style="white-spacere Tpfc_Device_GetDataOut DeviceData;<br/>
<span style="white-spacere TplgObjectID DeviceID;<br/>
<br/>
<br/>
<span style="white-spacere //....
<span style="white-spacere return Count;<br/>
}
Thank you very much for any help in advance!
View the full article