วันอาทิตย์ที่ 10 กุมภาพันธ์ พ.ศ. 2551

เมนู DOS-style

สมัยก่อน โปรแกรมที่ใช้ DOS จะนิยมเขียนเป็นเมนู
เลยทดลองสร้างดู

รหัสโปรแกรม main.c


/*
by Chakkree Tiyawongsuwan
10 Feb 2008
*/

include
include

include "menu.h"

int main(){
int i , num_munu;
MENU_ITEM Main_menu[] = {
{1,"Add"},
{2,"Delete"},
{3,"Edit"},
{0,"Exit"}
};

num_munu = sizeof(Main_menu) / sizeof(MENU_ITEM);
i = ChooseMenu(Main_menu, "Main Menu" , num_munu);

printf("\n\nyou choose menu no. %d \n" , i);

system("PAUSE");
return 0;
}



รหัสโปรแกรม menu.h


/*
by Chakkree Tiyawongsuwan
10 Feb 2008
*/

#ifndef _MENU_
#define _MENU_

#define FALSE 0
#define TRUE 1

typedef struct menu {
int id;
char name[10];
} MENU_ITEM;

int ChooseMenu(MENU_ITEM Menu[], char *msg ,int n);

#endif




รหัสโปรแกรม menu.c


/*
by Chakkree Tiyawongsuwan
10 Feb 2008
*/
#include "menu.h"

int ChooseMenu(MENU_ITEM Menu[], char *msg ,int n){
int i ,ch , done;
MENU_ITEM *myMenu;

done = FALSE;
//num_munu = sizeof(Menu) / sizeof(MENU_ITEM);

do{
system("CLS");
printf("===================\n");
printf(" %s\n", msg);
printf("===================\n");

myMenu = Menu;
for (i= 0; i < n; i++){
printf("%5d %-10s\n",myMenu->id , myMenu->name);
myMenu++;
}
printf("\n Select : ");

myMenu = Menu;
for (i= 0; i < n; i++) {
printf("%d " ,myMenu->id );
myMenu++;
}
printf(" : ");
scanf("%d", &ch);

myMenu = Menu;
for (i= 0; i < n; i++) {
if (ch==myMenu->id) {
done = (ch==myMenu->id);
myMenu++;
break;
}
myMenu++;
}
} while(!done);

return ch;
}



วันเสาร์ที่ 9 กุมภาพันธ์ พ.ศ. 2551

การเรียงลำดับข้อมูล Array of Structures

ต้องการสร้างข้อมูล สำหรับเก็บหน้าตัดเหล็กรูปพรรณ
แต่เวลานำไปใช้งานต้องมีการเรียงข้อมูลก่อน

เลยไปค้นข้อมูลวิธีการ ได้ตัวอย่างมาแล้ว เอามาฝากไว้ก่อน
แล้วจะดัดแปลงอีกครั้ง



/*
http://www.thescripts.com/forum/thread461852.html
Sorting Array of Structures

How would I go about sorting this structure by title?
*/

include
include

typedef struct {
char author[40];
char title[40];
char code[4];
int hold;
int loan;
} LIBRARY;

int complib(const void *vp1, const void *vp2)
{
const LIBRARY *p1 = vp1;
const LIBRARY *p2 = vp2;
// return strcmp(p1->title, p2->title);

/* case Number */
if(p1->loan > p2->loan) return 1;
if(p1->loan < p2->loan) return -1;
return 0;
}

void printyourdata(LIBRARY *b ,int n )
{
int i;
for (i = 0; i < n ; i++){
printf("%-12s\t%-25s\t%s\t%d\t%d\n" ,
b[i].author, b[i].title, b[i].code , b[i].hold ,b[i].loan );
}
}

int main()
{
int n;
LIBRARY book[]= {
{"Galvin","Operating Systems","G02",15,2} ,
{"Golumbic","Graph Theory","G01",5,2} ,
{"Habermann","Operating Systems","H01",10,5} ,
{"Herzog","Computing Structures","H03",10,7} ,
{"Holub","Compiler Design","H05",11,8} ,
{"Horowitz","Programming Languages","H06",16,10} ,
{"Hughs","Structured Programming","H02",4,4} ,
{"Hunter","Understanding C","H04",6,6} ,
{"Jacobs","Database Logic","J01",3,1} ,
{"Kanter","Management Information","K01",8,1} ,
{"Kindred","Data Systems","K04",2,0} ,
{"Kleinrock","Queueing Systems","K03",14,0} ,
{"Kuo","Numerical Methods","K02",2,0} ,
{"Lane","Data Communications","L01",20,3} ,
{"Mano","Computer Architecture","M01",2,2}
};

n = sizeof book / sizeof book[0];
printyourdata(book, n);

qsort(book, n, sizeof book[0], complib);

printf("\n\n");
printf("==============================================\n");
printyourdata(book, n);


system("PAUSE");
return 0;
}

/*
Function getData(t1, t2, t3, t4, t5)
str1 = "{"
str1 = str1 & Chr(34) & t1 & Chr(34) & ","
str1 = str1 & Chr(34) & t2 & Chr(34) & ","
str1 = str1 & Chr(34) & t3 & Chr(34) & ","
str1 = str1 & t4 & ","
str1 = str1 & t5 & "}"
getData = str1
End Function
*/

วันจันทร์ที่ 27 สิงหาคม พ.ศ. 2550

Haru Free PDF Library II

เป็นไลบรารี ฟรี สำหรับสร้างไฟล์ pdf


http://libharu.sourceforge.net/index.html

วันศุกร์ที่ 17 สิงหาคม พ.ศ. 2550

wxDev-C++



wxDev-C++ โปรแกรมนี้พัฒนาขยายเพิ่มเติมต่อจาก Dev-C++ ซึ่งโปรแกรมนี้จะสามารถสร้าง Dialog และหน้าต่างได้โดยสามารถมองเห็นลักษณะได้เลย คล้าย ๆ กับ SharpDeveloper แต่ ยังอยู่ในระหว่างการพัฒนาอยู่ โดยโปรแกรม จะใช้การเขียนส่วน GUI ของ wxWidgets

ถ้าต้องการติดตั้งโปรแกรม wxDev-C++ จะต้องถอดโปรแกรม Dev-C++ ออกก่อน โดนดาวน์โหลดโปรแกรมได้ที่
http://wxdsgn.sourceforge.net/

ส่วนคู่มือ ให้ดาวน์โหลดได้ที่
http://wxdevcpp-book.sourceforge.net/

วันพุธที่ 15 สิงหาคม พ.ศ. 2550

เว็บไซท์สอน Windows Programming

1. สอนการสร้างโปรแกรมด้วยระบบ Win32 และอธิบายแต่ละส่วนของโปรแกรม ด้วย Dev-C++
http://in.geocities.com/pravinparatey/

2. Windows API Tutorial
http://www.relisoft.com/win32/index.htm

3. Windows Programming Tutorial
http://www.geocities.com/Heartland/Meadows/9818/win32tut/index.html

4. Win32 programming
http://www.functionx.com/win32/


ทำเมนูภาษาไทยให้กับ Dev-C++


ไม่เห็นมีเมนูภาษาไทย เลยกำลังทดลองทำเองอยู่
ใน Path c:\devcpp\lang ให้ทำการคัดลอกไฟล์ English.lng แล้วบันทึกเป็น Thai.lng
แล้วแก้ไขคำต่าง ๆ ตามเมนูให้เป็นภาษาไทย

เมื่อเปิดโปรแกรม Dev-C++ ก็จะได้หน้าต่างที่มีเมนูเป็นภาษาไทย

วันพฤหัสบดีที่ 9 สิงหาคม พ.ศ. 2550

โปรแกรม ResEd Resource editor

ในกรณีที่ต้องการสร้างไฟล์ .rc
Dev-C++ ไม่ได้เตรียมเครื่องมือไว้ให้ ดังนั้นจึงมีผู้แนะนำให้ใช้งานโปรแกรม ResEd Resource editor

ดาวน์โหลดได้ที่ ResEd Resource editor.