Subject: Set/GetWindowLong doesn't seem work
From: [email-masked] (Miron the Master)

8 Feb 1998 03:59:35 -0800
Message-ID: <01bd3483$cd981c20$LocalHost.cygnus.gnu-win32@ppp>
Mime-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_003D_01BD348C.2F5C8420"
To: "GNU-Win32 Mailing list" <[email-masked]>

This is a multi-part message in MIME format.

------=_NextPart_000_003D_01BD348C.2F5C8420
Content-Type: text/plain;
	charset="iso-8859-2"
Content-Transfer-Encoding: 7bit

Hi,
I'm workin on a small text editor. I use edit class for editing text.
Here's what I do:

1. Create new window using SendMessage & WM_MDICREATE
2. In document callback proc in respond to WM_CREATE i create EDIT window
using
hEdit = CreateWindowEx(...);
and remember edit handle
SetWindowLong(hwnd, 0, (LONG)hEdit);
And when i use GetWindowLong(hwnd, 0) to get edit handle I don't get it.

hEdit - edit handle
hwnd - parameter passed to document window proc.

Look at the sample source...

Thanx for all help.

Daniel Mironowicz                 [email-masked]

------=_NextPart_000_003D_01BD348C.2F5C8420
Content-Type: application/octet-stream;
	name="EX.CC"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="EX.CC"

#include <windows.h>
#include "ex.h"

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DocWindowProc(HWND, UINT, WPARAM, LPARAM);

HINSTANCE hInstance;
HWND hWindow;

// MDI client
HWND MDIClient;

char className[] =3D "EXCALSS";
char docClass[] =3D "EXOCCLASS";

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
            char * cmdParam, int cmdShow)
{
    WNDCLASS wnd;
    wnd.style =3D 0;
    wnd.hInstance =3D hInst;
    wnd.lpszClassName =3D className;
    wnd.lpfnWndProc =3D WindowProcedure;
    wnd.hIcon =3D LoadIcon(hInst, MAKEINTRESOURCE(IDI_WINLOGO));
    wnd.hCursor =3D LoadCursor (0, IDC_ARROW);
    wnd.lpszMenuName =3D "MENU1";
    wnd.cbClsExtra =3D 0;
    wnd.cbWndExtra =3D 0;
    wnd.hbrBackground =3D NULL;

    // if the class wasn't already registered then register it
    if(!hPrevInst)
    if(!RegisterClass(&wnd)) return 0;

    wnd.style =3D 0;
    wnd.hInstance =3D hInst;
    wnd.lpszClassName =3D docClass;
    wnd.lpfnWndProc =3D DocWindowProc;
    wnd.hIcon =3D LoadIcon(hInst, MAKEINTRESOURCE(IDI_WINLOGO));
    wnd.hCursor =3D LoadCursor (0, IDC_ARROW);
    wnd.lpszMenuName =3D (char *)NULL;
    wnd.cbClsExtra =3D 0;
    wnd.cbWndExtra =3D 0;
    wnd.hbrBackground =3D (HBRUSH) (COLOR_WINDOW+1);

    // if the class wasn't already registered then register it
    if(!hPrevInst)
    if(!RegisterClass(&wnd)) return 0;

    // remember our app's instance handle
    hInstance =3D hInst;

    // create window
    hWindow =3D CreateWindowEx(0, className, "Example", =
WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, =
0, 0,
            hInstance,0);
    ShowWindow(hWindow, cmdShow);
    UpdateWindow(hWindow);

    // message loop starts here
    MSG  msg;
    while (GetMessage (&msg, NULL, 0, 0))
    if(!TranslateMDISysAccel(MDIClient, &msg))
    {
        TranslateMessage (&msg);
        DispatchMessage (&msg);   =20
    }
    return msg.wParam;
}

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT msg,
                                 WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CREATE:
        {
            // create mdi client window
            CLIENTCREATESTRUCT ccs;
            ccs.hWindowMenu =3D GetSubMenu(GetMenu(hwnd), 5);
            ccs.idFirstChild =3D 2010;
            MDIClient =3D CreateWindowEx(WS_EX_CLIENTEDGE | =
WS_EX_WINDOWEDGE,
                        "MDICLIENT", NULL, WS_CHILD | WS_VISIBLE |
                        WS_CLIPCHILDREN, 0, 0, 0, 0, hwnd, NULL,=20
                        hInstance, (LPSTR)&ccs);
            break;
        }
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDM_NEW:
                    {
                        // fill in MDICREATESTRUCT struct & create new =
window
                        MDICREATESTRUCT mdic;
                        mdic.szClass =3D docClass;
                        mdic.szTitle =3D "Untitled";
                        mdic.hOwner =3D hInstance;
                        mdic.x =3D mdic.y =3D mdic.cx =3D mdic.cy =3D =
CW_USEDEFAULT;
                        mdic.style =3D 0;
                        SendMessage(MDIClient, WM_MDICREATE, 0, =
(LPARAM)&mdic);
                        break;
                    }
                case IDM_TILE:
                    SendMessage(MDIClient, WM_MDITILE, 0, 0);
                    break;
                case IDM_CASCADE:
                    SendMessage(MDIClient, WM_MDICASCADE, 0, 0);
                    break;
                case IDM_ARRICONS:
                    SendMessage(MDIClient, WM_MDIICONARRANGE, 0, 0);
                    break;
                case IDM_CLOSE:
                {
                    HWND hActive =3D (HWND)GetWindowLong(hwnd, 0);
                    SendMessage(MDIClient, WM_MDIDESTROY, =
(WPARAM)hActive, 0);
                    break;
                }
                default:
                    return DefFrameProc(hwnd, MDIClient, msg, wParam, =
lParam);
            }
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefFrameProc(hwnd, MDIClient, msg, wParam, lParam);
    }
}

LRESULT CALLBACK DocWindowProc(HWND hwnd, UINT msg, WPARAM wParam,
                               LPARAM lParam)
{
    switch(msg)
    {
        case WM_CREATE:
            {
                RECT r;
                GetWindowRect(hwnd, &r);
                HWND hEdit =3D CreateWindowEx(0, "EDIT", "", WS_CHILD |
                        WS_VISIBLE | WS_VSCROLL | WS_BORDER | =
ES_MULTILINE |
                        ES_LEFT | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0,
                        0, r.right-r.left-8, r.bottom-r.top-27, hwnd, =
NULL,
                        hInstance, NULL);
               =20
                SetWindowLong(hwnd, 0, (LONG)hEdit);
                if(hEdit =3D=3D (HWND)GetWindowLong(hwnd, 0))
                    MessageBox(hWindow, "WndLong =3D hEdit", "Msg", =
MB_OK |
                               MB_ICONINFORMATION);
                else
                    MessageBox(hWindow, "WndLong !=3D hEdit", "Msg", =
MB_OK |
                               MB_ICONINFORMATION);
                SetFocus(hEdit);
                break;
            }
        case WM_SIZE:
            {
                HWND hEdit =3D (HWND)GetWindowLong(hwnd, 0);
                RECT r;
                GetClientRect(hwnd, &r);
                MoveWindow(hEdit,
                           r.left,
                           r.top,
                           r.right-r.left-8,
                           r.bottom-r.top-27, TRUE);
                return DefMDIChildProc(hwnd, msg, wParam, lParam);
            }
        default:
            return DefMDIChildProc(hwnd, msg, wParam, lParam);
    }
}

------=_NextPart_000_003D_01BD348C.2F5C8420
Content-Type: application/octet-stream;
	name="EX.H"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="EX.H"

#define IDM_NEW       100
#define IDM_CLOSE     101
#define IDM_TILE      102
#define IDM_CASCADE   103
#define IDM_ARRICONS  104

------=_NextPart_000_003D_01BD348C.2F5C8420
Content-Type: application/octet-stream;
	name="EX.RC"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="EX.RC"

#include "ex.h"

MENU1 MENU
{
  POPUP "&Document"
  {
    MENUITEM "&New",                    IDM_NEW
    MENUITEM "&Close",                  IDM_CLOSE
  }
  POPUP "&Windows"
  {
    MENUITEM "Tile",                    IDM_TILE
    MENUITEM "Cascade",                 IDM_CASCADE
    MENUITEM "Arrange icons"            IDM_ARRICONS 
  }
}

------=_NextPart_000_003D_01BD348C.2F5C8420--

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