How to open a window in a dll project?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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-space:pre PAINTSTRUCT ps;<br/>
<span style="white-space:pre HDC hdc;<br/>
<span style="white-space:pre TCHAR greeting[] = _T("Hello, World!");<br/>
<span style="white-space:pre switch (message)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre case WM_PAINT:<br/>
<span style="white-space:pre hdc = BeginPaint(hWnd, &ps);<br/>
<span style="white-space:pre TextOut(hdc, 5, 5, greeting, _tcslen(greeting));<br/>
<span style="white-space:pre EndPaint(hWnd, &ps);<br/>
<span style="white-space:pre break;<br/>
<span style="white-space:pre case WM_DESTROY:<br/>
<span style="white-space:pre PostQuitMessage(0);<br/>
<span style="white-space:pre break;<br/>
<span style="white-space:pre default:<br/>
<span style="white-space:pre return DefWindowProc(hWnd, message, wParam, lParam);<br/>
<span style="white-space:pre break;<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre return 0;<br/>
}<br/>
<br/>
void Sim::OnSimStart(TplgHandle Sende)<br/>
{<span style="white-space:pre
<span style="white-space:pre <span style="white-space:pre // Here I define a window resource
<span style="white-space:pre HINSTANCE hInst;<br/>
<span style="white-space:pre static TCHAR szWindowClass[] = _T("win32app");<br/>
<span style="white-space:pre static TCHAR szTitle[] = _T("Win32 Guided Tour Application");<br/>
<span style="white-space:pre WNDCLASSEX wcex;<br/>
<span style="white-space:pre wcex.cbSize = sizeof(WNDCLASSEX);<br/>
<span style="white-space:pre wcex.style = CS_HREDRAW | CS_VREDRAW;<br/>
<span style="white-space:pre wcex.lpfnWndProc = WndProc;<br/>
<span style="white-space:pre wcex.cbClsExtra = 0;<br/>
<span style="white-space:pre wcex.cbClsExtra = 0;<br/>
<span style="white-space:pre wcex.hInstance = hInstance;<br/>
<span style="white-space:pre wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));<br/>
<span style="white-space:pre wcex.hCursor = LoadCursor(NULL, IDC_ARROW);<br/>
<span style="white-space:pre wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);<br/>
<span style="white-space:pre wcex.lpszMenuName = NULL;<br/>
<span style="white-space:pre wcex.lpszClassName = szWindowClass;<br/>
<span style="white-space:pre wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));<br/>
<span style="white-space:pre if (!RegisterClassEx(&wcex))<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre MessageBox(NULL,<br/>
<span style="white-space:pre _T("Call to RegisterClassEx failed!"),<br/>
<span style="white-space:pre _T("Win32 Guided Tour"),<br/>
<span style="white-space:pre NULL);<br/>
<span style="white-space:pre //return 1;<br/>
<span style="white-space:pre <br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre hInst = hInstance;<br/>
<span style="white-space:pre HWND hWnd = CreateWindow(<br/>
<span style="white-space:pre szWindowClass,<br/>
<span style="white-space:pre szTitle,<br/>
<span style="white-space:pre WS_OVERLAPPEDWINDOW,<br/>
<span style="white-space:pre CW_USEDEFAULT, CW_USEDEFAULT,<br/>
<span style="white-space:pre 500, 100,<br/>
<span style="white-space:pre NULL,<br/>
<span style="white-space:pre NULL,<br/>
<span style="white-space:pre hInstance,<br/>
<span style="white-space:pre NULL<br/>
<span style="white-space:pre );<br/>
<br/>
<br/>
<span style="white-space:pre if(!hWnd)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre MessageBox(NULL,<br/>
<span style="white-space:pre _T("Call to CreateWindow failed!"),<br/>
<span style="white-space:pre _T("Win32 Guided Tour"),<br/>
<span style="white-space:pre NULL);<br/>
<span style="white-space:pre //return 1;<br/>
<span style="white-space:pre <br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre ShowWindow(hWnd, nCmdShow);<br/>
<span style="white-space:pre UpdateWindow(hWnd);<br/>
<span style="white-space:pre MSG msg;<br/>
<span style="white-space:pre while(GetMessage(&msg, NULL, 0, 0))<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre TranslateMessage(&msg);<br/>
<span style="white-space:pre DispatchMessage(&msg);<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre //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-space:pre <br/>
<span style="white-space:pre //......<br/>
}<br/>
<br/>
<br/>
void Sim::OnSimTargetReached(TplgObjectID DeviceID, TplgObjectID ReachedTargetID, TplgObjectID NextTargetID, TSimTargetReachedEventKind Kind)<br/>
{<br/>
<span style="white-space:pre //.....<br/>
}<br/>
<br/>
<br/>
long Sim::OnErgoStep(TplgHandle Sender, PplgErgoNodeData ErgoNodeData)<br/>
{<br/>
<br/>
<br/>
<span style="white-space:pre if (Device_GetActiveDeviceID() != ErgoNodeData->ActorDeviceID)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre return erUndefined;<br/>
<span style="white-space:pre }<br/>
<br/>
<span style="white-space:pre if (ErgoNodeData->SimTime < 0) <br/>
<span style="white-space:pre {<span style="white-space:pre <br/>
<span style="white-space:pre return erUndefined;<br/>
<span style="white-space:pre }<br/>
<br/>
<br/>
<span style="white-space:pre StepCounter++;<br/>
<span style="white-space:pre if(StepCounter % 100 == 0)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre <br/>
<span style="white-space:pre //......<br/>
<span style="white-space:pre if (StepCounter % 20 == 0)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre char DebugText1[1024];<br/>
<span style="white-space:pre char DebugText2[1024];<br/>
<span style="white-space:pre //char DebugText3[1024];<br/>
<span style="white-space:pre //char DebugText4[1024];<br/>
<span style="white-space:pre sprintf(DebugText1, "NTH X: %.2f Y: %.2f Z: %.2f",NTH[3][0],NTH[3][1],NTH[3][2]);<br/>
<span style="white-space:pre Log_Message(DebugText1);<br/>
<span style="white-space:pre <br/>
<span style="white-space:pre sprintf(DebugText2, "CTH Winkel X: %.2f Y: %.2f Z: %.2f",CTH[2][0],CTH[2][1],CTH[2][2]);<br/>
<span style="white-space:pre Log_Message(DebugText2);<br/>
<span style="white-space:pre //sprintf(DebugText3, "LTS X: %.2f Y: %.2f Z: %.2f",LTS[3][0],LeftHandToLeftShoulder[3][1],LTS[3][2]);<br/>
<span style="white-space:pre //Log_Message(DebugText3);<br/>
<span style="white-space:pre //sprintf(DebugText4, "RTS X: %.2f Y: %.2f Z: %.2f",RTS[3][0],RTS[3][1],RightHandToRightShoulder[3][2]);<br/>
<span style="white-space:pre //Log_Message(DebugText4);<br/>
<br/>
<span style="white-space:pre }<span style="white-space:pre <br/>
}<span style="white-space:pre <br/>
}<br/>
<br/>
<br/>
long Sim::UpdateActorCount()<br/>
{<br/>
<span style="white-space:pre long DeviceCount;<br/>
<span style="white-space:pre long Count = 0;<br/>
<span style="white-space:pre Tpfc_Device_GetDataOut DeviceData;<br/>
<span style="white-space:pre TplgObjectID DeviceID;<br/>
<br/>
<br/>
<span style="white-space:pre //....
<span style="white-space:pre return Count;<br/>
}

Thank you very much for any help in advance!

View the full article
 
Back
Top