Jump to content

Windows API

- - - - -

  • Please log in to reply
5 replies to this topic

#1
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
hi
How can I create a full screen window?
what must change in this program? or what should I add?:

#undef UNICODE

#define STRICT

#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

	switch(msg)

	{

		case WM_CLOSE:

			DestroyWindow(hwnd);

			return 0;

		case WM_DESTROY:

			PostQuitMessage(0);

			return 0;

		default:

			return DefWindowProc(hwnd,msg,wParam,lParam);

	}

}

void register_class(const HINSTANCE& hInstance)

{

	WNDCLASSEX wcx;

	wcx.cbSize        = sizeof(WNDCLASSEX);

	wcx.style         = 0;

	wcx.lpfnWndProc   = WndProc;

	wcx.cbClsExtra    = 0;

	wcx.cbWndExtra    = 0;

	wcx.hInstance     = hInstance;

	wcx.hIcon         = LoadIcon(0,IDI_APPLICATION);

	wcx.hCursor       = LoadCursor(0,IDC_ARROW);

	wcx.hbrBackground = (HBRUSH)(COLOR_WINDOWFRAME);

	wcx.lpszMenuName  = 0;

	wcx.lpszClassName = "classname";

	wcx.hIconSm       = LoadIcon(0,IDI_APPLICATION);

	RegisterClassEx(&wcx);

}

void message_loop()

{

	MSG Msg;

	while(GetMessage(&Msg,0,0,0) > 0)

	{

		TranslateMessage(&Msg);

		DispatchMessage(&Msg);

	}

}

void create_window(const int& nCmdShow)

{

	HWND hwnd = CreateWindowEx

	(

		0                   ,// dwExStyle

		"classname"         ,// lpClassName

		"title"             ,// lpWindowName

		WS_OVERLAPPEDWINDOW ,// dwStyle

		CW_USEDEFAULT       ,// x

		0                   ,// y

		CW_USEDEFAULT       ,// nWidth

		0                   ,// nHeight

		0                   ,// hWndParent

		0                   ,// hMenu

		0                   ,// hInstance

		0                    // lpParam

	);

	ShowWindow(hwnd, nCmdShow);

	UpdateWindow(hwnd);

}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

	LPSTR lpCmdLine, int nCmdShow)

{

	register_class(hInstance);

	create_window(nCmdShow);

	message_loop();

	return 0;

}


Edited by irancplusplus, 20 November 2011 - 05:42 PM.


#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US

irancplusplus said:

hi
How can I create a full screen window?
what must change in this program? or what should I add?:

#undef UNICODE
#define STRICT
#include <windows.h>
// window procedure:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
...

I didn't get to see your full post, but I know you would need to use the SetWindowLong () function after using CreateWindow () or CreateWindowEx (), and you also need to specify a particular value for the show style parameter of ShowWindow (); that's all I can remember off the top of my head. Ask if you need more details.

#3
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
Thanks
I don't know what's happen to my post! maybe a vBulletin bug.
the code is the simplest windows api program which creates a window.

Quote

Ask if you need more details.
what must be the arguments in:
LONG SetWindowLong(HWND hWnd,

    int nIndex,

    LONG dwNewLong

);


#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
Here's a segment from a program that I have written before:
	invoke SetWindowLong, eax, GWL_STYLE, WS_MAXIMIZE 

	

	invoke ShowWindow, [hwnd], SHOW_FULLSCREEN 

	invoke UpdateWindow, [hwnd] 

I no longer use the invoke syntax, as I have gone to doing things manually, but it's the same idea.

So the hWnd is obviously the handle to the window you just made, the nIndex is GWL_STYLE, and dwNewLong is WS_MAXIMIZE.

Also, instead of passing SW_SHOWDEFAULT, etc., to ShowWindow (), you pass SHOW_FULLSCREEN to it.

#5
irancplusplus

irancplusplus

    Learning Programmer

  • Members
  • PipPipPip
  • 65 posts
thanks.
with this code I get a full screen window:
SetWindowLong(hwnd,GWL_STYLE,WS_MAXIMIZE);

ShowWindow(hwnd, SHOW_FULLSCREEN);
how can I restore the full screen window to it's former style?

#6
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
dwStyle is the third parameter if you're using CreateWindow (), or fourth parameter if you're using CreateWindowEx (). You would perform another function call to SetWindowLong (), with the first two parameters the same, but with the third parameter equal to what you used for the dwStyle value, when you first made the window.

Also, you would want to make a call to ShowWindow (), with the second parameter as SW_SHOWDEFAULT, SW_SHOWNORMAL, or whatever you prefer to use.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users