Post by code on Mar 24, 2019 23:03:37 GMT
Hi,
This time i will post code wich you can compile on www.onlinecompiler.net .
The result will be a program with two buttons, we only need 'Start cam'.
In the .bas file you press a button... its searching for webcam.exe (RUN "webcam.exe test")...
The window from justbasic has the title test , so thats why after webcam.exe test is written
The parameter test arrives in the compiled program , that program searches for the windows with test as title and
displays the webcam in justbasic program when 'Start cam' is pressed.
You can make changes in the source (be sure when you have downloaded the program/'utility its name is changed to: webcam.exe')
Also put it in the same directory where your .bas file is
Here the two sources:
.bas :
UpperLeftX = 20
UpperLeftY = 20
WindowWidth = 820
WindowHeight = 820
nomainwin
button #scr.b1, "Click for test", [b1], UL, 40, 300,200,60
open "test" for window as #scr
print #scr, "trapclose [quit]"
''print #scr, "fill black;flush;"
wait
[b1]
RUN "webcam.exe test"
''b$ = "webcam.exe test"
''RUN "rundll32.exe url.dll,FileProtocolHandler ";b$
#scr "getbmp image1 0 0 640 480"
bmpsave "image1", "test.bmp"
wait
[quit]
close #scr
end
compile code:
#include <windows.h>
#include <stdio.h>
#include <vfw.h>
#include <conio.h>
#include <process.h>
#include <winsock.h>
#include <mmsystem.h>
#pragma comment(lib,'libwinmm.a')
#pragma comment(lib,'libavicap32.a')
#pragma comment(lib,'libwsock.a')
HWND hwnd;
HWND window1;
HINSTANCE hi1;
#define IDC_WIN1_BUTTON1 3
HWND window1button1;
#define IDC_WIN1_BUTTON2 4
HWND window1button2;
int a;
char tb[1000]="here text";
HWND cap;
HWND line;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam){
switch(Msg){
case WM_LBUTTONDOWN :
break;
case WM_COMMAND:
if(LOWORD(wParam)==IDC_WIN1_BUTTON1 && HIWORD(wParam)==BN_CLICKED){
//here code for Button1 on Window1
//cap=capCreateCaptureWindowA(NULL,WS_VISIBLE|WS_CHILD,350,0,300,250,line,0);
typedef HWND (__stdcall *ru)(LPCSTR,DWORD,int,int,int,int,HWND,int);
HINSTANCE hDLL;
hDLL= LoadLibrary("avicap32.dll");
if (hDLL == NULL) {
} else {
//aw=GetActiveWindow();
ru td = (ru)GetProcAddress(hDLL, "capCreateCaptureWindowA");
cap= td(NULL,WS_VISIBLE|WS_CHILD,10,10,300,150,line,0);
}
SendMessageA (cap,1034,0,0);
SendMessageA (cap,1077,1,0);
SendMessageA (cap,1076,20,0);
SendMessageA (cap,1074,1,0);
// FreeLibrary(hDLL);
}
if(LOWORD(wParam)==IDC_WIN1_BUTTON2 && HIWORD(wParam)==BN_CLICKED){
//here code for Button2 on Window1
//Beep(1000,1000);
#define ZW_TEST 0x0400
SendMessageA((HWND)cap,ZW_TEST+61,0,0);
SendMessageA((HWND)cap,ZW_TEST+25,0,(LPARAM)"webcam-image.bmp");
//HBITMAP hb1= (HBITMAP)LoadImage(0,"webcam-image.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_DEFAULTSIZE);
//HDC windc = GetDC(window1);
//HDC bitdc = CreateCompatibleDC(windc);
//SelectObject(bitdc, hb1);
//BitBlt(windc, 0, 50, 300, 250, bitdc, 0, 0, SRCCOPY);
//(bitdc);
//ReleaseDC(window1, windc);
//DeleteObject(hb1);
}
break;
case WM_CLOSE:
SendMessageA (cap,1035,0,0);
DestroyWindow(hwnd);
break;
default:
return DefWindowProc(hwnd, Msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
char clsw[10] ="window";
wc.lpfnWndProc = WndProc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName ="window";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Error...","Error!",MB_ICONERROR | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,clsw,"app",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 650, 500,NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Error...","Error!",MB_ICONERROR | MB_OK);
return 0;
}
window1= CreateWindowEx(WS_EX_TOOLWINDOW,clsw,"window1",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,900,400,window1,NULL,hi1,NULL);
ShowWindow(window1, SW_SHOW);
UpdateWindow(window1);
window1button1= CreateWindowEx(0,"BUTTON","Button1",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,8,11,184,38,window1,(HMENU)IDC_WIN1_BUTTON1,GetModuleHandle ( NULL ),NULL);
window1button2= CreateWindowEx(0,"BUTTON","Button2",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,214,13,136,34,window1,(HMENU)IDC_WIN1_BUTTON2,GetModuleHandle ( NULL ),NULL);
SetWindowText(window1button1,"Start cam");
SetWindowText(window1button2,"Take Snapshot");
SetWindowText(window1,"Webcam");
line = FindWindow(NULL, (LPSTR)lpCmdLine);
while (GetMessage(&Msg, NULL, 0, 0))
{
if (!TranslateAccelerator(Msg.hwnd, NULL, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}
Also under the button 'Click for test' there is some code wich make the test.bmp file (to make a sort of screenshot)...
for example you can write the year it was taken...
Till sofar... Good luck with it!
Regards,
code