mfc >> How to Create a Window - BASIC

by UmljaCBTLg » Mon, 27 Mar 2006 06:42:53 GMT

Hello,

I am having an unbelievable amount of trouble just creating a window with MFC.

First I construct a CWnd object.

Then my CWnd object calls CreateEx as follows: (I want to create a top-level
window)

BOOL Result = CreateEx( NULL ,
AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW) ,
NULL,
WS_OVERLAPPEDWINDOW ,
CRect(0, 0, 20, 20),
this,
999);

It fails without any error message, and the window is not created.

Do I have to Show() the window before it is actually created, or something
like that?

This is driving me nuts.

Thanks,
Rich S.




mfc >> RE: How to Create a Window - BASIC

by UmljaCBTLg » Mon, 27 Mar 2006 06:48:32 GMT


I Figured it out. I'm supposed to put NULL for the Parent CWnd object, not
"this".







mfc >> How to Create a Window - BASIC

by Jonathan Wood » Mon, 27 Mar 2006 06:49:41 GMT

Yes, you will need to show the window. (Use ShowWindow()).

How did you determine the window was not being created? Did you try using
Spy++ to see if your code creates a new top-level window?

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm







How to Create a Window - BASIC

by UmljaCBTLg » Mon, 27 Mar 2006 07:05:35 GMT





I did not use Spy++, I went by the fact that the window handle ( m_hWnd)
kept coming back NULL. Plus, when I called FindWindow() from another
application, it did not find the window by Window Text.

Is there any chance that a Window does not have a caption until it is Shown?


Similar Threads

1. create c# COM Component and call it from Visual basic 6.0

2. Creating two CAxDialogImpl-derived dialogs (basic question?)

Sorry, but I was not able to find a FAQ for this. I am just trying out ATL 
and I have the following scenario:

I am creating two modeless dialogs using a class derived from CAxDialogImpl. 
The first one creates okay, but the second one crashes with an invalid 
handle. Is there something specific I need to do? Right now it's just test 
code in a single thread, but eventually the two windows would be created in 
separate threads.

What happens is that I create one window and it works okay, when I create 
the second one, the Create() function returns a null handle. Also, for the 
second window, the OnInitDialog() no longer gets called.

Tracing in the code, I get to the following code in 
atlhost.h/AtlAxDialogCreateT. 
the nRet value comes back as 0 the second time around. This causes 
subsequent code to assert that the hwnd is not valid for the second window.
Is there something I need to do with the message loop?


if (pDlg != NULL)
{
	LPCDLGTEMPLATE lpDialogTemplate;

	lpDialogTemplate = _DialogSplitHelper::SplitDialogTemplate(pDlg, pInitData);

	nRet = (*pFunc)(hInstance, lpDialogTemplate, hWndParent, lpDialogProc, 
dwInitParam); 

	// ---> nRet is 0 for the second window

	if (!Helper::IsValidReturnVal(nRet)) 
	{
		dwLastError = ::GetLastError();
		// error code is 1400 (Invalid window handle)
	}
//...




this is my code (stripped):


// the window class
class CTestWindow: 
	public CAxDialogImpl<CTestWindow>
{
public:
	// left out empty ctors and dtors
	enum { IDD = IDD_TESTWINDOW };

BEGIN_MSG_MAP(CTestWindow)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	CHAIN_MSG_MAP(CAxDialogImpl<CTestWindow>)
END_MSG_MAP()

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		//..etc
		return 1;  // Let the system set the focus
	}
};

//The class that contains this window...


	class Wrapper {
	public:
		// left out ctor, dtor, operators, etc. dtor would clean up HostWindow

		void Create()
		{
			HostWindow = new CTestWindow();
			HWND wnd = HostWindow->Create(::GetDesktopWindow()); 
			// ...
		}
	private:
		CTestWindow *HostWindow;

	};


The code creates an instance of Wrapper class, calls Create() on it to 
initialize the window, and stores the pointer to the wrapper class in a 
stdext::hash_map.
I hope this code has transcribed okay, I had to strip down a lot for 
readability/posting. The objects do not get destroyed until the test
application exits, so I don't think it's a lifetime/scope issue.

Any help would be appreciated!



3. Can We Create a Control Like Shape Control of Visual Basic

4. How to create a dll in embedded vc for access from Visual Basic.net 2005

Hello Group,
i have a Touchscreen Display with Win CE 5.0 and Compact Framework 2.
The Main Application is written in VB 2005 and it was developed for an
other Display with the Same Processor (Arm).
The old Display was resetted by an API Function but the new Display is
resetted by a Function created by the
Manufacturer of the Display. Also is there a function to set the
Watchdog . My Expirence of C is not the Best because i'm
primary a Basic Programmer so i need a little Help to write a Dll that
can be acessed from the Basic Programm.
The Manufacturer of the Display send me the following C Program to
test the Reset Function:

// New Reset.cpp : Defines the entry point for the application.
//
// #pragma comment ( lib, "IEI_PXA270_SDK.lib" )
#include "stdafx.h"
#include <IEI_PXA270_SDK.h>
// #include "IEI_PXA270_SDK.h"


// extern void WatchdogReboot(void);

int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)

{
 	// TODO: Place code here.
	void WatchdogReboot(void);
     WatchdogReboot();
	 return(0);
	}

I had compiled it with Embedded VC 4.0 and it works.
What im looking for is a Dll that contains this Function and an other
Funktion EnableWatchdogTimer
that i can call from Basic as WathdogReboot() or
EnableWatchdogTimer(Time in Msek) Variable is Uint32.
I have Visual Studio 2005 and Embedded VC 4.0. Who can help me to
write such a dll.
Thanks for Help
Wilfried

5. A basic question of creating a table in run-time

6. Basic Question: Update Parent Window

I have a form that shows a list of items.

I click a button which opens a child form.  On the child form i can create 
new items.

How can I refresh the list of items on the parent form ?

I'm not sure how i can trigger an event which will call the refresh on the 
parent.

Thanks in advance. 


7. Compatabilty of Visual Basic C++ with windows vista

8. 2 basic question of windows programming

An article says: "A file mapping cannot be expanded. You need to know the
maximum size when creating file mapping, and it may be difficult or
impossible to determine this size."

How could it be "difficult or impossible to know the maximum size when
creating file mapping", since you can always read file size attribute of a
file before creating file mapping?

In Windows, right-click on a file and it shows "size" and "size on disk".

Why are they different numbers?

Thanks in advance!