Advertisement

Two child windows.

Started by January 15, 2002 07:42 PM
6 comments, last by Lugie 22 years, 9 months ago
I''m trying to figure out how to make two child windows of the same type. i gave them different define numbers, like this:
#define IDC_hBU_StaticText 40001
#define IDC_hBU_EDIT 40002
#define IDC_hBU_StaticText 40003
#define IDC_hBU_EDIT 40004
#define IDC_hBU_BUTTON 40005
#define IDC_hBU_BUTTON 40006 
but it isnt working, what should i do?
War is how Americans learn geography.
The type of a resource depends on how it is defined in the resource file, not how you name the symbol used to access it.

And obviously, you cannot have two symbols with the same name, otherwise the compiler won't be able to discern between them.

Note to purists: yes I know, these are preprocessor macros and successive #define overwrite each other.

Edit : clarification :

You have somewhere a .rc resource file, which is a text file btw, which defines your buttons, windows, etc. To each, a number is associated. To make it easier on the programmer, macros are generated so that you don't have to remember (or even care about) the actual identifying numbers of each resource. So, whenever you are writing, say, IDC_hBU_StaticText, the preprocessor translates it into the appropriate number.

What you have done, is redefine the macro IDC_hBU_StaticText to make it point to another resource. This won't help you if the resource doesn't exist, or isn't of the right type. The name you give it doesn't matter, the compiler never sees it, only you do.

The only ways I can see to solve your problem is to either go edit the .rc file yourself, or use the resource editor that (may) come with your compiler.

Edited by - Fruny on January 15, 2002 9:01:27 PM
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
im using the windows prergistered windows classes...

edit

okay, ill try my best

Edited by - Lugie on January 15, 2002 9:12:47 PM
War is how Americans learn geography.
i dont have an .rc file. sorry im a little new, what ive basically done was type out some code, i havent really added and resource files or anything, just the two headers. heres all i have:

#include <windows.h>
#include <stdio.h>

#define IDC_hBU_StaticText
#define IDC_hBU_EDIT
#define IDC_hBU_StaticText
#define IDC_hBU_EDIT
#define IDC_hBU_BUTTON
#define IDC_hBU_BUTTON

LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wndclass;
LOGBRUSH background;

wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = fnMessageProcessor;
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 (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "Sweet";
wndclass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
background.lbStyle = BS_PATTERN;
background.lbHatch = (long) LoadImage( hInstance, "loginbg.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
wndclass.hbrBackground = CreateBrushIndirect(&background);

if( ( RegisterClassEx( &wndclass ) == 0 ) ) {
exit(1);
}


hWnd = CreateWindow( "Sweet",
"Totally Sweet Flipped Out Ninjas",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
400,
200,
NULL,
NULL,
hInstance,
NULL );

hBU_StaticText = CreateWindow(
"static",
"Account:",
WS_CHILD | SS_CENTER | WS_VISIBLE,
80,
120,
20,
80,
hWnd,(HMENU)IDC_hBU_Sweet,hInstance,NULL );


ShowWindow( hWnd, iCmdShow );
UpdateWindow( hWnd );


while( GetMessage ( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

return ( msg.wParam );
}

LRESULT CALLBACK fnMessageProcessor ( HWND hWnd, UINT iMsg,
WPARAM wParam, LPARAM lParam )
{

switch( iMsg )
{
case WM_CREATE:
return( 0 );
case WM_PAINT:
return( 0 );
case WM_DESTROY:
PostQuitMessage( 0 );
return( 0 );
}
return DefWindowProc( hWnd, iMsg, wParam, lParam );

}

thats basically it :\
War is how Americans learn geography.
*BUMP*

any help?
War is how Americans learn geography.
Firstly, I am also a newbie using VC++.

My newbie advice:
If you''re using VC++, look under the resource folder and you might find your .rc file. That''s all

Hope it helps.

The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant
The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant
Advertisement
quote: Original post by Lugie
hBU_StaticText = CreateWindow("static",...);

hBU_StaticText has to be an HWND (I didn''t see it in your post; you may just omitted to post it here), and "static" should be "STATIC".

From MSDN:
STATIC
Designates a simple text field, box, or rectangle used to label, box, or separate other controls. Static controls take no input and provide no output. For more information, see Static Controls.

From this it should be apparent that a static control should also have no menu.

Now, as to how to create two child windows (same type or otherwise), well you have to call CreateWindow twice - once for each of them! The define numbers have nothing to do with it.

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
i got everything to work and compile properly, but now they dont show up in the window. and when i set the (HMENU) param to anything but NULL, i get an error. is that my problem? heres what i have right now (sorry i dont know how to implement that code thing into my post, somebody tell me how?):

#include <windows.h>
#include <stdio.h>

#define IDC_hBU_STATIC 40001
#define IDC_hBU_EDIT 40002

HWND hBU_STATIC = NULL;
HWND hBU_EDIT = NULL;

LPCTSTR lpszApplicationName = "Sweet";
LPCTSTR lpszTitle = "Totally Sweet Flipped Out Ninjas";

LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow) {

HWND hWnd;
MSG msg;
WNDCLASSEX wndclass;
LOGBRUSH background;

wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = fnMessageProcessor;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "Sweet";
wndclass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
background.lbStyle = BS_PATTERN;
background.lbHatch = (long) LoadImage( hInstance, "loginbg.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
wndclass.hbrBackground = CreateBrushIndirect(&background);

if( ( RegisterClassEx( &wndclass ) == 0 ) ) {
exit(1);
}


hWnd = CreateWindow("SWEET",
"Totally Sweet Flipped Out Ninjas",
WS_EX_TRANSPARENT | WS_EX_CLIENTEDGE,
CW_USEDEFAULT,
CW_USEDEFAULT,
400,
200,
NULL,
NULL,
hInstance,
NULL );

hBU_STATIC = CreateWindow( "account",
"Account:",
WS_CHILD | WS_VISIBLE,
80,
72,
120,
28,
hWnd,
NULL,
hInstance,
NULL );

hBU_EDIT = CreateWindow( "accountfield",
"!",
WS_CHILD | WS_VISIBLE | SS_CENTER,
80,
72,
120,
28,
hWnd,
NULL,
hInstance,
NULL );

ShowWindow( hWnd, iCmdShow );
UpdateWindow( hWnd );


while( TRUE ) {

if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!GetMessage(&msg, NULL, 0, 0))
break;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}

return ( msg.wParam );
}

LRESULT CALLBACK fnMessageProcessor ( HWND hWnd, UINT iMsg,
WPARAM wParam, LPARAM lParam )
{

switch( iMsg )
{
case WM_CREATE:
return( 0 );
case WM_PAINT:
return( 0 );
case WM_DESTROY:
PostQuitMessage( 0 );
return( 0 );
}

return DefWindowProc( hWnd, iMsg, wParam, lParam );

}
War is how Americans learn geography.

This topic is closed to new replies.

Advertisement