I did look at your post. But at that time I was looking at a slightly different problem: as you helpfully pointed out my failure to initialise mythis during WM_CREATE.
I completely missed the fact I was getting the pointer out of lParam instead of (LPCREATESTRUCT)lParam)->lpCreateParams. As this thread shows:
I am trying to develop a wrapper class for a Windows MDI application.
This is the class declaration for the application:
#ifndef INCLUDEGUARD_MDIAPP_H
#define INCLUDEGUARD_MDIAPP_H
#include <windows.h>
void ShowError();
class MDIApp
{
private:
HINSTANCE hInst;
HMENU hMenu;
HWND hwndClient;
public:
MDIApp(HINSTANCE hInstance, int iCmdShow);
private:
int OnCommand(HWND hwnd, UINT Message, WPARAM wParam,
LPARAM lParam);
int OnCreate(HWND hwnd, UINT Message, WPARAM wParam,
LPARAM lParam);
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT Message,
WPARAM wParam, LPARAM lParam);
};
#endif
The problem is in the On.... member functions, the values of the members are seemingly incorrect.
For example, debugging code:
TCHAR szBug[100];
wsprintf(szBug, "hInstance %Ix", hInstance);
MessageBox (NULL, szBug,
TEXT("Main"), 0);
in main and the constructor, reports hInstance and hInst as 0x400000. However identical code in OnCreate reports various incorrect figures for hInst:
int MDIApp::OnCreate(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
TCHAR szBug[100];
wsprintf(szBug, "hInst %Ix", hInst);
MessageBox (NULL, szBug,
TEXT("MDIApp::OnCreate"), 0);
static TCHAR szClientName [] = TEXT("Text Client");
CLIENTCREATESTRUCT ccs;
ccs.hWindowMenu = hMenu;
ccs.idFirstChild = IDM_FIRSTCHILD;
hwndClient = CreateWindow("MDICLIENT",
szClientName,
WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
0,
0,
0,
0,
hwnd,
(HMENU) 1,
hInst,
(PSTR) &ccs);
if(!hwndClient)
{
MessageBox (NULL, TEXT("Could not create client window"),
TEXT("MDIApp::OnCreate"), 0);
}
ShowWindow(hwndClient, SW_SHOW);
return 0;
}
What is going on?
Apologies for the length of the post, but I wanted to include all the information I thought relevant.
Thanks in advance
Derek
In case anyone is interested, I got the answer.
See here:
http://arstechnica.infopop.net/OpenTopic/page?a=tpc&s=50009562&f=6330927813&m=3880982845
Derek
I had posted the answer to you problem in another thread, but as it seems you never bothered to look at it...
http://sourceforge.net/forum/message.php?msg_id=1846407
Yiannis.
My apologies Yiannis,
I did look at your post. But at that time I was looking at a slightly different problem: as you helpfully pointed out my failure to initialise mythis during WM_CREATE.
I completely missed the fact I was getting the pointer out of lParam instead of (LPCREATESTRUCT)lParam)->lpCreateParams. As this thread shows:
http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_20482207.html
I'd totally got the idea there was nothing wrong there, and it took tiny on the thread I posted earlier to set me straight.
I do appreciate the help you gave, and it was useful.
You may be pleased to know the class is now working - of course you may not be pleased, if you now don't like me!
Thanks
Derek
> You may be pleased to know the class is now working - of course you may not be pleased, if you now don't like me!
Why not like you? You are where I was 6 months ago, when I was starting my C++ wrapper classes for WinAPI...
The fact that you didn't notice my answer, cost you three more days on your problem (judging by the messages timestamps). That's fine with me ;))
Cheers,
Yiannis.
Cool of you.
You might like to know, it took me some five days to get the class working at the most basic level - only five times what I originally estimated!
Derek