[LL][Romeo-G]
29.01.2004, 18:56
Hallo,
fokgendes Problem:
Ich habe meine WebCam in eine Win32-Anwendung angebunden und lese die Bilder mit API Funktionen aus.
Soweit so gut!
Allerdings möchte ich grafische Elemente wie Linien, 4-Ecke etc. auf das WebCam Bild malen (Später will ich mal bestimmte PIxelwerte durch beispielsweise ein Rechteck umrahmen <= dafür brauche ich das) und hier ist das Problem.
Wenn ich mit ebendfalls API Funktionen eine GErade male dann liegt diese "unter" dem Child und ich sehe die LInie entweder gar nicht bzw wenn ich das Child verschiebe bis dahin wo es anfängt .. wie gesagt ... das Child verdeckt halt die grafischen Elemente.
Wie kann ich das ändern ????
Habe was von wegen subclassing gehört allerdings habe ich das nicht hinbekommen so zum laufen zu kriegen, dass gewünschter Effekt erzielt wird.
Hier mal mein Code:
#include <windows.h>
#include <vfw.h>
#define ID_BUTTON_FOTO 1
#define ID_BUTTON_CLOSE 2
#define ID_VIDEO_WINDOW 3
#define BUTTON_BREITE 60
#define BUTTON_HOHE 20
#define FENSTER_BREITE 350
#define FENSTER_HOHE 320
#define P_FILM 0
#define P_FOTO 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL FensterSkalieren (HWND) ;
BOOL ButtonsSkalieren (HWND, int, int) ;
const char szAppName[] = "V. 01";
OPENFILENAME ofn ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclassex ;
wndclassex.cbSize = sizeof (WNDCLASSEX) ;
wndclassex.style = CS_HREDRAW | CS_VREDRAW ;
wndclassex.lpfnWndProc = WndProc ;
wndclassex.cbClsExtra = 0 ;
wndclassex.cbWndExtra = 0 ;
wndclassex.hInstance = hInstance ;
wndclassex.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (101)) ;
wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclassex.hbrBackground = CreateSolidBrush(RGB(200,200,255));
wndclassex.lpszMenuName = szAppName ;
wndclassex.lpszClassName = szAppName ;
wndclassex.hIconSm = NULL ;
RegisterClassEx (&wndclassex) ;
hwnd = CreateWindowEx (NULL ,
szAppName, szAppName,
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION,
CW_USEDEFAULT , CW_USEDEFAULT ,
FENSTER_BREITE, FENSTER_HOHE,
NULL, LoadMenu (hInstance, MAKEINTRESOURCE (102)), hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
static HINSTANCE hInstance ;
static HWND hwndVideo ;
static int iIndex = 0 ;
char szDeviceName[80],
szDeviceVersion[80],
str[161];
static int iBreite = 0,
iHoche = 0,
iPruef = P_FOTO ;
static RECT rect;
switch (message){
case WM_CREATE :
hInstance = ((LPCREATESTRUCT) lParam) -> hInstance ;
hwndVideo = capCreateCaptureWindow((LPSTR) "WebCam",WS_CHILD| WS_VISIBLE,0, 0, 0, 0,(HWND) hwnd, (int) ID_VIDEO_WINDOW) ;
if (!capDriverConnect (hwndVideo, iIndex)) {
MessageBox (hwnd, "Treiber für die Webcam kann nicht geladen werden...", "Fehler", MB_ICONERROR) ;
SendMessage (hwnd, WM_DESTROY, 0, 0) ;
return 0;
}
capPreviewRate (hwndVideo, 33.3) ;
capPreview (hwndVideo, TRUE) ;
capGetDriverDescription (iIndex, szDeviceName, sizeof (szDeviceName),
szDeviceVersion, sizeof (szDeviceVersion)) ;
wsprintf (str, "%s, %s", szDeviceName, szDeviceVersion) ;
MessageBox (NULL, str, "Verbunden über...", NULL) ;
FensterSkalieren (hwnd) ;
ButtonsSkalieren (hwnd, iBreite, iHoche) ;
return 0 ;
case WM_SIZE :
rect.left = 0;
rect.top = 0;
rect.right = LOWORD(lParam);
rect.bottom = HIWORD(lParam);
iBreite = LOWORD (lParam) ;
iHoche = HIWORD (lParam) ;
return 0 ;
case WM_COMMAND :
switch (LOWORD (wParam)){
case ID_BUTTON_CLOSE :
SendMessage (hwnd, WM_DESTROY, 0, 0) ;
break ;
}
return 0 ;
case WM_DESTROY :
capPreview (hwndVideo, FALSE) ;
capDriverDisconnect (hwndVideo) ;
PostQuitMessage (0) ;
return 0 ;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC;
const char szUeberschrift[] = "Cam_Einbindung_v01";
hDC = BeginPaint(hwnd, &ps);
{
int iStrLen = 0;
DrawText(hDC, szUeberschrift, lstrlen(szUeberschrift), &rect , DT_SINGLELINE | DT_CENTER | DT_TOP );
for(int i=0; i<1024; i++) SetPixel( hDC, i, 100, RGB(255,0,0) );
}
EndPaint(hwnd, &ps);
return 0;
}
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
BOOL ButtonsSkalieren (HWND hwndParent, int iBreite, int iHoche){
MoveWindow (GetDlgItem (hwndParent, ID_BUTTON_CLOSE),
iBreite - BUTTON_BREITE, iHoche - BUTTON_HOHE,
BUTTON_BREITE, BUTTON_HOHE, TRUE) ;
MoveWindow (GetDlgItem (hwndParent, ID_BUTTON_FOTO),
iBreite - (2 * BUTTON_BREITE) - 5, iHoche - BUTTON_HOHE,
BUTTON_BREITE, BUTTON_HOHE, TRUE) ;
return TRUE ;
}
BOOL FensterSkalieren (HWND hParent){
CAPSTATUS CS ;
capGetStatus (GetDlgItem (hParent, ID_VIDEO_WINDOW), &CS, sizeof (CAPSTATUS)) ;
SetWindowPos (GetDlgItem (hParent, ID_VIDEO_WINDOW), NULL, 0, 0, CS.uiImageWidth,
CS.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE) ;
SetWindowPos (hParent, NULL, CW_USEDEFAULT, CW_USEDEFAULT, CS.uiImageWidth,
CS.uiImageHeight /*+ 75*/, SWP_NOZORDER | SWP_NOMOVE) ;
return TRUE ;
}
Vielen Dank
[LL][Romeo-G]
fokgendes Problem:
Ich habe meine WebCam in eine Win32-Anwendung angebunden und lese die Bilder mit API Funktionen aus.
Soweit so gut!
Allerdings möchte ich grafische Elemente wie Linien, 4-Ecke etc. auf das WebCam Bild malen (Später will ich mal bestimmte PIxelwerte durch beispielsweise ein Rechteck umrahmen <= dafür brauche ich das) und hier ist das Problem.
Wenn ich mit ebendfalls API Funktionen eine GErade male dann liegt diese "unter" dem Child und ich sehe die LInie entweder gar nicht bzw wenn ich das Child verschiebe bis dahin wo es anfängt .. wie gesagt ... das Child verdeckt halt die grafischen Elemente.
Wie kann ich das ändern ????
Habe was von wegen subclassing gehört allerdings habe ich das nicht hinbekommen so zum laufen zu kriegen, dass gewünschter Effekt erzielt wird.
Hier mal mein Code:
#include <windows.h>
#include <vfw.h>
#define ID_BUTTON_FOTO 1
#define ID_BUTTON_CLOSE 2
#define ID_VIDEO_WINDOW 3
#define BUTTON_BREITE 60
#define BUTTON_HOHE 20
#define FENSTER_BREITE 350
#define FENSTER_HOHE 320
#define P_FILM 0
#define P_FOTO 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL FensterSkalieren (HWND) ;
BOOL ButtonsSkalieren (HWND, int, int) ;
const char szAppName[] = "V. 01";
OPENFILENAME ofn ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclassex ;
wndclassex.cbSize = sizeof (WNDCLASSEX) ;
wndclassex.style = CS_HREDRAW | CS_VREDRAW ;
wndclassex.lpfnWndProc = WndProc ;
wndclassex.cbClsExtra = 0 ;
wndclassex.cbWndExtra = 0 ;
wndclassex.hInstance = hInstance ;
wndclassex.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (101)) ;
wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclassex.hbrBackground = CreateSolidBrush(RGB(200,200,255));
wndclassex.lpszMenuName = szAppName ;
wndclassex.lpszClassName = szAppName ;
wndclassex.hIconSm = NULL ;
RegisterClassEx (&wndclassex) ;
hwnd = CreateWindowEx (NULL ,
szAppName, szAppName,
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION,
CW_USEDEFAULT , CW_USEDEFAULT ,
FENSTER_BREITE, FENSTER_HOHE,
NULL, LoadMenu (hInstance, MAKEINTRESOURCE (102)), hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
static HINSTANCE hInstance ;
static HWND hwndVideo ;
static int iIndex = 0 ;
char szDeviceName[80],
szDeviceVersion[80],
str[161];
static int iBreite = 0,
iHoche = 0,
iPruef = P_FOTO ;
static RECT rect;
switch (message){
case WM_CREATE :
hInstance = ((LPCREATESTRUCT) lParam) -> hInstance ;
hwndVideo = capCreateCaptureWindow((LPSTR) "WebCam",WS_CHILD| WS_VISIBLE,0, 0, 0, 0,(HWND) hwnd, (int) ID_VIDEO_WINDOW) ;
if (!capDriverConnect (hwndVideo, iIndex)) {
MessageBox (hwnd, "Treiber für die Webcam kann nicht geladen werden...", "Fehler", MB_ICONERROR) ;
SendMessage (hwnd, WM_DESTROY, 0, 0) ;
return 0;
}
capPreviewRate (hwndVideo, 33.3) ;
capPreview (hwndVideo, TRUE) ;
capGetDriverDescription (iIndex, szDeviceName, sizeof (szDeviceName),
szDeviceVersion, sizeof (szDeviceVersion)) ;
wsprintf (str, "%s, %s", szDeviceName, szDeviceVersion) ;
MessageBox (NULL, str, "Verbunden über...", NULL) ;
FensterSkalieren (hwnd) ;
ButtonsSkalieren (hwnd, iBreite, iHoche) ;
return 0 ;
case WM_SIZE :
rect.left = 0;
rect.top = 0;
rect.right = LOWORD(lParam);
rect.bottom = HIWORD(lParam);
iBreite = LOWORD (lParam) ;
iHoche = HIWORD (lParam) ;
return 0 ;
case WM_COMMAND :
switch (LOWORD (wParam)){
case ID_BUTTON_CLOSE :
SendMessage (hwnd, WM_DESTROY, 0, 0) ;
break ;
}
return 0 ;
case WM_DESTROY :
capPreview (hwndVideo, FALSE) ;
capDriverDisconnect (hwndVideo) ;
PostQuitMessage (0) ;
return 0 ;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC;
const char szUeberschrift[] = "Cam_Einbindung_v01";
hDC = BeginPaint(hwnd, &ps);
{
int iStrLen = 0;
DrawText(hDC, szUeberschrift, lstrlen(szUeberschrift), &rect , DT_SINGLELINE | DT_CENTER | DT_TOP );
for(int i=0; i<1024; i++) SetPixel( hDC, i, 100, RGB(255,0,0) );
}
EndPaint(hwnd, &ps);
return 0;
}
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
BOOL ButtonsSkalieren (HWND hwndParent, int iBreite, int iHoche){
MoveWindow (GetDlgItem (hwndParent, ID_BUTTON_CLOSE),
iBreite - BUTTON_BREITE, iHoche - BUTTON_HOHE,
BUTTON_BREITE, BUTTON_HOHE, TRUE) ;
MoveWindow (GetDlgItem (hwndParent, ID_BUTTON_FOTO),
iBreite - (2 * BUTTON_BREITE) - 5, iHoche - BUTTON_HOHE,
BUTTON_BREITE, BUTTON_HOHE, TRUE) ;
return TRUE ;
}
BOOL FensterSkalieren (HWND hParent){
CAPSTATUS CS ;
capGetStatus (GetDlgItem (hParent, ID_VIDEO_WINDOW), &CS, sizeof (CAPSTATUS)) ;
SetWindowPos (GetDlgItem (hParent, ID_VIDEO_WINDOW), NULL, 0, 0, CS.uiImageWidth,
CS.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE) ;
SetWindowPos (hParent, NULL, CW_USEDEFAULT, CW_USEDEFAULT, CS.uiImageWidth,
CS.uiImageHeight /*+ 75*/, SWP_NOZORDER | SWP_NOMOVE) ;
return TRUE ;
}
Vielen Dank
[LL][Romeo-G]