devrandom Posted March 14, 2011 Posted March 14, 2011 (edited) Hello, I created this simple code, but it always returns 1. Where's the problem? expandcollapse popup#include <stdio.h> #include <windows.h> int main(void) { HINSTANCE instance; HWND handle; handle = CreateWindow ( "MainWClass", // Class name "Window!!", // Title WS_MINIMIZEBOX|// \ WS_CAPTION| // \__> style WS_POPUP| // / WS_SYSMENU, // / CW_USEDEFAULT, // Left CW_USEDEFAULT, // Top 250, // Width 250, // Height (HWND) NULL, (HMENU) NULL, instance, NULL ); if (!handle) { return 1; } ShowWindow(handle, SW_SHOW); while (1) { UpdateWindow(handle); } return 0; } Note: it is C, not C++... Is this the problem? I know only C, how can I create windows in C with Windows APIs? Thank you Edited March 14, 2011 by devrandom
Mat Posted March 14, 2011 Posted March 14, 2011 You aren't initialising instance for a start. How about setting up a simple error catching mechanism. If you just use return GetLastError(); then look up the code on msdn then we would be a bit closer to finding out, saying that it just failed is not really enough.Mat AutoIt Project Listing
Richard Robertson Posted March 14, 2011 Posted March 14, 2011 It's fine to use C. The problem is that you are attempting to use "MainWClass" but I don't see where you registered this class anywhere.
devrandom Posted March 14, 2011 Author Posted March 14, 2011 (edited) You aren't initialising instance for a start. How about setting up a simple error catching mechanism. If you just use return GetLastError(); then look up the code on msdn then we would be a bit closer to finding out, saying that it just failed is not really enough.MatThank you It's fine to use C. The problem is that you are attempting to use "MainWClass" but I don't see where you registered this class anywhere.Yes, I think this is the problem, I just modified a bit the MSDN example that evidently isn't working :SHow I can create a class? I looked at RegisterClass but being at the beginning with the Windows APIs, I have no idea on how to create the structure to pass as parameter for that function...Is there any example on how to do this?Sorry for my bad english Edited March 14, 2011 by devrandom
danielkza Posted March 14, 2011 Posted March 14, 2011 (edited) How I can create a class? I looked at RegisterClass but being at the beginning with the Windows APIs, I have no idea on how to create the structure to pass as parameter for that function...Something like this should work (untested):WNDCLASS class = {0}; class.style = 0; class.hInstance = GetModuleHandle(NULL); class.lpfnWndProc = (WNDPROC) myWindowProcedure; class.lpszClassName = (LPCTSTR) _T("MyWindowClass"); // etc Edited March 14, 2011 by danielkza
Richard Robertson Posted March 15, 2011 Posted March 15, 2011 (edited) _T is a macro that will create a string that is either ANSI or Unicode depending on your platform. I'm surprised anyone still uses it and doesn't just move to Unicode. Edited March 15, 2011 by Richard Robertson
danielkza Posted March 15, 2011 Posted March 15, 2011 _T is a macro that will create a string that is either ANSI or Unicode depending on your platform.I'm surprised anyone still uses it and doesn't just move to Unicode.I usually use Unicode exclusively, but for the example I thought I'd stick to the definition on MSDN.
devrandom Posted March 15, 2011 Author Posted March 15, 2011 Mhhh I think there is a problem: when I use _T() my compiler says that isn't declared :|
wraithdu Posted March 15, 2011 Posted March 15, 2011 Do I have to be the one to say it? Go buy a book and learn C. You clearly know next to nothing and are going to ask 100 more questions each time one is answered.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now