🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

It wont show.....

Started by
8 comments, last by Nothingness 22 years, 9 months ago
I am just learning how to make a window, and the first one i made had no errors, but the window wont show up. Also the size of it is huge, the *.exe is 153kb and that has to be to big for a window that does nothing! Heres the source for the window
    
#include <windows.h>

#include <windowsx.h>

#include <stdio.h>

#include <math.h>




LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{

   PAINTSTRUCT ps;
   HDC        hdc;
   

   switch(msg)
   {

    case WM_CREATE:
	 {
	    return 0;
	 } break;

	case WM_PAINT:
	 {
	    hdc = BeginPaint(hwnd,&ps);
		EndPaint(hwnd,&ps);
		return 0;
	 }break;

	case WM_DESTROY:
	  {
	    PostQuitMessage(0);
		  return 0;
	  }break;

	default:break;
   }//close  switch

   

return(DefWindowProc(hwnd,msg,wparam,lparam));
} //close winproc



int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance,
				   LPSTR cmdline, int cmdshow)
{


WNDCLASSEX winclass;
HWND       hwnd;
MSG        msg;


winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC | CS_DBLCLKS;
winclass.lpfnWndProc = WinProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "winclass";
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&winclass))
   return 0;


if(!(hwnd = CreateWindowEx(NULL,
                           "WINCLASSEX1",         //clss name

	         "Your Basic Window",             //title

						   WS_OVERLAPPEDWINDOW |WS_VISIBLE, //kind of window

						   0,0,                             //x,y starting coordinates

						   400,400,                         //width and hieght of window

						   NULL,                            //handle to parent

						   NULL,                            // handle to menu

						   hinstance,                       // insance of this application

						   NULL)))                          //extra creation params.

return 0;



while(GetMessage(&msg,NULL,0,0))
     {
	   TranslateMessage(&msg);
	   DispatchMessage(&msg);
	  }

return(msg.wParam);
}
    
Edited by - Nothingness on October 1, 2001 7:42:06 PM
Advertisement
Call these two functions right after you call the createwindowEx function:

ShowWindow (hwnd, cmdshow);
UpdateWindow (hwnd);


I''m learning the Win32 api right now and I took a look at my basic applications that are similar to yours and the executables were around the same size as yours (152kb). So it''s probably normal.
As the AP has said, you need to call ShowWindow() to display the window. As for the "huge" size of the executable for a window that "does nothing", that window has set up a message queue with the operating system directing appropriatve events to it. All that takes up code (but it''s done for you so you don''t notice it).

What, did you think libraries and DLLs were empty?
It still dosent show.
In the WNDCLASS structure you set the Class Name to "winclass", while in the CreateWindowEx call you specify the Class Name to be "WINCLASSEX1". These two strings must be the same for the window to be created properly. The string you pass in the function call is used as an id, so that Windows knows which WNDCLASS to use for the new window.
AHHHH!!!! it still dosent work! I''m so fustrated. I cant make a little window show up! I did all that you all said, and still, it says nothing is wrong but then the window dosent show. Im so fustrated!
YES!! I figured out why it wont show, i missed one of the part of the window class. (winclass.hInstance = hinstance)
the reason your exe is so big is because you are compiling it in debug mode. try going to project->set active mode or something and set to release mode.
I''ll give it another try. Some of these suggestions might not be related to your problem but try them just in case.

You can take out all those break statements that you have in the switch statement. They are not needed. The return statements are sufficient. Just have your switch statement with the 3 messages your currently processing and at the end return the DefWindowProc like your doing. You can take out the default:break; line also.

The register and CreateWindowEx function could be failing for some reason and you wouldn''t know because all you do is return 0. Your program might not be getting past that point. So I suggest adding a call to the MessageBox function to each of those if statements. Just have it display a simple message like "register function failed". Don''t forget to add curly braces for the if statement since it''s more than one line now.

Also, after you launch your program hit ctrl-alt-del to see the list of currently running programs and check if your program is on there.

I don''t see what else could be wrong. If this still doesn''t help, I would suggest posting your code again with all of the corrections that everyone has said.
Thanks AP, but I dont think you read above, but I figured out the Problem. I left out an important part of the window class.

(winclass.hInstance = hinstance);

This topic is closed to new replies.

Advertisement