May 19, 2024, 12:13:13 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Trying to create a button

Started by Bruce Peaslee, December 17, 2005, 11:04:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

Although I know controls are coming, I like to play around with the language in the interim. I am trying to put a button on a window but can't quite get it. Here is what I have:


Declare Import, CreateWindow(LPCTSTR lpClassName,
ÂÃ,  ÂÃ,  int lpWindowName,
ÂÃ,  ÂÃ,  int dwStyle,
ÂÃ,  ÂÃ,  int x,
ÂÃ,  ÂÃ,  int y,
ÂÃ,  ÂÃ,  int nWidth,
ÂÃ,  ÂÃ,  int nHeight,
ÂÃ,  ÂÃ,  int hWndParent,
ÂÃ,  ÂÃ,  int hMenu,
ÂÃ,  ÂÃ,  int *hInstance,
ÂÃ,  ÂÃ,  int *lpParam),int;
declare import, GetWindowLong(int hwnd, int nIndex),int;

...

hwndCloseButton = CreateWindow("Button", "OK",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,10,
100,100,
winMain.m_hwnd,
0,
GetWindowLong(winMain.m_hwnd,GWL_HINSTANCE),
NULL);


Thanks.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

change your imports to this.


declare import, CreateWindow(string *lpClassName,int lpWindowName,int dwStyle,int x,int y,int nWidth,int nHeight,int hWndParent,int hMenu,int *hInstance,int *lpParam),int;
declare import, GetWindowLong(int hwnd,int nIndex),int;


You had a C++ type in there.

Lewis

Ionic Wind Support Team

I usually use CreateWindowExA

DECLARE IMPORT,CreateWindowExA(dwExStyle as UINT,
lpClassName as STRING,
lpWindowName as STRING,
dwStyle as UINT,
x as INT,
y as INT,
nWidth as INT,
nHeight as INT,
hWndParent as UINT,
hMenu as UINT,
hInstance as UINT,
lpParam as POINTER),INT;

The classname for a button is "BUTTON".  It could be case sensetive.
Ionic Wind Support Team

Zen

December 17, 2005, 11:41:22 AM #3 Last Edit: December 17, 2005, 01:02:49 PM by Lewis
here is some working code to create a button control.


/**************************/
/* Include Required Files */
/**************************/

#include "Classes/MainWindow.inc"

/*******************************/
/* Declare Windows API Imports */
/*******************************/

declare import,CreateWindowExA(dwExStyle as unsigned int,lpClassName as STRING,lpWindowName as STRING,dwStyle as unsigned int,x as INT,y as INT,nWidth as INT,nHeight as INT,hWndParent as unsigned int,hMenu as unsigned int,hInstance as unsigned int,lpParam as pointer),INT;
declare import,GetModuleHandleA(int num),unsigned int;

/********************/
/* Define Constants */
/********************/

#define WS_VISIBLE 0x10000000
#define WS_CHILD 0x40000000
#define BS_DEFPUSHBUTTON 0x1

#define GWL_HINSTANCE -6

#define AWS_DEFAULT AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_SIZE|AWS_MINIMIZEBOX

/*************************/
/* Begin Main Subroutine */
/*************************/

global sub main() {

/* Define Variables */

myWindow Main;

/* Create The Main Window */

Main.Create(0,0,640,480,AWS_DEFAULT,0,"Test Window",null);

hinst = GetModuleHandleA(null);
hwndCloseButton = CreateWindowExA(0,"Button","OK",WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,10,10,70,25,Main.m_hwnd,0,hinst,null);

/* Wailt Until Window Is Closed */

do {

wait();

} until Main.m_hwnd = 0;

/* End Main Subroutine */

return;

}


Lewis

Bruce Peaslee

That did it, thanks.

Note: "UNIT" doesn't work, but "unsigned int" does.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Zen

No UINT is not a core type but you can use the #typedef pre-processor command to use uint as an alias.


#typedef uint unsigned int
#typedef bool int


Lewis

Ionic Wind Support Team

Which I do in almost all of my files ;)

Once I have all of the windows include files converted I'll have a standard include file that defines all of the normal types.

Paul.
Ionic Wind Support Team

Doc

Hummm... the code as copied above doesn't work for me.

Compiling...
ButtonSource.src
Unable to Open - Classes/MainWindow.inc
File: C:\Program Files\Aurora\examples\ButtonSource.src (34) unknown type
File: C:\Program Files\Aurora\examples\ButtonSource.src (38) undefined variable - Main
File: C:\Program Files\Aurora\examples\ButtonSource.src (38) unknown class
File: C:\Program Files\Aurora\examples\ButtonSource.src (41) undefined variable - Main
File: C:\Program Files\Aurora\examples\ButtonSource.src (41) invalid use of dot operator, unknown type
File: C:\Program Files\Aurora\examples\ButtonSource.src (49) undefined variable - Main
File: C:\Program Files\Aurora\examples\ButtonSource.src (49) invalid use of dot operator, unknown type
File: C:\Program Files\Aurora\examples\ButtonSource.src (49) invalid argument to UNTIL statement
File: C:\Program Files\Aurora\examples\ButtonSource.src (56) unexpected end of file: DO - }

Error(s) in compiling "C:\Program Files\Aurora\examples\ButtonSource.src"


I'm certain that I've installed the latest and greatest update, so any ideas?

-Doc-

Zen

Yes. The file MainWindow is just my file that i made with my window class declarations in. Nothing special.


class myWindow : Window {

declare OnCreate(),int;
declare OnClose(),int;

}

myWindow :: OnCreate(),int {

CenterWindow();

return true;

}

myWindow :: OnClose(),int {

Destroy();

return true;

}


Lewis