Use Vc.net to achieve a refreshing and convenient Windows game window

Source: Internet
Author: User
Tags resource
Because the first game demo is full screen with the mouse exclusive, and can not full-screen/window switch, plus their own game and rough, feel extremely uncomfortable. Now think about it, in fact, when I play the game, I like the window, you can drag, so play the game can also do other things, and the mouse must not be exclusive, it is best to put in is personalized mouse, moved out is the system mouse. If you want to do such a window, you can change the following several places.

Let Vc.net first build a Win32 Project, and then application type to make it the default Windows application. It is also OK if you want to let it be an empty project and write those main functions yourself.
 
The first one to change is the window position, I hope it just came out in the middle of the screen, is the 800*600 window.

After the CreateWindow () function in the InitInstance () function Add the following sentence:

SetWindowPos (HWnd, Hwnd_top, swp_showwindow|, Swp_nocopybits);

The first argument is the handle to it itself, and the second of course is to let it just come out on top,

The third to sixth is the upper-left corner of the X,y value and the width of the window itself, note that this time the client area is not 800*600

The following sentence is the appearance of the generation:

HWnd = CreateWindow (Szwindowclass, SzTitle, Ws_overlappedwindow,
Cw_usedefault, 0, cw_usedefault, 0, NULL, NULL, HINSTANCE, NULL);

Which Ws_overlappedwindow said a lot of things;

#define WS_OVERLAPPEDWINDOW (ws_overlapped | \
ws_caption | \
Ws_sysmenu | \
Ws_thickframe | \
Ws_minimizebox | \
Ws_maximizebox)

I'll change it to these four:

ws_overlapped| ws_caption| ws_sysmenu| Ws_minimizebox,

ws_caption| Ws_sysmenu if it's gone, it's gone. Icon and the top right corner of the closure, maximize the minimization of such, so to stay, Ws_thickframe and Ws_maximizebox Remove the reason is not allow users to arbitrarily change the window size, If the player likes Full-screen play words can give a button in the game, Ws_minimizebox is sure to leave, do the game if not provide the boss key to feel sorry players, not to mention this minimized box?!

What's the next change? To get rid of the default menu, we don't need the file, close and the About box ... My practice is to open resource in the menu, the column has been deleted;

Then the mouse, the game should be with their own mouse picture and the system mouse screen off, if not their own mouse will not have to change. Add this case:wm_ncmousemove in the switch (message), which means that the mouse is moving in a non customer area, so the system mouse is displayed, because the player may need to click here to drag the window, and then let the system mouse hide when wm_mousemove. The specific code is as follows:

Add a static variable to record the mouse display state
static BOOL cursorstate = TRUE;
Switch (message)
{
Case Wm_ncmousemove:
{
if (cursorstate = = FALSE)
{
Cursorstate = TRUE;
ShowCursor (TRUE);
}
}
Break
Case WM_MOUSEMOVE:
{
if (cursorstate = = TRUE)
{
Cursorstate = FALSE;
ShowCursor (FALSE);
}
And then do something else.
}
Break
The other case items will not change.
}

The last is the icon, always can not use its own icon is difficult to see. If you are willing to draw a few strokes, change the resource inside the icon bar, but this may be more ugly, hehe. If you take a. icon file from somewhere else, you can add it like this:

First add this icon to the resource file, and then look at the resource.h in the name of what it is called, if called Idi_icon1, in the registration window class change these two words

If the window class is named Winclass
Winclass.hicon = LoadIcon (hinstance, Makeintresource (Idi_icon1));
WINCLASS.HICONSM = LoadIcon (hinstance, Makeintresource (Idi_icon1));

Pretty much. My Favorite Game window is this.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.