1) Keep a window from being resized?
2) Launch another window with buttons and such?
Being trying to find a good example for #2 for a couple days but coming up dry. Any help would be great. Thanks
Printable View
1) Keep a window from being resized?
2) Launch another window with buttons and such?
Being trying to find a good example for #2 for a couple days but coming up dry. Any help would be great. Thanks
launching another window is just a matter of a CreateWindow() call, or is that not what you mean.
I think a window that is not WS_OVERLAPPED is not sizeable
Problem I'm facing is when doing the WM_PAINT is setting up the code to determine which window to put the info into.
so you're using the same callback? If so, you can either key off of the hWnd (bad method) or use GetWindowLong() and SetWindowLong with the GWL_USERDATA parameter to store a pointer specific to that window.
Most people use the WS_OVERLAPPEDWINDOW style for a standard window which is the same as the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles. Remove the WS_THICKFRAME style to remove the re-sizing border.
If you wish to restrict resizing in a specific way, you can process the WM_SIZING message, and change the resizing rectangle before it takes effect, as the user is resizing the window. I use this to allow for a user to resize a window that is stuck to the corner of the screen.
Ok here is what I got so far. This creates two windows and its a good base for what I want to do I think. Problem is that the second window shows up on the task bar and when alt-tabing. Anyway to keep that from happening?
Code:#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <winuser.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc2 (HWND, UINT, WPARAM, LPARAM);
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...);
char *titles (void);
char *names (void);
int title=2, name=1;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin");
static TCHAR szAppName2[] = TEXT ("#2 Win");
int tmp;
HWND hwnd, hwnd2, hwnd3, hwnd4;
MSG msg;
WNDCLASS wndclass, wndclass2;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass2.style = CS_HREDRAW | CS_VREDRAW;
wndclass2.lpfnWndProc = WndProc2;
wndclass2.cbClsExtra = 0;
wndclass2.cbWndExtra = 0;
wndclass2.hInstance = hInstance;
wndclass2.hIcon = LoadIcon (NULL, IDC_ARROW);
wndclass2.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass2.lpszMenuName = NULL;
wndclass2.lpszClassName = szAppName2;
wndclass2.hCursor=LoadCursor(NULL,IDC_ARROW);
if ( !RegisterClass (&wndclass))
{
tmp = GetLastError();
MessageBoxPrintf( TEXT ("Error"),
TEXT ("Error Number: %i"), tmp);
return 0;
}
if ( !RegisterClass (&wndclass2))
{
tmp = GetLastError();
MessageBoxPrintf( TEXT ("Error"),
TEXT ("Error Number: %i"), tmp);
return 0;
}
hwnd = CreateWindow (szAppName,
TEXT ("The Hello Program"),
WS_OVERLAPPEDWINDOW,
10,
10,
200,
200,
NULL,
NULL,
hInstance,
NULL);
hwnd2 = CreateWindow (szAppName2,
TEXT("POPUP"),
WS_OVERLAPPED,
500,
500,
200,
200,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
ShowWindow (hwnd2, iCmdShow);
UpdateWindow (hwnd2);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
TCHAR szBuffer[100];
switch (message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rect);
wsprintf(szBuffer, TEXT ("%s %s"), titles(), names());
DrawText ( hdc, szBuffer, -1, &rect,
DT_SINGLELINE | DT_CENTER);
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WndProc2 (HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
TCHAR szBuffer[100];
switch (message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd2, &ps);
GetClientRect (hwnd2, &rect);
DrawText ( hdc, TEXT("#2"), -1, &rect,
DT_SINGLELINE | DT_CENTER);
EndPaint (hwnd2, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd2, message, wParam, lParam);
}
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024];
va_list pArgList;
va_start (pArgList, szFormat);
_vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList);
va_end (pArgList);
return MessageBox (NULL, szBuffer, szCaption, 0);
}
char* titles(void)
{
switch (title)
{
case 0:
return ("Dirt Ball");
break;
case 1:
return ("Serf");
break;
case 2:
return ("Peasant");
break;
case 3:
return ("Adventurer");
break;
case 4:
return ("Governer");
break;
case 5:
return ("Grand Governer");
break;
case 6:
return ("Duke");
break;
case 7:
return ("King");
break;
}
}
char* names (void)
{
switch (name)
{
case 0:
return ("Gnos");
case 1:
return ("Bob");
case 2:
return ("Michael");
case 3:
return ("Shirley");
}
}
Make it a child window of the first one and then subclass it to give it its own WNDPROC.
Better yet, use CreateWindowEx() and specify the extended style WS_EX_TOOLWINDOW. It seems like the one you need.
Thanks, using CreateWindowEX did the trick perfectly.