Jump to content

win32 API - Problema com registo de classe


Dexter's Lab

Recommended Posts

Boas pessoal, estou com um problema no registo de uma classe no win32 api.

Não sei porque razão, a última classe que estou a tentar registar está a fazer retornar 0, ou seja, algo ali está errado. Mas sou novo nesta API e gostaria de saber o motivo de isto estar assim. Estou de volta disto há horas. Tenho lido imensa documentação mas no entanto não encontro a solução.

	int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
static char mainW_class[ ] = "MainWindow";
static char toolsW_class[ ] = "ToolsWindow";
static char submenuW_class[ ] = "SubmenuWindow";

HWND hwnd, tools, submenu; //handle
MSG messages;			

WNDCLASSEX mainWStruct, toolsWStruct, submenuWStruct;

/*		 generates main window	*/
mainWStruct.hInstance = hThisInstance;
mainWStruct.lpszClassName = mainW_class;
mainWStruct.lpfnWndProc = WindowProcedure;
mainWStruct.style = CS_DBLCLKS;
mainWStruct.cbSize = sizeof(WNDCLASSEX);
mainWStruct.hIcon = LoadIcon (NULL, IDI_APPLICATION);
mainWStruct.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
mainWStruct.hCursor = LoadCursor (NULL, IDC_ARROW);
mainWStruct.lpszMenuName = NULL;		
mainWStruct.cbClsExtra = 0;					
mainWStruct.cbWndExtra = 0;					
mainWStruct.hbrBackground = GetSysColorBrush(10);

if (!RegisterClassEx (&mainWStruct))
	return 0;							[b]  //<-----REGISTADO OK![/b]

hwnd = CreateWindowEx (
	   0,
	   mainW_class,
	   "project title",
	   WS_SYSMENU | WS_BOXES,
	   0, 0,
	   GetSystemMetrics(SM_CXSCREEN),
	   GetSystemMetrics(SM_CYSCREEN)-1,
	   HWND_DESKTOP,
	   NULL, //menu
	   hThisInstance,
	   NULL);


toolsWStruct.hInstance = hThisInstance;
toolsWStruct.lpszClassName = toolsW_class;
toolsWStruct.lpfnWndProc = WindowProcedure;
toolsWStruct.style = CS_DBLCLKS;
toolsWStruct.cbSize = sizeof(WNDCLASSEX);
toolsWStruct.hIcon = LoadIcon(NULL, IDI_APPLICATION);
toolsWStruct.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
toolsWStruct.hCursor = LoadCursor (NULL, IDC_HAND);
toolsWStruct.lpszMenuName = NULL;
toolsWStruct.cbClsExtra = 0;
toolsWStruct.cbWndExtra = 0;
toolsWStruct.hbrBackground = GetSysColorBrush(0);

if (!RegisterClassEx (&toolsWStruct))
	return 0;						  [b] //<-------------REGISTADO OK![/b]

  tools = CreateWindowEx(
	  0,
	  toolsW_class,
	  "Ferramentas",
	  WS_CHILD | WS_DLGFRAME | WS_EX_PALETTEWINDOW,
	  -SM_CXBORDER,
	  -SM_CYBORDER,
	  GetSystemMetrics(SM_CXFULLSCREEN) / 4,
	  GetSystemMetrics(SM_CYFULLSCREEN),
	  hwnd,
	  NULL,
	  hThisInstance,
	  NULL);


 submenuWStruct.hInstance = hThisInstance;
 submenuWStruct.lpszClassName = submenuW_class;
 submenuWStruct.lpfnWndProc = WindowProcedure;
 submenuWStruct.style = WS_BORDER;
 submenuWStruct.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
 submenuWStruct.cbSize = sizeof(WNDCLASSEX);
 submenuWStruct.hIcon = LoadIcon(NULL, IDI_APPLICATION);
 submenuWStruct.hCursor = LoadCursor(NULL, IDC_ARROW);
 submenuWStruct.lpszMenuName = NULL;
 submenuWStruct.cbClsExtra = 0;
 submenuWStruct.cbWndExtra = 0;
 submenuWStruct.hbrBackground = GetSysColorBrush(4);

if (!RegisterClassEx(&submenuWStruct))
	return 0;							   [b] //<-----RETORNA 0.. NAO REGISTA... PORQUÊ?[/b]

 submenu = CreateWindowEx(
				   0,
				   submenuW_class,
				   "add",
				   WS_VISIBLE | WS_CHILD,
				   0,
				   0,
				   GetSystemMetrics(SM_CXFULLSCREEN),
				   GetSystemMetrics(SM_CYFULLSCREEN) / 5,
				   hwnd,
				   (HMENU) NULL,
				   hThisInstance,
				   NULL);


ShowWindow (hwnd, nFunsterStil);
ShowWindow (tools, nFunsterStil);
ShowWindow (submenu, nFunsterStil);


while (GetMessage (&messages, NULL, 0, 0))
{

	TranslateMessage(&messages);

	DispatchMessage(&messages);
}

return messages.wParam;
}
Edited by Dexter's Lab
Link to comment
Share on other sites

HHHippo, estou apenas a aprender, não é nenhum projecto.

Preciso criar uma biblioteca dinâmica (dll) e preenchê-la com as classes que necessito e depois chamá-la. Porque a que vem, já tem 4 campos definidos. A minha ideia é criar um layout com duas toolbars. Precisava 3 classes neste caso, para ambas as toolbars e para a main-window.

Edited by Dexter's Lab
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.