RE: [Dev-C++] What's wrong with this code?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Marc H. <ma...@e-...> - 2002-11-27 07:28:40
|
Hi there,
Change the TCHAR *NAME="OWDB"; to TCHAR NAME="OWDB"; in the header.
_____________________________
Marc Heiligers
-----Original Message-----
From: Dreamjunky [mailto:li...@dr...]
Sent: 27 November 2002 06:40 AM
To: Post Dev-cpp
Subject: [Dev-C++] What's wrong with this code?
Hello again,
I have a beginners question for anyone who would be willing to answer it for
me. I wouldn't have bothered bringing it here if I hadn't gone over it for
an hour already to no avail. It's not enough code to warrant going over for
that long. When I run this my CreateWindow call fails. Any idea why? The
only thing in the .h worth mentioning is TCHAR *NAME="OWDB". I'd appreciate
any help you can offer.
#include <windows.h>
#include "OtherWorldsDB.h"
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, PSTR szCmd, int
iCmdShow) {
WNDCLASS wndclass; // main window
HWND hWnd; // handle to main window
MSG msg; // messages rec'd from msgserv
wndclass.lpszClassName = NAME;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
if(!RegisterClass(&wndclass)) {
error("Unable to register class");
return 1;
}
hWnd = CreateWindow(NAME, TEXT("Otherworlds Database"), WS_OVERLAPPEDWINDOW
| WS_VISIBLE, 5,
5, 50, 50, NULL, NULL, hInst, NULL)
if(!hWnd) {
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
0, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
error(lpMsgBuf);
return 1; // this is where the prg exits
every time
}
ShowWindow(hWnd, SW_SHOW);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND handle, UINT msg, WPARAM wp, LPARAM lp) {
switch(msg) {
case WM_DESTROY: // close
PostQuitMessage(0);
break;
default: // default
DefWindowProc(handle,msg,wp,lp);
}
return 0;
}
void error(TCHAR *msg) {
MessageBox(NULL, msg, TEXT("OWDB Error!"), MB_ICONERROR);
}
|