-
Window won't show
Hey. I just started working on some windows api programs, really basic stuff. Well, I have winProc and winMain and everything runs fine, but when I run it, the window I created does not show up. Here is the code I used:
#include <windows.h>
HWND hWnd;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
};
return DefWindowProc(hWnd, msg, wParam, lParam);
};
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wcx;
MSG msg;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH));
wcx.hIcon = LoadCursor(NULL, IDC_ARROW);
wcx.hInstance = hInstance;
wcx.lpszClassName = "Learning";
wcx.lpfnWndProc = WindowProc;
wcx.lpszMenuName = 0;
RegisterClassEx(&wcx);
hWnd = CreateWindowEx(WS_EX_LEFT, "Learning", "Learning", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nShowCmd);
while(GetMessage(&msg, hWnd, NULL, NULL))
{
DispatchMessage(&msg);
};
return 0;
};
So I don't know why it doesn't work, it just doesn't. The window doesn't show up but it runs in the background and I have to ctrl-alt-del to kill it. Thanks in advance.
Toraton
-
Moved to the Windows forum...
-
you need to assign a height and width, heres mine:
hwMain = CreateWindowEx(0, "LIQUID_BOT_SERVER_WINDOW", "L!quid Bot Server", WS_CAPTION|WS_BORDER|WS_SYSMENU|WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 645, 500, 0, 0, hInst, 0);
-
I've already tried that, but thanks anyway. CW_USEDEFAULT means use the default height and width, that shouldn't be the problem.
Any other ideas?
Toraton
-
Okay here are some errors in your code.
#1: In your window proc, you have semicolon after your switch statement, do not do this. Actually you have semicolon's after all your end braces! This is bad! Don't do it.
Your RegisterWindowEx( ) function is failing. You would know this is you checked the return value. Always check the return value!
You need to fill in the cbSize member with the sizeof the structure in bytes. Also you need to give it a style try this.
Code:
wcx.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
I tryed it and it worked after those changes.