Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnetic-Fox committed Sep 10, 2023
1 parent 0b01145 commit 1a4daa7
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 0 deletions.
3 changes: 3 additions & 0 deletions WinAPI_test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project : H:\Projekty_Watcom\WinAPI_test\WinAPI_test.exe .SYMBOLIC

!include H:\Projekty_Watcom\WinAPI_test\WinAPI_test.mk1
Binary file added WinAPI_test.sym
Binary file not shown.
81 changes: 81 additions & 0 deletions WinAPI_test.tgt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
40
targetIdent
0
MProject
1
MComponent
0
2
WString
4
WEXE
3
WString
5
w_6en
1
0
1
4
MCommand
0
5
MCommand
0
6
MItem
15
WinAPI_test.exe
7
WString
4
WEXE
8
WVList
0
9
WVList
0
-1
1
1
0
10
WPickList
2
11
MItem
5
*.cpp
12
WString
6
CPPOBJ
13
WVList
0
14
WVList
0
-1
1
1
0
15
MItem
8
main.cpp
16
WString
6
CPPOBJ
17
WVList
0
18
WVList
0
11
1
1
0
43 changes: 43 additions & 0 deletions WinAPI_test.wpj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
40
projectIdent
0
VpeMain
1
WRect
-21
-37
10282
10031
2
MProject
3
MCommand
0
4
MCommand
0
1
5
WFileName
15
WinAPI_test.tgt
6
WVList
1
7
VComponent
8
WRect
0
0
5722
4323
2
0
9
WFileName
15
WinAPI_test.tgt
0
1
7
169 changes: 169 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#include <windows.h>
#include <stdlib.h>

#define BST_UNCHECKED 0x0000
#define BST_CHECKED 0x0001

#define ID_PRZYCISK1 501
#define ID_PRZYCISK2 502
#define ID_CHECKBOX 503
#define ID_LISTBOX 504
#define ID_PRZYCISK3 505
#define ID_EDITBOX 506
#define ID_LISTBOX2 507

HWND hText;
HWND hListBox, hListBox2;

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

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// MessageBox(NULL,"Fender!","Test",MB_ICONINFORMATION | MB_OK);

WNDCLASS wc;
LPSTR NazwaKlasy = "Klasa Okienka";

wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = NazwaKlasy;

if(!RegisterClass(&wc))
{
MessageBox(NULL,"Nie uda³o siê utworzyæ okna.","B³¹d",MB_ICONEXCLAMATION | MB_OK);
return 1;
}

HWND hwnd;

hwnd = CreateWindow(NazwaKlasy, "Oto okienko", WS_OVERLAPPEDWINDOW, 20, 20, 640, 480,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL,"Nie uda³o siê wyœwietliæ okna.","B³¹d",MB_ICONEXCLAMATION | MB_OK);
return 1;
}

HWND hPrzycisk, hPrzycisk2, hPrzycisk3;
HWND hCheckBox;
HWND hStatic;

hPrzycisk = CreateWindow("BUTTON", "Wyœwietl tekst", WS_CHILD | WS_VISIBLE, 160, 5, 150, 30,
hwnd, (HMENU)ID_PRZYCISK1, hInstance, NULL);

hPrzycisk2 =CreateWindow("BUTTON", "Wyœwietl stan", WS_CHILD | WS_VISIBLE, 160, 35, 150, 30,
hwnd, (HMENU)ID_PRZYCISK2, hInstance, NULL);

hPrzycisk3 =CreateWindow("BUTTON", "Wyœwietl wybrany", WS_CHILD | WS_VISIBLE, 160, 65, 150, 30,
hwnd, (HMENU)ID_PRZYCISK3, hInstance, NULL);

hText = CreateWindow("EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL,
5, 5, 150, 150, hwnd, (HMENU)ID_EDITBOX, hInstance, NULL);

hCheckBox = CreateWindow("BUTTON", "Opcja", WS_CHILD | WS_VISIBLE | BS_CHECKBOX, 5, 165, 150, 30,
hwnd, (HMENU)ID_CHECKBOX, hInstance, NULL);

hStatic = CreateWindow("STATIC", "Test", WS_CHILD | WS_VISIBLE | SS_LEFT, 5, 195, 150, 205, hwnd, NULL, hInstance, NULL);

hListBox = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_AUTOVSCROLL | LBS_NOTIFY,
320, 5, 150, 150, hwnd, (HMENU)ID_LISTBOX, hInstance, NULL);

hListBox2 =CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_AUTOVSCROLL | LBS_NOTIFY,
320, 155, 150, 150, hwnd, (HMENU)ID_LISTBOX2, hInstance, NULL);

SetWindowText(hStatic, "Test 2");

for(unsigned int x=0; x<1000; ++x)
{
char test[10];
ltoa(x,test,10);
SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM) test);
}

SendMessage(hListBox2, LB_ADDSTRING, 0, (LPARAM) "xD");

ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);

MSG Komunikat;

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

return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case ID_PRZYCISK1:
// Odczyt danych z pola tekstowego
DWORD dlugosc = GetWindowTextLength(hText);
LPSTR Bufor = (LPSTR)GlobalAlloc(GPTR, dlugosc+1);
GetWindowText(hText,Bufor,dlugosc+1);
MessageBox(hwnd,Bufor,"Pobrany tekst",MB_OK);
GlobalFree((unsigned)Bufor);
break;
case ID_PRZYCISK2:
if(IsDlgButtonChecked(hwnd, ID_CHECKBOX))
{
MessageBox(0,"Zaznaczony!","Stan",MB_ICONINFORMATION);
}
else
{
MessageBox(0,"Niezaznaczony!","Stan",MB_ICONINFORMATION);
}
break;
case ID_CHECKBOX:
if(IsDlgButtonChecked(hwnd, ID_CHECKBOX))
{
CheckDlgButton(hwnd, ID_CHECKBOX, BST_UNCHECKED); // = 0
}
else
{
CheckDlgButton(hwnd, ID_CHECKBOX, BST_CHECKED); // = 1
}
break;
case ID_PRZYCISK3:
long int index=SendMessage(hListBox, LB_GETCURSEL, 0, 0);
char test[10];
ltoa(index,test,10);
MessageBox(0,test,"WartoϾ",MB_OK);
break;
case ID_LISTBOX:
if(HIWORD(lParam)==LBN_DBLCLK)
{
long int index=SendMessage(hListBox, LB_GETCURSEL, 0, 0);
char test[10];
ltoa(index,test,10);
MessageBox(0,test,"WartoϾ",MB_OK);
}
break;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}

0 comments on commit 1a4daa7

Please sign in to comment.