|
I made a toolbar in my program, and on the main menubar, made a "View" menu item with a list of toolbars.
So I wrote CreateWindowEx to create the toolbar on program load. When you click the red X on the toolbar, I DestroyWindow, and the toolbar is gone. Then if I go to View, and click the toolbar, I run CreateWindowEx and make the Toolbar again.
Symptom:
When I make the toolbar the 2nd time, the toolbar window is not active. I can load stuff in it, but can't use the red x or the treeview inside the window. I get get focus on the window to use it.
Question:
I'm not sure what I did wrong, or if I'm just missing something in one of the Proc's.
|
|
|
|
|
That was a really bad idea there. I went back to hide and show, and figured out how to avoid the WM_DESTROY message when clicking the close button on the window bar.
|
|
|
|
|
could you post the CreateWindowEx() code snippet
|
|
|
|
|
It turned out to be a big mess. The Bool bRegister was a unsuccessful attempt to unregister the class after it was created. I thought if I could create the class, create the window, that I could destroy the window, and unregister the class to create a clean slate, and start the process again.
On the 2nd time around, the window would paint, but it would not respond. When I took the other toolbar and dragged it across the regenerated toolbar, the regenerated toolbar would not paint again and dissappear. So I added the WS_CLIPSIBLINGS, and upon regeneration, no window at all.
So I went back to show and hide, and added a return 1 to the WM_CLOSE in the Windows Proc, to cancel destroying the window, and to just run ShowWindow and update the checkbox in the main menu.
HWND _project_Explorer_Create( HWND hWndMain, HINSTANCE hInstance, HWND hMDIClientArea, HWND hWndStatusBar )
{
hProjectExplorer_Instance = hInstance;
LoadString( hInstance, IDM_PROJECT_EXPLORER_CLASS, sz_ProjectExplorer_Class, MAX_LOADSTRING );
WNDCLASSEX toolWindow;
toolWindow.cbSize = sizeof(WNDCLASSEX);
if ( !GetClassInfoEx( hInstance, sz_ProjectExplorer_Class, &toolWindow ) ) {
toolWindow.style = CS_HREDRAW | CS_VREDRAW;
toolWindow.lpfnWndProc = _project_Explorer_WndProc;
toolWindow.cbClsExtra = 0;
toolWindow.cbWndExtra = 0;
toolWindow.hInstance = hInstance;
toolWindow.hIcon = 0;
toolWindow.hCursor = 0;
toolWindow.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
toolWindow.lpszMenuName = 0;
toolWindow.lpszClassName = sz_ProjectExplorer_Class;
toolWindow.hIconSm = 0;
RegisterClassEx( &toolWindow );
}
RECT winRect, statusBarRect;
INT winWidth, winHeight, tbWidth, tbHeight, sbWidth, sbHeight;
if(GetWindowRect( hMDIClientArea, &winRect)) {
winWidth = winRect.right - winRect.left;
winHeight = winRect.bottom - winRect.top;
GetWindowRect( hWndStatusBar, &statusBarRect );
sbWidth = statusBarRect.right - statusBarRect.left;
sbHeight = statusBarRect.bottom - statusBarRect.top;
tbWidth = 250;
tbHeight = (INT)floor(( (float)winHeight * (float).60 ) - 1 );
hWnd_ProjectExplorer = CreateWindowEx(
WS_EX_TOOLWINDOW,
sz_ProjectExplorer_Class,
TEXT( "Project Explorer" ),
WS_CHILD | WS_SYSMENU | WS_CAPTION | WS_VISIBLE | WS_CLIPSIBLINGS,
winWidth - tbWidth - 1, 1,
tbWidth, tbHeight,
hWndMain,
NULL,
GetModuleHandle(0),
NULL
);
ShowWindow( hWnd_ProjectExplorer, SW_SHOW);
UpdateWindow( hWndMain );
}
return hWnd_ProjectExplorer;
}
|
|
|
|
|
thanks for ur reply,
use this code snippet
..........
static bool reg =false;
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
if( reg )
{
UnregisterClass(szWindowClass, hInstance );
}
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Win32 Guided Tour"),
NULL);
return 1;
}
reg = true;
.............
|
|
|
|
|
Well thanks, but I'm not going to try that. I don't see the point of it. I'd rather have an explanation as to why I can't destroy a window and it's class and recreate it like an MDI Child Window.
|
|
|
|
|
Toolbar with treeview?
What kind of toolbar you are referring to? Are you sure you are creating a toolbar? Maybe it is a tool window?
Could you please post a snippet showing how you create this toolbar.
JohnCz
|
|
|
|
|
It's a tool window, I just called it a toolbar so folks got the bigger picture of what I was trying to do.
So far so good, I have my MDI frame, and the 2 sidebars (toolbars) on the left. They size correctly, move and resize upon mid resize. The hide and show works good.
Next phase is to dock them, but I need to tighten up the program first, and do an initial alpha test release. Hopefully this week.
|
|
|
|
|
I can do the following:
boost::scoped_ptr<MyClass> class;
class->DoSomething();
class.reset(new MyClass);
Doesn't it go against RAII? I keep reading that scoped_ptr is RAII but i can use object before it is initialized.
Thanks
|
|
|
|
|
and what happens when you run that?
|
|
|
|
|
He won't even get as far as compiling it, let alone running it
|
|
|
|
|
I got a segmentation fault, as expected.
Could you please explain.
|
|
|
|
|
you declared a pointer, but never pointed it to an object. what's to explain?
|
|
|
|
|
Is the purpose of RAII not to allow such a thing?
Currently i am acquiring a resource but do not initialize it.
|
|
|
|
|
elelont2 wrote: Currently i am acquiring a resource but do not initialize it.
but you're not acquiring any resource; you're just declaring an uninitialized pointer. the scoped_ptr c'tor allows you to defer allocation - but you do need to allocate it at some time, before you start using it.
look at boost's examples[^]:
boost::scoped_ptr<Shoe> x(new Shoe);
they allocate (acquire) the object while declaring the pointer.
also:
class MyClass {
boost::scoped_ptr<int> ptr;
public:
MyClass() : ptr(new int) { *ptr = 0; }
int add_one() { return ++*ptr; }
};
they declare the pointer, but defer allocation until the 'add_one' call.
|
|
|
|
|
So, apart from the fact you'll never be able to call an object class (naughty, naughty) how does writing:
boost::scoped_ptr<any_old_iron> ptr;
leave you with an unitialised object? Or in other words what's not initialised in that statement?
If you can work that out you'll see that scoped_ptr supports RAII (or as I prefer to call it these days scoped based resource management, SBRM) perfectly.
Cheers,
Ash
|
|
|
|
|
I have an uninitialized object in that case and ptr->Func() will probably crash?
|
|
|
|
|
ny_old_iron class will be uninitialized. How is it initialized?
Also, what do you mean by "object class"?
RAII says that the object is initialized during acquisition. scoped_ptr is supposed to support RAII but it allows to defer allocation, which means that the object pointed by the scoped_ptr is uninitialized.
Therefore i would say that scoped_ptr is not RAII.
|
|
|
|
|
When in the .net platform, it is easy to operate database, but when in the unmanaged c++,
how to operate the sql server 2005?
Can someone give me a example link?
|
|
|
|
|
|
you can connect your table to display in data format to make possible for it. So Sql(Sequence query language) to use,we do in edit,delete and update our data into the table.
|
|
|
|
|
I think the OP would be more interested in this information.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
As well as Richard's link if you do a search for ODBC you'll find (IMHO) the best interface to use databases through while programming in C or C++. While there are other methods to plug into databases ODBC has the advantage of being portable at both ends of the connection - so your C++ code can use any RDBS that has an ODBC connector AND your C++ code can be compiled on another compiler or operating system.
And instead of a concrete link I'd like to recommend a very good book - "Inside ODBC" by Kyle Geiger - instead. It's out of print but you can pick up cheap second hand copies on Amazon marketplace [1]. It's well worth a read and got me started on the rocky road to being an informed C++ DB programmer.
Cheers,
Ash
[1] At least you could 20 minutes ago when I recommended it as part of an answer to another question. I might have caused a run on them.
|
|
|
|
|
Dear All,
i'm beginner in c++ and I write template somethin like this :
template< class Type > class T1
{
bool MyMatch( int in )
{
return true;
}
public:
typedef bool (*T1<Type>::Match)( int in );
bool DoSomething( int& out, Match inConditionMethod )
{
return true;
}
};
but after compile i get this error :
error C2061: syntax error : identifier 'Match'
I google it and read MSDN but i can't find my mistake please help me to solve it.
sorry for my poor english
|
|
|
|
|
Should not be "MyMatch" ?
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|