|
I'm making a program with API (not MFC), and I know how to make a window quite well, but for some reason, more than one is difficult.
I can CreateWindow() more than one window in the Main function, but when I try to do ShowWindow() one of those windows in a Window Procedure, it says the handle of the window Im trying to show is undeclared. And I don't think I can make it global.
How do I make more than one window, and then show or hide them as I please? Any help would be appreciated, thanks =) Dave
|
|
|
|
|
I have been writing a set of classes to create windows dynamically using API, and I found that I had trouble with the Window classes until I removed code to check if the class was already registered. Could you post an example of your code and I'd be glad to try and help more.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Sure, here's some code..
This is MAIN.
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
// define variables
static TCHAR MainClass[] = "GRE",TestClass[]="Test";
static HWND wndMain,wndTest;
MSG msg;
WNDCLASS wndclass,testclass;
strcat(AboutPacer,AboutPacer2);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = MainClass;
testclass.style = CS_HREDRAW | CS_VREDRAW;
testclass.lpfnWndProc = WndProc;
testclass.cbClsExtra = 0;
testclass.cbWndExtra = 0;
testclass.hInstance = hInstance;
testclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
testclass.hCursor = LoadCursor (NULL, IDC_ARROW);
testclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
testclass.lpszMenuName = NULL;
testclass.lpszClassName = TestClass;
if(!RegisterClass (&wndclass))
{
MessageBox (NULL, "This program requires Windows NT.", MainClass, MB_ICONERROR);
return 0;
}
if(!RegisterClass (&testclass))
{
MessageBox (NULL, "This program requires Windows NT.", TestClass, MB_ICONERROR);
return 0;
}
//Create all windows
wndMain = CreateWindow (MainClass, "GMAT/GRE INTRODUCTION", WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 80, 80, 650, 450, NULL, NULL, hInstance, NULL);
wndTest = CreateWindow (TestClass, "Test", WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 80, 80, 650, 450, NULL, NULL, hInstance, NULL);
ShowWindow(wndMain, SW_SHOWNORMAL);
UpdateWindow(wndMain);
Then in window wndMain's procedure, I try to show the test window I created earlier... (this is a portion of the procedure, not the whole thing)
case WM_COMMAND:
if(lParam==cmdAbout)
{
SetWindowText(txtMain,AboutPacer);
}
else if (lParam==cmdInstructions)
{
SetWindowText(txtMain,instructions);
}
else if(lParam==cmdStart)
{
ShowWindow(wndTest,SW_SHOWMAXIMIZED);
}
it says wndTest doesn't exist. This is obvously because wndTest was declared in MAIN and not procedure, but I dont know how to work this then. Any ideas?
|
|
|
|
|
declaring the variable static makes it exist only once for all instances of a class, I don't know what it achieves in a global function. I use a map of HWND to instances of my Window classes ( which I later found out MFC does too ) in order to access the varaibles associated with each Window. Apart from a similar scheme, I think you need to declare the handle globally. Just put the static HWND wndMain,wndTest; at the head of the program, and I suspect lose 'static'.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
You can trace the source code in MFC project,then you will
find the idea .
The MFC could Create more than one window.So if you look
into the source code ,you could have a entire understand
about the method.;)
|
|
|
|
|
I get this to work on Local directories, but when I try a remote machine, I get this:
11/08/01 21:28:03: Failed to start watch: The specified path is invalid. [\\DMADDEN01\Snort\Logs]
I have tried everything (that I can think of)...any ideas
Thanks in advance,
Dan
|
|
|
|
|
I have the same problem with cretedirectory, but I have no problem when I use a shared resource.
Cheers
Carlos Antollini.
|
|
|
|
|
I was always under the impression that this only worked for local drives.
Joel Lucsy (jjlucsy@concentric.net)
|
|
|
|
|
Hey Guys
Does anyone know much on the Crypto API, i just ask cos i seem to be the expert at the moment. Anyway if anyone does do you know a way of detecting the presence of a key rather then detecting the type of key.
Peter
|
|
|
|
|
Hi all!
How we change the mouse cursor to a glass hour and turn it back to normal?
There got to be an easy way to show busy and normal status right?
Thank You
Vu
vucsuf
|
|
|
|
|
If you're using MFC, use CWaitCursor. Otherwise, call SetCursor() before and after your processing.
--Mike--
http://home.inreach.com/mdunn/
#include "witty_sig.h"
your with and
|
|
|
|
|
Hi
I just coded an app that can be minimized into systemtray.
In resource-editor I created an icon of 16x16 pixels with 256 colors.
But how I can use this icon? It is scaled down to 16 colors at runtime.
One more question:
Is there a way to send my application directly into systray with showing in on the screen when ist starts?
thanks in advance
|
|
|
|
|
in the init_instance of your program you have to call
BOOL CSetTimeApp::InitInstance()
{
...
CMyDlg dlg;
dlg.Create (IDD_MYDIALOG, NULL);
dlg.ShowWindow (SW_HIDE);
....
hope this helps... (i can't help you with the sheband with your icon)
bernhard
""Politicians and diapers have one thing in common. They should both be changed regularly and for the same reason."
|
|
|
|
|
I have a collection of .cpp modules (some classes some just methods) that I use in my various projects. How do you orgainze these shared modules? I'm starting to get classes that depend on other classes and when I use one in a project I don't what other files I need until I get link errors. So I'm wondering how you folks oganize your shared source repositories. Keep in mind that my applications have to be as small as possible so I can't turn them into a library of some kind.
Todd Smith
|
|
|
|
|
putting functions and classes in a library doesn't really increase the size of the application that uses them. linkers are smart enough nowdays to only pull in the functions/members they need.
i put my stuff in libraries.
-c
POKE 808,234
|
|
|
|
|
I've never had a clear explanation of the advantages of putting the files in libraries, either. Seems it's done that way just because C programmers used to do it that way.
OK, it's because you can distribute the libraries and headers without source; but for internal use, where's the advantage?
|
|
|
|
|
i do it because it keeps all of my utility functions in a single project (i call mine ToolLib). it helps keep my application projects smaller (VC tends to slow down when projects get too big). i just drop all of my utils into Toollib and manage them as a subproject. and, i don't have to worry about adding each utility class file to my projects separately - include the lib project, link to it and that's it.
-c
POKE 808,234
|
|
|
|
|
Libs are good places to store 'the one you wrote earlier'.
How to group code in Libs has always been a point for argument amongst programmers (tsk, as if programmers would argue). My personal preference comes from my electronics. I would create libraries of devices. With the code controlling all aspects of that device, so that a calling function would (in many cases) have a single call in and a single status/data call.
So for example,
irq59.lib would hold all the routines tat control an irq controller.
pcdisp.lib all of the character display device code.
and so on.
In C++ I tried a few in the lines of,
dirtree.lib with the code for Directory trees
omron.lib code to control an Omron
In each case it is code that is fixed in terms of its operation and only requires control/data to work.
It is just as easy in the IDE to add a class into a project in source form. But as was said earlier you have to remember to add all the right base classes, with the libs you must have already taken care of this for your code to have compiled.
We do it for the joy of seeing the users struggle.
|
|
|
|
|
Keep in mind that my applications have to be as small as possible so I can't turn them into a library of some kind.
You can if the library is static. In this case, the linker discards the code not used by the program.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I simply have a set of directories where I group together related classes. e.g I have my MFCExt folder and my littleTAPI folder and a Template folder. I then just add the relevant files to my projects.
I used to use static libraries but problems with linking the same libraries to MFC, ATL, WIN32 projects has changed my mind.
Michael
|
|
|
|
|
Our product RadVC employs a similar concept of C++ control repository you've just mentioned. Whenever a new C++ control (we call them RAD C++ controls, because they can be used in a RAD environment later on) is created or installed, the source files of the control are saved in the respective directories (such as .cpp in \\src, .h in \\include, resource files in \\res directories etc.).
The fun part is, as you've pointed out, these files don't need to be copied again and again every time they are used in new projects.
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
Right now my program is an MDI, where you have to select an item in the menu bar to open up the opengl window. The opening of the opengl window works fine
except for the fact that when I minimize the child window the animating objects appear in the paretn window. Can anyone help me figure out how to make sure the animation only appears in the child window.
|
|
|
|
|
Is it possible to change full ActiveX control's size (extents) from inside control at run-time, sort of notifying the container about the change in size, so then the container would call GetExtent and the control would let him know of its prefferd size.
|
|
|
|
|
How can I change the title of a sdi application?
I used CDocument->SetTitle() - doesn't work (nothing changes)
used CMainFrame->SetWindowText - but this crashes my app (Unhandled exception - memory violation - as It got a NULL pointer, when i debugged, inside the MFC function SetWindowText, there was an ASSERT(::IsWindow(m_hWnd)), but this(==m_hWnd) was equal to NULL, so that is why there was memory violation ...
used m_pszAppName (changed it) and nothing changes ...
heard about taking care of OnUpdateFrameTitle, but this method is not a member of frame, or document, but an ole class ...
used many other strange ways, and did not succeed ...
Anyone having an idea ?PLZ
|
|
|
|
|
Where abouts in your code were you changing the window title via the CMainFrame::SetWindowText. It sounds like you were trying to do it before the window was created.
Michael
|
|
|
|
|