Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Can you make a Windows application in C ?
New Posts  All Forums:Forum Nav:

Can you make a Windows application in C ?

post #1 of 14
Thread Starter 
Hello people!

Is it possible or can you only make console applications ?

I make some simple calculating programs but I'd want them to be in "windows" you know what I mean
post #2 of 14
Assuming you are using Visual Studio, choose "windows forms application" when you start a project, as opposed to "console application". I'm afraid I can't help with other software.
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
post #3 of 14
I do not think that is quite what he is asking for. Yes you can make (assuming your talking about Win32 windows) using C. C is the native language for Win32 API. I know how hard it is for beginners to pick up the API so I will provide some code to get you started, but I will require you to implement your calculator. Here is the "simple" code to create a WINDOW. Remember this is just a window, you need to implement the calculator your self (otherwise you learn nothing)

MAIN.CPP
Code:

//Simple WIN32 API window.

//Windows.h is required to program with the Win32 API.
//It contains all of the "C" functions.
#include <Windows.h>

//Function Prototypes
LRESULT CALLBACK MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);


//Entry point for the application and windows.
//This is the same thing as "int main" in console application
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
MSG msg; //Our message that is to get switched.
HWND hWnd; //Handle to our window.
WNDCLASSEX wcex; //Window creation parameters.

//Zero out the struct so we can use it.
ZeroMemory(&wcex, sizeof(WNDCLASSEX));

wcex.cbSize= sizeof(WNDCLASSEX);
wcex.style= CS_HREDRAW | CS_VREDRAW; //Redraw the window when resized.
wcex.lpfnWndProc= (WNDPROC)MsgProc;
wcex.cbClsExtra= NULL;
wcex.cbWndExtra= NULL;
wcex.hInstance= hInstance;
wcex.hIcon= LoadIcon(NULL, IDI_APPLICATION);
wcex.hIconSm= NULL;
wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH); //This gets overridden by DirectX.
wcex.lpszClassName= "Win32Window";
wcex.lpszMenuName= NULL; //We do not have any menus so this is NULL.

//Register the window parameters.
RegisterClassEx(&wcex);

//Create a new window using our registered stuct.
hWnd = CreateWindow("Win32Window",//Window class name.
    "Win32Window",//Name of window.
WS_OVERLAPPEDWINDOW,//style,//Style of window.
CW_USEDEFAULT,//X-Position of window.
CW_USEDEFAULT,//Y-Position of window.
800,//Width of the window.
600,//Height of the window.
NULL,//Parent menu.
NULL,//Menu.
hInstance,//Handle to instance of application in memory.
NULL);//Window parameters.


//Display our window.
ShowWindow(hWnd, nShowCmd);

UpdateWindow(hWnd);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}//End while

return msg.wParam;

}

//Handles message switching for window.
LRESULT CALLBACK MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}

return DefWindowProc(hWnd, msg, wParam, lParam);
}


I did not comment the code very well because I wrote it quickly. Also note that there are many ways to create a window, and I provided the bare minimum required. I am sorry about the formatting, the code button hates me. If you need help feel free to pm me and I would be glad to help.

~ Strych
Edited by Tig-O-Bitties - 11/13/11 at 4:31pm
    
CPUMotherboardGraphicsRAM
Athlon(tm) II X4 640 Msi 880GM-E41 EVGA 9800 GT G.SKILL Ripjaws 4GB 
Hard DriveOptical DriveOSOS
Seagate Unknown Windows 7 Professional (64-Bit) Ubuntu 11.10 x86 (Debian Linux) 
MonitorKeyboardPowerCase
Dell Logitech G15 Kingwin 730-Watt Rosewell 
Mouse
Trust Predator 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Athlon(tm) II X4 640 Msi 880GM-E41 EVGA 9800 GT G.SKILL Ripjaws 4GB 
Hard DriveOptical DriveOSOS
Seagate Unknown Windows 7 Professional (64-Bit) Ubuntu 11.10 x86 (Debian Linux) 
MonitorKeyboardPowerCase
Dell Logitech G15 Kingwin 730-Watt Rosewell 
Mouse
Trust Predator 
  hide details  
Reply
post #4 of 14
You would gain a lot more if you went out a picked up a book, being spoon fed code doesn't really help you any. Go learn console c or c++ then go pick up a book on Visual C++ or win32 API programming or hell ,even better D3D. All 3 can be used to create GUIs. Then profit...
post #5 of 14
Quote:
Originally Posted by Tig-O-Bitties View Post

I do not think that is quite what he is asking for. Yes you can make (assuming your talking about Win32 windows) using C. C is the native language for Win32 API. I know how hard it is for beginners to pick up the API so I will provide some code to get you started, but I will require you to implement your calculator. Here is the "simple" code to create a WINDOW. Remember this is just a window, you need to implement the calculator your self (otherwise you learn nothing)

The thought did cross my mind. Now I see the OP mentioned C and not C++ thumb.gif

I started coding a GUI using the win32 API. It wasn't fun. I stopped after it took me days to create two forms rolleyes.gif
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
post #6 of 14
Thread Starter 
Quote:
Originally Posted by Madog View Post

You would gain a lot more if you went out a picked up a book, being spoon fed code doesn't really help you any. Go learn console c or c++ then go pick up a book on Visual C++ or win32 API programming or hell ,even better D3D. All 3 can be used to create GUIs. Then profit...

Why would I want a book on C++ ?
I made a little program to calculate something, and I just want it into something better formatted than console. I don't want to program a game or anything.
I would take a book on C though... but I don't know which one I should order (again, just wanna do basic).
Profit I do not make with programming C, but automates. smile.gif C looks rather fun to learn (at small doses).
Quote:
Originally Posted by Tig-O-Bitties View Post


I did not comment the code very well because I wrote it quickly. Also note that there are many ways to create a window, and I provided the bare minimum required. I am sorry about the formatting, the code button hates me. If you need help feel free to pm me and I would be glad to help.
~ Strych

Wow thanks a lot for this template !! I know that I have to play around with it to understand how it works and with having a "template" I can investigate further more. Thanks a lot again.

(edit: but I get an error in the compiling) frown.gif wcex.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH); //This gets overridden by DirectX.
Edited by Slime - 11/15/11 at 7:20pm
post #7 of 14
@SLIME: As far as the coding goes, if you want to get good at programming you should expect to get a book (or two, or 60) and read. Not only read, but program til' your fingers bleed. I know it can be hard learning Win32 which is why I gave you the template, however like Maddog said (or along the lines of) "When someone spoon feeds you, you learn nothing." You really are going to need to learn on your own, however I do not mind helping out; occasionally.

@ARandomOwl: Yea bud, I totally hate the Win32 libraries. Sadly they are what we are stuck with (though there not as bad as MFC thumb.gif).

Finally Slime, I am not sure why you are getting linker errors, I tested the code before I posted it. Sadly, this is one of the things you need to teach yourself if you want to be a programmer in any language; debugging. I can not tell why the code is failing, from the code you posted. With out errors I can do not good (it might be a good idea to post them!). As far as the call to
wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH) goes, that is one of those lines that really should not get an error; at all. I am sorry about the comment, I pulled the template from an old game I made, but I am interested to see the errors you got.

~ Strych
    
CPUMotherboardGraphicsRAM
Athlon(tm) II X4 640 Msi 880GM-E41 EVGA 9800 GT G.SKILL Ripjaws 4GB 
Hard DriveOptical DriveOSOS
Seagate Unknown Windows 7 Professional (64-Bit) Ubuntu 11.10 x86 (Debian Linux) 
MonitorKeyboardPowerCase
Dell Logitech G15 Kingwin 730-Watt Rosewell 
Mouse
Trust Predator 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Athlon(tm) II X4 640 Msi 880GM-E41 EVGA 9800 GT G.SKILL Ripjaws 4GB 
Hard DriveOptical DriveOSOS
Seagate Unknown Windows 7 Professional (64-Bit) Ubuntu 11.10 x86 (Debian Linux) 
MonitorKeyboardPowerCase
Dell Logitech G15 Kingwin 730-Watt Rosewell 
Mouse
Trust Predator 
  hide details  
Reply
post #8 of 14
Thread Starter 
Yes, I am willing to get a book but I do not know what... I wanna make some math programs and stuff.

Here are the errors and I will also post you the code of my calculator.

"
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c||In function 'WinMain':|
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c|25|warning: assignment makes integer from pointer without a cast|
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c|26|warning: assignment makes integer from pointer without a cast|
obj\Debug\main.o||In function `WinMain@16':|
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c|31|undefined reference to `GetStockObject@4'|
||=== Build finished: 1 errors, 2 warnings ===|
"
Code:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
   double Bpm, Result;
   while(1)
  {
   printf("Bpm: ");
   scanf("%lf", &Bpm); // User's input (a number)

   // Calculations in relation with the input number.
   Result = 360000/Bpm;
    printf("\n1/1. = %.lf ms.\n",Result);
   Result = 240000/Bpm;
    printf("1/1 = %.lf ms.\n",Result);
   Result = 160000/Bpm;
    printf("1/1T = %.lf ms.\n\n",Result);

   Result = 180000/Bpm;
    printf("1/2. = %.lf ms.\n",Result);
   Result = 120000/Bpm;
    printf("1/2 = %.lf ms.\n",Result);
   Result = 80000/Bpm;
    printf("1/2T = %.lf ms.\n\n",Result);

   Result = 90000/Bpm;
    printf("1/4. = %.lf ms.\n",Result);
   Result = 60000/Bpm;
    printf("1/4 = %.lf ms.\n",Result);
   Result = 40000/Bpm;
    printf("1/4T = %.lf ms.\n\n",Result);

   Result = 45000/Bpm;
    printf("1/8. = %.lf ms.\n",Result);
   Result = 30000/Bpm;
    printf("1/8 = %.lf ms.\n",Result);
   Result = 20000/Bpm;
    printf("1/8T = %.lf ms.\n\n",Result);

   Result = 22500/Bpm;
    printf("1/16. = %.lf ms.\n",Result);
   Result = 15000/Bpm;
    printf("1/16 = %.lf ms.\n",Result);
   Result = 10000/Bpm;
    printf("1/16T = %.lf ms.\n\n",Result);

   Result = 11250/Bpm;
    printf("1/32. = %.lf ms.\n",Result);
   Result = 7500/Bpm;
    printf("1/32 = %.lf ms.\n",Result);
   Result = 5000/Bpm;
    printf("1/32T = %.lf ms.\n\n",Result);

   Result = 5625/Bpm;
    printf("1/64. = %.lf ms.\n",Result);
   Result = 3750/Bpm;
    printf("1/64 = %.lf ms.\n",Result);
   Result = 2500/Bpm;
    printf("1/64T = %.lf ms.\n\n",Result);

   Result = 2812.5/Bpm;
    printf("1/128. = %.lf ms.\n",Result);
   Result = 1875/Bpm;
    printf("1/128 = %.lf ms.\n",Result);
   Result = 1250/Bpm;
    printf("1/128T = %.lf ms.\n\n",Result);

   Result = 1406.25/Bpm;
    printf("1/256. = %.lf ms.\n",Result);
   Result = 937.5/Bpm;
    printf("1/256 = %.lf ms.\n",Result);
   Result = 625/Bpm;
    printf("1/256T = %.lf ms.\n\n",Result);

   Result = 703.125/Bpm;
    printf("1/512. = %.lf ms.\n",Result);
   Result = 468.75/Bpm;
    printf("1/512 = %.lf ms.\n",Result);
   Result = 312.5/Bpm;
    printf("1/512T = %.lf ms.\n\n\n",Result);
  }
 getch();
 return 0;
}

post #9 of 14
Quote:
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c||In function 'WinMain':|
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c|25|warning: assignment makes integer from pointer without a cast|
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c|26|warning: assignment makes integer from pointer without a cast|
obj\Debug\main.o||In function `WinMain@16':|
C:\Users\Studio\Desktop\V 0.9.1.3\testfenetre\main.c|31|undefined reference to `GetStockObject@4'|
||=== Build finished: 1 errors, 2 warnings ===|

I can not tell what is wrong based on the code you have provided, because it does not contain any Win32 API. I use Visual Studio 2010, so your errors are different from mine, however I think I can take a shot at this. Your warnings are pretty self explanatory. As far as the "Undefined Reference," this one is pretty universal. You are calling a function, but either it is A:) not implemented (which obliviously it is) or B:) the definition can not be found (which is more than likely your problem). You need to link the appropriate library(s) with your project. In Visual Studio they are done automatically (at least if you create a Win32 project), but if I remember right you need to link AT THE BARE MINIMUM : kernel32.lib and, user32.lib.

I think that kernel32.lib is extra, however I am almost certain user32.lib is not. Now that this is out of the way I am going to give you a little programming secret; one of which every programmer needs: I call it Google. This is very important, and you should ALWAYS LOOK HERE FIRST before asking questions. Believe it or not some people hate when people do not Google first!

Finally, if you are dead set on learning C/C++ here are a few books I can recommend.
1:) http://www.cplusplus.com/files/tutorial.pdf <-Not a book, but still worth it; I highly recommend this one.
2:) The C++ Programming Language by Bjarne Stroustrup <- Written by the create of C++, it does not get any better than this. This is considered the C++ bible, and every C++ programmer should have it.
3: Google. <- C++ is considered the industry standard, thus you can find a plethora of information on topics ranging from beginner to advanced.
    
CPUMotherboardGraphicsRAM
Athlon(tm) II X4 640 Msi 880GM-E41 EVGA 9800 GT G.SKILL Ripjaws 4GB 
Hard DriveOptical DriveOSOS
Seagate Unknown Windows 7 Professional (64-Bit) Ubuntu 11.10 x86 (Debian Linux) 
MonitorKeyboardPowerCase
Dell Logitech G15 Kingwin 730-Watt Rosewell 
Mouse
Trust Predator 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Athlon(tm) II X4 640 Msi 880GM-E41 EVGA 9800 GT G.SKILL Ripjaws 4GB 
Hard DriveOptical DriveOSOS
Seagate Unknown Windows 7 Professional (64-Bit) Ubuntu 11.10 x86 (Debian Linux) 
MonitorKeyboardPowerCase
Dell Logitech G15 Kingwin 730-Watt Rosewell 
Mouse
Trust Predator 
  hide details  
Reply
post #10 of 14
Hi Slime

Have you considered making your program in C#?
It's alot easier for making windows programs. You can get the Visual C# 2010 Express free of charge.

That's at least my recommendation.
Have fun coding!

/NwP
T3h R1g[FTW]
(17 items)
 
   
CPUMotherboardGraphicsGraphics
Q9550 E0 @ 3.88 GHz (1.26v) Evga 780i SLi FTW XFX 9800 GT XFX 9800 GT 
RAMHard DriveHard DriveHard Drive
OCZ Blade PC8500 CL5 OCZ Vertex WD Caviar Green WD Caviar Green 
CoolingOSMonitorKeyboard
Noctua NH-U12P Windows 7 Pro x64 Samsung P2350 23" 2ms Razer Lycosa 
PowerCaseMouseMouse Pad
CM Real Power RS-520 CM 690 Roccat Kone QcK SK Limited 
Audio
Sennheiser PC 151 
CPUMotherboardGraphicsRAM
i7 950 @ 4 GHz no HT Asus Sabertooth X58 Evga GTX480 SC Mushkin Redline CL6 
Hard DriveCoolingCoolingOS
Seagate EK Supreme Cupper/Acetal EK FC480 GTX Nickle/Acetal Win 7 Pro x64 
MonitorKeyboardPowerCase
Samsung 23" Razor Lycosa Coolermaster Silent Pro M 850 Silverstone TJ07B-W 
MouseMouse Pad
Roccat Kone QcK Limited 
  hide details  
Reply
T3h R1g[FTW]
(17 items)
 
   
CPUMotherboardGraphicsGraphics
Q9550 E0 @ 3.88 GHz (1.26v) Evga 780i SLi FTW XFX 9800 GT XFX 9800 GT 
RAMHard DriveHard DriveHard Drive
OCZ Blade PC8500 CL5 OCZ Vertex WD Caviar Green WD Caviar Green 
CoolingOSMonitorKeyboard
Noctua NH-U12P Windows 7 Pro x64 Samsung P2350 23" 2ms Razer Lycosa 
PowerCaseMouseMouse Pad
CM Real Power RS-520 CM 690 Roccat Kone QcK SK Limited 
Audio
Sennheiser PC 151 
CPUMotherboardGraphicsRAM
i7 950 @ 4 GHz no HT Asus Sabertooth X58 Evga GTX480 SC Mushkin Redline CL6 
Hard DriveCoolingCoolingOS
Seagate EK Supreme Cupper/Acetal EK FC480 GTX Nickle/Acetal Win 7 Pro x64 
MonitorKeyboardPowerCase
Samsung 23" Razor Lycosa Coolermaster Silent Pro M 850 Silverstone TJ07B-W 
MouseMouse Pad
Roccat Kone QcK Limited 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Can you make a Windows application in C ?