March 29, 2024, 01:43:02 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


I know which I prefer ..

Started by GWS, June 17, 2008, 08:58:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi folks, :)

Here's a snippet of how to get a Window onscreen in another language ..


'   Abbreviated Translation of HELLOWIN.C from Charles Petzold's book:
'
'   'Programming Windows 95" published by Microsoft Press.
'   ISBN 1-55615-676-6
'
'   Note: This is not a complete program
'
'==============================================================================

#INCLUDE "Win32API.inc"

'==============================================================================
FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                  BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG
'------------------------------------------------------------------------------
    ' Program entry point
'--------------------------------------------------------------------------

    LOCAL Msg       AS tagMsg
    LOCAL wce       AS WndClassEx
    LOCAL szAppName AS ASCIIZ * 80
    LOCAL hWnd      AS DWORD

    ' Setup and register a window class for the main window
    ' CODEPTR is used to pass the address of the function that will
    ' receive all messages sent to any window created with this class
    szAppName         = "HelloWin"
    wce.cbSize        = SIZEOF(wce)
    wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
    wce.lpfnWndProc   = CODEPTR(WndProc)
    wce.cbClsExtra    = 0
    wce.cbWndExtra    = 0
    wce.hInstance     = hInstance
    wce.hIcon         = LoadIcon(hInstance, "HELLOWIN")
    wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
    wce.hbrBackground = %NULL ' No class background, we do it outselves
    wce.lpszMenuName  = %NULL
    wce.lpszClassName = VARPTR(szAppName)
    wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)

    RegisterClassEx wce

' Create a window using the registered class
    hWnd = CreateWindow(szAppName, _               ' window class name
                        "Another Hello Program", _     ' window caption
                        %WS_OVERLAPPEDWINDOW, _    ' window style
                        %CW_USEDEFAULT, _          ' initial x position
                        %CW_USEDEFAULT, _          ' initial y position
                        %CW_USEDEFAULT, _          ' initial x size
                        %CW_USEDEFAULT, _          ' initial y size
                        %NULL, _                   ' parent window handle
                        %NULL, _                   ' window menu handle
                        hInstance, _               ' program instance handle
                        BYVAL %NULL)               ' creation parameters

    IF hWnd = 0 THEN  ' exit on failure
        MSGBOX "Unable to create window"
        EXIT FUNCTION
    END IF

' Display the window on the screen
    ShowWindow hWnd, iCmdShow
    UpdateWindow hWnd

' Main message loop:
    ' Messages sent to HELLOWIN while it has the focus are received by
    ' GetMessage().  This loop translates each message and dispatches it
    ' to the appropriate handler.  When PostQuitMessage() is called, the
    ' loop terminates which ends the application.
    DO WHILE GetMessage(Msg, %NULL, 0, 0)
        TranslateMessage Msg
        DispatchMessage Msg
    LOOP

    FUNCTION = msg.wParam

END FUNCTION



Yikes  :o .. and here's how it's done in CBasic ..


def w:WINDOW
def wstyle,key:int

'  Note: This is a Complete working program ..

wstyle = @SIZE|@MINBOX|@MAXBOX

' Open a window ..
WINDOW w,50,50,500,400,wstyle,0,"Window Title",main

SETWINDOWCOLOR w,RGB(0,50,150)

WAITUNTIL w = 0

END

' Message handling routine ..
SUB main
SELECT @CLASS
case @IDCLOSEWINDOW
closewindow w
ENDSELECT
RETURN



That's just one line to open the Window - you can't get much simpler than that ..  :)

best wishes,

Graham

Tomorrow may be too late ..

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB


REDEBOLT

I'm going to have to read that book.

:D
Regards,
Bob

aurelCB

Hi Graham you give me idea i will add window style keyword in my interpreter.
Something like this:
WIN 0 0 400 300 Name @fixed
WIN 0 0 400 300 Name @resize