| | |
Creating a window with CreateWindowA(...)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 16
Reputation:
Solved Threads: 0
Hello,
I'm trying to create a window with a C++ win32 app project. I am using creating the HWND object, setting its properties, and then registering the object. Also, there is a WindowProc function.
What seems to happen is that the object registers but when I call CreateWindowA(...), this function call fails and no window is created.
Also, it seems that Error 1407 is generated on the CreateWindowA call.
Here is the code, any help is appreciated:
****************************************************************************
I'm trying to create a window with a C++ win32 app project. I am using creating the HWND object, setting its properties, and then registering the object. Also, there is a WindowProc function.
What seems to happen is that the object registers but when I call CreateWindowA(...), this function call fails and no window is created.
Also, it seems that Error 1407 is generated on the CreateWindowA call.
Here is the code, any help is appreciated:
****************************************************************************
C++ Syntax (Toggle Plain Text)
// INCLUDES #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <windowsx.h> #include <stdio.h> #include <math.h> #include <iostream> // DEFINES #define WINDOW_CLASS_NAME "WINCLASS1" // GLOBALS HWND main_window_handle = NULL; // declares the window handle // FUNCTIONS LRESULT CALLBACK WindowProc(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; } return (DefWindowProc(hwnd, msg, wparam, lparam)); } // WINMAIN int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASS winclass; HWND hwnd; MSG msg; winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = (LPCWSTR)WINDOW_CLASS_NAME; if(!RegisterClass(&winclass)) return(0); hwnd = CreateWindowA( WINDOW_CLASS_NAME, "Hello Dave", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 320, 200, NULL, NULL, hinstance, NULL); if(hwnd == NULL) { return(0); } main_window_handle = hwnd; while(1) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message = WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } } return (msg.wParam); }
Last edited by cscgal; Sep 15th, 2008 at 11:24 am. Reason: forgot to add some info / Added code tags
•
•
Join Date: Dec 2007
Posts: 360
Reputation:
Solved Threads: 69
1407 is ERROR_CANNOT_FIND_WND_CLASS (see http://msdn.microsoft.com/en-us/libr...85(VS.85).aspx)
If you are forced to reinvent the wheel at least try to invent a better one!
Please use code tags - Please mark solved threads as solved
Please use code tags - Please mark solved threads as solved
![]() |
Other Threads in the C++ Forum
- Previous Thread: Huffman coding Issue
- Next Thread: need help in operator overloading...?
Views: 829 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





