Board Logo
« 2 windows code... »

Welcome Guest. Please Login or Register.
Sep 25th, 2017, 7:17pm


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: 2 windows code...  (Read 354 times)
code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 21
xx 2 windows code...
« Thread started on: May 3rd, 2017, 10:47am »

Here a code for two windows with buttons ... it can be freezing...
it gives you an idea how much/long such a code/program is...(C++)
Compile it on http://www.onlinecompiler.net/

Greetings,
Frederik Pot
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;
HWND window2;
HINSTANCE hi2;
#define IDC_WIN1_BUTTON1 3
HWND window1button1;
#define IDC_WIN1_BUTTON2 4
HWND window1button2;
#define IDC_WIN1_BUTTON3 5
HWND window1button3;
#define IDC_WIN2_BUTTON1 7
HWND window2button1;
#define IDC_WIN2_BUTTON2 8
HWND window2button2;
#define IDC_WIN2_BUTTON3 9
HWND window2button3;
#define IDC_WIN2_BUTTON4 10
HWND window2button4;
int a;
char tb[1000]="here text";

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 
Beep(1000,1000);
 
} 
if(LOWORD(wParam)==IDC_WIN1_BUTTON2 && HIWORD(wParam)==BN_CLICKED){
 //here code for Button2 on Window1 
Beep(1000,100);
Beep(100,100);
} 
if(LOWORD(wParam)==IDC_WIN1_BUTTON3 && HIWORD(wParam)==BN_CLICKED){
 //here code for Button3 on Window1 
Beep(1000,1000);
 
} 
if(LOWORD(wParam)==IDC_WIN2_BUTTON1 && HIWORD(wParam)==BN_CLICKED){
 //here code for Button1 on Window2 
Beep(1000,1000);
 
} 
if(LOWORD(wParam)==IDC_WIN2_BUTTON2 && HIWORD(wParam)==BN_CLICKED){
 //here code for Button2 on Window2 
Beep(1000,1000);
 
} 
if(LOWORD(wParam)==IDC_WIN2_BUTTON3 && HIWORD(wParam)==BN_CLICKED){
 //here code for Button3 on Window2 
Beep(1000,1000);
 
} 
if(LOWORD(wParam)==IDC_WIN2_BUTTON4 && HIWORD(wParam)==BN_CLICKED){
 //here code for Button4 on Window2 
Beep(1000,1000);
 
} 
break;
case WM_CLOSE:
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,313,454,window1,NULL,hi1,NULL);
ShowWindow(window1, SW_SHOW);
UpdateWindow(window1);
window2= CreateWindowEx(WS_EX_TOOLWINDOW,clsw,"window2",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,552,86,window2,NULL,hi2,NULL);
ShowWindow(window2, SW_SHOW);
UpdateWindow(window2);
window1button1= CreateWindowEx(0,"BUTTON","Button1",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,19,16,156,82,window1,(HMENU)IDC_WIN1_BUTTON1,GetModuleHandle ( NULL ),NULL);
window1button2= CreateWindowEx(0,"BUTTON","Button2",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,23,119,150,98,window1,(HMENU)IDC_WIN1_BUTTON2,GetModuleHandle ( NULL ),NULL);
window1button3= CreateWindowEx(0,"BUTTON","Button3",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,29,234,264,39,window1,(HMENU)IDC_WIN1_BUTTON3,GetModuleHandle ( NULL ),NULL);
window2button1= CreateWindowEx(0,"BUTTON","Button1",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,13,22,97,34,window2,(HMENU)IDC_WIN2_BUTTON1,GetModuleHandle ( NULL ),NULL);
window2button2= CreateWindowEx(0,"BUTTON","Button2",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,139,23,97,34,window2,(HMENU)IDC_WIN2_BUTTON2,GetModuleHandle ( NULL ),NULL);
window2button3= CreateWindowEx(0,"BUTTON","Button3",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,254,24,97,34,window2,(HMENU)IDC_WIN2_BUTTON3,GetModuleHandle ( NULL ),NULL);
window2button4= CreateWindowEx(0,"BUTTON","Button4",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,375,26,97,34,window2,(HMENU)IDC_WIN2_BUTTON4,GetModuleHandle ( NULL ),NULL);


while (GetMessage(&Msg, NULL, 0, 0))
{
if (!TranslateAccelerator(Msg.hwnd, NULL, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}
	



 
User IP Logged

tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3553
xx Re: 2 windows code...
« Reply #1 on: May 3rd, 2017, 11:49am »

That's why we code in BASIC, no?
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 21
xx Re: 2 windows code...
« Reply #2 on: May 3rd, 2017, 12:14pm »

For now i would say : YESSSS !
Thx for your reply !
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1157
xx Re: 2 windows code...
« Reply #3 on: May 3rd, 2017, 1:55pm »

Hi code,

Are the # symbols compiler commands?
User IP Logged

B+
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3553
xx Re: 2 windows code...
« Reply #4 on: May 3rd, 2017, 2:47pm »

#include and #define are preprocessor directives.
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 21
xx Re: 2 windows code...
« Reply #5 on: May 3rd, 2017, 2:50pm »

Hi, bplus

You asked me if the '#' are compiler commands... well I don't know.
I have studied this sort of codes / programs for years ,about for 17 years now.
I had my own compiler-site(on linux) .. (also mingw).. with lets say the compiler command:
(from the DOS command/screen)for MinGW like:
C:\mingw\bin\mingw32c++ copied.c -o outputapplication.exe -mwindows -lwsock32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lwsock32 -lopengl32 -lole32 -loleaut32 -lavicap32 -lgdi32

Where i must say you use the '-mwindows' to get rid of black screen...

Still some computer-speech done ?
wink

Regards,

Frederik Pot
User IP Logged

code
Member in Training
ImageImage


member is offline

Avatar




Homepage PM


Posts: 21
xx Re: 2 windows code...
« Reply #6 on: May 22nd, 2017, 04:54am »

Hi , here i have another code to write a file when you press the button on 'window1' ... i heared i beep when i clicked on 'window2'...something wrong with the code...?
This is more for the 'die hard'.
Compile it on onlinecompiler.net
(when you press the button it launches testing.html (ShellExecute)).

Greetings, Frederik Pot

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;
HWND window2;
HINSTANCE hi2;
#define IDC_WIN1_BUTTON1 3
HWND window1button1;
#define IDC_WIN2_TEXT1 7
HWND window2text1;
int a;
char tb[1000]="here text";

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 
Beep(600,400);
 FILE * fl;
fl=fopen ("testing.html","w");
if (fl!=NULL)
{
fputs ("hi world<img src=http://www.justbasic.com/justbasictitle.jpg>",fl);

fclose (fl);
}
ShellExecute(NULL, "open","testing.html", NULL, NULL, SW_SHOWNORMAL);
} 
if(LOWORD(wParam)==IDC_WIN2_TEXT1 && HIWORD(wParam)==EN_SETFOCUS){
 //here code for TextArea1 on Window2 
Beep(500,500);
 
} 
break;
case WM_CLOSE:
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,212,202,window1,NULL,hi1,NULL);
ShowWindow(window1, SW_SHOW);
UpdateWindow(window1);
window2= CreateWindowEx(WS_EX_TOOLWINDOW,clsw,"window2",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,239,239,window2,NULL,hi2,NULL);
ShowWindow(window2, SW_SHOW);
UpdateWindow(window2);
window1button1= CreateWindowEx(0,"BUTTON","Button1",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON ,50,68,97,34,window1,(HMENU)IDC_WIN1_BUTTON1,GetModuleHandle ( NULL ),NULL);
window2text1= CreateWindowEx(0,"EDIT","TextArea1",WS_CHILD | WS_VISIBLE ,4,21,229,186,window2,(HMENU)IDC_WIN2_TEXT1,GetModuleHandle ( NULL ),NULL);


while (GetMessage(&Msg, NULL, 0, 0))
{
if (!TranslateAccelerator(Msg.hwnd, NULL, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}


 
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1157
xx Re: 2 windows code...
« Reply #7 on: May 23rd, 2017, 09:45am »

quote: "This is more for the die hard.'

Bruce Willis, are you available? cheesy

OK this might be one for Rod or tsh73 wink

I shy away from API stuff,
but you must use Windows! ( ? )
So there is one person left!
(besides Rod and tsh73)
No, no you have been infected too (Reply #5) it is like I am in one of those zombie movies... wink

quote: ".... it can be freezing..."
Are you saying this might be cool? Or cold as H... eck!?
« Last Edit: May 23rd, 2017, 09:54am by bplus » User IP Logged

B+
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3553
xx Re: 2 windows code...
« Reply #8 on: May 23rd, 2017, 2:08pm »

Really, it doesn't make sense to ask C questions on BASIC forum.
And JB cannot use Windows API.
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls