microwindows icon indicating copy to clipboard operation
microwindows copied to clipboard

WNDCLASSEX

Open rofl0r opened this issue 4 years ago • 5 comments

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 ?

rofl0r avatar Sep 04 '20 19:09 rofl0r

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.

ghaerr avatar Sep 04 '20 19:09 ghaerr

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...

rofl0r avatar Sep 04 '20 20:09 rofl0r

Just change

wc.hCursor   = LoadCursor(NULL, IDC_ARROW);

to

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

for now, same with LoadIcon.

ghaerr avatar Sep 04 '20 20:09 ghaerr

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 ?

rofl0r avatar Sep 04 '20 20:09 rofl0r

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.

ghaerr avatar Sep 04 '20 20:09 ghaerr