Hi. I just got a copy of Pure Basic. The demo does not include the API but it was supposed to work "just like a regular basic command" after purchase. I am new to Pure Basic but have a lot of API experience. Can someone tell me why this code won't run and I have tried the usual suspect variations.
Import "User32.lib"
If OpenWindow(0, 0, 0, 300, 300, "Resize me !", PB_Window_SystemMenu | PB_Window_ScreenCentered | PB_Window_SizeGadget)
hMainMenu.i = CreateMenu()
hFileMenu.i = CreatePopupMenu()
ret1.b = AppendMenu(hMainMenu, MF_POPUP, hFileMenu, "File")
ret2.b = AppendMenu(hFileMenu. MF_STRING, 10, "New")
Repeat
Event = WaitWindowEvent()
Until Event = PB_Event_CloseWindow
EndIf
EndImport
There should be a menu heading with "File" and a one item dropdown "New"
Cant get Win32 API
- Fangbeast
- PureBasic Protozoa
- Posts: 4790
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Cant get Win32 API
You are missing the '#' in front of your constants to actually make them constants and API names need the '_' after them.
Some of the constants may not already be defined in the compiler as well.
I.e: #PB_Window_SystemMenu
Some of the constants may not already be defined in the compiler as well.
I.e: #PB_Window_SystemMenu
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: Cant get Win32 API
Hi 649psoft2,649psoft2 wrote:Hi. I just got a copy of Pure Basic. The demo does not include the API but it was supposed to work "just like a regular basic command" after purchase. I am new to Pure Basic but have a lot of API experience. Can someone tell me why this code won't run and I have tried the usual suspect variations.
like Fangbeast wrote :
- constants start with #
- you may use API functions directly, simply add an underscore to the function name (no need to import / declare)
And you forgot SetMenu_()
This should work :
Code: Select all
hWnd = OpenWindow(0, 0, 0, 300, 300, "Resize me !", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
If hWnd
hMainMenu = CreateMenu_()
hFileMenu = CreatePopupMenu_()
AppendMenu_(hMainMenu, #MF_POPUP, hFileMenu, "File")
AppendMenu_(hFileMenu, #MF_STRING, 10, "New")
SetMenu_(hWnd, hMainMenu)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
Last edited by gnozal on Tue Mar 27, 2012 12:07 pm, edited 1 time in total.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Re: Cant get Win32 API
The problems:
1) Import is not used that way (automagically). You need to actually import using the appropriate declarations. See the HELP.
2) Your constants are variables. Use the # prefix.
3) I believe you need to associate the API-style menu to the PB window, so you need to call the SetMenu API.
I don't have the demo version installed, so I cannot check with it, but this should work.
4) You should use EnableExplicit. Doing so you would have at least trapped the problem with the constants not being constants.
5) No need to specify .i or use .b unless really required. Go with the .i by default.
See also: http://www.purebasic.fr/blog/?p=42
1) Import is not used that way (automagically). You need to actually import using the appropriate declarations. See the HELP.
2) Your constants are variables. Use the # prefix.
3) I believe you need to associate the API-style menu to the PB window, so you need to call the SetMenu API.
I don't have the demo version installed, so I cannot check with it, but this should work.
Code: Select all
#MF_POPUP = 16
#MF_STRING = 0
Import "User32.lib"
CreateMenu_() As "_CreateMenu"
AppendMenu_(hMenu, uFlags, uIDNewItem, *lpNewItem) As "_AppendMenuA@16"
SetMenu_(hWnd, hMenu) As "_SetMenu@8"
EndImport
If OpenWindow(0, 0, 0, 300, 300, "Resize me !", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
hMainMenu = CreateMenu_()
hFileMenu = CreateMenu_()
ret1 = AppendMenu_(hMainMenu, #MF_POPUP, hFileMenu, @"File")
ret2 = AppendMenu_(hFileMenu, #MF_STRING, 10, @"New")
SetMenu_(WindowID(0), hMainMenu)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
5) No need to specify .i or use .b unless really required. Go with the .i by default.
See also: http://www.purebasic.fr/blog/?p=42
Last edited by luis on Tue Mar 27, 2012 12:55 pm, edited 1 time in total.
"Have you tried turning it off and on again ?"
- Fangbeast
- PureBasic Protozoa
- Posts: 4790
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Cant get Win32 API
This is good stuff, I learned a few things today as well:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Re: Cant get Win32 API
Oh, what the hell
You BOUGHT PB right ? You talked about the demo version and I misunderstood you still had that one.
So you can discard my example where I painfully tried to make all work for the demo version like an idiot.
BTW probably it's not enough, you need to define the Win32 constants also. I just added them to that post (maybe can be useful to someone else still trying the demo).
*SIGH*

You BOUGHT PB right ? You talked about the demo version and I misunderstood you still had that one.
So you can discard my example where I painfully tried to make all work for the demo version like an idiot.

BTW probably it's not enough, you need to define the Win32 constants also. I just added them to that post (maybe can be useful to someone else still trying the demo).
*SIGH*
"Have you tried turning it off and on again ?"
Re: Cant get Win32 API
Thanks a lot for your responses they have been a great help.
Yes the demo won't work for the API I have purchased the full version.
I didn't expect such a good reply so there is a little syntax variation to learn.
I will have to get use to the explicit declarations.

Yes the demo won't work for the API I have purchased the full version.
I didn't expect such a good reply so there is a little syntax variation to learn.
I will have to get use to the explicit declarations.

-
- Addict
- Posts: 1676
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: Cant get Win32 API
It will help you to learn the language better if you use the "Enable Explicit" command at the top of your source file.
This will help correct you on various syntax issues, as well as refuse to compile on warnings that may interest you.
This will help correct you on various syntax issues, as well as refuse to compile on warnings that may interest you.
Re: Cant get Win32 API
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )