You are not logged in.

  • Login

1

Saturday, January 7th 2012, 3:12pm

Dll in GUI

Hallo Community,

nachdem mein Problem mit der GUI gelößt wurde, habe ich nun eine einwandfrei funktionierende hübsche Oberfläche: :)

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <windows.h>
#include <stdio.h>
#include <cstdio>

#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

HWND hwndButton;
HWND hwndEdit;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow)
{
	LPWSTR szName = L"Fensterklasse";
	WNDCLASS wc;

	wc.style			= CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc		= WndProc;
	wc.cbClsExtra		= 0;
	wc.cbWndExtra		= 0;
	wc.hInstance		= hI;
	wc.hIcon			= LoadIcon (NULL,IDI_WINLOGO);
	wc.hCursor			= LoadCursor (NULL, IDC_ARROW);
	wc.hbrBackground	= (HBRUSH) GetStockObject(LTGRAY_BRUSH);
	//wc.hbrBackground	= CreateSolidBrush(RGB(0,0,0));
	wc.lpszMenuName		= NULL;
	wc.lpszClassName	= szName;
	RegisterClass(&wc);

	HWND hwnd = CreateWindow(szName, L"<Graphical User Interface>", WS_SYSMENU | WS_SIZEBOX,
						 	0,0,300,200,NULL,NULL,hI,NULL);

	ShowWindow(hwnd, iCmdShow);
	UpdateWindow(hwnd);

	MSG msg;
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return msg.wParam;
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;

	switch(message)
	{
	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);
			SetBkMode(hdc,TRANSPARENT);
			SetTextColor(hdc,RGB(0,0,0));

			TextOut(hdc, 20, 20, L"Wert", 4);
		EndPaint(hwnd, &ps);
		return 0;
	case WM_CREATE:
		hwndButton = CreateWindow(L"button", L"Einlesen!", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
								160, 20, 100, 18, hwnd, (HMENU)1, GetModuleHandle(0),0);

		hwndEdit = CreateWindow(L"edit",L"50", WS_VISIBLE | WS_CHILD, 
								60,20,80,17,hwnd,0, GetModuleHandle(0),0);
		break;
	case WM_COMMAND:
		switch(wParam)
		{
		case 1:
		{
			wchar_t text[256];

			SendMessage(hwndEdit, WM_GETTEXT, 256, (LPARAM)text);
			MessageBox(hwnd, text, L"Edit -- Feld", MB_OK);

			break;
		}
		}
		break;

	case WM_DESTROY:
		PostQuitMessage(0);

		return 0;
		
	}
	
	return DefWindowProc(hwnd, message, wParam, lParam);
}


In dem rot gekennzeichneten Bereich, lese ich einen Wert aus einem Edit Feld aus und speichere diesen in der Variable "text".

Nun habe ich eine weitere Datei: Eine Dll.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <windows.h>
#include <detours.h>

BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD Reason, LPVOID Reserved)
{
	switch(Reason)
	{
		case DLL_PROCESS_ATTACH:
			MessageBox(0,L"Attached.",L"Info",0);

			break;
		case DLL_PROCESS_DETACH:
			MessageBox(0,L"Detached.",L"Info",0);
			break;
	}
	return TRUE;
}

2

Saturday, January 7th 2012, 3:33pm

Einmal reicht doch! :(

MfG
Check

3

Saturday, January 7th 2012, 4:48pm

Jo ;)

Wenn es C-Quelltext werden soll:

C/C++ Quellcode

1
#include <stdio.h>

und wenn es doch C++ werden soll:

C/C++ Quellcode

1
#include <cstdio>

Letzteres sollte überflüssig sein, denn ich sehe nichts von C++ in deinem Quelltext, oder ist doch C++ noch drin :?:

Möglichst nur die Header einbinden, die auch für euer Projekt benötigt werden.

MfG bcc-fan

4

Saturday, January 7th 2012, 6:29pm

Danke :)


#Bitte Thema löschen! :)

Social bookmarks