Back To Main
:: Rocking The Control ::
เรียนรู้เกี่ยวกับระบบควบคุม
เบื้องต้น โปรแกรมาเบิลลอจิก
คอนโทรล์ ไมโครคอนโทร -
เลอร์ และการประยุกต์ใช้งาน
เบื้องต้น
...........................................
.................................
Control  Overview
.................................
 + PLC Operation
      -
Toshiba T2
      -
SIEMENS S5
      -
SIEMENS S7
      -
Touch Screen
................................
 
Instrument &
               
Measurement
................................
 
Elec / MCS-51
 
Program Interface
...............................
+Basic Application
       -
SIEMENS plc
       -
TOSHIBA plc
       -
AT89C8252/53
...............................
This site is best viwed with IE4 or later version with resolution set at least 800 x 600



This site is host by geocities server

 
ET/COM/MCS->Win32 :In the beginning
.....Win 32 API เป็นชุดคำสั่งมาตรฐานในการเขียนโปรแกรมบน windows หากเรามองกลับไปถึงการโปรแกรมใน dos รูปแบบง่ายๆของโปรแกรม ที่เราเห็นก็จะเป็น
......Header Include
                  ....main(....)
         {
                   ..............Command Statement.......;
         }
ส่วนที่เป็นฟังก์ชั่นหลักที่จะต้องมีคือฟังก์ชั่น main( ) ซึ่งใน window เองก็จะมีฟังก์ชั่น main นี้เหมือนกัน อาจจะต่างกันตรงชื่อและ parameter ที่ใช้ แต่รูปแบบโดยรวมก็ยังคล้ายกัน หากเราคุ้นเคยกับโปรแกรมบน dos โดย "อภิมหาอมตะโปรแกรม" แบบนี้
                       #include <stdio.h>
                           int main(void)
                          {
                                  printf("Hello World\n");
                                  return 0;
                           }
หรือหากเราใช้ VC++ สร้างโปรเจคแบบ win32 console application และใช้ window API function
                      #include <windows.h>
                         i
nt main(void)
                        {
                                 MessageBox(NULL, "Hello world!", "Title", MB_OK);
                                 return 0;
                      }
ซึ่งโปรแกรมก็จะแสดงข้อความเป็น message box... แต่ตอนนี้เราก็ยังอยู่ในรูปแบบของ console application ..ถึงแม้ว่า dos จะ never die (ในความคิดของผม... ฮ่า) แต่เราก็ต้องพัฒนาให้เหมือนชาวบ้าน โดยการเปลี่ยน code ใหม่จากข้างต้นเป็น GUI application
                  #include <windows.h>

                  int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                                            PSTR szCmdLine, int iCmdShow)
                  {
                              MessageBox (NULL, "Hello, world", "Title", 0) ;
                              return 0 ;
                   }
WINAPI : calling convention เป็นรูปแบบหรือวิธีการในการการเรียก/ส่ง argument หรือ parameter ไปยังฟังก์ชั่น
hInstance: Instance handle เป็น handle ที่เก็บ(ชี้ไปยัง)ข้อมูลของ program ซึ่งค่าที่ได้นี้จะเป็น argument ของบาง function call ที่เราเรียกใช้งาน หากเราเปิด application เดียวกันหลายครั้ง PrevInstance จะเป็น handle ที่ชี้(เก็บ)ข้อมูลของ application ก่อนหน้า เพื่อที่จะทำการ share ข้อมูลที่สามารถใช้ร่วมกันได้ใน application เดียวกัน
PSTR szCMdLine : เป็น pointer ชี้ไปยัง string ซึ่งเป็น argument จาก command line
int iCmdShow : เป็นการกำหนดรูปแบบการการแสดง window ซึ่งกำหนดได้หลายลักษณะ อันนี้ก็ค่อยว่ากันต่อไป...


Referrence :
บทความใน series ของ WIN32 API Programming ได้แปล เรียบเรียง และสรุป จาก
Programming Windows 5 th Edittion : Charles Petzold
.............................................................................................................................................................
Copyright ©2002 EPrivacy Homepage.
For more information, and any suggestion please contact
EPrivacy Webmaster 
............................................................................................................................................................