Creating a window through menu
Im trying to create a window through my menu, instead of using a dialog. But when the window is created, it gets all the information that my main window has... I have no idea how to fix this. Here is my code:
Code:
case WM_COMMAND:
switch(GET_WM_COMMAND_ID(wParam,lParam))
{
case HWND_FILE_EXIT:
PostQuitMessage(0);
break;
case HWND_BASE_CONVERT:
{
HWND hBaseC;
HINSTANCE hInstance_base;
HWND hBase_Edit_Bin;
HWND hBase_Edit_Oct;
HWND hBase_Edit_Hex;
HFONT hf_BaseC = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
RegisterClassEx(&bccl);
hBaseC = CreateWindowEx(WS_EX_TOOLWINDOW,
BC_ClassName,
"Base Converter",
WS_SYSMENU,
CW_USEDEFAULT,CW_USEDEFAULT,
200,200,
hwnd,
NULL,
hInstance_base,
NULL);
ShowWindow(hBaseC,SW_NORMAL);
UpdateWindow(hBaseC);
}
break;
}
break;
I tried many things, this is what its currently at =/.
EDIT:
Ok, i tried creating the window in the main function... and having it called when HWND_BASE_CONVERT was called... but its not displaying it to the screen ....
im calling the window like so:
Code:
case WM_COMMAND:
switch(GET_WM_COMMAND_ID(wParam,lParam))
{
case HWND_FILE_EXIT:
PostQuitMessage(0);
break;
case HWND_BASE_CONVERT:
{
ShowWindow(GetDlgItem(hwnd,HWND_BASE_CONVERT),SW_NORMAL);
UpdateWindow(GetDlgItem(hwnd,HWND_BASE_CONVERT));
}
break;
}
break;
I dunno why this isnt working
Ya, I forgot about declaring WS_CHILD =/, but I still get the same type of error ( making a window (but smaller) like my main window ).
Things I tried:
- creating a window class just for this tool window
- making it show to screen using ShowWindow and WS_VISIBLE
- Creating window in the main function and in the WM_COMMAND message
I can't think of anything else that might work =/... right now I have it set up that I have my window created in the main function and assigning it to the identifier. Then using the identifier to print out the window to screen when the HWND_BASE_CONVERT message is handled.
my code in the main function that creates the child window of hwnd
Code:
hBaseC = CreateWindowEx(WS_EX_TOOLWINDOW,
BC_ClassName,
"Base Converter",
WS_CHILD|WS_SYSMENU,
CW_USEDEFAULT,CW_USEDEFAULT,
200,200,
hwnd,
(HMENU)HWND_BASE_CONVERT,
NULL,
NULL);
my code using to print it out
Code:
case WM_COMMAND:
switch(GET_WM_COMMAND_ID(wParam,lParam))
{
case HWND_FILE_EXIT:
PostQuitMessage(0);
break;
case HWND_BASE_CONVERT:
{
HWND hBase_Edit = GetDlgItem(hwnd,HWND_BASE_CONVERT);
ShowWindow(hBase_Edit,SW_NORMAL);
UpdateWindow(hwnd);
UpdateWindow(hBase_Edit);
}
break;
}
break;
I figured hwnd might need to be updated since a child window was being created on it =/.
EDIT:
ahhh, i think i see my problem, ok, I THINK CreateWindowEx sends a WM_CREATE message, and if it does so... its recreating my edit controls ontop of it , since i have my edit controls (for main window) created in it. I am almost positive this is my problem. Please respond if you have any suggestions or w/e....
I tried so many different ways =(
I can't get it to work =/, can someone give me a working example, and tell me why this isnt working:
Code:
#include <windows.h> //using win32 api
#include <windowsx.h>//for additional win32 api functions
#include "identifiers.h"//so I can access my identifiers
const char g_ClassName[]="hwnd window class name";
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(GET_WM_COMMAND_ID(wParam,lParam))
{
case HWND_FILE_EXIT:
PostQuitMessage(0);
break;
case EXTRA_BASE_CONVERT:
ShowWindow(GetDlgItem(hwnd,EXTRA_BASE_CONVERT),SW_NORMAL);
UpdateWindow(GetDlgItem(hwnd,EXTRA_BASE_CONVERT));
break;
}
break;
case WM_SIZE:
{
HWND hEdit = GetDlgItem(hwnd,HWND_EDIT);
HFONT hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
RECT hwnd_cord;
GetClientRect(hwnd,&hwnd_cord);
SetWindowPos(hEdit,NULL,0,0,hwnd_cord.right,hwnd_cord.bottom,SWP_NOZORDER);
SendMessage(hEdit,WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(false,0));
}
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR nCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG Message;
HWND hEdit;
HWND hBaseC;
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.style = CS_DBLCLKS;
wc.hbrBackground = CreateSolidBrush(RGB(0,0,100));
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.lpszMenuName = MAKEINTRESOURCE(HWND_MENU);
wc.lpszClassName = g_ClassName;
wc.lpfnWndProc = WndProc;
RegisterClassEx(&wc);
hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,
g_ClassName,
"Base Converter/NotePad",
WS_SYSMENU,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hInstance,
NULL);
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
"",
WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
hwnd,
(HMENU)HWND_EDIT,
GetModuleHandle(NULL),
NULL);
hBaseC = CreateWindowEx(WS_EX_TOOLWINDOW,
g_ClassName,
"Base Converter",
WS_CHILD|WS_SYSMENU,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
hwnd,
(HMENU)EXTRA_BASE_CONVERT,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Message,NULL,0,0)>0)
{
TranslateMessage(&Message);
DispatchMessage (&Message);
}
return Message.wParam;
}
I tried so many things =/ I decided to to try and make a notepadish program and implement my base converter in the menu (to see if I could create child windows through my menu...). If I do get something to appear, its like a blank square.