C++ 3D DirectX Tutorial [Window Creation] 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys it's chilly here welcome back to hardware 3d in last video we got our project set up we got our build settings all done up nice like we like it and we got our entry point here and in this video we are gonna create our first window but before we do that let's just take a look at what all this junk in our entry point actually means so we're gonna go back to MSDN and we're gonna look at what does a lot is all this stuff well it's an entry point obviously it's gonna return a exit code which means zero means success no problem and anything other than zero means there was a problem and generally we just return zero right now we are taking four parameters here and this is a little bit of because this entry point is that it basically hasn't changed since Windows 3.1 back in the early 1980s so there's some stuff here that doesn't really make sense specifically we have two things called H instance these are pointers to structures that hold information about our program where it's you know where it's loaded into memory stuff like that and the thing is the second one is always gonna be no in Windows back in 16-bit windows it was something else now it's always no so you could just ignore that one you can ignore this one each instance you could also ignore it because there's a function that returns each instance when you want it it's called the jet module handle or something like that but you could also get it from this entry point and you need it when you're creating Windows this one is very important this is your command line so when someone runs your program and they they pass extra parameters through and the command line here is where you're gonna receive them so you receive the entire command line as a single string which is different than the standard C and C++ entry point where you receive it as a parsed array of tokens so here you just receive a single string and you process it any way you like the last value here we're not going to use it it is command show and it is basically an indication to the probe of how the window should be shown when it is created for your program on startup so we don't care we're just gonna show the window I'm not we're gonna ignore this value but it's here all the information about it is in here if you want to use it for some reason and the last thing that might be unfamiliar to you guys is the call back here this little modifier for the function and it is telling C++ to use a different calling convention for this function it should use stood call which passes parameters on the stack a little differently than the standard C calling convention which is C deckle and you'll see this for functions that the windows API has to call so callback functions they because the windows API uses did call any functions that you create that the windows API will call have to have this did call calling convention and there you go that is the explanation of our entry point now let's create our window like I said in the last video to create a window you have to register window class and then you have to create instance of your window so the function the register windows class is register class and there's a bunch of versions here usually for a lot of windows functions you're gonna have a normal version and then an e X version which is extended and that's the newer version of the function so we could probably get away with just a normal version but let's use the new version anyways we're just your class e X was it take well it takes a constant pointer to windows class X a a is just you know non unicode so that means we've got to create a windows class X structure and this is a very common in windows API and direct3d when you want to initial when you want to configure some object or something instead of passing a whole bunch of parameters to a constructor you generally fill a configuration structure and then pass a pointer to that structure to the creation function so let's create a Windows class the X and then we'll call will just call it WC it's always good practice to zero out a configuration structure before you fill it so we'll do that here and then we type WC dot and we can get a list of all the different members here it's quite a few of them you might be wondering what they do it's pretty important so very simple look upwind class X on MSDN and you will get the syntax of the structure and you will get an explanation of all the members so let's go through them first member size this is very common for configuration structures you got to fill this guy with the size of the structure next thing here is the style of the class the class style so there's a bunch of those guys click this link here you get a link to a page that doesn't have the class styles classic MSDN but if you look at class styles here now you can get a link to the actual list of class styles so does a bunch of class styles here these are if you look at them you can see there are binary flag bit flags you can or them together to combine styles the one that we're gonna be using is right down here CS own DC so this is a bunch of but basically DC is device context and this is important for when you draw to window using the normal windows graphics API called GDI so doing own DC will give every window that we create its own device context and they can be rendered two independently which might be useful if you want to spawn multiple windows for your application at once it's not something that you usually do with a game but I want to be able to support that so we're gonna make it own DC now the next one here is the most important member of this whole structure it's called the whole long pointer to function window proc and this is a pointer to a function that is going to handle all the messages for this window so this is very important because the process that handles all the messages determines the behavior of the window and it also determines the how the window looks because one of the messages that you handle is the draw message which tells you to draw the window so how you handle that message determines how the window is going to look so for this guy we're gonna start off by passing him a pointer to default windows procedure which just has basic catch-all to handle all the important messages that need to be handled for a window but later on we're gonna create our own custom window procedure and we are going to pass a point of that when we create the class so this is gonna be the default guide for now class extra so this allows us to allocate some extra bytes in the the class that we can use to store custom data we don't need that çb wind extra allows us to allocate extra bytes of data when for every instance of a window that we create of this class again we don't need this extra data to be stored on the windows api side so we just set this these two to zero each instance is the instance that we get passed in now we can pass in custom icons and we can choose what cursor we want for application but if we set these guys to know then we'll just get the defaults and that's what we're gonna do we can also set a brush this is again a GDI thing for drawing and if we set a brush that's the brush that will be used to draw the background of the window now if we set this guy to no that means that Windows will not draw the background of the window and we will have to draw it ourselves which is good because we're gonna be drawing the whole window over with direct3d anyways we don't want windows to waste its time drawing over that when we're just gonna draw over top of what windows did next thing is we have a menu name we're not going to be using menus obviously because we're just making a game thing so we set this to null this one is important this is the class name this is the name that is gonna be used when we create windows of this class type so when we call the create window function we gotta pass it the same class name that we use to register our class and the last thing is we can give it a handle to an icon to set a custom icon for our application and we might do this later well we're not gonna do it right now for sure alright so that's all the members let's set them up so we set the size to the size of the structure set the style to see us own DC and we're gonna set what is it the LPF the windows procedure equal to death window proc which is similar but yet distinct from Def Leppard and Def Jam WC that all right so here's the extra data so we want 0 extra bytes in the class structure that is stored at the API side and the 0 extra bytes for every window that is created of this class we don't need it now each instance is just going to be the h instance that was passed in each icon h cursor and H background are all going to be null so cursor and I use the standard C++ null pointer I don't use the macro so that windows defines the capital no so that's cursor and each be our background there we go the menu name is also going to be null pointer because we don't got a menu and but the class name is very important and instead of using a magic constant let's just go Const auto class name is equal to hardware 3d buts because you know it's me after all you got to make a dumb there we go there's the class name each icon is again we don't need that so there you go we have set up our configuration structure beautiful get used to this because we're gonna be setting up a lot of configuration structures or descriptors as they're called because we're gonna be doing a lot of configuration all right register classy X and that's easy we just pass the pointer to our configuration and it should be done this should register our class for creating windows on the windows api side and now we can refer to that when we want to create specific window instances man let's create the window now so create window and we see now here there is an X version of that ok here we go so this one does not take a configuration struct it just takes a bunch of parameters in the function so we've got again more Styles beautiful more flags to look up and the class name that week for the class that we registered the name we want for our new window more Styles again style be we gotta be stylus right what a create our windows the position of the window dimensions of the window handle to the parent but since the window we're creating has no parent and it doesn't have it just we've just passed a null in here there's no menu each instance is again that that stuff that we got and this one is a parameter that we can pass in that will be able to be used to configure this custom data that we can pass to our window when we're creating it and we'll be using this guy later on when we create our sexy wrapper class but for right now we just ignore it no pointer so the most important thing here is what kind of styles do we want for our window there are two classes of styles there there's the X tiles those are the ones that are only available when you call the X version of create window and then they are the normal styles so in the extended windows styles you can see there's a whole bunch here and we can specify a whole bunch of different things about our window does it accept drag-and-drop files what kind of edge does it have how does it paint its descendants all this crazy horse crap MDI child yeah no we don't want I don't think we want any of these it's a transparent window now we're just we just want a normal window just give me the normal give me the give me the number one so let's just jump in here so create window is gonna return a handle to the window this is important you need that handle in order to do do operations on the window later on so we want to we want to store that so we each wind is equal to create window X so the first thing is the e X style I don't think we need any X tiles so we'll just put that as a zero the next thing is the class name that is just p class name right good now lost my intellisense it's back now thank you P window name so we need a name for our window and we'll just call this one happy hard window cuz we're doing hardware 3d well not today but eventually eventually in no time now DW style okay so this is the normal windows styles the Nani X of the Nani X persuasion as we say so what kind of styles to be gotten we can have a border we can have a caption something we can be a child or something like that we can clip our children we can clip our siblings we can do all sorts of stuff what do we want for our window well we're gonna want a caption and we're gonna want a minimize box so that we can have a minimize control so that is minimize box and we're gonna want a sis menu just because I like I like a window that has a syst menu here it is so we want these three but you could add different ones you could experiment with them see what they all do I'm not gonna you know spend an hour experimenting with all the different possible combinations of windows styles I don't think you would find that particularly interesting and I know I would as much as I respect your time I respect my time even more so minimize box is the one that we want and w-s this menu me that's not how you spell that is that it's this menu yeah there you go now please turn purple okay missed one men minam's minimes there we go beautiful so we've got our Styles set up here it's gonna mash all these flag bits together it's gonna make us a nice style next thing we got if I can get my intellisense back thank you very much is the position of the window now I don't really care where I put this one oh let's put it at 200 200 the width we'll put it at 640 by 480 because that's the resolution that Master of Orion two runs in now no point was this stuff the window handle to the parent that's a big null pointer what's the next one you can't see it but it is a handle to the menu that's a null pointer next one is the handle to the instance that's the ATT instance and the last one is long pointed to a custom parameter that's another big null pointer that's a null P all right this is a wrong that was the wrong kind of bracket that's the right kind of bracket so here theoretically we have created our window and it was good and then we can rest but the question is what will this do well it's gonna create the window and eggs it immediately starts now we want let's go while true beauty build builds cuz successfully let's run it and we get nothing we get nothing you lose good day sir why do we get nothing well well that's a good question that's a good question next question No ah here's the thing first off let's just make sure create window is actually working so we can verify that fairly simply well put a breakpoint there we'll step over this we'll check the value of each wind each wind seems to have a non value which means that create window did indeed work but we still we still got a little ways to go so you won't be able to actually see the window until you call show window on your window so again you should be familiar with the drill show window function show window takes handle to the window it takes the command what is the command well there's a bunch of different ones we want SW show to activate the window and display it in its current size and position alright so show window show windy hwn that's a handle to our window and the command will be SW show give-give there we go let's see what you get wait we got a happy hard window and you can't see this but it's also showing up in my in my task manager' forget what you call this thing anyways it's here the windows here you click on it absolutely nothing happens it is completely frozen which makes sense cuz we are in a while loop here but it's not responding to any kind of input here close that sucker so we've created our window we can see it but we clearly have some more work to do remember I told you Windows is about two things it's about Windows we got that now it's also about messages we ain't doing about messages yet so in the next video we are gonna get down with the message the message of our Lord and Savior Sir William Gates but until then I hope you enjoyed the video if you did please click the like button helps a lot and I will see you soon with some more hardware 3d [Music] [Applause] [Applause] [Music] you
Info
Channel: ChiliTomatoNoodle
Views: 55,642
Rating: undefined out of 5
Keywords: 3d game programming, c++ 3d, game programming tutorial, c++, C++ tutorial, c++ game engine, how to, 3d game engine, Directx programming, direct3d programming, how to program 3d games, DirectX, Direct3D, D3D, programming, game, lesson, cpp, guide, code, tutorial, coding, software, development, windows, visual studio, game dev, chili, winapi, windows sdk, win32
Id: nQTiSLiNyk4
Channel Id: undefined
Length: 18min 42sec (1122 seconds)
Published: Sun Dec 23 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.