Powerbasic Museum 2020-B

General Category => General Discussion => Topic started by: Frank Brübach on February 03, 2010, 12:46:33 PM

Title: toolbar question
Post by: Frank Brübach on February 03, 2010, 12:46:33 PM
hello all.
I am testing some toolbar examples and made this first style for my project (see picture below).

here are my questions:

a) - it's possible to load Icons separately from own sources (*.bmp, *.png files) ? I am meaning not load from existing 'icon bitmap bar' like for example "toolbar24hot.bmp".

b) - I am using for my example three different bitmaps sources (toolbar24hot.bmp, toolbar24disabled, toolbar24normal) to see how this ImageList (LoadImage) works, but wanted to get new Icons for my buttons in toolbar, so I have to load every Icon new by name, that's correct ? Any powerbasic example exists for this case ?

c) - last not least: I am looking for an mdi example here at the board (I have found example from josé  with "CWindow.inc"). Is there any other example ?

that's all for the moment.

best regards, thanks in advance, frank
Title: Re: toolbar question
Post by: Frederick J. Harris on February 03, 2010, 04:58:09 PM
At the Forger's Win32 Tutorial there is an Mdi example that uses Toolbars, but they just load standard Windows Icons.  The tutorial is here...

http://www.winprog.org/tutorial/app_four.html

...and its in C.  Don't know how helpful that would be as PowerBASIC has a few MDI examples in the Samples directory of your installation, but you've probably seen them. 
Title: Re: toolbar question
Post by: Frank Brübach on February 03, 2010, 05:18:31 PM
thanks fred for the link, but I am looking for a simple and pure mdi example  ;)
I have tried first steps with "pbnote2" from PBWIN folder some month ago, that was very ok for that job.
But now I would like to use other Icons and toolbar (double toolbar, see picture above!) plus MDI features. Perhaps I can catch and modify some old examples.

I have only managed to make menus but no MDI text editors and MDI client window. perhaps anybody has a link or existing example, I will check and manage to include this stuff into my existing example, I am sure :)

best regards, frank
ps: I add my new 'double toolbar window' exe as zip file
Title: Re: toolbar question
Post by: José Roca on February 03, 2010, 08:23:01 PM
 
RE Toolbars: LoadImage only works with bitmaps and icons, so forget about PNGs, JPEGs and the likes. Best way: Use icons and image lists.

RE MDI: A search of this forum returns the following link:
MDIDEMO - Multiple-Document Interface Demonstration
http://www.jose.it-berater.org/smfforum/index.php?topic=31.0

Title: Re: toolbar question
Post by: Frederick J. Harris on February 03, 2010, 11:12:57 PM
Might be a problem with that link Jose.  At least from here I'm getting a bad link message.
Title: Re: toolbar question
Post by: Frank Brübach on February 04, 2010, 12:38:10 AM

better take this one: http://www.jose.it-berater.org/smfforum/index.php?topic=1697.0
Title: Re: toolbar question
Post by: Frank Brübach on February 04, 2010, 02:21:44 PM
thanks josé for the little MDI example. must still adept this one for my purpose.

well, this is a general question, but for me important how to go on into future for creating an own little editor and learning more about window api and sdk window frame. special topic MDI client window.

1) ICON TOOLBAR resource loading where? -> the old "pbnote2" example from powerbasic folder (samples/sdk folder) uses MDI related calls, very fine so far. but where does this powerbasic example gets his ICONS for TOOLBAR from ? what resource does this example use to fetch this little window icons, I have read some weeks ago this is an automatic process, but how does it work ? and it's possible to change these boring (I suggest predefined) TOOLBAR ICONS ? Must laugh a little one, but that's important for me!

2) other way would be to make new window api with new ICONS (via ImageList) for toolbar and I like the way to make a double ICON toolbar gui you can see in my last post. but to add MDI client window for this way it's hard and this will take some days to manage. - I have grasped to build in this little mdi window for my double Icon Toolbar window, but it's not perfect. step by step climbing to the mountain.

Perhaps anybody can give more information about ICON TOOLBAR loading for this "pbnote2" example I have made for my new exercise (AdamEvaBasic Editor, it's only a dummy test example) too.

My wish is to make new layout and button handling for graphic work ( so I prefer second way with double Icon toolbar!), it's just a beginning but it's important to choose the right way. I am thinking you know what I am meaning :)

be curious to get an answer about toolbar Icons ("pbnote2") where they are coming from ;)

nice day, frank
Title: Re: toolbar question
Post by: José Roca on February 04, 2010, 09:58:32 PM
Quote
1) ICON TOOLBAR resource loading where? -> the old "pbnote2" example from powerbasic folder (samples/sdk folder) uses MDI related calls, very fine so far. but where does this powerbasic example gets his ICONS for TOOLBAR from ? what resource does this example use to fetch this little window icons,

From commctrl.dll. It uses pre-defined STD_XXX constants that are identifiers for them.

Quote
I have read some weeks ago this is an automatic process, but how does it work ? and it's possible to change these boring (I suggest predefined) TOOLBAR ICONS ? Must laugh a little one, but that's important for me!

Sure. Make a bitmap strip with your icons and use an image list.
Title: Re: toolbar question
Post by: Frank Brübach on February 13, 2010, 04:46:58 PM
question about cWindow + toolbar :)

hi josé, perhaps you can give advice. I try to use your cWindow class (MDI example) and thought it's perhaps also possible to make a toolbar and load Icons with "addImage".

   pWindow.AddToolbar(hwnd, %IDToolbar, "&Toolbar", 0, 0, 0, 0, -1, -1)
   pWindow.AddImageLabel(hwnd, %IDImageLabel, "&Static", 0, 0, 0, 0, -1, -1)


do you have made any example with cWindows and *.AddImageLabel ?

I am asking because I like this short way of coding with cWindow!

best regards, franko
Title: Re: toolbar question
Post by: José Roca on February 13, 2010, 09:03:19 PM
 
Quote
[...] and thought it's perhaps also possible to make a toolbar and load Icons with "addImage".

No. AddImageLabel is to add an image label. It is equivalent to DDT's CONTROL ADD IMAGE.

A toolbar needs an image list. It is not a caprice of SDK programmers, always wanting to make things the hard way :) . If you want to build the image list at runtime, instead of using a bitmap strip and a resource file, then you can do the following (remember to change the paths and names of the icons with yours):


#COMPILE EXE
#DIM ALL

%USEMACROS = 1                      ' // Use macros
#INCLUDE ONCE "CWindow.inc"         ' // CWindow class
#INCLUDE ONCE "CommCtrl.inc"        ' // Common controls

%IDC_TOOLBAR  = 1001
%IDM_16_FIRST = 100
%IDM_16_LAST  = 101

' ########################################################################################
' Main
' ########################################################################################
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

  ' // Create an instance of the class
  LOCAL pWindow AS IWindow
  pWindow = CLASS "CWindow"
  IF ISNOTHING(pWindow) THEN EXIT FUNCTION

  ' // Create the main window
  LOCAL hwnd AS DWORD
  hwnd = pWindow.CreateWindow(%NULL, "SDK Window", 0, 0, 500, 350, -1, -1, CODEPTR(WindowProc))

  ' // Add a Toolbar
  LOCAL hToolbar AS DWORD
  hToolbar = pWindow.AddToolBar(hwnd, %IDC_TOOLBAR, "", 0, 0, 500, 28, %WS_CHILD OR %WS_VISIBLE OR %CCS_TOP OR %TBSTYLE_FLAT)

  ' // Create and initialize the image list
  LOCAL hImageList AS DWORD
  hImageList = ImageList_Create(16, 16, %ILC_MASK OR %ILC_COLOR24, 2, 0)
  IF hImageList THEN
     ' // Set the background color to use for drawing images
     ImageList_SetBkColor hImageList, %CLR_NONE
     ' // Add the images to the imagelist (change the paths of the icons if needed)
     LOCAL hImage AS DWORD
     hImage = LoadImage(%NULL, "C:\WINAPI\CWindow\16_FIRST.ico", %IMAGE_ICON, 16, 16, %LR_DEFAULTCOLOR OR %LR_LOADFROMFILE)
     ImageList_ReplaceIcon hImageList, -1, hImage
     DeleteObject hImage
     hImage = LoadImage(%NULL, "C:\WINAPI\CWindow\16_LAST.ico", %IMAGE_ICON, 16, 16, %LR_DEFAULTCOLOR OR %LR_LOADFROMFILE)
     ImageList_ReplaceIcon hImageList, -1, hImage
     DeleteObject hImage
  END IF

  ' // Set the imagelist used with default images
  SendMessage hToolbar, %TB_SETIMAGELIST, 0, hImageList

  ' // Allocate memory for the button info array
  LOCAL pttbb AS TBBUTTON PTR
  pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 2 * SIZEOF(TBBUTTON))
  IF pttbb THEN
     ' // Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
     SendMessage hToolbar, %TB_BUTTONSTRUCTSIZE, SIZEOF(TBBUTTON), 0
     ' // Set the size of the bitmaps
     SendMessage hToolbar, %TB_SETBITMAPSIZE, 0, MAKLNG(16, 16)
     ' // Add buttons to the toolbar
     @pttbb[0].iBitmap   = 0
     @pttbb[0].idCommand = %IDM_16_FIRST
     @pttbb[0].fsState   = %TBSTATE_ENABLED
     @pttbb[0].fsStyle   = %BTNS_BUTTON
     @pttbb[0].dwData    = 0
     @pttbb[0].iString   = -1

     @pttbb[1].iBitmap   = 1
     @pttbb[1].idCommand = %IDM_16_LAST
     @pttbb[1].fsState   = %TBSTATE_ENABLED
     @pttbb[1].fsStyle   = %BTNS_BUTTON
     @pttbb[1].dwData    = 0
     @pttbb[1].iString   = -1
     SendMessage hToolbar, %TB_ADDBUTTONS, 2, pttbb
     ' // Free memory that was allocated for the button info
     HeapFree GetProcessHeap(), 0, pttbb
     ' // Update the size of the toolbar
     SendMessage hToolbar, %TB_AUTOSIZE, 0, 0
  END IF

  ' // Default message pump (you can replace it with your own)
  pWindow.DoEvents

END FUNCTION
' ########################################################################################

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

  SELECT CASE uMsg

     CASE %WM_COMMAND
        SELECT CASE LO(WORD, wParam)
           CASE %IDCANCEL
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 SendMessage hwnd, %WM_CLOSE, 0, 0
                 EXIT FUNCTION
              END IF
        END SELECT

     CASE %WM_DESTROY
        ' // Destroy the image list used by the toolbar
        LOCAL hToolbar AS DWORD
        hToolbar = GetDlgItem(hWnd, %IDC_TOOLBAR)
        ImageList_Destroy SendMessage(hToolbar, %TB_SETIMAGELIST, 0, %NULL)
        ' // Close the main window
        PostQuitMessage 0
        EXIT FUNCTION

  END SELECT

  FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


Quote
I am asking because I like this short way of coding with cWindow!

I wrote it to ease the use of SDK windows. Sort of DDT for SDK programmers without the limitations of the Windows dialog engine (no MDI with DDT). It simplifies the creation of the main window and controls (even ActiveX controls can be added easily), provides a default message pump and makes very easy to subclass a control.

Before you ask, I don't have plans to add additional classes for each control, and the reason is that it will add a lot of bloat. If I do it, they will be implemented in separate include files and its usage will be optional.

Title: Re: toolbar question
Post by: Frank Brübach on February 13, 2010, 10:58:16 PM
thanks josé, your little example helped a lot. I have got it and my little cWindow example looks like cute and a really nice little app with a lot of horrible secrets behind the icon buttons (sic: a joke!). my modified example I add as picture and exe in zip file.

do you think it's smart to use cWindow class for making an editor or it's nearly fussy to do that? otherwise I prefer "pbnote2" sdk example (I have already expand it for my purposes. I will show next weeks, if I am ready). I am thinking it's a similar technique for setting an imagelist for toolbar with icons. I liked the idea with bigger icons and double toolbar (like one of my examples some posts before) and perhaps I will manage that to include a mdi child window for it, don't know. - I am not sure what's the best way. I like cWindow because it's thin and fast and I have a good overview, not coding overkill by more than one or two hundred lines ;)

QuoteIf you want to build the image list at runtime, instead of using a bitmap strip and a resource file, then you can do the following (remember to change the paths and names of the icons with yours):

thanks for showing about this handling with separately loading of different icons! I was exactly looking for this kind of spread variety for making a good and unique toolbar :)

by the way. interesting idea "to ease the use of sdk windows". many thanks!

good evening, thanks, franko
Title: Re: toolbar question
Post by: José Roca on February 13, 2010, 11:48:10 PM
 
Quote
do you think it's smart to use cWindow class for making an editor or it's nearly fussy to do that?

CWindow doesn't allow you to do anything more than using pure SDK code. Its main advantage is that you need to write less code. Newbies are scared when they see the Petzold's examples with a lot of lines of code to register the class, find CreateWindowEx cumbersome and don't fully understand message pumps. CWindow allows them to create a main window and add controls as easily as with DDT, yet it is more powerful.

You can also add OCXs (registered or not, licensed or not) in the same way that standard controls and instances of the WebBrowser control that you can use to display HTML code or a web page, or to embed Word documents, .pdf files, Excel spreadsheets or other ActiveX controls like Windows Media Player, Flash movies or anything else supported by Internet Explorer.

It also offers optional High-DPI awareness. Call the SET DPI property passing the DPI used at design time and the window and the controls will be scaled if the user changes the DPI setting of his computer to a different value.
Title: Re: toolbar question
Post by: Edwin Knoppert on February 14, 2010, 12:05:33 AM
But it's rather unlikely a 'newbie' will visit your site for alternatives because he got 'scared' about the sdk code.
The new includes will scare them more than the sdk code i guess.
A class as a black box will not help much as well.

We need a poll :)
Title: Re: toolbar question
Post by: José Roca on February 14, 2010, 04:15:26 AM
 
I'm providing the source of the class, so it is not a black box.

Anyway, I don't care if they use it or not. It can be useful only to those coding GUIs by hand. The users of visual designers will use what the tool of his choice provides: DDT statements, EZ_ functions, FF_ functions, VD_ dispatch classes...

Users of other compilers seem less scared by my code.

See how this old function:


' ****************************************************************************************
' Creates a licensed instance of a visual control (OCX) and attaches it to a window.
' StrProgID can be the ProgID or the ClsID. If you pass a version dependent ProgID or a ClsID,
' it will work only with this particular version.
' hWndControl is the handle of the window and strLicKey the license key.
' ****************************************************************************************
FUNCTION TB_CreateControlLic (BYVAL strProgID AS STRING, BYVAL hWndControl AS DWORD, BYVAL strLicKey AS STRING) AS LONG

   LOCAL HRESULT AS LONG               ' Result code
   LOCAL ppUnknown AS DWORD            ' IUnknown pointer
   LOCAL ppDispatch AS DWORD           ' IDispatch pointer
   LOCAL ppObj AS DWORD                ' Dispatch interface of the control
   LOCAL ppClassFactory2 AS DWORD      ' IClassFactory2 pointer
   LOCAL ppUnkContainer AS DWORD       ' IUnknown of the container
   LOCAL IID_NULL AS GUID              ' Null GUID
   LOCAL IID_IUnknown AS GUID          ' Iunknown GUID
   LOCAL IID_IDispatch AS GUID         ' IDispatch GUID
   LOCAL IID_IClassFactory2 AS GUID    ' IClassFactory2 GUID
   LOCAL ClassID AS GUID               ' CLSID
   LOCAL pbstrLicKey AS STRING         ' Unicode license key string

   pbstrLicKey = UCODE$(strLicKey)     ' Convert the license key to Unicode

   ' Standard interface GUIDs
   IID_NULL = GUID$("{00000000-0000-0000-0000-000000000000}")
   IID_IUnknown = GUID$("{00000000-0000-0000-c000-000000000046}")
   IID_IDispatch = GUID$("{00020400-0000-0000-c000-000000000046}")
   IID_IClassFactory2 = GUID$("{b196b28f-bab4-101a-b69c-00aa00341d07}")

   ' Exit if strProgID is a null string
   IF strProgID = "" THEN
      FUNCTION = &H80070057 ' %E_INVALIDARG
      EXIT FUNCTION
   END IF

   ' Convert the ProgID to a CLSID
   ClassID = CLSID$(strProgID)

   ' If it fails, see if it is a CLSID
   IF ClassID = IID_NULL THEN ClassID = GUID$(strProgID)

   ' If not a valid ProgID or CLSID return an error
   IF ClassID = IID_NULL THEN
      FUNCTION = &H80070057 ' %E_INVALIDARG
      EXIT FUNCTION
   END IF

   ' Get a reference to the IClassFactory2 interface of the control
   ' Context: &H17 (%CLSCTX_ALL) =
   ' %CLSCTX_INPROC_SERVER OR %CLSCTX_INPROC_HANDLER OR _
   ' %CLSCTX_LOCAL_SERVER OR %CLSCTX_REMOTE_SERVER
   HRESULT = CoGetClassObject(ClassID, &H17, %NULL, IID_IClassFactory2, ppClassFactory2)
   IF ISTRUE HRESULT THEN
      FUNCTION = HRESULT
      EXIT FUNCTION
   END IF

   ' Create a licensed instance of the control
   HRESULT = IClassFactory2_CreateInstanceLic(ppClassFactory2, %NULL, %NULL, IID_IUnknown, STRPTR(pbstrLicKey), ppUnknown)
   ' First release the IClassFactory2 interface
   IUnknown_Release ppClassFactory2
   IF HRESULT <> %S_OK OR ppUnknown = %NULL THEN
      FUNCTION = HRESULT
      EXIT FUNCTION
   END IF

   ' Ask for the dispatch interface of the control
   HRESULT = IUnknown_QueryInterface(ppUnknown, IID_IDispatch, ppDispatch)

   ' If it fails, use the IUnknown of the control, else use IDispatch
   IF HRESULT <> %S_OK OR ppDispatch = %NULL THEN
      ppObj = ppUnknown
   ELSE
      ' Release the IUnknown interface
      IUnknown_Release ppUnknown
      ppObj = ppDispatch
   END IF

   ' Attach the control to the window
   HRESULT = AtlAxAttachControl(ppObj, hWndControl, ppUnkContainer)

   ' Note: Do not release ppObj or your application will GPF when it ends because
   ' ATL will release it when the window that hosts the control is destroyed.

   FUNCTION = HRESULT

END FUNCTION
' ****************************************************************************************


Has been translated to FreeBasic:


' ****************************************************************************************
' Creates a licensed instance of a visual control (OCX) and attaches it to a window.
' StrProgID can be the ProgID or the ClsID. If you pass a version dependent ProgID or a ClsID,
' it will work only with this particular version.
' hWndControl is the handle of the window and strLicKey the license key.
' ****************************************************************************************
FUNCTION AxCreateControlLic (BYVAL strProgID AS LPOLESTR, byval hWndControl AS uinteger, byval strLicKey AS lpwstr) AS LONG
DIM ppUnknown AS lpunknown        ' IUnknown pointer
DIM ppDispatch AS lpdispatch      ' IDispatch pointer
DIM ppObj AS lpvoid               ' Dispatch interface of the control
DIM ppClassFactory2 AS IClassFactory2 ptr  ' IClassFactory2 pointer
DIM ppUnkContainer AS lpunknown   ' IUnknown of the container
'DIM IID_NULL as IID               ' Null GUID
'DIM IID_IUnknown as IID           ' Iunknown GUID
'DIM IID_IDispatch as IID          ' IDispatch GUID
'DIM IID_IClassFactory2 as IID     ' IClassFactory2 GUID
DIM ClassID AS clsid              ' CLSID

' Standard interface GUIDs
'IIDFromString("{00000000-0000-0000-0000-000000000000}",@IID_NULL)
'IIDFromString("{00000000-0000-0000-C000-000000000046}",@IID_IUnknown)
'IIDFromString("{00020400-0000-0000-C000-000000000046}",@IID_IDispatch)
'IIDFromString("{b196b28f-bab4-101a-b69c-00aa00341d07}",@IID_IClassFactory2)
' Exit if strProgID is a null string
IF *strProgID = "" THEN
FUNCTION = E_INVALIDARG
EXIT FUNCTION
END If
' Convert the ProgID in a CLSID
AxScode=CLSIDFromProgID(strProgID,@ClassID)
' If it fails, see if it is a CLSID
IF AxScode<>0 THEN AxScode=IIDFromString(strProgID,@ClassID)
' If not a valid ProgID or CLSID return an error
IF AxScode<>0 THEN    
FUNCTION = E_INVALIDARG
EXIT FUNCTION
END If
' Get a reference to the IClassFactory2 interface of the control
' Context: &H17 (%CLSCTX_ALL) =
' %CLSCTX_INPROC_SERVER OR %CLSCTX_INPROC_HANDLER OR _
' %CLSCTX_LOCAL_SERVER OR %CLSCTX_REMOTE_SERVER    
AxScode = CoGetClassObject(@ClassID,&H17,null,@IID_IClassFactory2,@ppClassFactory2)
IF AxScode<>0 THEN
FUNCTION = AxScode
EXIT FUNCTION
END If
' Create a licensed instance of the control
AxScode=IClassFactory2_CreateInstanceLic(ppClassFactory2,NULL,NULL,@IID_IUnknown,strlickey,@ppUnknown)
DeAllocate(strLicKey)
' First release the IClassFactory2 interface
IClassFactory2_Release(ppClassFactory2)
IF AxScode<>0  OR ppUnknown=0 Then
FUNCTION = AxScode
EXIT FUNCTION
END If
' Ask for the dispatch interface of the control
AxScode = IUnknown_QueryInterface(ppUnknown, @IID_IDispatch, @ppDispatch)
' If it fails, use the IUnknown of the control, else use IDispatch
IF AxScode<>0 OR ppDispatch=0 THEN
ppObj = ppUnknown
Else
' Release the IUnknown interface
IUnknown_Release(ppUnknown)
ppObj = ppDispatch
END If
' Attach the control to the window
AxScode=AtlAxAttachControl(ppObj, hwndcontrol, @ppunkcontainer)
' Note: Do not release ppObj or your application will GPF when it ends because
' ATL will release it when the window that hosts the control is destroyed.
FUNCTION = AxScode
END Function

Title: Re: toolbar question
Post by: Patrice Terrier on February 14, 2010, 09:32:34 AM
QuoteAnyway, I don't care if they use it or not. It can be useful only to those coding GUIs by hand. The users of visual designers will use what the tool of his choice provides: DDT statements, EZ_ functions, FF_ functions, VD_ dispatch classes...

Users of other compilers seem less scared by my code.

Coding GUIs by hand is the only way to control everything, thus it seems very logic for a SDK programmer like myself.

But if people need to have their work done fast, then they better look for a true RAD tool or L5G.
Whyle hobbyist programmers could limit themselves to one single tool, professionnal programmers can't, they must have an arsenal at their finger tip and use the best to achieve a specific task. The tools you can use to build a hut, would be totaly inadequate to build a Dubai skyscraper.

José, always provides examples with full source code, and that is the best way to learn from a master, but of course only for those wanting to make the effort to learn and that is the limit of what he can do for you.

...
Title: Re: toolbar question
Post by: Frank Brübach on February 16, 2010, 12:15:13 AM
little work in progress..

now it's possible to open a new cWindow sdk frame by a) "ok" button-click or b) via "icon" at toolbar (here for my example the seventh. icon from left side, woman with dark hair and sunglasses ).

to manage this one I had to make c) "opennewSDK" function and d) include there a "richedit" control, just for fun :)

some important part of my code:  
' ===============================================================================
FUNCTION openNewsdk() AS LONG

      ' // Create an instance of the class
  LOCAL pWindow AS IWindow
  pWindow = CLASS "CWindow"
  IF ISNOTHING(pWindow) THEN EXIT FUNCTION

  ' // Create the main window
  LOCAL hwnd AS DWORD

  hwnd = pWindow.CreateWindow(%NULL, "Frankos SDK cWindow 200 with gradient & Toolbar & RichEdit", %CW_USEDEFAULT, %CW_USEDEFAULT, _
         %CW_USEDEFAULT, %CW_USEDEFAULT, -1, -1, CODEPTR(WindowProc2))

  ' // Change the style of the main window class
  SetClassLong hwnd, %GCL_STYLE, %CS_DBLCLKS OR %CS_HREDRAW OR %CS_VREDRAW

  ' // Add two buttons without position or size (they will be resized
  ' // in the WM_SIZE message).
  pWindow.AddButton(hwnd, %IDOK,     "&Ok2",   0, 0, 0, 0, -1, -1)
  pWindow.AddButton(hwnd, %IDCANCEL, "&Quit2", 0, 0, 0, 0, -1, -1)
  ' // Add a rich edit control
  pWindow.AddRichEdit(hwnd, %IDC_RICHEDIT, "my lovely RichEdit box wit first part of lord of the rings story", 0, 0, 0, 0, -1, -1)

  ' // Force the resizing of the buttons by sending a WM_SIZE message
  SendMessage hwnd, %WM_SIZE, 0, 0

  ' // Default message pump (you can replace it with your own)
  pWindow.DoEvents

END FUNCTION
===============================================================================

FUNCTION WindowProc2 (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

  LOCAL hDC AS DWORD
  LOCAL pPaint AS PAINTSTRUCT
  LOCAL rc AS RECT

  SELECT CASE uMsg

     CASE %WM_COMMAND
        SELECT CASE LO(WORD, wParam)
           CASE %IDCANCEL
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 SendMessage hwnd, %WM_CLOSE, 0, 0
                 EXIT FUNCTION
              END IF

             CASE %IDOK
              IF HI(WORD, wParam) = %BN_CLICKED THEN
                 openNewsdk()
                 EXIT FUNCTION
              END IF

            END SELECT

     CASE %WM_PAINT
        hDC = BeginPaint(hwnd, pPaint)
        GetClientRect hwnd, rc
        SetBkMode hDC, %TRANSPARENT
        SetTextColor hDC, %GREEN
        DrawText hDC, "Hello, my little new AdamEva Windows!", -1, rc, %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER
        EndPaint hwnd, pPaint
        FUNCTION = %TRUE
        EXIT FUNCTION

     CASE %WM_ERASEBKGND
        hDC = wParam
        DrawGradient hwnd, hDC
        FUNCTION = %TRUE
        EXIT FUNCTION

     CASE %WM_SIZE
        IF wParam <> %SIZE_MINIMIZED THEN
           GetClientRect hwnd, rc
           MoveWindow GetDlgItem(hwnd, %IDOK), (rc.nRight - rc.nLeft) - 185, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDCANCEL), (rc.nRight - rc.nLeft) - 95, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDToolbar), (rc.nRight - rc.nLeft) - 5, (rc.nBottom - rc.nTop) - 5, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDC_RICHEDIT), (rc.nRight - rc.nLeft) - 305, (rc.nBottom - rc.nTop) - 425, 250, 150, %TRUE
        END IF

     CASE %WM_DESTROY
        PostQuitMessage 0
        EXIT FUNCTION

  END SELECT

  FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' =========================================


perhaps somebody can use it or find this stuff helpful :)

by the way: it wasn't easy to find my little fault and need some time to explore the mistake I've done to add new "windowProc2" function with

CASE %WM_SIZE
        IF wParam <> %SIZE_MINIMIZED THEN
           GetClientRect hwnd, rc
           MoveWindow GetDlgItem(hwnd, %IDOK), (rc.nRight - rc.nLeft) - 185, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDCANCEL), (rc.nRight - rc.nLeft) - 95, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDToolbar), (rc.nRight - rc.nLeft) - 5, (rc.nBottom - rc.nTop) - 5, 75, 23, %TRUE
           MoveWindow GetDlgItem(hwnd, %IDC_RICHEDIT), (rc.nRight - rc.nLeft) - 305, (rc.nBottom - rc.nTop) - 425, 250, 150, %TRUE
     


to size and realize these buttons and the richedit box, that wasn't very clear for me at the start of coding, as I have defined all

  LOCAL hButton AS DWORD
  hButton = pWindow.AddButton(hwnd, %IDOK,     "&Ok",   0, 0, 0, 0, -1, -1)
  hButton = pWindow.AddButton(hwnd, %IDCANCEL, "&Quit", 0, 0, 0, 0, -1, -1)
  hButton = pWindow.AddButton(hwnd, %IDC_RICHEDIT, "&LORD OF THE RING RICH EDIT INPUT", 0, 0, 0, 0, -1, -1)


with "0" values (numbers), that was new for me ;)

Picture of new cWindow sdk window with toolbar, richedit I add as zipfile with exe file for demo showing.

good night, frank
ps: it's also possible to change the color of "menubar" ? (that's too grey and boring for me)
Title: Re: toolbar question
Post by: Frank Brübach on February 17, 2010, 06:31:45 PM
I have forgotten to include a Picture path folder for my Icons in my last cWindow example above, sorry. This example hasn't shown at all Icons, because therefore you need all collected icons in one folder.

Here I show a new example with new Icons and an cute Art_Picture with a woman, all done with gdiplus power :)

one favour: perhaps anybody can test this "AEB_Art" Demo if everything works fine, would be nice to get any feedback.

If you're using Icon Buttons 1,2,7,9 (from left side) you will get more features and Infos ;)
I like combination "cWindow" + "gdiplus" class and want to use this for future examples !

the whole powerbasic code increase to nearly 900 lines, uff, that's too much for me, but I need all these commands for my picture features and cWindow frames ! May be I will find shorter way next week, if I know more about cWindow (popup windows) behaviour or related tricky ways. Learning by doing. Work in progress, good to see how gdiplus works and cWindow. some weeks ago I felt like to go in a dark forrest, but now it's brighter and clearer although new questions around cWindow/gdiplus appear every day new :D

I am interested in graphic works and arts, so I will concentrate myself to these topics. three month ago powerbasic was an absolutely alien child for me, today this nice beast is now a little friend I can train for a serious moment... (take it with humour!)

zip File I add.

nice evening, thanks, frank
Title: Re: toolbar question
Post by: Frank Brübach on February 18, 2010, 03:41:42 PM
my task: in my "mdiWindowProc" function I have the simple problem to make a new line (empty, for new text input) after return key for my create MDI child window.

 CASE %IDM_NEW
              IF hwndClient THEN
                 nIdx += 1
                 hMdi = CreateMdiChild("PBFrameClass", hwndClient, "", 0)
                 SetWindowText hMdi, "my MDI Child Window" & STR$(nIdx)
              END IF
              EXIT FUNCTION


1) it's not possible to create a new line by hand via return key for a next new empty line with "pWindow.AddrichEdit" or "pWindow.AddTextBox". there must be missing something important, but what ?

     CASE %WM_CREATE
        ' // Retrieve a reference to the CWindow class from the MDI child window handle
        LOCAL pWindow AS IWindow
        pWindow = CWindow_GetObjectFromWindowHandle(hwnd)
        ' // Create and edit control control
        IF ISOBJECT(pWindow) THEN
           GetClientRect hwnd, rc
        'pWindow.AddRichEdit(hwnd, %IDC_EDIT, "test me :)", 0, 0, rc.nRight, rc.nBottom, _
                           'TextBox
        hEdit = pWindow.AddRichEdit(hwnd, %IDC_RICHEDIT, "test me with more lines and return to start a new line with text :)" & $CRLF & _
               "Text Editor (MDI) and in spe Art_Compiler for 'AEB' itself" & $CRLF & _
               "Text Editor (MDI) and in spe Art_Compiler for 'AEB' itself" & $CRLF & _
               "Text Editor (MDI) and in spe Art_Compiler for 'AEB' itself" & $CRLF & _
               "Text Editor (MDI) and in spe Art_Compiler for 'AEB' itself" & $CRLF & _
               "Text Editor (MDI) and in spe Art_Compiler for 'AEB' itself", 0, 0, rc.nRight, rc.nBottom, _
              %WS_CHILD OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR %ES_MULTILINE OR %WS_VSCROLL OR %WS_HSCROLL OR _
              %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL OR %ES_NOHIDESEL, 0)
           EXIT FUNCTION
        END IF


2) my new opened sdk-window (by icon button) with "pWindow.AddRichEdit" (button 7) hasn't this problem so I suppose it belongs to the mdi child window handling. anybody can help ?

I wish to create simple new text lines in this new mdi child window, nothing more ;)

best regards, frank
Title: Re: toolbar question
Post by: José Roca on February 18, 2010, 05:04:21 PM
 
You're missing the %ES_WANTRETURN style.
Title: Re: toolbar question
Post by: Frank Brübach on February 20, 2010, 02:48:59 PM
hello.

I am just looking for a simple possibility and command to "stretch" an Image with "gdiplus.inc".
with "gdipImageCTX.inc" that's possible, but not for my example, I would like to use gdiplus features.

Quote
CASE %IDC_STRETCHER
              IF HI(WORD, wParam) = %BN_CLICKED THEN
              'GdipImageCtx_SetImageAdjustment GetDlgItem(hwnd, %IDC_IMAGECTX), %GDIP_IMAGECTX_STRETCH, %TRUE '%IDC_IMAGECTX                  
                 EXIT FUNCTION
              END IF

I cannot mix "GdipImageCtx.inc" with "gdiplus.inc" + "cwindow.inc" for my examples, it doesn't work for me, I have tried this one. I am looking for similar command like:

QuoteGRAPHIC STRETCH hBMP, 0, (0, 0)-(BMPx-1,BMPy-1) TO (49,49)-(449,449)

does anybody has experience with stretching a picture (image) with gdiplus ? does any example or link exist to this problem or feature ? would be nice to find one. I was looking for that around some hours without success.

2) new edit :
sorry, but perhaps I have found a way and can solve this problem with:

QuotehStatus2 = GdipGetImageWidth(pImage2, nWidth)
   hStatus2 = GdipGetImageHeight(pImage2, nHeight)
   hStatus2 = GdipDrawImageRectI(pGraphics2, pImage2, 190, 190, nWidth, nHeight)

I will check if I can scale the image by one button click ;)

many thanks, nice day, Frank
Title: Re: toolbar question
Post by: Frank Brübach on February 23, 2010, 08:14:18 PM
topic: gdiplus + stretch (or manipulate image size).
sorry for asking again ;)

I am not gdiplus professional (more newbie with this!) , so I show my current problem.

a) If I load a picture with a new sdk frame and use for example "GDIP_SETPIXEL"

' // Draw the bitmap
  hStatus = GdipDrawImageI(pGraphics, pBitmap, 50, 250)

  ' // Get the width and height of the bitmap
  hStatus = GdipGetImageWidth(pBitmap, nWidth)
  hStatus = GdipGetImageHeight(pBitmap, nHeight)
 
 


I load my picture as well as I wish, all ok. but I load for this stretching a new sdk window. that wasn't my idea. I wanted to change the image in same sdk window frame (cWindow).

next step:

b) how can I stretch this picture in same sdk frame ? I use a button (for example: IDC_IMAGE_STRETCH) try to stretch to another size the image (picture), but therefore I need an own command I suggest.

because after clicking IDC_IMAGE_STRETCH button

     CASE %WM_PAINT
        hDC = BeginPaint(hWnd, ps)
        GDIP_SetPixel hDC
        EndPaint(hWnd, ps)


nothing will change, because in %WM_PAINT statement is defined to show the function of "GDIP_SetPixel" and not more. my idea was to delete whole image after showing this first %WM_PAINT for a second %WM_PAINT with new function (for example) "GDIP_SetPixelStretch hDC". that's nonsense ? ;)

any help would be appreciated. I didn't want to use GdipImageCTX include file , although there is exactly this command with my idea and statement I need for. see my last post.

GdipImageCtx_SetImageAdjustment GetDlgItem(hwnd, %IDC_IMAGECTX), %GDIP_IMAGECTX_STRETCH, %TRUE '%IDC_IMAGECTX      

I am walking in a circle with no exit :)

bye, frank
Title: Re: toolbar question
Post by: José Roca on February 23, 2010, 09:28:33 PM
 
The function GDIP_SetPixel draws the image using GdipDrawImageRectI. You can declare a global variable, e.g. bStretched, that you will set to TRUE when you click the button. Then, in the function, use:


IF bStretched THEN
   hStatus = GdipDrawImageRectI(pGraphics, pBitmap, x, y, MyWidth, MyHeight)
ELSE
   hStatus = GdipDrawImageI(pGraphics, pBitmap, x, y)
END IF


Where x, y, MyWidth and MyHeight specify the rectangular area where the image will be draw stretched.
Title: Re: toolbar question
Post by: Frank Brübach on February 25, 2010, 10:57:02 PM
thanks a lot for you help, josé! I will include this one for my new stretch pictures :)

in general: may I ask you about an optimazing code topic? What is the advantage about/between using sdk frame like cWindow.inc for example to an usual "ddt dialog" (new dialog) editor for popup or loading/saving pictures menus ? I am asking myself it's necessary to use more sdk window frames to bloat my codes. my art editor increases a  lot of lines, be sure ;)

there is any "disadvantage" of using sdk (I think there is factor * 3 in code lines for usual ddt frame code) for application speed ? it's a serious question to run an application. I think you know what I mean.

my idea is to launch an "Art_Editor" for pictures/Images using cWindow and gdiplus features. my idea is to create a picture manipulation software and petzold was some weeks ago my friend ;) not today, I am sorry. that's what I am intending to do for my personal aims using powerbasic and sdk frame windows. I like the idea to shorten code and so I was starting with cWindows and I am on the best way to fulfil my task. I am learning with powerbasic al lot of things and special gdiplus include statements, but sometimes I am wondering about speed optimation or "easy" handling with a long code example, I suggest it's not very smart to use a big bloat of code lines. it's better to use or build a DLL instead of ? this is a very important question for me. My knowledge about this one is less and  therefore  I am asking. My suggestions about this topic is, that a DLL for all processes and compiler actions are faster than usual include files (there might be for one application more than four, five include files). that's true ?

to be truly: I am not sure what it's the best way for creating a fast application without any speed relays and it's stabile and serious application for use !

hope you can answer about this topic or anybody else :)

good night, best regards, frank    
Title: Re: toolbar question
Post by: José Roca on February 26, 2010, 02:04:38 AM
Quote
there is any "disadvantage" of using sdk (I think there is factor * 3 in code lines for usual ddt frame code) for application speed ? it's a serious question to run an application. I think you know what I mean.

Pure SDK code produces smaller and faster executables. You use less lines of code with DDT, but the binary produced is somewhat bigger and slower because the compiler has to generate all the code you have been too lazy to write, and some more.

Quote
I suggest it's not very smart to use a big bloat of code lines. it's better to use or build a DLL instead of ? this is a very important question for me. My knowledge about this one is less and  therefore  I am asking. My suggestions about this topic is, that a DLL for all processes and compiler actions are faster than usual include files (there might be for one application more than four, five include files). that's true ?

Faster than what? If there are less lines of code, it will take less time to compile, but this doesn't mean that the program will run faster. Calling a function in a DLL is somewhat slower that if it is incorporated in the program.

But the differences are quite small, so what you use is mainly a matter of preferences.
Title: Re: statusbar / toolbar question
Post by: Frank Brübach on April 26, 2010, 07:04:23 PM
hello again :)

1) one more little question to my toolbar project. I will follow next time this task. Now I would like to add a "statusbar" with cWin. I have included this line

QuoteLOCAL hStatusbar AS DWORD
  hStatusbar = pWindow.AddStatusBar(hwnd, %IDSTATUSBAR, "", 0, 347, 535, 23, %WS_CHILD OR %WS_VISIBLE OR %CCS_TOP OR %TBSTYLE_FLAT)
  SendMessage hStatusbar, %WM_SETFONT, hFont, %TRUE

also thought it was necessary to include

Quote"msctls_statusbar32"
, but it doesn't work.

My new "statusbar" appears directly below or partly through my toolbar with button images (see picture below). I am sure something is missing. perhaps anybody can give a good hint where's my mistake.


2) quite other thing: one favour: one person (I don't know who was it) has changed my charma from "0" to "1" some weeks (month) ago, at that time I have done a lot of work here. After some weeks I think it was the same person changed backward my charma from "1" to "0". I don't understand such thing. I don't like this anonymous behaviour. in my eyes it's a disadvantage of this charma element at this website. this motivation elements for applauds or smiting people is only good if you can see from whom this "+" or "-" points were given. And I would like to know who is the person who did it in my case.
-> Would be better to install a "charma modul" with input for changing charma (who for what person and the reason why). such charma modul exists ! ;)

thanks, frank
Title: Re: toolbar question
Post by: José Roca on April 26, 2010, 09:18:10 PM

Use:


hStatusbar = pWindow.AddStatusBar(hwnd, %IDSTATUSBAR, "", 0, 347, 535, 23, %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS OR %CCS_BOTTOM OR %SBARS_SIZEGRIP)


and don't mix styles of other controls: %TBSTYLE_FLAT is for toolbars.

Quote
Would be better to install a "charma modul" with input for changing charma (who for what person and the reason why). such charma modul exists !

I know, but I don't like to install mods. They can became a nightmare when you update the forum to a new version.
Title: Re: statusbar / toolbar question
Post by: Frank Brübach on April 26, 2010, 09:55:59 PM
thanks jose for fast reply. my example works correctly with "statusbar" below placed where it should be. You are right: I've copied some styles from Toolbar control, didn't check that. my mistake.

QuoteI know, but I don't like to install mods. They can became a nightmare when you update the forum to a new version.

that's new for me. good to know that's a technical problem and probably sysiphos work. but I think it would be better to install such module (my personal opinion). I like to act with each nice person around me (private like professional) in a very fair and heartly way. so I am wondering why it's here anonymous to applaude or smite persons for their engagement. it's ok, I can't change that. today I can live with humour about this little red laughing evil thing ;)

servus, best regards, frank
Title: Re: toolbar question
Post by: Jürgen Huhn on July 26, 2010, 10:26:32 AM
Servus Frank!

At this point i have to say:

I like to read all your post`s very much and even your Strain to go a fair and heartly way.

That`s making the World a bit nicer! Thank you!

All my Best,

Jürgen
  ;)