Subject: Re: Toolbar and MDI app
From: [email-masked] (Miron the Master)

30 Jan 1998 15:59:43 -0800
Message-ID: <01bd2dbc$a37690c0$LocalHost.cygnus.gnu-win32@ppp>
Mime-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_00B1_01BD2DC5.053AF8C0"
To: "GNU-Win32 Mailing list" <[email-masked]>

This is a multi-part message in MIME format.

------=_NextPart_000_00B1_01BD2DC5.053AF8C0
Content-Type: text/plain;
	charset="iso-8859-2"
Content-Transfer-Encoding: 7bit

>> 
>> Hi again,
>> I'm working on a small text editor which uses MDI.
>> Can anyone tell me how to create a working toolbar for it.
>> I've tried using CreateToolbarEx but it just draws the toolbar and
>> doesn't do anything else.
>
>CreateToolbarEx doesn't write the callback functions for you. You have
>to tell the system what to do when a toolbar button is pressed. Read the
>docs because this is not very simple
>
>
>-- 
>Jacob Navia Logiciels/Informatique
>41 rue Maurice Ravel Tel 01 48.23.51.44
>93430 Villetaneuse Fax 01 48.23.95.39
>France

I see you don't understand what my problem is, so here's the source.

Daniel Mironowicz             [email-masked]

------=_NextPart_000_00B1_01BD2DC5.053AF8C0
Content-Type: application/octet-stream;
	name="tbmdi.cc"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="tbmdi.cc"

#include <windows.h>
#include <string.h>

#include "tbmdi.h"

LRESULT CALLBACK WinMainProc(HWND, UINT, WPARAM, LPARAM);

HINSTANCE hInst;
HWND hWindow;
HWND hToolbar;
HWND MDIClient;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nShowCmd)
{
    WNDCLASS wndClass;

    wndClass.style =3D 0;
    wndClass.hInstance =3D hInstance;
    wndClass.lpszClassName =3D "MY_MDI_CLASS";
    wndClass.lpfnWndProc =3D WinMainProc;
    wndClass.hIcon =3D LoadIcon(NULL, IDI_APPLICATION);
    wndClass.hCursor =3D LoadCursor(NULL, IDC_ARROW);
    wndClass.lpszMenuName =3D NULL;
    wndClass.cbClsExtra =3D 0;
    wndClass.cbWndExtra =3D 0;
    wndClass.hbrBackground =3D (HBRUSH)(COLOR_WINDOW);
    if(!RegisterClass(&wndClass)) return 0;

    hInst =3D hInstance;

    InitCommonControls();

    hWindow =3D CreateWindowEx(0, "MY_MDI_CLASS", "Example",
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             CW_USEDEFAULT, CW_USEDEFAULT,=20
                             NULL, NULL, hInstance, NULL);
    // show window
    ShowWindow(hWindow, nShowCmd);
    UpdateWindow(hWindow);

    MSG message;
    while(GetMessage(&message, NULL, 0, 0))
        if(!TranslateMDISysAccel(MDIClient, &message))
        {
            TranslateMessage(&message);
            DispatchMessage(&message);
        }
    return message.wParam;
}

LRESULT CALLBACK WinMainProc(HWND hwnd, UINT msg,
                             WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CREATE:
        {
            // fill structure to create toolbar
            CLIENTCREATESTRUCT ccs;
            ccs.hWindowMenu =3D GetSubMenu(GetMenu(hwnd), 5);
            ccs.idFirstChild =3D 1000;
            MDIClient =3D CreateWindow("MDICLIENT", NULL, WS_CHILD | =
WS_VISIBLE |
                                     WS_CLIPCHILDREN, 0, 0, 0, 0, hwnd, =
NULL,
                                     hInst, (LPSTR)&ccs);
            TBBUTTON buttons[8];
            memset(buttons, 0, sizeof(TBBUTTON)*8);

            buttons[0].iBitmap =3D 0;
            buttons[0].idCommand =3D IDM_NEW;
            buttons[0].fsState =3D TBSTATE_ENABLED;
            buttons[0].fsStyle =3D TBSTYLE_BUTTON;

            buttons[1].iBitmap =3D 1;
            buttons[1].idCommand =3D IDM_OPEN;
            buttons[1].fsState =3D TBSTATE_ENABLED;
            buttons[1].fsStyle =3D TBSTYLE_BUTTON;

            buttons[2].iBitmap =3D 2;
            buttons[2].idCommand =3D IDM_SAVE;
            buttons[2].fsState =3D TBSTATE_ENABLED;
            buttons[2].fsStyle =3D TBSTYLE_BUTTON;

            buttons[3].iBitmap =3D 3;
            buttons[3].idCommand =3D IDM_PRINT;
            buttons[3].fsState =3D TBSTATE_ENABLED;
            buttons[3].fsStyle =3D TBSTYLE_BUTTON;

            buttons[4].iBitmap =3D 4;
            buttons[4].idCommand =3D IDM_CUT;
            buttons[4].fsState =3D TBSTATE_ENABLED;
            buttons[4].fsStyle =3D TBSTYLE_BUTTON;
                   =20
            buttons[5].iBitmap =3D 5;
            buttons[5].idCommand =3D IDM_COPY;
            buttons[5].fsState =3D TBSTATE_ENABLED;
            buttons[5].fsStyle =3D TBSTYLE_BUTTON;

            buttons[6].iBitmap =3D 6;
            buttons[6].idCommand =3D IDM_PASTE;
            buttons[6].fsState =3D TBSTATE_ENABLED;
            buttons[6].fsStyle =3D TBSTYLE_BUTTON;

            buttons[7].iBitmap =3D 7;
            buttons[7].idCommand =3D IDM_FIND;
            buttons[7].fsState =3D TBSTATE_ENABLED;
            buttons[7].fsStyle =3D TBSTYLE_BUTTON;

            // create toolbar
            hToolbar =3D CreateToolbarEx(hwnd,=20
                       WS_CHILD | WS_BORDER | WS_VISIBLE | =
TBSTYLE_TOOLTIPS,
                       350, 8, hInst, ID_BITMAP, buttons,
                       8, 0, 0, 16, 16, sizeof(TBBUTTON));
            return 0;
        }
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDM_NEW:
                {
                    MessageBox(hWindow, "New            ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    break;
                }
                case IDM_OPEN:
                {
                    MessageBox(hWindow, "Open           ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    return 0;
                }
                case IDM_SAVE:
                {
                    MessageBox(hWindow, "Save           ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    return 0;
                }
                case IDM_PRINT:
                {
                    MessageBox(hWindow, "Print          ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    return 0;
                }
                case IDM_CUT:
                {
                    MessageBox(hWindow, "Cut            ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    return 0;
                }
                case IDM_COPY:
                {
                    MessageBox(hWindow, "Copy           ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    return 0;
                }
                case IDM_PASTE:
                {
                    MessageBox(hWindow, "Paste          ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    return 0;
                }
                case IDM_FIND:
                {
                    MessageBox(hWindow, "Find           ", "Message",
                               MB_OK | MB_ICONINFORMATION);
                    return 0;
                }
            }
            return 0;
	case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
        default:
            return DefFrameProc(hwnd, MDIClient, msg, wParam, lParam);
    }
}

------=_NextPart_000_00B1_01BD2DC5.053AF8C0
Content-Type: application/octet-stream;
	name="tbmdi.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="tbmdi.h"

#define ID_BITMAP               150
#define IDM_NEW                 100
#define IDM_OPEN                101
#define IDM_SAVE                102
#define IDM_PRINT               105

#define IDM_CUT                 202
#define IDM_COPY                203
#define IDM_PASTE               204

#define IDM_FIND                300

------=_NextPart_000_00B1_01BD2DC5.053AF8C0
Content-Type: application/octet-stream;
	name="tbmdi.rc"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="tbmdi.rc"

#include "tbmdi.h"

ID_BITMAP BITMAP "winIDEtb.bmp"

------=_NextPart_000_00B1_01BD2DC5.053AF8C0
Content-Type: application/x-msdownload;
	name="tbmdi.exe"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="tbmdi.exe"

------=_NextPart_000_00B1_01BD2DC5.053AF8C0--

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".