CreateWindow
-
I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick
-
I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick
-
I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick
You need to call to ShowWindow Function, but you are missing same values in the style parameter like WS_CHILD | WS_VISIBLE whit this last parameter don't you need to call to ShowWindow function. Cheers Carlos Antollini.
-
I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick
Button style should contain WS_CHILD and WS_VISIBLE:
CreateWindow("BUTTON",
"sample",
WS_CHILD | WS_VISIBLE | BS_BITMAP,
5,
5,
100,
100,
m_hWnd,
NULL,
NULL,
NULL);You should also pass a child window id after m_hWnd. Tomasz Sowinski -- http://www.shooltz.com
-
thanks, but do I put those in the constructor of the containing dialog because obviously the buttons will be part of this. When doing this I get an assertion error, I think its talking about a NULL handle to this dialog which I thought would be a problem. Nick
-
thanks, but do I put those in the constructor of the containing dialog because obviously the buttons will be part of this. When doing this I get an assertion error, I think its talking about a NULL handle to this dialog which I thought would be a problem. Nick
Don't call CreateWindow on the buttons in the dialog's constructor - the dialog window won't be created yet so you can't use it as a parent window. Call CreateWindow in CYourDialog::OnCreate() (if you use MFC) or in response to the WM_CREATE msg (if non-MFC) instead. Since it's a dialog you can also put the calls in OnInitDialog/WM_INITDIALOG instead. Cheers Steen. "To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
-
Don't call CreateWindow on the buttons in the dialog's constructor - the dialog window won't be created yet so you can't use it as a parent window. Call CreateWindow in CYourDialog::OnCreate() (if you use MFC) or in response to the WM_CREATE msg (if non-MFC) instead. Since it's a dialog you can also put the calls in OnInitDialog/WM_INITDIALOG instead. Cheers Steen. "To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
thanks a lot, that worked fine Nick :-D
-
Button style should contain WS_CHILD and WS_VISIBLE:
CreateWindow("BUTTON",
"sample",
WS_CHILD | WS_VISIBLE | BS_BITMAP,
5,
5,
100,
100,
m_hWnd,
NULL,
NULL,
NULL);You should also pass a child window id after m_hWnd. Tomasz Sowinski -- http://www.shooltz.com
How do I get this child window ID? So far I have the following code: CreateWindow( "BUTTON", "sample", WS_CHILD | WS_VISIBLE | BS_BITMAP, 5, 5, 20, 20, m_hWnd, /*the child window ID will go here*/, NULL, NULL); HBITMAP hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\1.bmp", IMAGE_BITMAP, 16, 16, LR_LOADFROMFILE); ::SendMessage((HWND)hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp); Thanks for the help so far Nick
-
How do I get this child window ID? So far I have the following code: CreateWindow( "BUTTON", "sample", WS_CHILD | WS_VISIBLE | BS_BITMAP, 5, 5, 20, 20, m_hWnd, /*the child window ID will go here*/, NULL, NULL); HBITMAP hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\1.bmp", IMAGE_BITMAP, 16, 16, LR_LOADFROMFILE); ::SendMessage((HWND)hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp); Thanks for the help so far Nick
How do I get this child window ID? You don't get this ID, you have to come up with one yourself. This ID is passed back (as LOWORD(wParam) in WM_COMMAND) to the parent window when somebody clicks the button - you'll need to recognize which button was pressed, right? You can use any scheme to create IDs to your buttons. Tomasz Sowinski -- http://www.shooltz.com
-
How do I get this child window ID? You don't get this ID, you have to come up with one yourself. This ID is passed back (as LOWORD(wParam) in WM_COMMAND) to the parent window when somebody clicks the button - you'll need to recognize which button was pressed, right? You can use any scheme to create IDs to your buttons. Tomasz Sowinski -- http://www.shooltz.com
So for example, I could set it as 966 by doing int hButton = 966; and including hButton under/after the m_hWnd parameter, because I already tried that. If that is correct, there is something else wrong, probably in the loading of the bitmap because when the program is run it show's no bitmap on the button. Nick
-
So for example, I could set it as 966 by doing int hButton = 966; and including hButton under/after the m_hWnd parameter, because I already tried that. If that is correct, there is something else wrong, probably in the loading of the bitmap because when the program is run it show's no bitmap on the button. Nick
hButton is a window handle, not a child ID. Store value returned from CreateWindow in hButton. Use some predefined constant and pass it as child ID to CreateWindow. Use the same constant when handling WM_COMMAND - you'll be able to respond differently to different buttons being pressed. Tomasz Sowinski -- http://www.shooltz.com
-
hButton is a window handle, not a child ID. Store value returned from CreateWindow in hButton. Use some predefined constant and pass it as child ID to CreateWindow. Use the same constant when handling WM_COMMAND - you'll be able to respond differently to different buttons being pressed. Tomasz Sowinski -- http://www.shooltz.com
Sorted, thank you very much, much appreciated. Nick :-D
-
hButton is a window handle, not a child ID. Store value returned from CreateWindow in hButton. Use some predefined constant and pass it as child ID to CreateWindow. Use the same constant when handling WM_COMMAND - you'll be able to respond differently to different buttons being pressed. Tomasz Sowinski -- http://www.shooltz.com