Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WNDCLASSEX #51

Open
rofl0r opened this issue Sep 4, 2020 · 5 comments
Open

WNDCLASSEX #51

rofl0r opened this issue Sep 4, 2020 · 5 comments

Comments

@rofl0r
Copy link
Collaborator

rofl0r commented Sep 4, 2020

hi, today i wanted to try out the MW_FEATURE_RESIZEFRAME feature (#26) so i went looking for some win32 sample programs and found this http://www.winprog.org/tutorial/

here is a small sample program i wanted to compile against microwindows (simple_window.c)

#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
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;
		default:
			return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc;
	HWND hwnd;
	MSG Msg;

	//Step 1: Registering the Window Class
	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.style		 = 0;
	wc.lpfnWndProc	 = WndProc;
	wc.cbClsExtra	 = 0;
	wc.cbWndExtra	 = 0;
	wc.hInstance	 = hInstance;
	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = g_szClassName;
	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, "Window Registration Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	// Step 2: Creating the Window
	hwnd = CreateWindowEx(
		WS_EX_CLIENTEDGE,
		g_szClassName,
		"The title of my window",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
		NULL, NULL, hInstance, NULL);

	if(hwnd == NULL)
	{
		MessageBox(NULL, "Window Creation Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	// Step 3: The Message Loop
	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}

but it seems WNDCLASSEX isn't implemented in microwindows. are there any plans to add this ?

@ghaerr
Copy link
Owner

ghaerr commented Sep 4, 2020

Hi @rofl0r,

It would not be a big deal to implement WNDCLASSEX, its just an expanded window class structure that has a few more fields (like hIconSm to support small icons as well as normal icons), that aren't used by Microwindows anyways.

For now, probably easier to just edit simple_window.c and change all WNDCLASSEX to WNDCLASS, and then the following:

//wc.cbSize		 = sizeof(WNDCLASSEX);
//wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc)) -> change to RegisterClass

That should compile and run.

@rofl0r
Copy link
Collaborator Author

rofl0r commented Sep 4, 2020

thanks for your suggestion.

now i get

simple_window.c: In function 'WinMain':
simple_window.c:36:15: warning: implicit declaration of function 'LoadIcon' [-Wimplicit-function-declaration]
  wc.hIcon   = LoadIcon(NULL, IDI_APPLICATION);
               ^~~~~~~~
simple_window.c:36:30: error: 'IDI_APPLICATION' undeclared (first use in this function)
  wc.hIcon   = LoadIcon(NULL, IDI_APPLICATION);
                              ^~~~~~~~~~~~~~~
simple_window.c:36:30: note: each undeclared identifier is reported only once for each function it appears in
simple_window.c:37:17: warning: implicit declaration of function 'LoadCursor' [-Wimplicit-function-declaration]
  wc.hCursor   = LoadCursor(NULL, IDC_ARROW);
                 ^~~~~~~~~~
simple_window.c:37:34: error: 'IDC_ARROW' undeclared (first use in this function)
  wc.hCursor   = LoadCursor(NULL, IDC_ARROW);
                                  ^~~~~~~~~

trying to disable those too...

@ghaerr
Copy link
Owner

ghaerr commented Sep 4, 2020

Just change

wc.hCursor   = LoadCursor(NULL, IDC_ARROW);

to

wc.hCursor   = 0; //LoadCursor(NULL, IDC_ARROW);

for now, same with LoadIcon.

@rofl0r
Copy link
Collaborator Author

rofl0r commented Sep 4, 2020

thanks, that works and i get a working window. cool stuff!

regarding cursor: the default cursor which is almost horizontal in shape looks really 80ies, like in openmotif.
is it possible to use the standard X11 cursor instead, or at least a windows-xp style cursor ?

@ghaerr
Copy link
Owner

ghaerr commented Sep 4, 2020

The (80's style) Win32 cursor is declared in src/mwin/winmain.c:

    static MWCURSOR arrow = {   /* default arrow cursor*/
        16, 16,
        0,  0,
        RGB(255, 255, 255), RGB(0, 0, 0),
        { 0xe000, 0x9800, 0x8600, 0x4180,
          0x4060, 0x2018, 0x2004, 0x107c,
          0x1020, 0x0910, 0x0988, 0x0544,
          0x0522, 0x0211, 0x000a, 0x0004 },
        { 0xe000, 0xf800, 0xfe00, 0x7f80,
          0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc,
          0x1fe0, 0x0ff0, 0x0ff8, 0x077c,
          0x073e, 0x021f, 0x000e, 0x0004 }
    };

You can look up the format of MWCURSOR in include/mwtypes.h, but basically its a 16x16 bitmap, with the first array being the cursor bits, and the second array being the mask bits. If you rearrange those hex numbers into a better column, or even better yet, arrange them as C binary numbers (0111111000111b, etc), you should be able to visually play with a replacement cursor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants