Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
translating win32API C tutorial to fB ::New question::
#1
Some time ago I decided to learn win32API
(or whatever the real name is) for C/C++ and I found a tutorial on the
net that seemed to be on my level.

(that I later gave up because of lack of amition is beside the point -coding apathy )

Now when fB came out I decided to give it a try again, but this time
translating the code in the examples to fB with the help from the
hello.bas win32API example coming with fB.

I have some problems/questions...

1) What is byval? and why do I pass numbers but not strings as byval?
2)why can't I put gszclassname as const in fB It complains about
wrong parameter type ar something like that. Is it about pointers to
string data and the stuff I've seen people have problems with in other threads?
3)Uh. Yeah, also: the code doesn't work (window creation failed) what am i doing wrong?

The C code
[syntax="c"]#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
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;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
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 = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

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

// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}[/syntax]

not working fB code...

[syntax="qbasic"]defint a-z
option explicit
option private

'$include once:'win\kernel32.bi'
'$include once:'win\user32.bi'
'$include once:'win\gdi32.bi'

declare function wndproc (byval hwnd as long, _
byval msg as long, _
byval wparam as long, _
byval lparam as long,) as integer

declare function WinMain(byval hinstance as long, _
byval hprevinstance as long, _
lpcmdline as string, _
byval nCmdShow as integer) as integer

end WinMain( GetModuleHandle(0), 0, Command$, SW_NORMAL )

function wndproc (byval hwnd as long, _
byval msg as long, _
byval wparam as long, _
byval lparam as long,) as integer
select case msg
case wm_close: destroywindow(hwnd)
case wm_destroy: postquitmessage 0
case else: wndproc=defwindowproc(hwnd,msg,wparam,lparam)
end select

wndproc=0
end function

function WinMain(byval hinstance as long, _
byval hprevInstance as long, _
lpcommandline as string, _
byval ncmdshow as integer) as integer
dim wc as wndclassex
dim hwnd as long
dim msg as msg
dim gszclassname as string
gszclassname="myWindowClass"
wc.cbsize=len(wndclassex)
wc.style=0
wc.lpfnwndproc=@wndproc
wc.cbclsextra=0
wc.cbwndextra=0
wc.hinstance=hinstance
wc.hicon=loadicon(0,IDI_APPLICATION)
wc.hcursor=loadcursor(0,IDC_ARROW)
wc.hbrbackground=GetStockObject( WHITE_BRUSH )
wc.lpszmenuname=0
wc.lpszclassname=strptr(gszclassname)
wc.hiconsm=loadicon(0,IDI_APPLICATION)

if registerclassex(wc)=0 then
messagebox 0,"window registration failed","error",MB_ICONEXCLAMATION or MB_OK
winmain=0
end 0
else
messagebox 0,"window registration sucsessful","woot",MB_ICONEXCLAMATION or MB_OK
end if

hwnd=createwindowex(WS_EX_CLIENTEDGE ,_
gszclassname ,_
"My window title" ,_
WS_OVERLAPPEDWINDOW ,_
CW_USEDEFAULT ,_
CW_USEDEFAULT ,_
240 ,_
120 ,_
0 ,_
0 ,_
hinstance ,_
0)
if hwnd=0 then
messagebox 0,"window creation failed","error",MB_ICONEXCLAMATION or MB_OK
winmain=0
end 0
end if

showwindow hwnd,ncmdshow
updatewindow hwnd
while getmessage(msg,0,0,0)>0
translatemessage(msg)
dispatchmessage(msg)
wend

winmain=msg.wparam
end function[/syntax] :-? :-? Sad
/post]
Reply


Messages In This Thread
translating win32API C tutorial to fB ::New question:: - by red_Marvin - 03-13-2005, 10:18 PM
Next question: - by red_Marvin - 03-16-2005, 07:53 PM
Win32 Api wgl - by Glu - 03-18-2005, 01:29 AM
Win32 Api wgl - by Glu - 03-22-2005, 07:00 AM
Win 32 - by Glu - 03-23-2005, 10:31 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)