Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Computer Forums > Software Programming
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Software Programming Software programming talk, ask questions about computer software programming or help others

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-12-2007, 9:46 PM   #1
Werner Schultz
 
Werner Schultz's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need help with my win32 app. It compiles but I can't even get it to close when I click the X on top

I am posting here the source to an item editor I have tried to
program. I have no idea what I have done wrong but when it launches
the buttons on it refuse to do anything. I can't even close the
window, I need to CTRL-ALT-DEL and end process.
I'm compiling it in visual studio .net
Any help would be appreciated, as I've been over it many times and it
all seems normal.

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include "Resource.h"


#include "editor.h"

// Application variables ////////////////////////////////////////////
HWND g_hWnd; // Window handle
char g_szClass[] = "MILEDIT"; // Class name

OPENFILENAME g_ofn; // Open/Save dialog data
char g_MILFile[MAX_PATH]; // Filename for item files

sItem g_Items[1024]; // Item list
long g_EditItem; // Item to modify

// Application prototypes ///////////////////////////////////////////
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine,
int nCmdShow);
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam);
BOOL CALLBACK ModifyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);

BOOL UpdateEntry(HWND hWnd, long ItemNum);
BOOL LoadItems(char *Filename);
BOOL NewMIL();
BOOL LoadMIL();
BOOL SaveMIL();

// Application //////////////////////////////////////////////////////
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine,
int nCmdShow)
{
WNDCLASS wc;
MSG Msg;

// Register window class
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbCl***tra = 0;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClass;
RegisterClass(&wc);

// Create the dialog box window and show it
g_hWnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_EDIT), 0, NULL);
UpdateWindow(g_hWnd);
ShowWindow(g_hWnd, nCmdShow);

// Force a load of items from default.mil
LoadItems("itemconfig.mil");

// Message loop
while(GetMessage(&Msg, NULL, 0, 0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

// Clean up
UnregisterClass(g_szClass, hInst);

return 0;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
int Selection;
char Text[256];

switch(uMsg) {
case WM_COMMAND:
switch(LOWORD(wParam)) {

// New MIL file
case IDC_NEW:
NewMIL();
break;

// Load a MIL file
case IDC_LOAD:
LoadMIL();
break;

// Save a MIL file
case IDC_SAVE:
SaveMIL();
break;

// Clear an entry
case IDC_CLEAR:
// See if an item was selected
if((Selection = SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS),
LB_GETCURSEL, 0, 0)) == LB_ERR)
break;

ZeroMemory(&g_Items[Selection], sizeof(sItem));
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_DELETESTRING,
Selection, 0);
sprintf(Text, "%5lu: %s", Selection,
g_Items[Selection].Name);
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_INSERTSTRING,
Selection, (LPARAM)Text);
break;

// Edit an entry
case IDC_ITEMS:
if(HIWORD(wParam) != LBN_DBLCLK)
break;
case IDC_EDIT:
// See if an item was selected
if((Selection = SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS),
LB_GETCURSEL, 0, 0)) == LB_ERR)
break;

// Setup the item to edit
g_EditItem = Selection;

// Call the modify item dialog
DialogBox(NULL, MAKEINTRESOURCE(IDD_MODIFY), hWnd,
ModifyDialogProc);

// Update item
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_DELETESTRING,
Selection, 0);
sprintf(Text, "%5lu: %s", Selection,
g_Items[Selection].Name);
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_INSERTSTRING,
Selection, (LPARAM)Text);
break;
}
break;

case WM_CREATE:
// Initialize the save/load dialog box info
ZeroMemory(&g_ofn, sizeof(OPENFILENAME));
g_ofn.lStructSize = sizeof(OPENFILENAME);
g_ofn.nMaxFile = MAX_PATH;
g_ofn.nMaxFileTitle = MAX_PATH;
g_ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT |
OFN_OVERWRITEPROMPT;

// Set default MIL filename
strcpy(g_MILFile, "itemcfg.mil");

break;

case WM_DESTROY:
PostQuitMessage(0);
break;

default: return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

return 0;
}

BOOL CALLBACK ModifyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
WORD Categories[11] = {
IDC_MONEY, IDC_EDIBLE, IDC_RAW, IDC_WEAPON,
IDC_ARMOUR, IDC_SHIELD, IDC_ACCESSORY,
IDC_HPREC, IDC_MPREC, IDC_SPREC,
IDC_OTHER
};
WORD Flags[8] = {
IDC_SELLABLE, IDC_CANDROP, IDC_USEONCE, IDC_DYEABLE,
IDC_REPAIRABLE, IDC_NOTRANSFER, IDC_UPGRADABLE, IDC_HANDSFREE
};
char Text[16];
long i;

switch(uMsg) {
case WM_INITDIALOG:
// Return an error if there's no item to modify
if(g_EditItem > 9999) {
EndDialog(hWnd, FALSE);
return FALSE;
}

// Set up current item attributes

// Category
SendMessage(GetDlgItem(hWnd,
Categories[g_Items[g_EditItem].Category]), BM_SETCHECK, 1, 0);

// Flags
for(i=0;i<4;i++)
SendMessage(GetDlgItem(hWnd, Flags[i]), BM_SETCHECK,
CheckItemFlag(g_Items[g_EditItem].Flags, i), 0);

// Usage
SendMessage(GetDlgItem(hWnd, IDC_USAGE), LB_RESETCONTENT, 0, 0);
for(i=0;i<32;i++) {
sprintf(Text, "%5lu", i);
SendMessage(GetDlgItem(hWnd, IDC_USAGE), LB_INSERTSTRING, i,
(LPARAM)Text);
if(CheckUsageBit(g_Items[g_EditItem].Usage, i))
SendMessage(GetDlgItem(hWnd, IDC_USAGE), LB_SETSEL, TRUE,
i);
}

// Item Number
sprintf(Text, "%lu", g_EditItem);
SetWindowText(GetDlgItem(hWnd, IDC_NUM), Text);

// Entries
SetWindowText(GetDlgItem(hWnd, IDC_NAME),
g_Items[g_EditItem].Name);
SetWindowText(GetDlgItem(hWnd, IDC_DESCRIPTION),
g_Items[g_EditItem].Description);

sprintf(Text, "%lf", g_Items[g_EditItem].Weight);
SetWindowText(GetDlgItem(hWnd, IDC_WEIGHT), Text);
sprintf(Text, "%lf", g_Items[g_EditItem].MaxLife);
SetWindowText(GetDlgItem(hWnd, IDC_MAXLIFE), Text);
sprintf(Text, "%ld", g_Items[g_EditItem].Value);
SetWindowText(GetDlgItem(hWnd, IDC_VALUE), Text);
sprintf(Text, "%lu", g_Items[g_EditItem].Price);
SetWindowText(GetDlgItem(hWnd, IDC_PRICE), Text);

SetWindowText(GetDlgItem(hWnd, IDC_SCRIPT),
g_Items[g_EditItem].ScriptFilename);
SetWindowText(GetDlgItem(hWnd, IDC_PAK),
g_Items[g_EditItem].PakFilename);
SetWindowText(GetDlgItem(hWnd, IDC_FRAME),
g_Items[g_EditItem].FrameFilename);

return TRUE;

case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_OK:
UpdateEntry(hWnd, g_EditItem);
EndDialog(hWnd, TRUE);
return TRUE;

case IDC_CANCEL:
EndDialog(hWnd, FALSE);
return TRUE;

case IDC_SETALL:
for(i=0;i<32;i++)
SendMessage(GetDlgItem(hWnd, IDC_USAGE), LB_SETSEL, TRUE,
i);
break;

case IDC_CLEARALL:
for(i=0;i<32;i++)
SendMessage(GetDlgItem(hWnd, IDC_USAGE), LB_SETSEL, FALSE,
i);
break;
}
break;
}

return FALSE;
}

BOOL UpdateEntry(HWND hWnd, long ItemNum)
{
WORD Categories[11] = {
IDC_MONEY, IDC_EDIBLE, IDC_RAW, IDC_WEAPON,
IDC_ARMOUR, IDC_SHIELD, IDC_ACCESSORY,
IDC_HPREC, IDC_MPREC, IDC_SPREC,
IDC_OTHER
};
WORD Flags[8] = {
IDC_SELLABLE, IDC_CANDROP, IDC_USEONCE, IDC_DYEABLE,
IDC_REPAIRABLE, IDC_NOTRANSFER, IDC_UPGRADABLE, IDC_HANDSFREE
};
char Text[32];
long i;

// Get category
for(i=0;i<11;i++) {
if(SendMessage(GetDlgItem(hWnd, Categories[i]), BM_GETCHECK, 0, 0)
== TRUE) {
g_Items[ItemNum].Category = i;
break;
}
}

// Get flags
g_Items[ItemNum].Flags = 0;
for(i=0;i<4;i++) {
if(SendMessage(GetDlgItem(hWnd, Flags[i]), BM_GETCHECK, 0, 0) ==
TRUE)
SetItemFlag(g_Items[ItemNum].Flags, i);
}

// Get usage
g_Items[ItemNum].Usage = 0;
for(i=0;i<32;i++) {
if(SendMessage(GetDlgItem(hWnd, IDC_USAGE), LB_GETSEL, i, 0) ==
TRUE)
SetUsageBit(g_Items[ItemNum].Usage, i);
}

// Get entries
GetWindowText(GetDlgItem(hWnd, IDC_NAME),
g_Items[ItemNum].Name, 32);
GetWindowText(GetDlgItem(hWnd, IDC_DESCRIPTION),
g_Items[ItemNum].Description, 128);

GetWindowText(GetDlgItem(hWnd, IDC_WEIGHT), Text, 32);
g_Items[ItemNum].Weight = (float)atof(Text);

GetWindowText(GetDlgItem(hWnd, IDC_MAXLIFE), Text, 32);
g_Items[ItemNum].MaxLife = (float)atof(Text);

GetWindowText(GetDlgItem(hWnd, IDC_VALUE), Text, 32);
g_Items[ItemNum].Value = atol(Text);

GetWindowText(GetDlgItem(hWnd, IDC_PRICE), Text, 32);
g_Items[ItemNum].Price = atol(Text);

GetWindowText(GetDlgItem(hWnd, IDC_SCRIPT),
g_Items[ItemNum].ScriptFilename, 16);
GetWindowText(GetDlgItem(hWnd, IDC_PAK),
g_Items[ItemNum].PakFilename, 16);
GetWindowText(GetDlgItem(hWnd, IDC_FRAME),
g_Items[ItemNum].FrameFilename, 16);

return TRUE;
}

BOOL LoadItems(char *Filename)
{
FILE *fp;
long i;
char Text[256];

// Clear item structures
for(i=0;i<1024;i++)
ZeroMemory(&g_Items[i], sizeof(sItem));

// Open the file
if((fp=fopen(Filename, "rb")) != NULL) {
// Read in all items
for(i=0;i<1024;i++)
fread(&g_Items[i], 1, sizeof(sItem), fp);

// Close file
fclose(fp);
}

// Update items box
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_RESETCONTENT, 0, 0);
for(i=0;i<1024;i++) {
sprintf(Text, "%5lu: %s", i, g_Items[i].Name);
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_INSERTSTRING, i,
(LPARAM)Text);
}


return TRUE;
}

BOOL NewMIL()
{
char Buf[16];

if(MessageBox(g_hWnd, "Are you sure? (Looses any unsaved Item Config
information)", "New MIL", MB_YESNO) == IDYES) {
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_RESETCONTENT, 0, 0);
for(long i=0;i<1024;i++) {
ZeroMemory(&g_Items[i], sizeof(sItem));

sprintf(Buf, "%5lu:", i);
SendMessage(GetDlgItem(g_hWnd, IDC_ITEMS), LB_INSERTSTRING, i,
(LPARAM)Buf);
}
return TRUE;
}

return FALSE;
}

BOOL LoadMIL()
{
// Setup the open dialog info
g_ofn.hwndOwner = g_hWnd;
g_ofn.lpstrFile = g_MILFile;
g_ofn.lpstrTitle = "Load MIL File";
g_ofn.lpstrFilter = "MIL Item Files (*.mil)\0*.mil\0All Files
(*.*)\0*.*\0\0";
g_ofn.lpstrDefExt = "mil";

// Ask for filename
if(!GetOpenFileName(&g_ofn))
return FALSE;

// Load the file and return result
if(LoadItems(g_MILFile) == FALSE) {
MessageBox(g_hWnd, g_MILFile, "Unable to open file.", MB_OK);
return FALSE;
}

return TRUE;
}

BOOL SaveMIL()
{
FILE *fp;
long i;

// Setup the open dialog info
g_ofn.hwndOwner = g_hWnd;
g_ofn.lpstrFile = g_MILFile;
g_ofn.lpstrTitle = "Load MIL File";
g_ofn.lpstrFilter = "MIL Item Files (*.mil)\0*.mil\0All Files
(*.*)\0*.*\0\0";
g_ofn.lpstrDefExt = "mil";

// Ask for filename
if(!GetSaveFileName(&g_ofn))
return FALSE;

// Open filename for saving
if((fp=fopen(g_MILFile, "wb")) == NULL)
return FALSE;

// Save all objects
for(i=0;i<1024;i++)
fwrite(&g_Items[i], 1, sizeof(sItem), fp);

// Close file and return success
fclose(fp);

return TRUE;
}

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-12-2007, 9:46 PM   #2
Frank Andreas de Groot
 
Frank Andreas de Groot's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need help with my win32 app. It compiles but I can't even get it to close when I click the X on top

I think you need to trap the WM_CLOSE message.
Frank


"Werner Schultz" <none@none.none> wrote in message news:4ltslvc5l85tb24t2er6u14a70qe6s7e5f@4ax.com...
> the buttons on it refuse to do anything. I can't even close the
> window, I need to CTRL-ALT-DEL and end process.



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: , , , , , , , ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Close Encounters With The Drive Bay Fans :) Thisn2s Computer Cases (Case moding), Power Supplies (PSU) and Cooling 3 02-18-2008 1:43 PM
PHOTO BOOK CLOSE-OUT Vince Pilutis Ebay Technical Questions 0 05-31-2007 1:16 AM
PHOTO BOOKS CLOSE OUT Vince Pilutis Ebay Technical Questions 0 05-31-2007 1:16 AM
My CD8 wan't run on XP Home, not a valid Win32 application PeterM Graphics in general 6 05-28-2007 7:47 PM


Featured Websites




All times are GMT +1. The time now is 12:30 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

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 89 90 91 92 93 94 95 96 97 98