1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <windows.h>
#include <strsafe.h>
//-----------------
#include <fstream>
#include <string>
//debug - function retrieved from: http://msdn.microsoft.com/en-us/library/windows/desktop/ms680582(v=vs.85).aspx
void ErrorExit(LPTSTR lpszFunction)
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}
//handle declarations
HWND txtfld;
HWND btn;
HWND txtbx;
HANDLE hfile;
//variable declarations
std::string line;
LPVOID* ntns;
/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
char txtmem[20];
switch(Message) {
case WM_CREATE:
{
txtfld = CreateWindowA("STATIC", " CommonwealthCore Database Application", WS_VISIBLE | WS_CHILD | WS_BORDER, 150, 20, 300, 20, hwnd, NULL, NULL, NULL);
txtfld = CreateWindowA("STATIC", " Find A Nation:", WS_VISIBLE | WS_CHILD | WS_BORDER, 20, 70, 250, 20, hwnd, NULL, NULL, NULL);
txtbx = CreateWindowA("EDIT", "NationShortName", WS_VISIBLE | WS_CHILD | WS_BORDER, 20, 110, 250, 20, hwnd, NULL, NULL, NULL);
btn = CreateWindowA("BUTTON", "SEARCH", WS_VISIBLE | WS_CHILD | WS_BORDER, 100, 150, 100, 30, hwnd, (HMENU) 1, NULL, NULL);
break;
}
case WM_COMMAND:
{
switch (LOWORD (wParam) )
{
case 1:
{
int gwt1=0;
char * txtmemptr = &txtmem[0];
gwt1=GetWindowText(txtbx, &txtmem[0], 20);
::MessageBeep(MB_ICONERROR);
::MessageBoxA(hwnd, txtmemptr , "Searching For Nation:", MB_OK);
hfile=CreateFile("nations.txt", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
int x=ReadFile(hfile, ntns, 1000000, NULL, NULL);
//DWORD xx=GetLastError();
//::MessageBoxA(hwnd, (LPCSTR)xx, "-", MB_OK);
//LPCSTR ntnst=(LPCSTR)ntns;
ErrorExit("GetProcessId");
//::MessageBoxA(hwnd, ntnst, "SearchData", MB_OK);
break;
}
}
}
//[-snip-]
}
|